chore: use install button in tool item

pull/12560/head
JzoNg 1 year ago
parent f03631ff9e
commit aac2184069

@ -32,7 +32,7 @@ import {
useInvalidateAllBuiltInTools, useInvalidateAllBuiltInTools,
useUpdateProviderCredentials, useUpdateProviderCredentials,
} from '@/service/use-tools' } from '@/service/use-tools'
import { useInstallPackageFromMarketPlace, useInvalidateInstalledPluginList } from '@/service/use-plugins' import { useInvalidateInstalledPluginList } from '@/service/use-plugins'
import { usePluginInstalledCheck } from '@/app/components/plugins/plugin-detail-panel/tool-selector/hooks' import { usePluginInstalledCheck } from '@/app/components/plugins/plugin-detail-panel/tool-selector/hooks'
import { CollectionType } from '@/app/components/tools/types' import { CollectionType } from '@/app/components/tools/types'
import type { ToolDefaultValue } from '@/app/components/workflow/block-selector/types' import type { ToolDefaultValue } from '@/app/components/workflow/block-selector/types'
@ -172,23 +172,15 @@ const ToolSelector: FC<Props> = ({
}) })
// install from marketplace // install from marketplace
const { mutateAsync: installPackageFromMarketPlace, isPending } = useInstallPackageFromMarketPlace()
const manifestIcon = useMemo(() => { const manifestIcon = useMemo(() => {
if (!manifest) if (!manifest)
return '' return ''
return `${MARKETPLACE_API_PREFIX}/plugins/${(manifest as any).plugin_id}/icon` return `${MARKETPLACE_API_PREFIX}/plugins/${(manifest as any).plugin_id}/icon`
}, [manifest]) }, [manifest])
const handleInstall = async () => { const handleInstall = async () => {
if (!manifest) invalidateAllBuiltinTools()
return invalidateInstalledPluginList()
try {
await installPackageFromMarketPlace(manifest.latest_package_identifier)
invalidateAllBuiltinTools()
invalidateInstalledPluginList()
}
catch (e: any) {
Toast.notify({ type: 'error', message: `${e.message || e}` })
}
} }
return ( return (
@ -225,7 +217,7 @@ const ToolSelector: FC<Props> = ({
noAuth={currentProvider && !currentProvider.is_team_authorization} noAuth={currentProvider && !currentProvider.is_team_authorization}
onAuth={() => setShowSettingAuth(true)} onAuth={() => setShowSettingAuth(true)}
uninstalled={!currentProvider && inMarketPlace} uninstalled={!currentProvider && inMarketPlace}
isInstalling={isPending} installInfo={manifest?.latest_package_identifier}
onInstall={() => handleInstall()} onInstall={() => handleInstall()}
isError={!currentProvider && !inMarketPlace} isError={!currentProvider && !inMarketPlace}
errorTip={<div className='space-y-1 max-w-[240px] text-xs'> errorTip={<div className='space-y-1 max-w-[240px] text-xs'>

@ -5,8 +5,6 @@ import {
RiDeleteBinLine, RiDeleteBinLine,
RiEqualizer2Line, RiEqualizer2Line,
RiErrorWarningFill, RiErrorWarningFill,
RiInstallLine,
RiLoader2Line,
} from '@remixicon/react' } from '@remixicon/react'
import { Group } from '@/app/components/base/icons/src/vender/other' import { Group } from '@/app/components/base/icons/src/vender/other'
import AppIcon from '@/app/components/base/app-icon' import AppIcon from '@/app/components/base/app-icon'
@ -15,6 +13,7 @@ import Button from '@/app/components/base/button'
import Indicator from '@/app/components/header/indicator' import Indicator from '@/app/components/header/indicator'
import ActionButton from '@/app/components/base/action-button' import ActionButton from '@/app/components/base/action-button'
import Tooltip from '@/app/components/base/tooltip' import Tooltip from '@/app/components/base/tooltip'
import { InstallPluginButton } from '@/app/components/workflow/nodes/_base/components/install-plugin-button'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
type Props = { type Props = {
@ -30,7 +29,7 @@ type Props = {
isError?: boolean isError?: boolean
errorTip?: any errorTip?: any
uninstalled?: boolean uninstalled?: boolean
isInstalling?: boolean installInfo?: string
onInstall?: () => void onInstall?: () => void
open: boolean open: boolean
} }
@ -47,7 +46,7 @@ const ToolItem = ({
noAuth, noAuth,
onAuth, onAuth,
uninstalled, uninstalled,
isInstalling, installInfo,
onInstall, onInstall,
isError, isError,
errorTip, errorTip,
@ -115,20 +114,15 @@ const ToolItem = ({
<Indicator className='ml-2' color='orange' /> <Indicator className='ml-2' color='orange' />
</Button> </Button>
)} )}
{!isError && uninstalled && ( {!isError && uninstalled && installInfo && (
<Button <InstallPluginButton
className={cn('flex items-center')} onClick={e => e.stopPropagation()}
size='small' size={'small'}
variant='secondary' uniqueIdentifier={installInfo}
disabled={isInstalling} onSuccess={() => {
onClick={(e) => {
e.stopPropagation()
onInstall?.() onInstall?.()
}} }}
> />
{!isInstalling ? t('workflow.nodes.agent.pluginInstaller.install') : t('workflow.nodes.agent.pluginInstaller.installing')}
{!isInstalling ? <RiInstallLine className='size-4 ml-1' /> : <RiLoader2Line className='size-4 ml-1 animate-spin' />}
</Button>
)} )}
{isError && ( {isError && (
<Tooltip <Tooltip

Loading…
Cancel
Save