Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix integration item auto-gen-form issue #1647

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const OneOfConditionField = ({
size,
isHidden,
isRequired,
lowCodeComponentEraSchema,
}: {
tree: InstillFormConditionItem;
selectedConditionMap: Nullable<SelectedConditionMap>;
Expand All @@ -52,6 +53,7 @@ export const OneOfConditionField = ({

// In the above example, the formConditionLayerPath will be foo.bar.baz
formConditionLayerPath: string;
lowCodeComponentEraSchema?: boolean;
} & Omit<AutoFormFieldBaseProps, "path">) => {
const conditionOptions = React.useMemo(() => {
return Object.entries(conditionComponentsMap).map(([k, v]) => ({
Expand Down Expand Up @@ -116,6 +118,8 @@ export const OneOfConditionField = ({
// getValues,
// ]);

console.log(tree);

return (
<div key={constFullPath} className="flex flex-col gap-y-5">
{isHidden ? null : (
Expand Down Expand Up @@ -200,6 +204,17 @@ export const OneOfConditionField = ({
</Form.Control>
<Select.Content>
{conditionOptions.map((option) => {
let title = option.title ?? option.key;
const conditionItemSchema = tree.conditions[option.key];

if (
lowCodeComponentEraSchema &&
conditionItemSchema &&
conditionItemSchema.title
) {
title = conditionItemSchema.title;
}

return (
<Select.Item
key={option.key}
Expand All @@ -210,7 +225,7 @@ export const OneOfConditionField = ({
? "!product-body-text-4-regular"
: "product-body-text-4-regular",
)}
label={option.title ?? option.key}
label={title}
/>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ export type PickRegularFieldsFromInstillFormTreeOptions = {
objectArrayIndex?: number;
parentPath?: string;
parentIsFormCondition?: boolean;

/** In the low code era, we no longer use the const's title to determine
* the conditional field select item's title. Now we are using the oneOf
* itme root level's title to determine the conditional field select item's title
* */
lowCodeComponentEraSchema?: boolean;
};

export function pickRegularFieldsFromInstillFormTree(
Expand Down Expand Up @@ -75,6 +81,7 @@ export function pickRegularFieldsFromInstillFormTree(
const objectArrayIndex = options?.objectArrayIndex ?? undefined;
const parentPath = options?.parentPath ?? undefined;
const parentIsFormCondition = options?.parentIsFormCondition ?? false;
const lowCodeComponentEraSchema = options?.lowCodeComponentEraSchema ?? false;

let title: Nullable<string> = null;

Expand Down Expand Up @@ -308,6 +315,7 @@ export function pickRegularFieldsFromInstillFormTree(
}
size={size}
isHidden={tree.isHidden}
lowCodeComponentEraSchema={lowCodeComponentEraSchema}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
| "supportInstillCredit"
| "updateSupportInstillCredit"
| "updateIsUsingInstillCredit"
| "lowCodeComponentEraSchema"
>;

export function useInstillForm(
Expand All @@ -57,16 +58,16 @@
const collapsibleDefaultOpen = options?.collapsibleDefaultOpen ?? false;
const supportInstillCredit = options?.supportInstillCredit ?? false;
const updateSupportInstillCredit = options?.updateSupportInstillCredit;
const forceCloseCollapsibleFormGroups =

Check warning on line 61 in packages/toolkit/src/lib/use-instill-form/useInstillForm.tsx

View workflow job for this annotation

GitHub Actions / unit-test

The 'forceCloseCollapsibleFormGroups' logical expression could make the dependencies of useMemo Hook (at line 186) change on every render. Move it inside the useMemo callback. Alternatively, wrap the initialization of 'forceCloseCollapsibleFormGroups' in its own useMemo() Hook
options?.forceCloseCollapsibleFormGroups ?? [];
const updateForceCloseCollapsibleFormGroups =
options?.updateForceCloseCollapsibleFormGroups;
const forceOpenCollapsibleFormGroups =

Check warning on line 65 in packages/toolkit/src/lib/use-instill-form/useInstillForm.tsx

View workflow job for this annotation

GitHub Actions / unit-test

The 'forceOpenCollapsibleFormGroups' logical expression could make the dependencies of useMemo Hook (at line 186) change on every render. Move it inside the useMemo callback. Alternatively, wrap the initialization of 'forceOpenCollapsibleFormGroups' in its own useMemo() Hook
options?.forceOpenCollapsibleFormGroups ?? [];
const updateForceOpenCollapsibleFormGroups =
options?.updateForceOpenCollapsibleFormGroups;
const updateIsUsingInstillCredit = options?.updateIsUsingInstillCredit;

const lowCodeComponentEraSchema = options?.lowCodeComponentEraSchema ?? false;
const [formTree, setFormTree] = React.useState<InstillFormTree | null>(null);
const [ValidatorSchema, setValidatorSchema] = React.useState<z.ZodTypeAny>(
z.any(),
Expand Down Expand Up @@ -177,6 +178,7 @@
forceOpenCollapsibleFormGroups,
updateForceOpenCollapsibleFormGroups,
updateIsUsingInstillCredit,
lowCodeComponentEraSchema,
},
);

Expand All @@ -201,6 +203,7 @@
forceOpenCollapsibleFormGroups,
updateForceOpenCollapsibleFormGroups,
updateIsUsingInstillCredit,
lowCodeComponentEraSchema,
]);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ export const ConnectionForm = ({
const { fields, form, ValidatorSchema } = useInstillForm(
schema || null,
values || null,
{
lowCodeComponentEraSchema: true,
},
);

const [connectionId, setConnectionId] = React.useState("");
Expand Down
Loading