From 547e3d098e235785693a91220564d562e0d3485d Mon Sep 17 00:00:00 2001 From: Junyan Qin Date: Sun, 12 Oct 2025 19:57:42 +0800 Subject: [PATCH] perf: add component list in plugin detail dialog --- .../plugin-installed/PluginCardVO.ts | 0 .../plugin-installed/PluginComponentList.tsx | 75 +++++++++++++++++++ .../PluginInstalledComponent.tsx | 6 +- .../plugin-card/PluginCardComponent.tsx | 67 +++-------------- .../plugin-form/PluginForm.tsx | 12 +++ .../plugin-market/PluginMarketComponent.tsx | 0 .../PluginDetailDialog.tsx | 0 .../PluginMarketCardComponent.tsx | 0 .../plugin-market-card/PluginMarketCardVO.ts | 0 .../plugin-sort/PluginSortDialog.tsx | 0 web/src/app/home/plugins/page.tsx | 4 +- web/src/i18n/locales/en-US.ts | 8 +- web/src/i18n/locales/ja-JP.ts | 8 +- web/src/i18n/locales/zh-Hans.ts | 8 +- web/src/i18n/locales/zh-Hant.ts | 8 +- 15 files changed, 122 insertions(+), 74 deletions(-) rename web/src/app/home/plugins/{ => components}/plugin-installed/PluginCardVO.ts (100%) create mode 100644 web/src/app/home/plugins/components/plugin-installed/PluginComponentList.tsx rename web/src/app/home/plugins/{ => components}/plugin-installed/PluginInstalledComponent.tsx (97%) rename web/src/app/home/plugins/{ => components}/plugin-installed/plugin-card/PluginCardComponent.tsx (82%) rename web/src/app/home/plugins/{ => components}/plugin-installed/plugin-form/PluginForm.tsx (90%) rename web/src/app/home/plugins/{ => components}/plugin-market/PluginMarketComponent.tsx (100%) rename web/src/app/home/plugins/{ => components}/plugin-market/plugin-detail-dialog/PluginDetailDialog.tsx (100%) rename web/src/app/home/plugins/{ => components}/plugin-market/plugin-market-card/PluginMarketCardComponent.tsx (100%) rename web/src/app/home/plugins/{ => components}/plugin-market/plugin-market-card/PluginMarketCardVO.ts (100%) rename web/src/app/home/plugins/{ => components}/plugin-sort/PluginSortDialog.tsx (100%) diff --git a/web/src/app/home/plugins/plugin-installed/PluginCardVO.ts b/web/src/app/home/plugins/components/plugin-installed/PluginCardVO.ts similarity index 100% rename from web/src/app/home/plugins/plugin-installed/PluginCardVO.ts rename to web/src/app/home/plugins/components/plugin-installed/PluginCardVO.ts diff --git a/web/src/app/home/plugins/components/plugin-installed/PluginComponentList.tsx b/web/src/app/home/plugins/components/plugin-installed/PluginComponentList.tsx new file mode 100644 index 00000000..603599f8 --- /dev/null +++ b/web/src/app/home/plugins/components/plugin-installed/PluginComponentList.tsx @@ -0,0 +1,75 @@ +import { PluginComponent } from '@/app/infra/entities/plugin'; +import { TFunction } from 'i18next'; +import { Wrench, AudioWaveform, Hash } from 'lucide-react'; +import { Badge } from '@/components/ui/badge'; + +export default function PluginComponentList({ + components, + showComponentName, + showTitle, + useBadge, + t, +}: { + components: PluginComponent[]; + showComponentName: boolean; + showTitle: boolean; + useBadge: boolean; + t: TFunction; +}) { + const componentKindCount: Record = {}; + + for (const component of components) { + const kind = component.manifest.manifest.kind; + if (componentKindCount[kind]) { + componentKindCount[kind]++; + } else { + componentKindCount[kind] = 1; + } + } + + const kindIconMap: Record = { + Tool: , + EventListener: , + Command: , + }; + + const componentKindList = Object.keys(componentKindCount); + + return ( + <> + {showTitle &&
{t('plugins.componentsList')}
} + {componentKindList.length > 0 && ( + <> + {componentKindList.map((kind) => { + return ( + <> + {useBadge && ( + + {kindIconMap[kind]} + {showComponentName && + t('plugins.componentName.' + kind) + ' '} + {componentKindCount[kind]} + + )} + + {!useBadge && ( +
+ {kindIconMap[kind]} + {showComponentName && + t('plugins.componentName.' + kind) + ' '} + {componentKindCount[kind]} +
+ )} + + ); + })} + + )} + + {componentKindList.length === 0 &&
{t('plugins.noComponents')}
} + + ); +} diff --git a/web/src/app/home/plugins/plugin-installed/PluginInstalledComponent.tsx b/web/src/app/home/plugins/components/plugin-installed/PluginInstalledComponent.tsx similarity index 97% rename from web/src/app/home/plugins/plugin-installed/PluginInstalledComponent.tsx rename to web/src/app/home/plugins/components/plugin-installed/PluginInstalledComponent.tsx index 5581fc7a..77368a1a 100644 --- a/web/src/app/home/plugins/plugin-installed/PluginInstalledComponent.tsx +++ b/web/src/app/home/plugins/components/plugin-installed/PluginInstalledComponent.tsx @@ -1,9 +1,9 @@ 'use client'; import { useState, useEffect, forwardRef, useImperativeHandle } from 'react'; -import { PluginCardVO } from '@/app/home/plugins/plugin-installed/PluginCardVO'; -import PluginCardComponent from '@/app/home/plugins/plugin-installed/plugin-card/PluginCardComponent'; -import PluginForm from '@/app/home/plugins/plugin-installed/plugin-form/PluginForm'; +import { PluginCardVO } from '@/app/home/plugins/components/plugin-installed/PluginCardVO'; +import PluginCardComponent from '@/app/home/plugins/components/plugin-installed/plugin-card/PluginCardComponent'; +import PluginForm from '@/app/home/plugins/components/plugin-installed/plugin-form/PluginForm'; import styles from '@/app/home/plugins/plugins.module.css'; import { httpClient } from '@/app/infra/http/HttpClient'; import { diff --git a/web/src/app/home/plugins/plugin-installed/plugin-card/PluginCardComponent.tsx b/web/src/app/home/plugins/components/plugin-installed/plugin-card/PluginCardComponent.tsx similarity index 82% rename from web/src/app/home/plugins/plugin-installed/plugin-card/PluginCardComponent.tsx rename to web/src/app/home/plugins/components/plugin-installed/plugin-card/PluginCardComponent.tsx index a3e7596d..457ebdc3 100644 --- a/web/src/app/home/plugins/plugin-installed/plugin-card/PluginCardComponent.tsx +++ b/web/src/app/home/plugins/components/plugin-installed/plugin-card/PluginCardComponent.tsx @@ -1,21 +1,10 @@ -import { PluginCardVO } from '@/app/home/plugins/plugin-installed/PluginCardVO'; +import { PluginCardVO } from '@/app/home/plugins/components/plugin-installed/PluginCardVO'; import { useState } from 'react'; import { Badge } from '@/components/ui/badge'; import { useTranslation } from 'react-i18next'; -import { TFunction } from 'i18next'; -import { - AudioWaveform, - Wrench, - Hash, - BugIcon, - ExternalLink, - Ellipsis, - Trash, - ArrowUp, -} from 'lucide-react'; +import { BugIcon, ExternalLink, Ellipsis, Trash, ArrowUp } from 'lucide-react'; import { getCloudServiceClientSync } from '@/app/infra/http'; import { httpClient } from '@/app/infra/http/HttpClient'; -import { PluginComponent } from '@/app/infra/entities/plugin'; import { Button } from '@/components/ui/button'; import { DropdownMenu, @@ -23,49 +12,7 @@ import { DropdownMenuItem, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; - -function getComponentList(components: PluginComponent[], t: TFunction) { - const componentKindCount: Record = {}; - - for (const component of components) { - const kind = component.manifest.manifest.kind; - if (componentKindCount[kind]) { - componentKindCount[kind]++; - } else { - componentKindCount[kind] = 1; - } - } - - const kindIconMap: Record = { - Tool: , - EventListener: , - Command: , - }; - - const componentKindList = Object.keys(componentKindCount); - - return ( - <> -
{t('plugins.componentsList')}
- {componentKindList.length > 0 && ( - <> - {componentKindList.map((kind) => { - return ( -
- {kindIconMap[kind]} {componentKindCount[kind]} -
- ); - })} - - )} - - {componentKindList.length === 0 &&
{t('plugins.noComponents')}
} - - ); -} +import PluginComponentList from '@/app/home/plugins/components/plugin-installed/PluginComponentList'; export default function PluginCardComponent({ cardVO, @@ -180,7 +127,13 @@ export default function PluginCardComponent({
- {getComponentList(cardVO.components, t)} +
diff --git a/web/src/app/home/plugins/plugin-installed/plugin-form/PluginForm.tsx b/web/src/app/home/plugins/components/plugin-installed/plugin-form/PluginForm.tsx similarity index 90% rename from web/src/app/home/plugins/plugin-installed/plugin-form/PluginForm.tsx rename to web/src/app/home/plugins/components/plugin-installed/plugin-form/PluginForm.tsx index 09a79d2f..2a658f5f 100644 --- a/web/src/app/home/plugins/plugin-installed/plugin-form/PluginForm.tsx +++ b/web/src/app/home/plugins/components/plugin-installed/plugin-form/PluginForm.tsx @@ -7,6 +7,7 @@ import { Button } from '@/components/ui/button'; import { toast } from 'sonner'; import { extractI18nObject } from '@/i18n/I18nProvider'; import { useTranslation } from 'react-i18next'; +import PluginComponentList from '@/app/home/plugins/components/plugin-installed/PluginComponentList'; export default function PluginForm({ pluginAuthor, @@ -78,6 +79,17 @@ export default function PluginForm({ }, )} + +
+ +
+ {pluginInfo.manifest.manifest.spec.config.length > 0 && (