🐛 fix(parameterComponent): handleOnNewValue now accepts Object[] as a valid parameter type to support dict and NestedDict types

🐛 fix(parameterComponent): remove unused state variables obj and dictArr
 feat(parameterComponent): add support for dict and NestedDict types in ParameterComponent
🐛 fix(dictComponent): call onChange when value prop changes to ensure proper synchronization
🐛 fix(keypairListComponent): call onChange when value prop changes to ensure proper synchronization
🐛 fix(dialog.tsx): add missing classes to prevent panning, dragging, undoing, and copying in DialogPortal and DialogOverlay components
This commit is contained in:
Cristhian Zanforlin Lousa 2023-09-18 20:47:04 -03:00
commit 71dd9821ea
4 changed files with 32 additions and 23 deletions

View file

@ -80,7 +80,9 @@ export default function ParameterComponent({
const { data: myData } = useContext(typesContext);
const handleOnNewValue = (newValue: string | string[] | boolean): void => {
const handleOnNewValue = (
newValue: string | string[] | boolean | Object[]
): void => {
let newData = cloneDeep(data);
newData.node!.template[name].value = newValue;
setData(newData);
@ -99,22 +101,7 @@ export default function ParameterComponent({
renderTooltips();
};
const [obj, setObj] = useState({
arr: ["test", 123456, false, null],
boolean: false,
number: 123456,
try: {
k1: 123,
k2: "123",
k3: false,
},
string: "string",
});
const [errorDuplicateKey, setErrorDuplicateKey] = useState(false);
const [dictArr, setDictArr] = useState([
{ yourKey: "yourValue" },
] as Object[]);
useEffect(() => {
if (name === "openai_api_base") console.log(info);
@ -237,6 +224,8 @@ export default function ParameterComponent({
type === "code" ||
type === "prompt" ||
type === "file" ||
type === "dict" ||
type === "NestedDict" ||
type === "int") &&
!optionalHandle ? (
<></>
@ -378,10 +367,22 @@ export default function ParameterComponent({
<DictComponent
disabled={disabled}
editNode={false}
value={data.node!.template[name].value ?? obj}
value={
data.node!.template[name].value ?? {
arr: ["test", 123456, false, null],
boolean: false,
number: 123456,
try: {
k1: 123,
k2: "123",
k3: false,
},
string: "string",
}
}
onChange={(newValue) => {
setObj(newValue);
data.node!.template[name].value = newValue;
handleOnNewValue(newValue);
}}
/>
</div>
@ -393,14 +394,14 @@ export default function ParameterComponent({
value={
data.node!.template[name].value?.length === 0 ||
!data.node!.template[name].value
? dictArr
? [{ yourKey: "yourValue" }]
: convertObjToArray(data.node!.template[name].value)
}
duplicateKey={errorDuplicateKey}
onChange={(newValue) => {
setErrorDuplicateKey(hasDuplicateKeys(newValue));
setDictArr(newValue);
data.node!.template[name].value = newValue;
setErrorDuplicateKey(hasDuplicateKeys(newValue));
handleOnNewValue(newValue);
}}
/>
</div>

View file

@ -17,6 +17,10 @@ export default function DictComponent({
}
}, [disabled]);
useEffect(() => {
if (value) onChange(value);
}, [value]);
return (
<div
className={classNames(

View file

@ -34,6 +34,10 @@ export default function KeypairListComponent({
onChange(newInputList);
};
useEffect(() => {
if (value) onChange(value);
}, [value]);
return (
<div
className={classNames(

View file

@ -13,7 +13,7 @@ const DialogPortal = ({
...props
}: DialogPrimitive.DialogPortalProps) => (
<DialogPrimitive.Portal className={cn(className)} {...props}>
<div className="fixed inset-0 z-50 flex items-start justify-center sm:items-center">
<div className="nopan nodrag noundo nocopy fixed inset-0 z-50 flex items-start justify-center sm:items-center">
{children}
</div>
</DialogPrimitive.Portal>
@ -27,7 +27,7 @@ const DialogOverlay = React.forwardRef<
<DialogPrimitive.Overlay
ref={ref}
className={cn(
"noundo nocopy fixed inset-0 bottom-0 left-0 right-0 top-0 z-50 overflow-auto bg-blur-shared backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
"nopan nodrag noundo nocopy fixed inset-0 bottom-0 left-0 right-0 top-0 z-50 overflow-auto bg-blur-shared backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className
)}
{...props}