import React, { useState } from 'react' import useSWR from 'swr' import { useTranslation } from 'react-i18next' import { usePluginPageContext } from '@/app/components/plugins/plugin-page/context' import { useAppContext } from '@/context/app-context' import Button from '@/app/components/base/button' import Toast from '@/app/components/base/toast' import Indicator from '@/app/components/header/indicator' import ToolItem from '@/app/components/tools/provider/tool-item' import ConfigCredential from '@/app/components/tools/setting/build-in/config-credentials' import { fetchBuiltInToolList, fetchCollectionDetail, removeBuiltInToolCredential, updateBuiltInToolCredential, } from '@/service/tools' const ActionList = () => { const { t } = useTranslation() const { isCurrentWorkspaceManager } = useAppContext() const currentPluginDetail = usePluginPageContext(v => v.currentPluginDetail) const { data: provider } = useSWR( `builtin/${currentPluginDetail.plugin_id}/${currentPluginDetail.name}`, fetchCollectionDetail, ) const { data } = useSWR( `${currentPluginDetail.plugin_id}/${currentPluginDetail.name}`, fetchBuiltInToolList, ) const [showSettingAuth, setShowSettingAuth] = useState(false) const handleCredentialSettingUpdate = () => {} if (!data || !provider) return null return (
{t('plugin.detailPanel.actionNum', { num: data.length })} {provider.is_team_authorization && provider.allow_delete && ( )}
{!provider.is_team_authorization && provider.allow_delete && ( )}
{data.map(tool => ( ))}
{showSettingAuth && ( setShowSettingAuth(false)} onSaved={async (value) => { await updateBuiltInToolCredential(provider.name, value) Toast.notify({ type: 'success', message: t('common.api.actionSuccess'), }) handleCredentialSettingUpdate() setShowSettingAuth(false) }} onRemove={async () => { await removeBuiltInToolCredential(provider.name) Toast.notify({ type: 'success', message: t('common.api.actionSuccess'), }) handleCredentialSettingUpdate() setShowSettingAuth(false) }} /> )}
) } export default ActionList