plugin detail delete handler
This commit is contained in:
parent
a387cfbc9a
commit
c37615cd33
@ -1,4 +1,4 @@
|
|||||||
import React, { useMemo } from 'react'
|
import React, { useCallback, useMemo } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useBoolean } from 'ahooks'
|
import { useBoolean } from 'ahooks'
|
||||||
import {
|
import {
|
||||||
@ -22,6 +22,7 @@ import Confirm from '@/app/components/base/confirm'
|
|||||||
import Tooltip from '@/app/components/base/tooltip'
|
import Tooltip from '@/app/components/base/tooltip'
|
||||||
import { BoxSparkleFill } from '@/app/components/base/icons/src/vender/plugin'
|
import { BoxSparkleFill } from '@/app/components/base/icons/src/vender/plugin'
|
||||||
import { Github } from '@/app/components/base/icons/src/public/common'
|
import { Github } from '@/app/components/base/icons/src/public/common'
|
||||||
|
import { uninstallPlugin } from '@/service/plugins'
|
||||||
import { useGetLanguage } from '@/context/i18n'
|
import { useGetLanguage } from '@/context/i18n'
|
||||||
import { API_PREFIX, MARKETPLACE_URL_PREFIX } from '@/config'
|
import { API_PREFIX, MARKETPLACE_URL_PREFIX } from '@/config'
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
@ -43,6 +44,7 @@ const DetailHeader = ({
|
|||||||
const locale = useGetLanguage()
|
const locale = useGetLanguage()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
installation_id,
|
||||||
source,
|
source,
|
||||||
tenant_id,
|
tenant_id,
|
||||||
version,
|
version,
|
||||||
@ -68,8 +70,23 @@ const DetailHeader = ({
|
|||||||
setFalse: hideDeleteConfirm,
|
setFalse: hideDeleteConfirm,
|
||||||
}] = useBoolean(false)
|
}] = 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
|
// #plugin TODO# used in apps
|
||||||
const usedInApps = 3
|
// const usedInApps = 3
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('shrink-0 p-4 pb-3 border-b border-divider-subtle bg-components-panel-bg')}>
|
<div className={cn('shrink-0 p-4 pb-3 border-b border-divider-subtle bg-components-panel-bg')}>
|
||||||
@ -147,11 +164,13 @@ const DetailHeader = ({
|
|||||||
content={
|
content={
|
||||||
<div>
|
<div>
|
||||||
{t(`${i18nPrefix}.deleteContentLeft`)}<span className='system-md-semibold'>{label[locale]}</span>{t(`${i18nPrefix}.deleteContentRight`)}<br />
|
{t(`${i18nPrefix}.deleteContentLeft`)}<span className='system-md-semibold'>{label[locale]}</span>{t(`${i18nPrefix}.deleteContentRight`)}<br />
|
||||||
{usedInApps > 0 && t(`${i18nPrefix}.usedInApps`, { num: usedInApps })}
|
{/* {usedInApps > 0 && t(`${i18nPrefix}.usedInApps`, { num: usedInApps })} */}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
onCancel={hideDeleteConfirm}
|
onCancel={hideDeleteConfirm}
|
||||||
onConfirm={onDelete}
|
onConfirm={handleDelete}
|
||||||
|
isLoading={deleting}
|
||||||
|
isDisabled={deleting}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
|
||||||
import type { EndpointListItem, InstalledPlugin } from '../types'
|
import type { EndpointListItem, InstalledPlugin } from '../types'
|
||||||
import DetailHeader from './detail-header'
|
import DetailHeader from './detail-header'
|
||||||
import EndpointList from './endpoint-list'
|
import EndpointList from './endpoint-list'
|
||||||
@ -14,17 +13,15 @@ type Props = {
|
|||||||
pluginDetail: InstalledPlugin | undefined
|
pluginDetail: InstalledPlugin | undefined
|
||||||
endpointList: EndpointListItem[]
|
endpointList: EndpointListItem[]
|
||||||
onHide: () => void
|
onHide: () => void
|
||||||
|
onDelete: () => void
|
||||||
}
|
}
|
||||||
|
|
||||||
const PluginDetailPanel: FC<Props> = ({
|
const PluginDetailPanel: FC<Props> = ({
|
||||||
pluginDetail,
|
pluginDetail,
|
||||||
endpointList = [],
|
endpointList = [],
|
||||||
onHide,
|
onHide,
|
||||||
|
onDelete,
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
|
||||||
|
|
||||||
const handleDelete = () => {}
|
|
||||||
|
|
||||||
if (!pluginDetail)
|
if (!pluginDetail)
|
||||||
return null
|
return null
|
||||||
|
|
||||||
@ -43,7 +40,7 @@ const PluginDetailPanel: FC<Props> = ({
|
|||||||
<DetailHeader
|
<DetailHeader
|
||||||
detail={pluginDetail}
|
detail={pluginDetail}
|
||||||
onHide={onHide}
|
onHide={onHide}
|
||||||
onDelete={handleDelete}
|
onDelete={onDelete}
|
||||||
/>
|
/>
|
||||||
<div className='grow overflow-y-auto'>
|
<div className='grow overflow-y-auto'>
|
||||||
{!!pluginDetail.declaration.endpoint && (
|
{!!pluginDetail.declaration.endpoint && (
|
||||||
|
@ -12,6 +12,7 @@ import { useDebounceFn } from 'ahooks'
|
|||||||
const PluginsPanel = () => {
|
const PluginsPanel = () => {
|
||||||
const [filters, setFilters] = usePluginPageContext(v => [v.filters, v.setFilters])
|
const [filters, setFilters] = usePluginPageContext(v => [v.filters, v.setFilters])
|
||||||
const pluginList = usePluginPageContext(v => v.installedPluginList) as InstalledPlugin[]
|
const pluginList = usePluginPageContext(v => v.installedPluginList) as InstalledPlugin[]
|
||||||
|
const mutateInstalledPluginList = usePluginPageContext(v => v.mutateInstalledPluginList)
|
||||||
const currentPluginDetail = usePluginPageContext(v => v.currentPluginDetail)
|
const currentPluginDetail = usePluginPageContext(v => v.currentPluginDetail)
|
||||||
const setCurrentPluginDetail = usePluginPageContext(v => v.setCurrentPluginDetail)
|
const setCurrentPluginDetail = usePluginPageContext(v => v.setCurrentPluginDetail)
|
||||||
|
|
||||||
@ -50,7 +51,10 @@ const PluginsPanel = () => {
|
|||||||
endpointList={currentPluginEndpoints}
|
endpointList={currentPluginEndpoints}
|
||||||
onHide={() => {
|
onHide={() => {
|
||||||
setCurrentPluginDetail(undefined)
|
setCurrentPluginDetail(undefined)
|
||||||
setCurrentEndpoints([])
|
}}
|
||||||
|
onDelete={() => {
|
||||||
|
setCurrentPluginDetail(undefined)
|
||||||
|
mutateInstalledPluginList()
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
Loading…
Reference in New Issue
Block a user