fix(frontend) : add default support in oneOf field (#9352)
- Adding support of default value in oneOf field in `node-input-components.tsx` file - Also I have manually tested it and it's working.pull/9285/head^2
parent
8685df587b
commit
56dc5610e4
|
@ -390,6 +390,7 @@ export const NodeGenericInputField: FC<{
|
|||
nodeId={nodeId}
|
||||
propKey={propKey}
|
||||
propSchema={propSchema.anyOf[0]}
|
||||
defaultValue={propSchema.default}
|
||||
currentValue={currentValue}
|
||||
errors={errors}
|
||||
connections={connections}
|
||||
|
@ -556,6 +557,7 @@ export const NodeGenericInputField: FC<{
|
|||
propKey={propKey}
|
||||
propSchema={propSchema}
|
||||
currentValue={currentValue}
|
||||
defaultValue={propSchema.default}
|
||||
errors={errors}
|
||||
connections={connections}
|
||||
handleInputChange={handleInputChange}
|
||||
|
@ -700,6 +702,7 @@ const NodeOneOfDiscriminatorField: FC<{
|
|||
propKey: string;
|
||||
propSchema: any;
|
||||
currentValue?: any;
|
||||
defaultValue?: any;
|
||||
errors: { [key: string]: string | undefined };
|
||||
connections: ConnectionData;
|
||||
handleInputChange: (key: string, value: any) => void;
|
||||
|
@ -711,6 +714,7 @@ const NodeOneOfDiscriminatorField: FC<{
|
|||
propKey,
|
||||
propSchema,
|
||||
currentValue,
|
||||
defaultValue,
|
||||
errors,
|
||||
connections,
|
||||
handleInputChange,
|
||||
|
@ -718,7 +722,6 @@ const NodeOneOfDiscriminatorField: FC<{
|
|||
className,
|
||||
}) => {
|
||||
const discriminator = propSchema.discriminator;
|
||||
|
||||
const discriminatorProperty = discriminator.propertyName;
|
||||
|
||||
const variantOptions = useMemo(() => {
|
||||
|
@ -737,14 +740,31 @@ const NodeOneOfDiscriminatorField: FC<{
|
|||
.filter((v: any) => v.value != null);
|
||||
}, [discriminatorProperty, propSchema.oneOf]);
|
||||
|
||||
const currentVariant = variantOptions.find(
|
||||
(opt: any) => currentValue?.[discriminatorProperty] === opt.value,
|
||||
);
|
||||
const initialVariant = defaultValue
|
||||
? variantOptions.find(
|
||||
(opt: any) => defaultValue[discriminatorProperty] === opt.value,
|
||||
)
|
||||
: currentValue
|
||||
? variantOptions.find(
|
||||
(opt: any) => currentValue[discriminatorProperty] === opt.value,
|
||||
)
|
||||
: null;
|
||||
|
||||
const [chosenType, setChosenType] = useState<string>(
|
||||
currentVariant?.value || "",
|
||||
initialVariant?.value || "",
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (initialVariant && !currentValue) {
|
||||
handleInputChange(
|
||||
propKey,
|
||||
defaultValue || {
|
||||
[discriminatorProperty]: initialVariant.value,
|
||||
},
|
||||
);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleVariantChange = (newType: string) => {
|
||||
setChosenType(newType);
|
||||
const chosenVariant = variantOptions.find(
|
||||
|
@ -821,7 +841,9 @@ const NodeOneOfDiscriminatorField: FC<{
|
|||
propKey={childKey}
|
||||
propSchema={childSchema as BlockIOSubSchema}
|
||||
currentValue={
|
||||
currentValue ? currentValue[someKey] : undefined
|
||||
currentValue
|
||||
? currentValue[someKey]
|
||||
: defaultValue?.[someKey]
|
||||
}
|
||||
errors={errors}
|
||||
connections={connections}
|
||||
|
|
Loading…
Reference in New Issue