diff --git a/web/src/components/llm-setting-items/index.tsx b/web/src/components/llm-setting-items/index.tsx
index 8b88b8703..d5f349e6a 100644
--- a/web/src/components/llm-setting-items/index.tsx
+++ b/web/src/components/llm-setting-items/index.tsx
@@ -51,7 +51,7 @@ const LlmSettingItems = ({ prefix, formItemLayout = {} }: IProps) => {
{
- const updateNodeInternals = useUpdateNodeInternals();
- const form = Form.useFormInstance();
- const buildCategorizeToOptions = useBuildFormSelectOptions(
- Operator.Categorize,
- nodeId,
- );
- const { handleSelectChange } = useHandleFormSelectChange(nodeId);
const { t } = useTranslate('flow');
+ const options = useBuildComponentIdSelectOptions(nodeId);
+ const {
+ dataSource,
+ handleAdd,
+ handleRemove,
+ handleSave,
+ handleComponentIdChange,
+ } = useHandleOperateParameters(nodeId!);
+
+ const columns: TableProps['columns'] = [
+ {
+ title: t('key'),
+ dataIndex: 'key',
+ key: 'key',
+ onCell: (record: IGenerateParameter) => ({
+ record,
+ editable: true,
+ dataIndex: 'key',
+ title: 'key',
+ handleSave,
+ }),
+ },
+ {
+ title: t('componentId'),
+ dataIndex: 'component_id',
+ key: 'component_id',
+ align: 'center',
+ render(text, record) {
+ return (
+
+ );
+ },
+ },
+ {
+ title: t('operation'),
+ dataIndex: 'operation',
+ width: 20,
+ key: 'operation',
+ align: 'center',
+ render(_, record) {
+ return ;
+ },
+ },
+ ];
+
return (
- <>
-
- {(fields, { add, remove }) => {
- const handleAdd = () => {
- const idx = fields.length;
- add({ name: `parameter ${idx + 1}` });
- if (nodeId) updateNodeInternals(nodeId);
- };
- return (
-
- {fields.map((field) => (
- {
- remove(field.name);
- }}
- />
- }
- >
-
-
-
-
-
-
- ))}
-
-
-
- );
- }}
-
-
-
- {() => (
-
- {JSON.stringify(form.getFieldsValue(), null, 2)}
-
- )}
-
- >
+
+
+
+
+ styles.editableRow}
+ />
+
);
};
diff --git a/web/src/pages/flow/generate-form/hooks.ts b/web/src/pages/flow/generate-form/hooks.ts
new file mode 100644
index 000000000..28334ad68
--- /dev/null
+++ b/web/src/pages/flow/generate-form/hooks.ts
@@ -0,0 +1,102 @@
+import get from 'lodash/get';
+import { useCallback, useMemo } from 'react';
+import { v4 as uuid } from 'uuid';
+import { Operator } from '../constant';
+import { IGenerateParameter } from '../interface';
+import useGraphStore from '../store';
+
+// exclude nodes with branches
+const ExcludedNodes = [Operator.Categorize, Operator.Relevant];
+
+export const useBuildComponentIdSelectOptions = (nodeId?: string) => {
+ const nodes = useGraphStore((state) => state.nodes);
+
+ const options = useMemo(() => {
+ return nodes
+ .filter(
+ (x) =>
+ x.id !== nodeId && !ExcludedNodes.some((y) => y === x.data.label),
+ )
+ .map((x) => ({ label: x.data.name, value: x.id }));
+ }, [nodes, nodeId]);
+
+ return options;
+};
+
+export const useHandleOperateParameters = (nodeId: string) => {
+ const { getNode, updateNodeForm } = useGraphStore((state) => state);
+ const node = getNode(nodeId);
+ const dataSource: IGenerateParameter[] = useMemo(
+ () => get(node, 'data.form.parameters', []),
+ [node],
+ );
+
+ // const [x, setDataSource] = useState([]);
+
+ const handleComponentIdChange = useCallback(
+ (row: IGenerateParameter) => (value: string) => {
+ const newData = [...dataSource];
+ const index = newData.findIndex((item) => row.id === item.id);
+ const item = newData[index];
+ newData.splice(index, 1, {
+ ...item,
+ component_id: value,
+ });
+
+ updateNodeForm(nodeId, { parameters: newData });
+ // setDataSource(newData);
+ },
+ [updateNodeForm, nodeId, dataSource],
+ );
+
+ const handleRemove = useCallback(
+ (id?: string) => () => {
+ const newData = dataSource.filter((item) => item.id !== id);
+ updateNodeForm(nodeId, { parameters: newData });
+ // setDataSource(newData);
+ },
+ [updateNodeForm, nodeId, dataSource],
+ );
+
+ const handleAdd = useCallback(() => {
+ // setDataSource((state) => [
+ // ...state,
+ // {
+ // id: uuid(),
+ // key: '',
+ // component_id: undefined,
+ // },
+ // ]);
+ updateNodeForm(nodeId, {
+ parameters: [
+ ...dataSource,
+ {
+ id: uuid(),
+ key: '',
+ component_id: undefined,
+ },
+ ],
+ });
+ }, [dataSource, nodeId, updateNodeForm]);
+
+ const handleSave = (row: IGenerateParameter) => {
+ const newData = [...dataSource];
+ const index = newData.findIndex((item) => row.id === item.id);
+ const item = newData[index];
+ newData.splice(index, 1, {
+ ...item,
+ ...row,
+ });
+
+ updateNodeForm(nodeId, { parameters: newData });
+ // setDataSource(newData);
+ };
+
+ return {
+ handleAdd,
+ handleRemove,
+ handleComponentIdChange,
+ handleSave,
+ dataSource,
+ };
+};
diff --git a/web/src/pages/flow/generate-form/index.less b/web/src/pages/flow/generate-form/index.less
index 7af64e7ac..8de5a4f53 100644
--- a/web/src/pages/flow/generate-form/index.less
+++ b/web/src/pages/flow/generate-form/index.less
@@ -9,7 +9,7 @@
:global(.editable-cell-value-wrap) {
padding: 5px 12px;
cursor: pointer;
- height: 22px !important;
+ height: 30px !important;
}
&:hover {
:global(.editable-cell-value-wrap) {
diff --git a/web/src/pages/flow/generate-form/index.tsx b/web/src/pages/flow/generate-form/index.tsx
index 01a8346e3..159f1ad8a 100644
--- a/web/src/pages/flow/generate-form/index.tsx
+++ b/web/src/pages/flow/generate-form/index.tsx
@@ -3,9 +3,9 @@ import { useTranslate } from '@/hooks/commonHooks';
import { Form, Input, Switch } from 'antd';
import { useSetLlmSetting } from '../hooks';
import { IOperatorForm } from '../interface';
-import DynamicParameters from './next-dynamic-parameters';
+import DynamicParameters from './dynamic-parameters';
-const GenerateForm = ({ onValuesChange, form }: IOperatorForm) => {
+const GenerateForm = ({ onValuesChange, form, node }: IOperatorForm) => {
const { t } = useTranslate('flow');
useSetLlmSetting(form);
@@ -29,7 +29,7 @@ const GenerateForm = ({ onValuesChange, form }: IOperatorForm) => {
{
>
-
+
);
};
diff --git a/web/src/pages/flow/generate-form/next-dynamic-parameters.tsx b/web/src/pages/flow/generate-form/next-dynamic-parameters.tsx
deleted file mode 100644
index 8c848bc3b..000000000
--- a/web/src/pages/flow/generate-form/next-dynamic-parameters.tsx
+++ /dev/null
@@ -1,135 +0,0 @@
-import { EditableCell, EditableRow } from '@/components/editable-cell';
-import { useTranslate } from '@/hooks/commonHooks';
-import { DeleteOutlined } from '@ant-design/icons';
-import { Button, Flex, Select, Table, TableProps } from 'antd';
-import { useEffect, useState } from 'react';
-import { v4 as uuid } from 'uuid';
-import { IGenerateParameter } from '../interface';
-
-import { Operator } from '../constant';
-import { useBuildFormSelectOptions } from '../form-hooks';
-import styles from './index.less';
-
-interface IProps {
- nodeId?: string;
-}
-
-const components = {
- body: {
- row: EditableRow,
- cell: EditableCell,
- },
-};
-
-const DynamicParameters = ({ nodeId }: IProps) => {
- const [dataSource, setDataSource] = useState([]);
- const { t } = useTranslate('flow');
-
- const buildCategorizeToOptions = useBuildFormSelectOptions(
- Operator.Generate,
- nodeId,
- );
-
- const handleRemove = (id?: string) => () => {
- const newData = dataSource.filter((item) => item.id !== id);
- setDataSource(newData);
- };
-
- const handleAdd = () => {
- setDataSource((state) => [
- ...state,
- {
- id: uuid(),
- key: '',
- component_id: undefined,
- },
- ]);
- };
-
- const handleSave = (row: IGenerateParameter) => {
- const newData = [...dataSource];
- const index = newData.findIndex((item) => row.id === item.id);
- const item = newData[index];
- newData.splice(index, 1, {
- ...item,
- ...row,
- });
- setDataSource(newData);
- };
-
- useEffect(() => {}, [dataSource]);
-
- const handleOptionalChange = (row: IGenerateParameter) => (value: string) => {
- const newData = [...dataSource];
- const index = newData.findIndex((item) => row.id === item.id);
- const item = newData[index];
- newData.splice(index, 1, {
- ...item,
- component_id: value,
- });
- setDataSource(newData);
- };
-
- const columns: TableProps['columns'] = [
- {
- title: t('key'),
- dataIndex: 'key',
- key: 'key',
- onCell: (record: IGenerateParameter) => ({
- record,
- editable: true,
- dataIndex: 'key',
- title: 'key',
- handleSave,
- }),
- },
- {
- title: t('componentId'),
- dataIndex: 'component_id',
- key: 'component_id',
- align: 'center',
- render(text, record) {
- return (
-
- );
- },
- },
- {
- title: t('operation'),
- dataIndex: 'operation',
- width: 20,
- key: 'operation',
- align: 'center',
- render(_, record) {
- return ;
- },
- },
- ];
-
- return (
-
-
-
-
- styles.editableRow}
- />
-
- );
-};
-
-export default DynamicParameters;
diff --git a/web/src/pages/flow/store.ts b/web/src/pages/flow/store.ts
index fa208a588..f8f51b753 100644
--- a/web/src/pages/flow/store.ts
+++ b/web/src/pages/flow/store.ts
@@ -189,7 +189,17 @@ const useGraphStore = create()(
set({
nodes: get().nodes.map((node) => {
if (node.id === nodeId) {
- node.data = { ...node.data, form: values };
+ // node.data = {
+ // ...node.data,
+ // form: { ...node.data.form, ...values },
+ // };
+ return {
+ ...node,
+ data: {
+ ...node.data,
+ form: { ...node.data.form, ...values },
+ },
+ } as any;
}
return node;
diff --git a/web/src/utils/form.ts b/web/src/utils/form.ts
index 1f15c5ea1..7b33fd1f0 100644
--- a/web/src/utils/form.ts
+++ b/web/src/utils/form.ts
@@ -20,7 +20,7 @@ export const excludeUnEnabledVariables = (
export const removeUselessFieldsFromValues = (values: any, prefix?: string) => {
const nextValues: any = omit(values, [
...Object.keys(variableEnabledFieldMap),
- 'parameters',
+ 'parameter',
...excludeUnEnabledVariables(values, prefix),
]);