Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat committed Oct 29, 2024
1 parent 5b4c861 commit bb5555f
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions src/frontend/src/hooks/UsePluginPanels.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { useQuery } from '@tanstack/react-query';
import { useEffect, useMemo, useState } from 'react';
import { useMemo } from 'react';

import { api } from '../App';
import { PanelType } from '../components/panels/Panel';
import {
InvenTreeContext,
useInvenTreeContext
} from '../components/plugins/PluginContext';
import PluginPanelContent, {
isPluginPanelHidden
} from '../components/plugins/PluginPanel';
import PluginPanelContent from '../components/plugins/PluginPanel';
import {
PluginUIFeature,
PluginUIFeatureType
Expand Down Expand Up @@ -87,34 +85,13 @@ export function usePluginPanels({
};
}, [model, id, instance]);

// Track which panels are hidden: { panelName: true/false }
// We need to memoize this as the plugins can determine this dynamically
const [panelState, setPanelState] = useState<Record<string, boolean>>({});

// Clear the visibility cache when the plugin data changes
// This will force the plugin panels to re-calculate their visibility
useEffect(() => {
pluginData?.forEach((props: PluginUIFeature) => {
const identifier = identifierString(`${props.plugin_name}-${props.key}`);

// Check if the panel is hidden (defaults to true until we know otherwise)
isPluginPanelHidden({
pluginFeature: props,
pluginContext: contextData
}).then((result) => {
setPanelState((prev) => ({ ...prev, [identifier]: result }));
});
});
}, [pluginData, contextData]);

const pluginPanels: PanelType[] = useMemo(() => {
return (
pluginData?.map((props: PluginUIFeature) => {
const iconName: string = props.options?.icon || 'plugin';
const identifier = identifierString(
`${props.plugin_name}-${props.key}`
);
const isHidden: boolean = panelState[identifier] ?? true;

const pluginContext: any = {
...contextData,
Expand All @@ -130,12 +107,11 @@ export function usePluginPanels({
pluginFeature={props}
pluginContext={pluginContext}
/>
),
hidden: isHidden
)
};
}) ?? []
);
}, [panelState, pluginData, contextData]);
}, [pluginData, contextData]);

return pluginPanels;
}

0 comments on commit bb5555f

Please sign in to comment.