From 6174fbf67df317ed375f26f594aa6bae4c1508a8 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 7 Apr 2026 11:02:02 +0000 Subject: [PATCH] Expose global importer state to the plugin interface --- src/frontend/lib/types/Plugins.tsx | 10 ++++++++++ .../src/components/plugins/PluginContext.tsx | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/frontend/lib/types/Plugins.tsx b/src/frontend/lib/types/Plugins.tsx index cc10083b6e..840d695d6d 100644 --- a/src/frontend/lib/types/Plugins.tsx +++ b/src/frontend/lib/types/Plugins.tsx @@ -48,6 +48,13 @@ export type InvenTreeFormsContext = { stockActions: StockAdjustmentFormsContext; }; +export type ImporterDrawerContext = { + open: (sessionId: number, options?: { onClose?: () => void }) => void; + close: () => void; + isOpen: () => boolean; + sessionId: () => number | null; +}; + /** * A set of properties which are passed to a plugin, * for rendering an element in the user interface. @@ -59,6 +66,8 @@ export type InvenTreeFormsContext = { * @param globalSettings - The global settings (see ../states/SettingsState.tsx) * @param navigate - The navigation function (see react-router-dom) * @param theme - The current Mantine theme + * @param forms - A set of functions for opening various API forms (see ../components/Forms.tsx) + * @param importer - A set of functions for controlling the global importer drawer (see ../components/importer/GlobalImporterDrawer.tsx) * @param colorScheme - The current Mantine color scheme (e.g. 'light' / 'dark') * @param host - The current host URL * @param i18n - The i18n instance for translations (from @lingui/core) @@ -87,6 +96,7 @@ export type InvenTreePluginContext = { navigate: NavigateFunction; theme: MantineTheme; forms: InvenTreeFormsContext; + importer: ImporterDrawerContext; colorScheme: MantineColorScheme; model?: ModelType | string; id?: string | number | null; diff --git a/src/frontend/src/components/plugins/PluginContext.tsx b/src/frontend/src/components/plugins/PluginContext.tsx index 8ca6de68cb..d306db7d3f 100644 --- a/src/frontend/src/components/plugins/PluginContext.tsx +++ b/src/frontend/src/components/plugins/PluginContext.tsx @@ -36,6 +36,12 @@ import { useDeleteApiFormModal, useEditApiFormModal } from '../../hooks/UseForm'; +import { + type ImporterOpenOptions, + closeGlobalImporter, + getGlobalImporterState, + openGlobalImporter +} from '../../states/ImporterState'; import { useServerApiState } from '../../states/ServerApiState'; import { RenderInstance } from '../render/Instance'; @@ -70,6 +76,13 @@ export const useInvenTreeContext = () => { renderInstance: RenderInstance, theme: theme, colorScheme: colorScheme, + importer: { + open: (sessionId: number, options?: ImporterOpenOptions) => + openGlobalImporter(sessionId, options), + close: () => closeGlobalImporter(), + isOpen: () => getGlobalImporterState().isOpen, + sessionId: () => getGlobalImporterState().sessionId + }, forms: { bulkEdit: useBulkEditApiFormModal, create: useCreateApiFormModal,