diff --git a/src/frontend/lib/types/Plugins.tsx b/src/frontend/lib/types/Plugins.tsx index 2038b1f297..bf8bc48c59 100644 --- a/src/frontend/lib/types/Plugins.tsx +++ b/src/frontend/lib/types/Plugins.tsx @@ -69,6 +69,12 @@ export type ImporterDrawerContext = { sessionId: () => number | null; }; +export type PreviewDrawerContext = { + open: (modelType: ModelType, instance: any) => void; + close: () => void; + isOpen: () => boolean; +}; + /** * A set of properties which are passed to a plugin, * for rendering an element in the user interface. @@ -90,6 +96,7 @@ export type ImporterDrawerContext = { * @param forms - A set of functions for opening various API forms (see ../components/Forms.tsx) * @param tables - A set of functions for rendering API tables * @param importer - A set of functions for controlling the global importer drawer (see ../components/importer/GlobalImporterDrawer.tsx) + * @param preview - A set of functions for controlling the global preview drawer (see ../components/previews/GlobalPreviewDrawer.tsx) * @param model - The model type associated with the rendered component (if applicable) * @param id - The ID (primary key) of the model instance for the plugin (if applicable) * @param instance - The model instance data (if available) @@ -125,6 +132,7 @@ export type InvenTreePluginContext = { }; tables: InvenTreeTablesContext; importer: ImporterDrawerContext; + preview: PreviewDrawerContext; model?: ModelType | string; id?: string | number | null; instance?: any; diff --git a/src/frontend/src/components/plugins/PluginContext.tsx b/src/frontend/src/components/plugins/PluginContext.tsx index e6790c4c49..fac14d4626 100644 --- a/src/frontend/src/components/plugins/PluginContext.tsx +++ b/src/frontend/src/components/plugins/PluginContext.tsx @@ -46,6 +46,11 @@ import { openGlobalImporter } from '../../states/ImporterState'; import { usePluginState } from '../../states/PluginState'; +import { + closeGlobalPreview, + getGlobalPreviewState, + openGlobalPreview +} from '../../states/PreviewDrawerState'; import { useServerApiState } from '../../states/ServerApiState'; import { InvenTreeTableInternal } from '../../tables/InvenTreeTable'; import { EditApiForm } from '../forms/ApiForm'; @@ -97,6 +102,11 @@ export const useInvenTreeContext = () => { isOpen: () => getGlobalImporterState().isOpen, sessionId: () => getGlobalImporterState().sessionId }, + preview: { + open: (modelType, instance) => openGlobalPreview(modelType, instance), + close: () => closeGlobalPreview(), + isOpen: () => getGlobalPreviewState().isOpen + }, tables: { renderTable: (props: InvenTreeTableRenderProps) => (