'use client' import React, { useState } from 'react' import { useTranslation } from 'react-i18next' import { RiDeleteBinLine, RiEqualizer2Line, RiErrorWarningFill, } from '@remixicon/react' import { Group } from '@/app/components/base/icons/src/vender/other' import AppIcon from '@/app/components/base/app-icon' import Switch from '@/app/components/base/switch' import Button from '@/app/components/base/button' import Indicator from '@/app/components/header/indicator' import ActionButton from '@/app/components/base/action-button' import Tooltip from '@/app/components/base/tooltip' import { ToolTipContent } from '@/app/components/base/tooltip/content' import { InstallPluginButton } from '@/app/components/workflow/nodes/_base/components/install-plugin-button' import { SwitchPluginVersion } from '@/app/components/workflow/nodes/_base/components/switch-plugin-version' import cn from '@/utils/classnames' type Props = { icon?: any providerName?: string toolLabel?: string showSwitch?: boolean switchValue?: boolean onSwitchChange?: (value: boolean) => void onDelete?: () => void noAuth?: boolean onAuth?: () => void isError?: boolean errorTip?: any uninstalled?: boolean installInfo?: string onInstall?: () => void versionMismatch?: boolean open: boolean } const ToolItem = ({ open, icon, providerName, toolLabel, showSwitch, switchValue, onSwitchChange, onDelete, noAuth, onAuth, uninstalled, installInfo, onInstall, isError, errorTip, versionMismatch, }: Props) => { const { t } = useTranslation() const providerNameText = providerName?.split('/').pop() const isTransparent = uninstalled || versionMismatch || isError const [isDeleting, setIsDeleting] = useState(false) return (
{icon && (
{typeof icon === 'string' &&
} {typeof icon !== 'string' && }
)} {!icon && (
)}
{providerNameText}
{toolLabel}
{!noAuth && !isError && !uninstalled && !versionMismatch && ( )}
{ e.stopPropagation() onDelete?.() }} onMouseOver={() => setIsDeleting(true)} onMouseLeave={() => setIsDeleting(false)} >
{!isError && !uninstalled && !noAuth && !versionMismatch && showSwitch && (
e.stopPropagation()}>
)} {!isError && !uninstalled && !versionMismatch && noAuth && ( )} {!isError && !uninstalled && versionMismatch && installInfo && (
e.stopPropagation()}> {`${t('plugin.detailPanel.toolSelector.unsupportedContent')} ${t('plugin.detailPanel.toolSelector.unsupportedContent2')}`} } onChange={() => { onInstall?.() }} />
)} {!isError && uninstalled && installInfo && ( e.stopPropagation()} size={'small'} uniqueIdentifier={installInfo} onSuccess={() => { onInstall?.() }} /> )} {isError && (
)}
) } export default ToolItem