diff --git a/web/app/components/plugins/plugin-detail-panel/endpoint-card.tsx b/web/app/components/plugins/plugin-detail-panel/endpoint-card.tsx index 948cbdd225..1a984b4eda 100644 --- a/web/app/components/plugins/plugin-detail-panel/endpoint-card.tsx +++ b/web/app/components/plugins/plugin-detail-panel/endpoint-card.tsx @@ -4,12 +4,14 @@ import { useBoolean } from 'ahooks' import { RiDeleteBinLine, RiEditLine, RiLoginCircleLine } from '@remixicon/react' import type { EndpointListItem } from '../types' import EndpointModal from './endpoint-modal' +import { NAME_FIELD } from './utils' import { addDefaultValue, toolCredentialToFormSchemas } from '@/app/components/tools/utils/to-form-schema' import ActionButton from '@/app/components/base/action-button' import CopyBtn from '@/app/components/base/copy-btn' import Confirm from '@/app/components/base/confirm' import Indicator from '@/app/components/header/indicator' import Switch from '@/app/components/base/switch' +import Toast from '@/app/components/base/toast' import { deleteEndpoint, disableEndpoint, @@ -19,10 +21,12 @@ import { type Props = { data: EndpointListItem + handleChange: () => void } const EndpointCard = ({ data, + handleChange, }: Props) => { const { t } = useTranslation() const [active, setActive] = useState(data.enabled) @@ -38,9 +42,11 @@ const EndpointCard = ({ url: '/workspaces/current/endpoints/enable', endpointID, }) + await handleChange() } - catch (error) { + catch (error: any) { console.error(error) + Toast.notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) setActive(false) } } @@ -50,9 +56,12 @@ const EndpointCard = ({ url: '/workspaces/current/endpoints/disable', endpointID, }) + await handleChange() + hideDisableConfirm() } catch (error) { console.error(error) + Toast.notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) setActive(true) } } @@ -77,9 +86,12 @@ const EndpointCard = ({ url: '/workspaces/current/endpoints/delete', endpointID, }) + await handleChange() + hideDeleteConfirm() } catch (error) { console.error(error) + Toast.notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) } } @@ -89,25 +101,34 @@ const EndpointCard = ({ }] = useBoolean(false) const formSchemas = useMemo(() => { - return toolCredentialToFormSchemas(data.declaration.settings) + return toolCredentialToFormSchemas([NAME_FIELD, ...data.declaration.settings]) }, [data.declaration.settings]) const formValue = useMemo(() => { - return addDefaultValue(data.settings, formSchemas) - }, [data.settings, formSchemas]) + const formValue = { + name: data.name, + ...data.settings, + } + return addDefaultValue(formValue, formSchemas) + }, [data.name, data.settings, formSchemas]) - const handleUpdate = (state: any) => { + const handleUpdate = async (state: any) => { + const newName = state.name + delete state.name try { - updateEndpoint({ - url: '/workspaces/current/endpoints', + await updateEndpoint({ + url: '/workspaces/current/endpoints/update', body: { endpoint_id: data.id, settings: state, - name: state.name, + name: newName, }, }) + await handleChange() + hideEndpointModalConfirm() } catch (error) { console.error(error) + Toast.notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) } } diff --git a/web/app/components/plugins/plugin-detail-panel/endpoint-list.tsx b/web/app/components/plugins/plugin-detail-panel/endpoint-list.tsx index 495d451f90..6323e42365 100644 --- a/web/app/components/plugins/plugin-detail-panel/endpoint-list.tsx +++ b/web/app/components/plugins/plugin-detail-panel/endpoint-list.tsx @@ -5,21 +5,27 @@ import { useBoolean } from 'ahooks' import { RiAddLine } from '@remixicon/react' import EndpointModal from './endpoint-modal' import EndpointCard from './endpoint-card' +import { NAME_FIELD } from './utils' import { toolCredentialToFormSchemas } from '@/app/components/tools/utils/to-form-schema' import ActionButton from '@/app/components/base/action-button' import Tooltip from '@/app/components/base/tooltip' +import Toast from '@/app/components/base/toast' import { usePluginPageContext } from '@/app/components/plugins/plugin-page/context' import { createEndpoint, fetchEndpointList, } from '@/service/plugins' +import cn from '@/utils/classnames' -const EndpointList = () => { +type Props = { + showTopBorder?: boolean +} +const EndpointList = ({ showTopBorder }: Props) => { const { t } = useTranslation() const pluginDetail = usePluginPageContext(v => v.currentPluginDetail) const pluginUniqueID = pluginDetail.plugin_unique_identifier const declaration = pluginDetail.declaration.endpoint - const { data } = useSWR( + const { data, mutate } = useSWR( { url: '/workspaces/current/endpoints/list/plugin', params: { @@ -36,22 +42,27 @@ const EndpointList = () => { }] = useBoolean(false) const formSchemas = useMemo(() => { - return toolCredentialToFormSchemas(declaration.settings) + return toolCredentialToFormSchemas([NAME_FIELD, ...declaration.settings]) }, [declaration.settings]) - const handleCreate = (state: any) => { + const handleCreate = async (state: any) => { + const newName = state.name + delete state.name try { - createEndpoint({ - url: '/workspaces/current/endpoints', + await createEndpoint({ + url: '/workspaces/current/endpoints/create', body: { plugin_unique_identifier: pluginUniqueID, settings: state, - name: state.name, + name: newName, }, }) + await mutate() + hideEndpointModal() } catch (error) { console.error(error) + Toast.notify({ type: 'error', message: t('common.actionMsg.modifiedUnsuccessfully') }) } } @@ -59,7 +70,7 @@ const EndpointList = () => { return null return ( -