From b3cac2edb1880a8760b7f3c4f690dbfaf37258a8 Mon Sep 17 00:00:00 2001 From: wangsijie Date: Tue, 24 Sep 2024 15:40:40 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"fix(console):=20fix=20empty=20string?= =?UTF-8?q?=20update=20of=20connector=20config=20for=E2=80=A6=20(#6627)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revert "fix(console): fix empty string update of connector config form (#6626)" This reverts commit f8fd52b2f8ddc5963f0698bdbee69187bc1bc90f. --- .../src/hooks/use-connector-form-config-parser.tsx | 8 ++++++-- .../src/pages/ConnectorDetails/ConnectorContent/index.tsx | 6 +++++- packages/console/src/utils/connector-form.ts | 8 +++++++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/console/src/hooks/use-connector-form-config-parser.tsx b/packages/console/src/hooks/use-connector-form-config-parser.tsx index 38ef40dcc..d6e20f501 100644 --- a/packages/console/src/hooks/use-connector-form-config-parser.tsx +++ b/packages/console/src/hooks/use-connector-form-config-parser.tsx @@ -31,9 +31,13 @@ const useJsonStringConfigParser = () => { export const useConnectorFormConfigParser = () => { const parseJsonConfig = useJsonStringConfigParser(); - return (data: ConnectorFormType, formItems: ConnectorResponse['formItems']) => { + return ( + data: ConnectorFormType, + formItems: ConnectorResponse['formItems'], + skipFalsyValuesRemoval = false + ) => { return formItems - ? parseFormConfig(data.formConfig, formItems) + ? parseFormConfig(data.formConfig, formItems, skipFalsyValuesRemoval) : parseJsonConfig(data.jsonConfig); }; }; diff --git a/packages/console/src/pages/ConnectorDetails/ConnectorContent/index.tsx b/packages/console/src/pages/ConnectorDetails/ConnectorContent/index.tsx index 48541240f..da1c0dd9d 100644 --- a/packages/console/src/pages/ConnectorDetails/ConnectorContent/index.tsx +++ b/packages/console/src/pages/ConnectorDetails/ConnectorContent/index.tsx @@ -68,7 +68,11 @@ function ConnectorContent({ isDeleted, connectorData, onConnectorUpdated }: Prop const { syncProfile, name, logo, logoDark, target, rawConfig } = data; // Apply the raw config first to avoid losing data updated from other forms that are not // included in the form items. - const config = removeFalsyValues({ ...rawConfig, ...configParser(data, formItems) }); + // Explicitly SKIP falsy values removal logic (the last argument of `configParser()` method) for social connectors. + const config = removeFalsyValues({ + ...rawConfig, + ...configParser(data, formItems, isSocialConnector), + }); const payload = isSocialConnector ? { diff --git a/packages/console/src/utils/connector-form.ts b/packages/console/src/utils/connector-form.ts index 762704cef..f0a7f423c 100644 --- a/packages/console/src/utils/connector-form.ts +++ b/packages/console/src/utils/connector-form.ts @@ -22,11 +22,17 @@ const initFormData = (formItems: ConnectorConfigFormItem[], config?: Record, - formItems: ConnectorConfigFormItem[] + formItems: ConnectorConfigFormItem[], + skipFalsyValuesRemoval = false ) => { return Object.fromEntries( Object.entries(config) .map(([key, value]) => { + // Filter out empty input + if (!skipFalsyValuesRemoval && value === '') { + return null; + } + const formItem = formItems.find((item) => item.key === key); if (!formItem) {