From 05ce7b9d5e170ae0673d4495aca02c2f73792858 Mon Sep 17 00:00:00 2001 From: Yeuoly <45712896+Yeuoly@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:20:20 +0800 Subject: [PATCH] fix: deep copy customColletion (#2673) --- .../edit-custom-collection-modal/index.tsx | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/web/app/components/tools/edit-custom-collection-modal/index.tsx b/web/app/components/tools/edit-custom-collection-modal/index.tsx index 45e0a014ce..89cde8ca47 100644 --- a/web/app/components/tools/edit-custom-collection-modal/index.tsx +++ b/web/app/components/tools/edit-custom-collection-modal/index.tsx @@ -2,10 +2,9 @@ import type { FC } from 'react' import React, { useEffect, useState } from 'react' import { useTranslation } from 'react-i18next' -import produce from 'immer' import { useDebounce, useGetState } from 'ahooks' -import { clone } from 'lodash-es' import cn from 'classnames' +import produce from 'immer' import { LinkExternal02, Settings01 } from '../../base/icons/src/vender/line/general' import type { Credential, CustomCollectionBackend, CustomParamSchema, Emoji } from '../types' import { AuthHeaderPrefix, AuthType } from '../types' @@ -116,14 +115,16 @@ const EditCustomCollectionModal: FC = ({ const [isShowTestApi, setIsShowTestApi] = useState(false) const handleSave = () => { - const postData = clone(customCollection) - delete postData.tools + // const postData = clone(customCollection) + const postData = produce(customCollection, (draft) => { + delete draft.tools - if (postData.credentials.auth_type === AuthType.none) { - delete postData.credentials.api_key_header - delete postData.credentials.api_key_header_prefix - delete postData.credentials.api_key_value - } + if (draft.credentials.auth_type === AuthType.none) { + delete draft.credentials.api_key_header + delete draft.credentials.api_key_header_prefix + delete draft.credentials.api_key_value + } + }) if (isAdd) { onAdd?.(postData)