diff --git a/web/app/components/plugins/plugin-detail-panel/detail-header.tsx b/web/app/components/plugins/plugin-detail-panel/detail-header.tsx index 686d8c4572..c91cba093d 100644 --- a/web/app/components/plugins/plugin-detail-panel/detail-header.tsx +++ b/web/app/components/plugins/plugin-detail-panel/detail-header.tsx @@ -1,4 +1,4 @@ -import React, { useMemo } from 'react' +import React, { useCallback, useMemo } from 'react' import { useTranslation } from 'react-i18next' import { useBoolean } from 'ahooks' import { @@ -22,6 +22,7 @@ import Confirm from '@/app/components/base/confirm' import Tooltip from '@/app/components/base/tooltip' import { BoxSparkleFill } from '@/app/components/base/icons/src/vender/plugin' import { Github } from '@/app/components/base/icons/src/public/common' +import { uninstallPlugin } from '@/service/plugins' import { useGetLanguage } from '@/context/i18n' import { API_PREFIX, MARKETPLACE_URL_PREFIX } from '@/config' import cn from '@/utils/classnames' @@ -43,6 +44,7 @@ const DetailHeader = ({ const locale = useGetLanguage() const { + installation_id, source, tenant_id, version, @@ -68,8 +70,23 @@ const DetailHeader = ({ setFalse: hideDeleteConfirm, }] = useBoolean(false) + const [deleting, { + setTrue: showDeleting, + setFalse: hideDeleting, + }] = useBoolean(false) + + const handleDelete = useCallback(async () => { + showDeleting() + const res = await uninstallPlugin(installation_id) + hideDeleting() + if (res.success) { + hideDeleteConfirm() + onDelete() + } + }, [hideDeleteConfirm, hideDeleting, installation_id, showDeleting, onDelete]) + // #plugin TODO# used in apps - const usedInApps = 3 + // const usedInApps = 3 return (
@@ -147,11 +164,13 @@ const DetailHeader = ({ content={
{t(`${i18nPrefix}.deleteContentLeft`)}{label[locale]}{t(`${i18nPrefix}.deleteContentRight`)}
- {usedInApps > 0 && t(`${i18nPrefix}.usedInApps`, { num: usedInApps })} + {/* {usedInApps > 0 && t(`${i18nPrefix}.usedInApps`, { num: usedInApps })} */}
} onCancel={hideDeleteConfirm} - onConfirm={onDelete} + onConfirm={handleDelete} + isLoading={deleting} + isDisabled={deleting} /> )}
diff --git a/web/app/components/plugins/plugin-detail-panel/index.tsx b/web/app/components/plugins/plugin-detail-panel/index.tsx index 6f99915c14..3444cc8d1a 100644 --- a/web/app/components/plugins/plugin-detail-panel/index.tsx +++ b/web/app/components/plugins/plugin-detail-panel/index.tsx @@ -1,7 +1,6 @@ 'use client' import React from 'react' import type { FC } from 'react' -import { useTranslation } from 'react-i18next' import type { EndpointListItem, InstalledPlugin } from '../types' import DetailHeader from './detail-header' import EndpointList from './endpoint-list' @@ -14,17 +13,15 @@ type Props = { pluginDetail: InstalledPlugin | undefined endpointList: EndpointListItem[] onHide: () => void + onDelete: () => void } const PluginDetailPanel: FC = ({ pluginDetail, endpointList = [], onHide, + onDelete, }) => { - const { t } = useTranslation() - - const handleDelete = () => {} - if (!pluginDetail) return null @@ -43,7 +40,7 @@ const PluginDetailPanel: FC = ({
{!!pluginDetail.declaration.endpoint && ( diff --git a/web/app/components/plugins/plugin-page/plugins-panel.tsx b/web/app/components/plugins/plugin-page/plugins-panel.tsx index 243e44d77d..862576d48f 100644 --- a/web/app/components/plugins/plugin-page/plugins-panel.tsx +++ b/web/app/components/plugins/plugin-page/plugins-panel.tsx @@ -12,6 +12,7 @@ import { useDebounceFn } from 'ahooks' const PluginsPanel = () => { const [filters, setFilters] = usePluginPageContext(v => [v.filters, v.setFilters]) const pluginList = usePluginPageContext(v => v.installedPluginList) as InstalledPlugin[] + const mutateInstalledPluginList = usePluginPageContext(v => v.mutateInstalledPluginList) const currentPluginDetail = usePluginPageContext(v => v.currentPluginDetail) const setCurrentPluginDetail = usePluginPageContext(v => v.setCurrentPluginDetail) @@ -50,7 +51,10 @@ const PluginsPanel = () => { endpointList={currentPluginEndpoints} onHide={() => { setCurrentPluginDetail(undefined) - setCurrentEndpoints([]) + }} + onDelete={() => { + setCurrentPluginDetail(undefined) + mutateInstalledPluginList() }} />