diff --git a/python/src/aiconfig/editor/client/src/components/SettingsPropertyRenderer.tsx b/python/src/aiconfig/editor/client/src/components/SettingsPropertyRenderer.tsx index 95a06482c..08f99509c 100644 --- a/python/src/aiconfig/editor/client/src/components/SettingsPropertyRenderer.tsx +++ b/python/src/aiconfig/editor/client/src/components/SettingsPropertyRenderer.tsx @@ -20,6 +20,7 @@ import UnionPropertyControl, { UnionProperty, } from "./property_controls/UnionPropertyControl"; import { JSONObject, JSONValue } from "aiconfig"; +import JSONEditor from "./JSONEditor"; export type StateSetFromPrevFn = (prev: JSONValue) => void; export type SetStateFn = (val: StateSetFromPrevFn | JSONValue) => void; @@ -87,10 +88,28 @@ export default function SettingsPropertyRenderer({ [propertyName, propertyValue, setValue] ); + const itemValues = useRef( + Array.isArray(propertyValue) ? new Map(propertyValue.map(val => [uniqueId(), val])) : + new Map()); + // Used in the case the property is an array - // TODO: Should initialize with values from settings if available - const [itemControls, setItemControls] = useState([]); - const itemValues = useRef(new Map()); + const [itemControls, setItemControls] = useState(() => Array.from(itemValues.current, ([key, value]) => ( + + { + itemValues.current.set(key, newItem); + setAndPropagateValue(Array.from(itemValues.current.values())); + }} + /> + removeItemFromList(key)}> + + + + ))); + const removeItemFromList = useCallback( async (key: string) => { @@ -367,8 +386,22 @@ export default function SettingsPropertyRenderer({ {subpropertyControls} ); + } else { + propertyControl = ( + + +
+ +
+
+ ); } - break; } case "select": {