From 735ebf6c59303ae974777cb428197461331d1c52 Mon Sep 17 00:00:00 2001 From: yessenia Date: Tue, 21 Oct 2025 08:11:44 +0800 Subject: [PATCH] fix(trigger): oauth client params --- .../base/form/components/base/base-field.tsx | 2 +- .../subscription-list/create/index.tsx | 4 +- .../subscription-list/create/oauth-client.tsx | 13 +-- .../create/type-dropdown.tsx | 105 ------------------ .../workflow/block-selector/types.ts | 1 + web/i18n/en-US/plugin-trigger.ts | 1 - web/i18n/zh-Hans/plugin-trigger.ts | 1 - 7 files changed, 10 insertions(+), 117 deletions(-) delete mode 100644 web/app/components/plugins/plugin-detail-panel/subscription-list/create/type-dropdown.tsx diff --git a/web/app/components/base/form/components/base/base-field.tsx b/web/app/components/base/form/components/base/base-field.tsx index 79a554fa4a..124a0fbf52 100644 --- a/web/app/components/base/form/components/base/base-field.tsx +++ b/web/app/components/base/form/components/base/base-field.tsx @@ -311,7 +311,7 @@ const BaseField = ({ {renderI18nObject(formSchema?.help as any)} - + ) } diff --git a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/index.tsx b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/index.tsx index 6ff8d1dcde..3ec1c8cacf 100644 --- a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/index.tsx +++ b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/index.tsx @@ -93,7 +93,7 @@ export const CreateSubscriptionButton = ({ buttonType = CreateButtonType.FULL_BU }, { value: SupportedCreationMethods.MANUAL, - label: t('pluginTrigger.subscription.addType.options.manual.description'), // 使用 description 作为标题 + label: t('pluginTrigger.subscription.addType.options.manual.description'), extra: , show: supportedMethods.includes(SupportedCreationMethods.MANUAL), }, @@ -109,7 +109,7 @@ export const CreateSubscriptionButton = ({ buttonType = CreateButtonType.FULL_BU if (callbackData) { Toast.notify({ type: 'success', - message: t('pluginTrigger.modal.oauth.authorized'), + message: t('pluginTrigger.modal.oauth.authorization.authSuccess'), }) setSelectedCreateInfo({ type: SupportedCreationMethods.OAUTH, builder: response.subscription_builder }) } diff --git a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/oauth-client.tsx b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/oauth-client.tsx index 4d00f41ec9..c171600353 100644 --- a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/oauth-client.tsx +++ b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/oauth-client.tsx @@ -42,26 +42,25 @@ enum ClientTypeEnum { export const OAuthClientSettingsModal = ({ oauthConfig, onClose, showOAuthCreateModal }: Props) => { const { t } = useTranslation() const detail = usePluginStore(state => state.detail) - const { configured, custom_enabled, system_configured, params } = oauthConfig || {} + const { system_configured, params, oauth_client_schema } = oauthConfig || {} const [subscriptionBuilder, setSubscriptionBuilder] = useState() const [authorizationStatus, setAuthorizationStatus] = useState() - const [clientType, setClientType] = useState(((configured && !custom_enabled) || (!configured && system_configured)) ? ClientTypeEnum.Default : ClientTypeEnum.Custom) + const [clientType, setClientType] = useState(system_configured ? ClientTypeEnum.Default : ClientTypeEnum.Custom) const clientFormRef = React.useRef(null) const oauthClientSchema = useMemo(() => { - if (detail && params) { - const clientSchema = detail?.declaration.trigger?.subscription_constructor?.oauth_schema?.client_schema || [] + if (oauth_client_schema && oauth_client_schema.length > 0 && params) { const oauthConfigPramaKeys = Object.keys(params || {}) - for (const schema of clientSchema) { + for (const schema of oauth_client_schema) { if (oauthConfigPramaKeys.includes(schema.name)) schema.default = params?.[schema.name] } - return clientSchema + return oauth_client_schema } return [] - }, [detail, params]) + }, [oauth_client_schema, params]) const providerName = detail?.provider || '' const { mutate: initiateOAuth } = useInitiateTriggerOAuth() diff --git a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/type-dropdown.tsx b/web/app/components/plugins/plugin-detail-panel/subscription-list/create/type-dropdown.tsx deleted file mode 100644 index 9e360095dc..0000000000 --- a/web/app/components/plugins/plugin-detail-panel/subscription-list/create/type-dropdown.tsx +++ /dev/null @@ -1,105 +0,0 @@ -'use client' -import React, { useEffect, useRef } from 'react' -import { useTranslation } from 'react-i18next' -import { RiEqualizer2Line } from '@remixicon/react' -import cn from '@/utils/classnames' -import Tooltip from '@/app/components/base/tooltip' -import { ActionButton } from '@/app/components/base/action-button' -import { SupportedCreationMethods } from '../../../types' -import type { TriggerOAuthConfig } from '@/app/components/workflow/block-selector/types' - -type Props = { - onSelect: (type: SupportedCreationMethods) => void - onClose: () => void - position?: 'bottom' | 'right' - className?: string - supportedMethods: SupportedCreationMethods[] - oauthConfig?: TriggerOAuthConfig -} - -export const CreateTypeDropdown = ({ onSelect, onClose, position = 'bottom', className, supportedMethods }: Props) => { - const { t } = useTranslation() - const dropdownRef = useRef(null) - - useEffect(() => { - const handleClickOutside = (event: MouseEvent) => { - if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) - onClose() - } - - document.addEventListener('mousedown', handleClickOutside) - return () => document.removeEventListener('mousedown', handleClickOutside) - }, [onClose]) - - const onClickClientSettings = () => { - // todo: show client settings - } - - const allOptions = [ - { - key: SupportedCreationMethods.OAUTH, - title: t('pluginTrigger.subscription.addType.options.oauth.title'), - extraContent: , - show: supportedMethods.includes(SupportedCreationMethods.OAUTH), - }, - { - key: SupportedCreationMethods.APIKEY, - title: t('pluginTrigger.subscription.addType.options.apikey.title'), - show: supportedMethods.includes(SupportedCreationMethods.APIKEY), - }, - { - key: SupportedCreationMethods.MANUAL, - title: t('pluginTrigger.subscription.addType.options.manual.description'), // 使用 description 作为标题 - tooltip: t('pluginTrigger.subscription.addType.options.manual.tip'), - show: supportedMethods.includes(SupportedCreationMethods.MANUAL), - }, - ] - - const options = allOptions.filter(option => option.show) - - const handleOptionClick = (type: SupportedCreationMethods) => { - onSelect(type) - } - - return ( -
- - {options.map((option, index) => { - return ( - <> - {index === options.length - 1 &&
} - - - ) - })} -
- ) -} diff --git a/web/app/components/workflow/block-selector/types.ts b/web/app/components/workflow/block-selector/types.ts index e990695b15..94ef32956c 100644 --- a/web/app/components/workflow/block-selector/types.ts +++ b/web/app/components/workflow/block-selector/types.ts @@ -266,6 +266,7 @@ export type TriggerOAuthConfig = { custom_configured: boolean custom_enabled: boolean redirect_uri: string + oauth_client_schema: ParametersSchema[] params: { client_id: string client_secret: string diff --git a/web/i18n/en-US/plugin-trigger.ts b/web/i18n/en-US/plugin-trigger.ts index 5fee874104..b3bd2e8aa4 100644 --- a/web/i18n/en-US/plugin-trigger.ts +++ b/web/i18n/en-US/plugin-trigger.ts @@ -4,7 +4,6 @@ const translation = { listNum: '{{num}} subscriptions', empty: { title: 'No subscriptions', - description: 'Create your first subscription to start receiving events', button: 'New subscription', }, createButton: { diff --git a/web/i18n/zh-Hans/plugin-trigger.ts b/web/i18n/zh-Hans/plugin-trigger.ts index 5529edfe53..5476c96ed8 100644 --- a/web/i18n/zh-Hans/plugin-trigger.ts +++ b/web/i18n/zh-Hans/plugin-trigger.ts @@ -4,7 +4,6 @@ const translation = { listNum: '{{num}} 个订阅', empty: { title: '暂无订阅', - description: '创建您的第一个订阅以开始接收事件', button: '新建订阅', }, createButton: {