Commit dae22ca490e91828411c27fe54e3ba3304d45a78
1 parent
da7ebd3c
fix(web): add allowed-values + max-length inputs to custom field editor
When type is 'enum', show a comma-separated input for allowed values. When type is 'string', show a max-length input. Previously these type-specific options were missing from the UI.
Showing
1 changed file
with
37 additions
and
1 deletions
web/src/pages/MetadataAdminPage.tsx
| ... | ... | @@ -145,6 +145,8 @@ export function MetadataAdminPage() { |
| 145 | 145 | const [cfPii, setCfPii] = useState(false) |
| 146 | 146 | const [cfLabelEn, setCfLabelEn] = useState('') |
| 147 | 147 | const [cfLabelZh, setCfLabelZh] = useState('') |
| 148 | + const [cfAllowedValues, setCfAllowedValues] = useState('') | |
| 149 | + const [cfMaxLength, setCfMaxLength] = useState('') | |
| 148 | 150 | const [cfSaving, setCfSaving] = useState(false) |
| 149 | 151 | |
| 150 | 152 | // ── Loaders ─────────────────────────────────────────────────────── |
| ... | ... | @@ -192,6 +194,8 @@ export function MetadataAdminPage() { |
| 192 | 194 | setCfTargetEntity('') |
| 193 | 195 | setCfFieldKey('') |
| 194 | 196 | setCfTypeKind('string') |
| 197 | + setCfAllowedValues('') | |
| 198 | + setCfMaxLength('') | |
| 195 | 199 | setCfRequired(false) |
| 196 | 200 | setCfPii(false) |
| 197 | 201 | setCfLabelEn('') |
| ... | ... | @@ -222,7 +226,11 @@ export function MetadataAdminPage() { |
| 222 | 226 | const body: Omit<CustomFieldDef, 'source'> = { |
| 223 | 227 | key: cfFieldKey, |
| 224 | 228 | targetEntity: cfTargetEntity, |
| 225 | - type: { kind: cfTypeKind }, | |
| 229 | + type: { | |
| 230 | + kind: cfTypeKind, | |
| 231 | + ...(cfTypeKind === 'enum' && cfAllowedValues ? { allowedValues: cfAllowedValues.split(',').map((v) => v.trim()).filter(Boolean) } : {}), | |
| 232 | + ...(cfTypeKind === 'string' && cfMaxLength ? { maxLength: Number(cfMaxLength) } : {}), | |
| 233 | + }, | |
| 226 | 234 | required: cfRequired, |
| 227 | 235 | pii: cfPii, |
| 228 | 236 | labelTranslations: { |
| ... | ... | @@ -613,6 +621,34 @@ export function MetadataAdminPage() { |
| 613 | 621 | ))} |
| 614 | 622 | </select> |
| 615 | 623 | </div> |
| 624 | + {cfTypeKind === 'enum' && ( | |
| 625 | + <div> | |
| 626 | + <label className="block text-xs font-medium text-slate-700"> | |
| 627 | + Allowed values (comma-separated) | |
| 628 | + </label> | |
| 629 | + <input | |
| 630 | + type="text" | |
| 631 | + value={cfAllowedValues} | |
| 632 | + onChange={(e) => setCfAllowedValues(e.target.value)} | |
| 633 | + placeholder="LOW, NORMAL, HIGH, URGENT" | |
| 634 | + className="mt-1 w-full rounded-md border border-slate-300 px-2 py-1.5 text-sm" | |
| 635 | + /> | |
| 636 | + </div> | |
| 637 | + )} | |
| 638 | + {cfTypeKind === 'string' && ( | |
| 639 | + <div> | |
| 640 | + <label className="block text-xs font-medium text-slate-700"> | |
| 641 | + Max length | |
| 642 | + </label> | |
| 643 | + <input | |
| 644 | + type="number" | |
| 645 | + value={cfMaxLength} | |
| 646 | + onChange={(e) => setCfMaxLength(e.target.value)} | |
| 647 | + placeholder="255" | |
| 648 | + className="mt-1 w-full rounded-md border border-slate-300 px-2 py-1.5 text-sm" | |
| 649 | + /> | |
| 650 | + </div> | |
| 651 | + )} | |
| 616 | 652 | <div className="flex items-end gap-4 pb-1"> |
| 617 | 653 | <label className="flex items-center gap-1.5 text-sm text-slate-700"> |
| 618 | 654 | <input | ... | ... |