From 5bb9375055c241b0681517b3dc1f4353dd324e2f Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Thu, 24 Oct 2024 12:27:48 +0800 Subject: [PATCH] chore: add google connector default prompt (#6734) * chore: add google connector default prompt * fix: fix console integration tests --- .changeset/light-clocks-retire.md | 5 +++++ .changeset/tricky-walls-add.md | 5 +++++ packages/connectors/connector-google/src/constant.ts | 1 + packages/console/src/utils/connector-form.ts | 12 +++++++++++- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 .changeset/light-clocks-retire.md create mode 100644 .changeset/tricky-walls-add.md diff --git a/.changeset/light-clocks-retire.md b/.changeset/light-clocks-retire.md new file mode 100644 index 00000000000..6d7147a609c --- /dev/null +++ b/.changeset/light-clocks-retire.md @@ -0,0 +1,5 @@ +--- +"@logto/connector-google": minor +--- + +update the default `prompts` to be `select_account` diff --git a/.changeset/tricky-walls-add.md b/.changeset/tricky-walls-add.md new file mode 100644 index 00000000000..a94d03b6acf --- /dev/null +++ b/.changeset/tricky-walls-add.md @@ -0,0 +1,5 @@ +--- +"@logto/console": patch +--- + +Connector config default values should only show up when creating new connectors diff --git a/packages/connectors/connector-google/src/constant.ts b/packages/connectors/connector-google/src/constant.ts index 129ec67e024..c5378f431b2 100644 --- a/packages/connectors/connector-google/src/constant.ts +++ b/packages/connectors/connector-google/src/constant.ts @@ -69,6 +69,7 @@ export const defaultMetadata: ConnectorMetadata = { .map((prompt) => ({ value: prompt, })), + defaultValue: [OidcPrompt.SelectAccount], }, ], }; diff --git a/packages/console/src/utils/connector-form.ts b/packages/console/src/utils/connector-form.ts index f0a7f423c50..72592ec1c16 100644 --- a/packages/console/src/utils/connector-form.ts +++ b/packages/console/src/utils/connector-form.ts @@ -6,9 +6,19 @@ import { conditional } from '@silverhand/essentials'; import { SyncProfileMode, type ConnectorFormType } from '@/types/connector'; import { safeParseJson } from '@/utils/json'; +/** + * @remarks + * - When creating a new connector, this function will be called in the `convertFactoryResponseToForm()` method. At this time, there is no `config` data, so the default values in `formItems` are used. + * - When editing an existing connector, this function will be called in the `convertResponseToForm()` method. `config` data will always exist, and the `config` data is used, never using the default values. + */ const initFormData = (formItems: ConnectorConfigFormItem[], config?: Record) => { const data: Array<[string, unknown]> = formItems.map((item) => { - const value = config?.[item.key] ?? item.defaultValue; + const configValue = + config?.[item.key] ?? + conditional(item.type === ConnectorConfigFormItemType.Json && {}) ?? + conditional(item.type === ConnectorConfigFormItemType.MultiSelect && []); + const { defaultValue } = item; + const value = config ? configValue : defaultValue; if (item.type === ConnectorConfigFormItemType.Json) { return [item.key, JSON.stringify(value, null, 2)];