mirror of
https://github.com/langgenius/dify.git
synced 2026-04-27 02:36:29 +08:00
Fix plugin install detection for tool nodes
This commit is contained in:
parent
6e0765fbaf
commit
ff0f645e54
@ -7,15 +7,25 @@ import { useCheckInstalled, useInstallPackageFromMarketPlace } from '@/service/u
|
|||||||
|
|
||||||
type InstallPluginButtonProps = Omit<ComponentProps<typeof Button>, 'children' | 'loading'> & {
|
type InstallPluginButtonProps = Omit<ComponentProps<typeof Button>, 'children' | 'loading'> & {
|
||||||
uniqueIdentifier: string
|
uniqueIdentifier: string
|
||||||
|
extraIdentifiers?: string[]
|
||||||
onSuccess?: () => void
|
onSuccess?: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export const InstallPluginButton = (props: InstallPluginButtonProps) => {
|
export const InstallPluginButton = (props: InstallPluginButtonProps) => {
|
||||||
const { className, uniqueIdentifier, onSuccess, ...rest } = props
|
const {
|
||||||
|
className,
|
||||||
|
uniqueIdentifier,
|
||||||
|
extraIdentifiers = [],
|
||||||
|
onSuccess,
|
||||||
|
...rest
|
||||||
|
} = props
|
||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
|
const identifiers = Array.from(new Set(
|
||||||
|
[uniqueIdentifier, ...extraIdentifiers].filter((item): item is string => Boolean(item)),
|
||||||
|
))
|
||||||
const manifest = useCheckInstalled({
|
const manifest = useCheckInstalled({
|
||||||
pluginIds: [uniqueIdentifier],
|
pluginIds: identifiers,
|
||||||
enabled: !!uniqueIdentifier,
|
enabled: identifiers.length > 0,
|
||||||
})
|
})
|
||||||
const install = useInstallPackageFromMarketPlace()
|
const install = useInstallPackageFromMarketPlace()
|
||||||
const isLoading = manifest.isLoading || install.isPending
|
const isLoading = manifest.isLoading || install.isPending
|
||||||
@ -31,7 +41,13 @@ export const InstallPluginButton = (props: InstallPluginButtonProps) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (!manifest.data) return null
|
if (!manifest.data) return null
|
||||||
if (manifest.data.plugins.some(plugin => plugin.id === uniqueIdentifier)) return null
|
const identifierSet = new Set(identifiers)
|
||||||
|
const isInstalled = manifest.data.plugins.some(plugin => (
|
||||||
|
identifierSet.has(plugin.id)
|
||||||
|
|| (plugin.plugin_unique_identifier && identifierSet.has(plugin.plugin_unique_identifier))
|
||||||
|
|| (plugin.plugin_id && identifierSet.has(plugin.plugin_id))
|
||||||
|
))
|
||||||
|
if (isInstalled) return null
|
||||||
return <Button
|
return <Button
|
||||||
variant={'secondary'}
|
variant={'secondary'}
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
|
|||||||
@ -26,6 +26,10 @@ const Node: FC<NodeProps<DataSourceNodeType>> = ({
|
|||||||
<div className='absolute right-3 top-[-32px] z-20'>
|
<div className='absolute right-3 top-[-32px] z-20'>
|
||||||
<InstallPluginButton
|
<InstallPluginButton
|
||||||
size='small'
|
size='small'
|
||||||
|
extraIdentifiers={[
|
||||||
|
data.plugin_id,
|
||||||
|
data.provider_name,
|
||||||
|
].filter(Boolean) as string[]}
|
||||||
className='!font-medium !text-text-accent'
|
className='!font-medium !text-text-accent'
|
||||||
uniqueIdentifier={uniqueIdentifier!}
|
uniqueIdentifier={uniqueIdentifier!}
|
||||||
onSuccess={onInstallSuccess}
|
onSuccess={onInstallSuccess}
|
||||||
|
|||||||
@ -32,6 +32,11 @@ const Node: FC<NodeProps<ToolNodeType>> = ({
|
|||||||
<InstallPluginButton
|
<InstallPluginButton
|
||||||
size='small'
|
size='small'
|
||||||
className='!font-medium !text-text-accent'
|
className='!font-medium !text-text-accent'
|
||||||
|
extraIdentifiers={[
|
||||||
|
data.plugin_id,
|
||||||
|
data.provider_id,
|
||||||
|
data.provider_name,
|
||||||
|
].filter(Boolean) as string[]}
|
||||||
uniqueIdentifier={uniqueIdentifier!}
|
uniqueIdentifier={uniqueIdentifier!}
|
||||||
onSuccess={onInstallSuccess}
|
onSuccess={onInstallSuccess}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@ -65,6 +65,11 @@ const Node: FC<NodeProps<PluginTriggerNodeType>> = ({
|
|||||||
<div className="absolute right-3 top-[-32px] z-20">
|
<div className="absolute right-3 top-[-32px] z-20">
|
||||||
<InstallPluginButton
|
<InstallPluginButton
|
||||||
size="small"
|
size="small"
|
||||||
|
extraIdentifiers={[
|
||||||
|
data.plugin_id,
|
||||||
|
data.provider_id,
|
||||||
|
data.provider_name,
|
||||||
|
].filter(Boolean) as string[]}
|
||||||
className="!font-medium !text-text-accent"
|
className="!font-medium !text-text-accent"
|
||||||
uniqueIdentifier={uniqueIdentifier!}
|
uniqueIdentifier={uniqueIdentifier!}
|
||||||
onSuccess={onInstallSuccess}
|
onSuccess={onInstallSuccess}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user