mirror of
https://github.com/langgenius/dify.git
synced 2026-04-14 07:56:31 +08:00
fix(trigger): invalid subscription
This commit is contained in:
parent
b1f79c34d1
commit
850c5fec32
@ -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}
|
||||
|
||||
@ -20,8 +20,6 @@ type SubscriptionTriggerButtonProps = {
|
||||
onSelect: (v: SimpleSubscription, callback?: () => void) => void
|
||||
}
|
||||
|
||||
export const INVALID_SUBSCRIPTION_ID = 'INVALID_SUBSCRIPTION_ID'
|
||||
|
||||
const SubscriptionTriggerButton: React.FC<SubscriptionTriggerButtonProps> = ({
|
||||
selectedId,
|
||||
onClick,
|
||||
@ -46,19 +44,25 @@ const SubscriptionTriggerButton: React.FC<SubscriptionTriggerButtonProps> = ({
|
||||
}
|
||||
}
|
||||
|
||||
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])
|
||||
|
||||
|
||||
@ -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<PluginTriggerNodeType> = {
|
||||
} = {}) {
|
||||
let errorMessage = ''
|
||||
|
||||
if (!payload.subscription_id || payload.subscription_id === INVALID_SUBSCRIPTION_ID)
|
||||
if (!payload.subscription_id)
|
||||
errorMessage = t('workflow.nodes.triggerPlugin.subscriptionRequired')
|
||||
|
||||
const {
|
||||
|
||||
@ -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<NodeProps<PluginTriggerNodeType>> = ({
|
||||
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 (
|
||||
<div className="mb-1 px-3 py-1">
|
||||
<div className="space-y-0.5">
|
||||
{(!subscription_id || subscription_id === INVALID_SUBSCRIPTION_ID) && <NodeStatus status={NodeStatusEnum.warning} message={t('pluginTrigger.node.status.warning')} />}
|
||||
{subscription_id && subscription_id !== INVALID_SUBSCRIPTION_ID && configKeys.map((key, index) => (
|
||||
{!isValidSubscription && <NodeStatus status={NodeStatusEnum.warning} message={t('pluginTrigger.node.status.warning')} />}
|
||||
{isValidSubscription && configKeys.map((key, index) => (
|
||||
<div
|
||||
key={index}
|
||||
className="flex h-6 items-center justify-between space-x-1 rounded-md bg-workflow-block-parma-bg px-1 text-xs font-normal text-text-secondary"
|
||||
|
||||
@ -21,7 +21,6 @@ const Panel: FC<NodePanelProps<PluginTriggerNodeType>> = ({
|
||||
setTriggerParameterValue,
|
||||
outputSchema,
|
||||
hasObjectOutput,
|
||||
isAuthenticated,
|
||||
currentProvider,
|
||||
currentTrigger,
|
||||
} = useConfig(id, data)
|
||||
@ -37,7 +36,7 @@ const Panel: FC<NodePanelProps<PluginTriggerNodeType>> = ({
|
||||
return (
|
||||
<div className='mt-2'>
|
||||
{/* Dynamic Parameters Form - Only show when authenticated */}
|
||||
{isAuthenticated && triggerParameterSchema.length > 0 && (
|
||||
{triggerParameterSchema.length > 0 && (
|
||||
<>
|
||||
<div className='px-4 pb-4'>
|
||||
<TriggerForm
|
||||
|
||||
@ -217,13 +217,6 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => {
|
||||
)
|
||||
}, [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,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user