From 85b45a7cd03479177e68fcbf231e5f63c1c451e6 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 28 Mar 2024 11:34:31 +0800 Subject: [PATCH] fix: http json value would changed --- .../workflow/nodes/http/components/edit-body/index.tsx | 2 +- .../workflow/nodes/http/hooks/use-key-value-list.ts | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/web/app/components/workflow/nodes/http/components/edit-body/index.tsx b/web/app/components/workflow/nodes/http/components/edit-body/index.tsx index c738d2ccc1..06b9feca13 100644 --- a/web/app/components/workflow/nodes/http/components/edit-body/index.tsx +++ b/web/app/components/workflow/nodes/http/components/edit-body/index.tsx @@ -61,7 +61,7 @@ const EditBody: FC = ({ draft.data = value }) onChange(newBody) - }) + }, type === BodyType.json) const isCurrentKeyValue = type === BodyType.formData || type === BodyType.xWwwFormUrlencoded diff --git a/web/app/components/workflow/nodes/http/hooks/use-key-value-list.ts b/web/app/components/workflow/nodes/http/hooks/use-key-value-list.ts index 764a498124..75b5145cb9 100644 --- a/web/app/components/workflow/nodes/http/hooks/use-key-value-list.ts +++ b/web/app/components/workflow/nodes/http/hooks/use-key-value-list.ts @@ -9,15 +9,17 @@ const strToKeyValueList = (value: string) => { }) } -const useKeyValueList = (value: string, onChange: (value: string) => void) => { +const useKeyValueList = (value: string, onChange: (value: string) => void, noFilter?: boolean) => { const [list, setList] = useState(value ? strToKeyValueList(value) : []) useEffect(() => { + if (noFilter) + return const newValue = list.filter(item => item.key && item.value).map(item => `${item.key}:${item.value}`).join('\n') if (newValue !== value) onChange(newValue) // eslint-disable-next-line react-hooks/exhaustive-deps - }, [list]) + }, [list, noFilter]) const addItem = useCallback(() => { setList(prev => [...prev, { key: '', value: '' }]) }, [])