From 850c5fec324cbe826b377853726f3c13f56c2353 Mon Sep 17 00:00:00 2001 From: yessenia Date: Mon, 27 Oct 2025 21:15:55 +0800 Subject: [PATCH] fix(trigger): invalid subscription --- .../subscription-list/delete-confirm.tsx | 1 + .../subscription-list/selector-entry.tsx | 22 +++++++++++-------- .../workflow/nodes/trigger-plugin/default.ts | 3 +-- .../workflow/nodes/trigger-plugin/node.tsx | 16 +++++++------- .../workflow/nodes/trigger-plugin/panel.tsx | 3 +-- .../nodes/trigger-plugin/use-config.ts | 10 +-------- 6 files changed, 25 insertions(+), 30 deletions(-) diff --git a/web/app/components/plugins/plugin-detail-panel/subscription-list/delete-confirm.tsx b/web/app/components/plugins/plugin-detail-panel/subscription-list/delete-confirm.tsx index 95455b6e5c..178983c6b1 100644 --- a/web/app/components/plugins/plugin-detail-panel/subscription-list/delete-confirm.tsx +++ b/web/app/components/plugins/plugin-detail-panel/subscription-list/delete-confirm.tsx @@ -67,6 +67,7 @@ export const DeleteConfirm = (props: Props) => { : t(`${tPrefix}.content`)} isShow={isShow} isLoading={isDeleting} + isDisabled={isDeleting} onConfirm={onConfirm} onCancel={() => onClose(false)} maskClosable={false} diff --git a/web/app/components/plugins/plugin-detail-panel/subscription-list/selector-entry.tsx b/web/app/components/plugins/plugin-detail-panel/subscription-list/selector-entry.tsx index e6685b8011..ffaa4ab3a7 100644 --- a/web/app/components/plugins/plugin-detail-panel/subscription-list/selector-entry.tsx +++ b/web/app/components/plugins/plugin-detail-panel/subscription-list/selector-entry.tsx @@ -20,8 +20,6 @@ type SubscriptionTriggerButtonProps = { onSelect: (v: SimpleSubscription, callback?: () => void) => void } -export const INVALID_SUBSCRIPTION_ID = 'INVALID_SUBSCRIPTION_ID' - const SubscriptionTriggerButton: React.FC = ({ selectedId, onClick, @@ -46,19 +44,25 @@ const SubscriptionTriggerButton: React.FC = ({ } } - const selectedSubscription = subscriptions?.find(sub => sub.id === selectedId) + if (subscriptions && subscriptions.length > 0) { + const selectedSubscription = subscriptions?.find(sub => sub.id === selectedId) + + if (!selectedSubscription) { + return { + label: t('pluginTrigger.subscription.subscriptionRemoved'), + color: 'red' as const, + } + } - if (!selectedSubscription) { - onSelect({ id: INVALID_SUBSCRIPTION_ID, name: '' } as SimpleSubscription) return { - label: t('pluginTrigger.subscription.subscriptionRemoved'), - color: 'red' as const, + label: selectedSubscription.name, + color: 'green' as const, } } return { - label: selectedSubscription.name, - color: 'green' as const, + label: t('pluginTrigger.subscription.noSubscriptionSelected'), + color: 'red' as const, } }, [selectedId, subscriptions, t, isOpen]) diff --git a/web/app/components/workflow/nodes/trigger-plugin/default.ts b/web/app/components/workflow/nodes/trigger-plugin/default.ts index 5c956471af..6c82560a5a 100644 --- a/web/app/components/workflow/nodes/trigger-plugin/default.ts +++ b/web/app/components/workflow/nodes/trigger-plugin/default.ts @@ -1,4 +1,3 @@ -import { INVALID_SUBSCRIPTION_ID } from '@/app/components/plugins/plugin-detail-panel/subscription-list/selector-entry' import type { SchemaTypeDefinition } from '@/service/use-common' import type { NodeDefault, Var } from '../../types' import { BlockEnum, VarType } from '../../types' @@ -242,7 +241,7 @@ const nodeDefault: NodeDefault = { } = {}) { let errorMessage = '' - if (!payload.subscription_id || payload.subscription_id === INVALID_SUBSCRIPTION_ID) + if (!payload.subscription_id) errorMessage = t('workflow.nodes.triggerPlugin.subscriptionRequired') const { diff --git a/web/app/components/workflow/nodes/trigger-plugin/node.tsx b/web/app/components/workflow/nodes/trigger-plugin/node.tsx index 446781a7e3..9be517e97d 100644 --- a/web/app/components/workflow/nodes/trigger-plugin/node.tsx +++ b/web/app/components/workflow/nodes/trigger-plugin/node.tsx @@ -1,8 +1,7 @@ import NodeStatus, { NodeStatusEnum } from '@/app/components/base/node-status' -import { INVALID_SUBSCRIPTION_ID } from '@/app/components/plugins/plugin-detail-panel/subscription-list/selector-entry' import type { NodeProps } from '@/app/components/workflow/types' import type { FC } from 'react' -import React from 'react' +import React, { useMemo } from 'react' import { useTranslation } from 'react-i18next' import type { PluginTriggerNodeType } from './types' import useConfig from './use-config' @@ -40,20 +39,21 @@ const Node: FC> = ({ id, data, }) => { - const { isAuthenticated } = useConfig(id, data) + const { subscriptions } = useConfig(id, data) const { config = {}, subscription_id } = data const configKeys = Object.keys(config) const { t } = useTranslation() - // Only show config when authenticated and has config values - if (!isAuthenticated || configKeys.length === 0) - return null + + const isValidSubscription = useMemo(() => { + return subscription_id && subscriptions?.some(sub => sub.id === subscription_id) + }, [subscription_id, subscriptions]) return (
- {(!subscription_id || subscription_id === INVALID_SUBSCRIPTION_ID) && } - {subscription_id && subscription_id !== INVALID_SUBSCRIPTION_ID && configKeys.map((key, index) => ( + {!isValidSubscription && } + {isValidSubscription && configKeys.map((key, index) => (
> = ({ setTriggerParameterValue, outputSchema, hasObjectOutput, - isAuthenticated, currentProvider, currentTrigger, } = useConfig(id, data) @@ -37,7 +36,7 @@ const Panel: FC> = ({ return (
{/* Dynamic Parameters Form - Only show when authenticated */} - {isAuthenticated && triggerParameterSchema.length > 0 && ( + {triggerParameterSchema.length > 0 && ( <>
{ ) }, [outputSchema]) - // Authentication status check - const isAuthenticated = useMemo(() => { - return subscriptions.length > 0 - }, [subscriptions]) - - const showAuthRequired = !isAuthenticated && !!currentProvider - return { readOnly, inputs, @@ -235,8 +228,7 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => { setInputVar, outputSchema, hasObjectOutput, - isAuthenticated, - showAuthRequired, + subscriptions, } }