MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / ArrayField

Function ArrayField

packages/react/src/components/json-schema-form.tsx:624–689  ·  view source on GitHub ↗
(props: {
  readonly itemSchema: JsonSchema;
  readonly root: JsonSchema;
  readonly fieldId: string;
  readonly value: unknown;
  readonly onChange: (next: unknown) => void;
  readonly depth: number;
  readonly disabled?: boolean;
})

Source from the content-addressed store, hash-verified

622// ---------------------------------------------------------------------------
623
624function ArrayField(props: {
625 readonly itemSchema: JsonSchema;
626 readonly root: JsonSchema;
627 readonly fieldId: string;
628 readonly value: unknown;
629 readonly onChange: (next: unknown) => void;
630 readonly depth: number;
631 readonly disabled?: boolean;
632}): React.ReactElement {
633 const { itemSchema, root, fieldId, value, onChange, depth, disabled } = props;
634 const items = Array.isArray(value) ? value : [];
635
636 const setItem = (index: number, next: unknown): void => {
637 if (next === REMOVE) {
638 onChange(items.filter((_item: unknown, i: number) => i !== index));
639 return;
640 }
641 onChange(items.map((item: unknown, i: number) => (i === index ? next : item)));
642 };
643
644 return (
645 <div className="space-y-2 rounded-md border border-border/60 p-3">
646 {items.length === 0 ? (
647 <p className="text-[11px] text-muted-foreground">No items.</p>
648 ) : (
649 items.map((item: unknown, index: number) => {
650 const itemId = `${fieldId}-${index}`;
651 return (
652 <div key={index} className="flex items-start gap-2">
653 <div className="min-w-0 flex-1">
654 <FieldControl
655 schema={deepResolve(itemSchema, root)}
656 root={root}
657 fieldId={itemId}
658 value={item}
659 onChange={(next: unknown) => setItem(index, next)}
660 depth={depth + 1}
661 disabled={disabled}
662 />
663 </div>
664 <Button
665 type="button"
666 size="xs"
667 variant="ghost"
668 className="text-muted-foreground"
669 disabled={disabled}
670 onClick={() => setItem(index, REMOVE)}
671 >
672 Remove
673 </Button>
674 </div>
675 );
676 })
677 )}
678 <Button
679 type="button"
680 size="xs"
681 variant="outline"

Callers

nothing calls this directly

Calls 4

setItemFunction · 0.85
defaultForSchemaFunction · 0.85
deepResolveFunction · 0.70
onChangeFunction · 0.50

Tested by

no test coverage detected