fix credentials of action list
This commit is contained in:
parent
2511968cb4
commit
920d6d6882
@ -1,4 +1,4 @@
|
|||||||
import React, { useMemo, useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import useSWR from 'swr'
|
import useSWR from 'swr'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { usePluginPageContext } from '@/app/components/plugins/plugin-page/context'
|
import { usePluginPageContext } from '@/app/components/plugins/plugin-page/context'
|
||||||
@ -10,6 +10,7 @@ import ToolItem from '@/app/components/tools/provider/tool-item'
|
|||||||
import ConfigCredential from '@/app/components/tools/setting/build-in/config-credentials'
|
import ConfigCredential from '@/app/components/tools/setting/build-in/config-credentials'
|
||||||
import {
|
import {
|
||||||
fetchBuiltInToolList,
|
fetchBuiltInToolList,
|
||||||
|
fetchCollectionDetail,
|
||||||
removeBuiltInToolCredential,
|
removeBuiltInToolCredential,
|
||||||
updateBuiltInToolCredential,
|
updateBuiltInToolCredential,
|
||||||
} from '@/service/tools'
|
} from '@/service/tools'
|
||||||
@ -18,12 +19,10 @@ const ActionList = () => {
|
|||||||
const { t } = useTranslation()
|
const { t } = useTranslation()
|
||||||
const { isCurrentWorkspaceManager } = useAppContext()
|
const { isCurrentWorkspaceManager } = useAppContext()
|
||||||
const currentPluginDetail = usePluginPageContext(v => v.currentPluginDetail)
|
const currentPluginDetail = usePluginPageContext(v => v.currentPluginDetail)
|
||||||
const providerDeclaration = useMemo(() => {
|
const { data: provider } = useSWR(
|
||||||
return {
|
`builtin/${currentPluginDetail.plugin_id}/${currentPluginDetail.name}`,
|
||||||
...currentPluginDetail.declaration.tool.identity,
|
fetchCollectionDetail,
|
||||||
name: `${currentPluginDetail.plugin_id}/${currentPluginDetail.name}`,
|
)
|
||||||
}
|
|
||||||
}, [currentPluginDetail.declaration.tool.identity, currentPluginDetail.name, currentPluginDetail.plugin_id])
|
|
||||||
const { data } = useSWR(
|
const { data } = useSWR(
|
||||||
`${currentPluginDetail.plugin_id}/${currentPluginDetail.name}`,
|
`${currentPluginDetail.plugin_id}/${currentPluginDetail.name}`,
|
||||||
fetchBuiltInToolList,
|
fetchBuiltInToolList,
|
||||||
@ -33,7 +32,7 @@ const ActionList = () => {
|
|||||||
|
|
||||||
const handleCredentialSettingUpdate = () => {}
|
const handleCredentialSettingUpdate = () => {}
|
||||||
|
|
||||||
if (!data)
|
if (!data || !provider)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -41,7 +40,7 @@ const ActionList = () => {
|
|||||||
<div className='mb-1 py-1'>
|
<div className='mb-1 py-1'>
|
||||||
<div className='mb-1 h-6 flex items-center justify-between text-text-secondary system-sm-semibold-uppercase'>
|
<div className='mb-1 h-6 flex items-center justify-between text-text-secondary system-sm-semibold-uppercase'>
|
||||||
{t('plugin.detailPanel.actionNum', { num: data.length })}
|
{t('plugin.detailPanel.actionNum', { num: data.length })}
|
||||||
{providerDeclaration.is_team_authorization && providerDeclaration.allow_delete && (
|
{provider.is_team_authorization && provider.allow_delete && (
|
||||||
<Button
|
<Button
|
||||||
variant='secondary'
|
variant='secondary'
|
||||||
size='small'
|
size='small'
|
||||||
@ -53,7 +52,7 @@ const ActionList = () => {
|
|||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{!providerDeclaration.is_team_authorization && providerDeclaration.allow_delete && (
|
{!provider.is_team_authorization && provider.allow_delete && (
|
||||||
<Button
|
<Button
|
||||||
variant='primary'
|
variant='primary'
|
||||||
className='w-full'
|
className='w-full'
|
||||||
@ -67,7 +66,7 @@ const ActionList = () => {
|
|||||||
<ToolItem
|
<ToolItem
|
||||||
key={`${currentPluginDetail.plugin_id}${tool.name}`}
|
key={`${currentPluginDetail.plugin_id}${tool.name}`}
|
||||||
disabled={false}
|
disabled={false}
|
||||||
collection={providerDeclaration}
|
collection={provider}
|
||||||
tool={tool}
|
tool={tool}
|
||||||
isBuiltIn={true}
|
isBuiltIn={true}
|
||||||
isModel={false}
|
isModel={false}
|
||||||
@ -76,10 +75,10 @@ const ActionList = () => {
|
|||||||
</div>
|
</div>
|
||||||
{showSettingAuth && (
|
{showSettingAuth && (
|
||||||
<ConfigCredential
|
<ConfigCredential
|
||||||
collection={providerDeclaration}
|
collection={provider}
|
||||||
onCancel={() => setShowSettingAuth(false)}
|
onCancel={() => setShowSettingAuth(false)}
|
||||||
onSaved={async (value) => {
|
onSaved={async (value) => {
|
||||||
await updateBuiltInToolCredential(providerDeclaration.name, value)
|
await updateBuiltInToolCredential(provider.name, value)
|
||||||
Toast.notify({
|
Toast.notify({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: t('common.api.actionSuccess'),
|
message: t('common.api.actionSuccess'),
|
||||||
@ -88,7 +87,7 @@ const ActionList = () => {
|
|||||||
setShowSettingAuth(false)
|
setShowSettingAuth(false)
|
||||||
}}
|
}}
|
||||||
onRemove={async () => {
|
onRemove={async () => {
|
||||||
await removeBuiltInToolCredential(providerDeclaration.name)
|
await removeBuiltInToolCredential(provider.name)
|
||||||
Toast.notify({
|
Toast.notify({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: t('common.api.actionSuccess'),
|
message: t('common.api.actionSuccess'),
|
||||||
|
@ -15,6 +15,10 @@ export const fetchCollectionList = () => {
|
|||||||
return get<Collection[]>('/workspaces/current/tool-providers')
|
return get<Collection[]>('/workspaces/current/tool-providers')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const fetchCollectionDetail = (collectionName: string) => {
|
||||||
|
return get<Collection>(`/workspaces/current/tool-provider/${collectionName}/info`)
|
||||||
|
}
|
||||||
|
|
||||||
export const fetchBuiltInToolList = (collectionName: string) => {
|
export const fetchBuiltInToolList = (collectionName: string) => {
|
||||||
return get<Tool[]>(`/workspaces/current/tool-provider/builtin/${collectionName}/tools`)
|
return get<Tool[]>(`/workspaces/current/tool-provider/builtin/${collectionName}/tools`)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user