From 4ed2773bb09c13a3367bfe9122a79ce1f1d303d6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 11 Aug 2024 07:00:06 +0000 Subject: [PATCH] Update hook to auto-magically load plugin panels --- .../src/components/nav/PanelGroup.tsx | 25 ++++++++++++++++--- src/frontend/src/hooks/UsePluginPanels.tsx | 18 ++++++++++--- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/frontend/src/components/nav/PanelGroup.tsx b/src/frontend/src/components/nav/PanelGroup.tsx index 383a2ae77f..c8bffe052d 100644 --- a/src/frontend/src/components/nav/PanelGroup.tsx +++ b/src/frontend/src/components/nav/PanelGroup.tsx @@ -20,8 +20,10 @@ import { useParams } from 'react-router-dom'; +import { ModelType } from '../../enums/ModelType'; import { identifierString } from '../../functions/conversion'; import { navigateToLink } from '../../functions/navigation'; +import { usePluginPanels } from '../../hooks/UsePluginPanels'; import { useLocalState } from '../../states/LocalState'; import { Boundary } from '../Boundary'; import { StylishText } from '../items/StylishText'; @@ -30,6 +32,8 @@ import { PanelType } from './Panel'; export type PanelProps = { pageKey: string; panels: PanelType[]; + targetModel?: ModelType | string; + targetId?: number; selectedPanel?: string; onPanelChange?: (panel: string) => void; collapsible?: boolean; @@ -40,15 +44,28 @@ function BasePanelGroup({ panels, onPanelChange, selectedPanel, + targetModel, + targetId, collapsible = true }: Readonly): ReactNode { const location = useLocation(); const navigate = useNavigate(); const { panel } = useParams(); + // Hook to load plugins for this panel + const pluginPanels = usePluginPanels({ + targetModel: targetModel, + targetId: targetId + }); + + const allPanels = useMemo( + () => [...panels, ...pluginPanels.panels], + [panels, pluginPanels.panels] + ); + const activePanels = useMemo( - () => panels.filter((panel) => !panel.hidden && !panel.disabled), - [panels] + () => allPanels.filter((panel) => !panel.hidden && !panel.disabled), + [allPanels] ); const setLastUsedPanel = useLocalState((state) => @@ -112,7 +129,7 @@ function BasePanelGroup({ keepMounted={false} > - {panels.map( + {allPanels.map( (panel) => !panel.hidden && ( )} - {panels.map( + {allPanels.map( (panel) => !panel.hidden && ( globalSettings.isSet('ENABLE_PLUGINS_INTERFACE'), + [globalSettings] + ); + const { isFetching, data } = useQuery({ + enabled: pluginPanelsEnabled && !!targetModel, queryKey: [targetModel, targetId], queryFn: () => { + console.log('Fetching plugin panels:', targetModel, targetId); + return api .get(apiUrl(ApiEndpoints.plugin_panel_list), { params: {