From 0ff2f7f3cbd4d2097f1fa42077a8947f09223ac3 Mon Sep 17 00:00:00 2001 From: James Todd Date: Tue, 25 Aug 2026 00:00:39 +0100 Subject: [PATCH] PluginDrawer now fetches plugin details itself. (#12703) --- .../src/components/plugins/PluginDrawer.tsx | 67 ++++++++++++------- .../src/tables/plugin/PluginListTable.tsx | 12 ++-- 2 files changed, 49 insertions(+), 30 deletions(-) diff --git a/src/frontend/src/components/plugins/PluginDrawer.tsx b/src/frontend/src/components/plugins/PluginDrawer.tsx index a1f78215fa..b8286f432f 100644 --- a/src/frontend/src/components/plugins/PluginDrawer.tsx +++ b/src/frontend/src/components/plugins/PluginDrawer.tsx @@ -1,7 +1,7 @@ import { t } from '@lingui/core/macro'; import { Accordion, Alert, Card, Stack, Text } from '@mantine/core'; import { IconExclamationCircle } from '@tabler/icons-react'; -import { useMemo } from 'react'; +import { useEffect, useMemo } from 'react'; import { useParams } from 'react-router-dom'; import { StylishText } from '@lib/components/StylishText'; @@ -17,10 +17,10 @@ import PluginSettingsPanel from './PluginSettingsPanel'; */ export default function PluginDrawer({ pluginKey, - pluginInstance + onPluginLoaded }: Readonly<{ - pluginKey?: string; - pluginInstance: PluginInterface; + pluginKey: string; + onPluginLoaded?: (plugin: PluginInterface) => void; }>) { const { id } = useParams(); @@ -28,6 +28,15 @@ export default function PluginDrawer({ return pluginKey || id || ''; }, [pluginKey, id]); + const { + instance: plugin, + instanceQuery: { isFetching, error } + } = useInstance({ + endpoint: ApiEndpoints.plugin_list, + hasPrimaryKey: true, + pk: pluginPrimaryKey + }); + const { instance: pluginAdmin } = useInstance({ endpoint: ApiEndpoints.plugin_admin, pathParams: { key: pluginPrimaryKey }, @@ -36,11 +45,21 @@ export default function PluginDrawer({ refetchOnMount: true }); - const hasSettings: boolean = useMemo(() => { - return !!pluginInstance?.mixins?.settings; - }, [pluginInstance]); + useEffect(() => { + if (plugin) { + onPluginLoaded?.(plugin); + } + }, [plugin, onPluginLoaded]); - if (!pluginInstance.active) { + const hasSettings: boolean = useMemo(() => { + return !!plugin?.mixins?.settings; + }, [plugin]); + + if (isFetching || !plugin) { + return null; + } + + if (!plugin.active) { return ( - + - {pluginInstance?.meta.website && ( + {plugin?.meta.website && ( )} @@ -107,27 +122,27 @@ export default function PluginDrawer({ - {pluginInstance?.is_package && ( + {plugin?.is_package && ( )} diff --git a/src/frontend/src/tables/plugin/PluginListTable.tsx b/src/frontend/src/tables/plugin/PluginListTable.tsx index 9f3d2d7378..238b98fddb 100644 --- a/src/frontend/src/tables/plugin/PluginListTable.tsx +++ b/src/frontend/src/tables/plugin/PluginListTable.tsx @@ -151,7 +151,6 @@ export default function PluginListTable() { ]; }, []); - const [selectedPlugin, setSelectedPlugin] = useState({}); const [selectedPluginKey, setSelectedPluginKey] = useState(''); const [activate, setActivate] = useState(false); @@ -266,6 +265,7 @@ export default function PluginListTable() { ); const [pluginPackage, setPluginPackage] = useState(''); + const [pluginName, setPluginName] = useState(''); const activatePluginModal = useEditApiFormModal({ title: activate ? t`Activate Plugin` : t`Deactivate Plugin`, @@ -358,6 +358,10 @@ export default function PluginListTable() { }); }, []); + const handlePluginLoaded = useCallback((plugin: PluginInterface) => { + setPluginName(plugin.name); + }, []); + // Custom table actions const tableActions = useMemo(() => { if ( @@ -397,14 +401,15 @@ export default function PluginListTable() { {deletePluginModal.modal} {activatePluginModal.modal} { if (!pluginKey) return; + return ( ); }} @@ -417,7 +422,6 @@ export default function PluginListTable() { enableDownload: false, rowActions: rowActions, onRowClick: (plugin) => { - setSelectedPlugin(plugin); navigate(`${plugin.key}/`); }, tableActions: tableActions,