mirror of https://github.com/langgenius/dify.git
refactor(trigger): simplify provider path handling in workflow components
- Updated various components to directly use `provider.name` instead of constructing a path with `provider.plugin_id` and `provider.name`. - Adjusted related calls to `invalidateSubscriptions` and other functions to reflect this change. These modifications enhance code clarity and streamline the handling of provider information in the trigger plugin components.
This commit is contained in:
parent
ff30395dc1
commit
dc16f1b65a
|
|
@ -241,8 +241,8 @@ const BasePanel: FC<BasePanelProps> = ({
|
|||
// For trigger plugins, check if they have existing subscriptions (authenticated)
|
||||
const triggerProvider = useMemo(() => {
|
||||
if (data.type === BlockEnum.TriggerPlugin) {
|
||||
if (data.provider_id && data.provider_name)
|
||||
return `${data.provider_id}/${data.provider_name}`
|
||||
if (data.provider_name)
|
||||
return data.provider_name
|
||||
return data.provider_id || ''
|
||||
}
|
||||
return ''
|
||||
|
|
|
|||
|
|
@ -32,11 +32,8 @@ const NodeAuth: FC<NodeAuthProps> = ({ data, onAuthorizationChange }) => {
|
|||
const provider = useMemo(() => {
|
||||
if (data.type === BlockEnum.TriggerPlugin) {
|
||||
// If we have both plugin_id and provider_name, construct the full path
|
||||
if (data.provider_id && data.provider_name)
|
||||
return `${data.provider_id}/${data.provider_name}`
|
||||
|
||||
// Otherwise use provider_id as fallback (might be already complete)
|
||||
return data.provider_id || ''
|
||||
if (data.provider_name)
|
||||
return data.provider_name
|
||||
}
|
||||
return data.provider_id || ''
|
||||
}, [data.type, data.provider_id, data.provider_name])
|
||||
|
|
|
|||
|
|
@ -46,8 +46,6 @@ const ApiKeyConfigModal: FC<ApiKeyConfigModalProps> = ({
|
|||
const buildSubscription = useBuildTriggerSubscription()
|
||||
const invalidateSubscriptions = useInvalidateTriggerSubscriptions()
|
||||
|
||||
const providerPath = `${provider.plugin_id}/${provider.name}`
|
||||
|
||||
useEffect(() => {
|
||||
if (provider.credentials_schema) {
|
||||
const schemas = toolCredentialToFormSchemas(provider.credentials_schema as any)
|
||||
|
|
@ -85,7 +83,7 @@ const ApiKeyConfigModal: FC<ApiKeyConfigModalProps> = ({
|
|||
let builderId = subscriptionBuilderId
|
||||
if (!builderId) {
|
||||
const createResponse = await createBuilder.mutateAsync({
|
||||
provider: providerPath,
|
||||
provider: provider.name,
|
||||
credentials: tempCredential,
|
||||
})
|
||||
builderId = createResponse.subscription_builder.id
|
||||
|
|
@ -94,7 +92,7 @@ const ApiKeyConfigModal: FC<ApiKeyConfigModalProps> = ({
|
|||
else {
|
||||
// Update existing builder
|
||||
await updateBuilder.mutateAsync({
|
||||
provider: providerPath,
|
||||
provider: provider.name,
|
||||
subscriptionBuilderId: builderId,
|
||||
credentials: tempCredential,
|
||||
})
|
||||
|
|
@ -102,18 +100,18 @@ const ApiKeyConfigModal: FC<ApiKeyConfigModalProps> = ({
|
|||
|
||||
// Step 2: Verify credentials
|
||||
await verifyBuilder.mutateAsync({
|
||||
provider: providerPath,
|
||||
provider: provider.name,
|
||||
subscriptionBuilderId: builderId,
|
||||
})
|
||||
|
||||
// Step 3: Build final subscription
|
||||
await buildSubscription.mutateAsync({
|
||||
provider: providerPath,
|
||||
provider: provider.name,
|
||||
subscriptionBuilderId: builderId,
|
||||
})
|
||||
|
||||
// Step 4: Invalidate and notify success
|
||||
invalidateSubscriptions(providerPath)
|
||||
invalidateSubscriptions(provider.name)
|
||||
notify({
|
||||
type: 'success',
|
||||
message: t('workflow.nodes.triggerPlugin.apiKeyConfigured'),
|
||||
|
|
|
|||
|
|
@ -31,8 +31,7 @@ const AuthMethodSelector: FC<AuthMethodSelectorProps> = ({
|
|||
const initiateTriggerOAuth = useInitiateTriggerOAuth()
|
||||
const invalidateSubscriptions = useInvalidateTriggerSubscriptions()
|
||||
|
||||
const providerPath = `${provider.plugin_id}/${provider.name}`
|
||||
const { data: oauthConfig } = useTriggerOAuthConfig(providerPath, supportedMethods.includes('oauth'))
|
||||
const { data: oauthConfig } = useTriggerOAuthConfig(provider.name, supportedMethods.includes('oauth'))
|
||||
|
||||
const handleOAuthAuth = useCallback(async () => {
|
||||
// Check if OAuth client is configured
|
||||
|
|
@ -43,10 +42,10 @@ const AuthMethodSelector: FC<AuthMethodSelectorProps> = ({
|
|||
}
|
||||
|
||||
try {
|
||||
const response = await initiateTriggerOAuth.mutateAsync(providerPath)
|
||||
const response = await initiateTriggerOAuth.mutateAsync(provider.name)
|
||||
if (response.authorization_url) {
|
||||
openOAuthPopup(response.authorization_url, (callbackData) => {
|
||||
invalidateSubscriptions(providerPath)
|
||||
invalidateSubscriptions(provider.name)
|
||||
|
||||
if (callbackData?.success === false) {
|
||||
notify({
|
||||
|
|
@ -69,7 +68,7 @@ const AuthMethodSelector: FC<AuthMethodSelectorProps> = ({
|
|||
message: t('workflow.nodes.triggerPlugin.oauthConfigFailed', { error: error.message }),
|
||||
})
|
||||
}
|
||||
}, [providerPath, initiateTriggerOAuth, invalidateSubscriptions, notify, oauthConfig])
|
||||
}, [provider.name, initiateTriggerOAuth, invalidateSubscriptions, notify, oauthConfig])
|
||||
|
||||
const handleApiKeyAuth = useCallback(() => {
|
||||
setShowApiKeyModal(true)
|
||||
|
|
@ -135,7 +134,7 @@ const AuthMethodSelector: FC<AuthMethodSelectorProps> = ({
|
|||
onCancel={() => setShowApiKeyModal(false)}
|
||||
onSuccess={() => {
|
||||
setShowApiKeyModal(false)
|
||||
invalidateSubscriptions(providerPath)
|
||||
invalidateSubscriptions(provider.name)
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
|
|
|||
|
|
@ -28,8 +28,7 @@ const useConfig = (id: string, payload: PluginTriggerNodeType) => {
|
|||
|
||||
// Construct provider for authentication check
|
||||
const authProvider = useMemo(() => {
|
||||
if (provider_id && provider_name) return `${provider_id}/${provider_name}`
|
||||
return provider_id || ''
|
||||
return provider_name || ''
|
||||
}, [provider_id, provider_name])
|
||||
|
||||
const { data: subscriptions = [] } = useTriggerSubscriptions(
|
||||
|
|
|
|||
Loading…
Reference in New Issue