diff --git a/frontend/src/@types/piece/schema.d.ts b/frontend/src/@types/piece/schema.d.ts index e5732631..6d92a642 100644 --- a/frontend/src/@types/piece/schema.d.ts +++ b/frontend/src/@types/piece/schema.d.ts @@ -18,6 +18,7 @@ export interface Schema { type: "object"; properties: Properties; + required?: string[]; $defs: Definitions; } @@ -139,7 +140,7 @@ export interface ObjectDefinition { description: string; type: "object"; properties: Record; - required: string[]; + required?: string[]; } export {}; diff --git a/frontend/src/components/SelectInput/index.tsx b/frontend/src/components/SelectInput/index.tsx index 781efdae..40b776f7 100644 --- a/frontend/src/components/SelectInput/index.tsx +++ b/frontend/src/components/SelectInput/index.tsx @@ -16,32 +16,22 @@ import { } from "react-hook-form"; import { fetchFromObject } from "utils"; -type Props = - | (SelectProps & { - name: Path; - label: string; - options: string[] | Array<{ label: string; value: string }>; +type Props = SelectProps & { + name: Path; + label: string; + options: string[] | Array<{ label: string; value: string }>; - emptyValue: true; - defaultValue?: string; - registerOptions?: - | RegisterOptions> - | undefined; - }) - | (SelectProps & { - name: Path; - label: string; - options: string[] | Array<{ label: string; value: string }>; - - emptyValue?: boolean; - registerOptions?: RegisterOptions; - }); + defaultValue?: string; + registerOptions?: RegisterOptions< + FieldValues, + (string | undefined) & Path + >; +}; function SelectInput({ options, label, name, - emptyValue, ...rest }: Props) { const { @@ -70,11 +60,9 @@ function SelectInput({ field.onChange(e.target.value as any); }} > - {emptyValue && ( - - None - - )} + + None + {options.map((option) => { if (typeof option === "object") { return ( diff --git a/frontend/src/features/workflowEditor/components/Drawers/PieceFormDrawer/PieceForm/PieceFormItem/InputElement/EnumInput.tsx b/frontend/src/features/workflowEditor/components/Drawers/PieceFormDrawer/PieceForm/PieceFormItem/InputElement/EnumInput.tsx index 35aecdb4..62d4f0f0 100644 --- a/frontend/src/features/workflowEditor/components/Drawers/PieceFormDrawer/PieceForm/PieceFormItem/InputElement/EnumInput.tsx +++ b/frontend/src/features/workflowEditor/components/Drawers/PieceFormDrawer/PieceForm/PieceFormItem/InputElement/EnumInput.tsx @@ -24,7 +24,6 @@ export const EnumInput: React.FC = ({ return ( label={definition?.title ?? itemKey.split(".").pop() ?? ""} - emptyValue name={itemKey} options={enumOptions} /> diff --git a/frontend/src/features/workflowEditor/components/Drawers/PieceFormDrawer/PieceForm/PieceFormItem/InputElement/InputElement.tsx b/frontend/src/features/workflowEditor/components/Drawers/PieceFormDrawer/PieceForm/PieceFormItem/InputElement/InputElement.tsx index 1dceded2..94dae20d 100644 --- a/frontend/src/features/workflowEditor/components/Drawers/PieceFormDrawer/PieceForm/PieceFormItem/InputElement/InputElement.tsx +++ b/frontend/src/features/workflowEditor/components/Drawers/PieceFormDrawer/PieceForm/PieceFormItem/InputElement/InputElement.tsx @@ -47,7 +47,7 @@ const InputElement: React.FC = React.memo( checkedFromUpstream, definitions, isItemArray, - isItemObject, + isItemObject = false, }) => { const optionalType = getOptionalType(schema); @@ -64,7 +64,7 @@ const InputElement: React.FC = React.memo( if (checkedFromUpstream === true) { const options = upstreamOptions[upstreamKey]; const checkboxKey = isItemObject - ? itemKey.replace(/(\.value)(?!.*\.value)/, "fromUpstream") + ? itemKey.replace(/(\.value)(?!.*\.value)/, ".upstreamValue") : itemKey.replace(/\.value$/, ""); return ( @@ -72,6 +72,7 @@ const InputElement: React.FC = React.memo( name={checkboxKey as any} label={schema?.title} options={options ?? []} + object={isItemObject} /> ); } else if (isEnumType(schema, definitions)) { @@ -158,8 +159,6 @@ const InputElement: React.FC = React.memo( /> ); } else { - console.log("optionalType", optionalType); - return (
Unknown widget type for {schema.title} diff --git a/frontend/src/features/workflowEditor/components/Drawers/PieceFormDrawer/PieceForm/PieceFormItem/InputElement/SelectUpstreamInput.tsx b/frontend/src/features/workflowEditor/components/Drawers/PieceFormDrawer/PieceForm/PieceFormItem/InputElement/SelectUpstreamInput.tsx index e9c66a70..b56d6dc2 100644 --- a/frontend/src/features/workflowEditor/components/Drawers/PieceFormDrawer/PieceForm/PieceFormItem/InputElement/SelectUpstreamInput.tsx +++ b/frontend/src/features/workflowEditor/components/Drawers/PieceFormDrawer/PieceForm/PieceFormItem/InputElement/SelectUpstreamInput.tsx @@ -9,30 +9,33 @@ import { import { type WorkflowPieceData } from "features/workflowEditor/context/types"; import { type Option } from "features/workflowEditor/utils"; import React, { useCallback } from "react"; -import { Controller, useFormContext } from "react-hook-form"; +import { Controller, type FieldValues, useFormContext } from "react-hook-form"; import { fetchFromObject } from "utils"; type ObjectName = `inputs.${string}.value.${number}.upstreamValue.${string}`; type Name = `inputs.${string}`; -type Props = - | { - label: string; - name: Name; - options: Option[]; - object?: false; - } - | { - label: string; - name: ObjectName; - options: Option[]; - object: true; - }; +type Props = FieldValues & + ( + | { + label: string; + name: Name; + options: Option[]; + object?: false; + } + | { + label: string; + name: ObjectName; + options: Option[]; + object: true; + } + ); const SelectUpstreamInput: React.FC = ({ options, label, name, object, + ...rest }) => { const { setValue, @@ -48,8 +51,8 @@ const SelectUpstreamInput: React.FC = ({ let nameId = ""; if (object) { - nameArgument = name.replace(`.upstreamValue.`, ".upstreamArgument."); - nameId = name.replace(`.upstreamValue.`, ".upstreamId."); + nameArgument = name.replace(`upstreamValue`, ".upstreamArgument"); + nameId = name.replace(`upstreamValue`, ".upstreamId"); } else { nameArgument = `${name}.upstreamArgument`; nameId = `${name}.upstreamId`; @@ -72,19 +75,18 @@ const SelectUpstreamInput: React.FC = ({ return ( - + {label} (