feat: fixing registry ts errors

This commit is contained in:
kozhuhds
2025-11-17 11:34:59 +01:00
parent 5d5bca4f31
commit e89c83028f
7 changed files with 28 additions and 1 deletions
@@ -14,6 +14,7 @@ import { ExtensionRegistriesProvider } from '../extensions/ExtensionRegistriesCo
import { AddedComponentsRegistry } from '../extensions/registry/AddedComponentsRegistry';
import { AddedFunctionsRegistry } from '../extensions/registry/AddedFunctionsRegistry';
import { AddedLinksRegistry } from '../extensions/registry/AddedLinksRegistry';
import { CommandPaletteDynamicRegistry } from '../extensions/registry/CommandPaletteDynamicRegistry';
import { ExposedComponentsRegistry } from '../extensions/registry/ExposedComponentsRegistry';
import { pluginImporter } from '../importer/pluginImporter';
import { getPluginSettings } from '../pluginSettings';
@@ -93,6 +94,7 @@ function renderUnderRouter(page = '') {
exposedComponentsRegistry: new ExposedComponentsRegistry(),
addedLinksRegistry: new AddedLinksRegistry(),
addedFunctionsRegistry: new AddedFunctionsRegistry(),
commandPaletteDynamicRegistry: new CommandPaletteDynamicRegistry(),
};
const pagePath = page ? `/${page}` : '';
const route = {
@@ -31,6 +31,7 @@ import {
useAddedComponentsRegistry,
useExposedComponentsRegistry,
useAddedFunctionsRegistry,
useCommandPaletteDynamicRegistry,
} from '../extensions/ExtensionRegistriesContext';
import { pluginImporter } from '../importer/pluginImporter';
import { getPluginSettings } from '../pluginSettings';
@@ -65,6 +66,7 @@ export function AppRootPage({ pluginId, pluginNavSection }: Props) {
const addedComponentsRegistry = useAddedComponentsRegistry();
const exposedComponentsRegistry = useExposedComponentsRegistry();
const addedFunctionsRegistry = useAddedFunctionsRegistry();
const commandPaletteDynamicRegistry = useCommandPaletteDynamicRegistry();
const location = useLocation();
const [state, dispatch] = useReducer(stateSlice.reducer, initialState);
const currentUrl = config.appSubUrl + location.pathname + location.search;
@@ -124,6 +126,7 @@ export function AppRootPage({ pluginId, pluginNavSection }: Props) {
addedComponentsRegistry: addedComponentsRegistry.readOnly(),
exposedComponentsRegistry: exposedComponentsRegistry.readOnly(),
addedFunctionsRegistry: addedFunctionsRegistry.readOnly(),
commandPaletteDynamicRegistry: commandPaletteDynamicRegistry.readOnly(),
}}
>
<plugin.root
@@ -3,6 +3,7 @@ import { PropsWithChildren, createContext, useContext } from 'react';
import { AddedComponentsRegistry } from 'app/features/plugins/extensions/registry/AddedComponentsRegistry';
import { AddedFunctionsRegistry } from 'app/features/plugins/extensions/registry/AddedFunctionsRegistry';
import { AddedLinksRegistry } from 'app/features/plugins/extensions/registry/AddedLinksRegistry';
import { CommandPaletteDynamicRegistry } from 'app/features/plugins/extensions/registry/CommandPaletteDynamicRegistry';
import { ExposedComponentsRegistry } from 'app/features/plugins/extensions/registry/ExposedComponentsRegistry';
import { PluginExtensionRegistries } from './registry/types';
@@ -16,6 +17,9 @@ export const AddedLinksRegistryContext = createContext<AddedLinksRegistry | unde
export const AddedComponentsRegistryContext = createContext<AddedComponentsRegistry | undefined>(undefined);
export const AddedFunctionsRegistryContext = createContext<AddedFunctionsRegistry | undefined>(undefined);
export const ExposedComponentsRegistryContext = createContext<ExposedComponentsRegistry | undefined>(undefined);
export const CommandPaletteDynamicRegistryContext = createContext<CommandPaletteDynamicRegistry | undefined>(
undefined
);
export function useAddedLinksRegistry(): AddedLinksRegistry {
const context = useContext(AddedLinksRegistryContext);
@@ -49,6 +53,14 @@ export function useExposedComponentsRegistry(): ExposedComponentsRegistry {
return context;
}
export function useCommandPaletteDynamicRegistry(): CommandPaletteDynamicRegistry {
const context = useContext(CommandPaletteDynamicRegistryContext);
if (!context) {
throw new Error('No `CommandPaletteDynamicRegistryContext` found.');
}
return context;
}
export const ExtensionRegistriesProvider = ({
registries,
children,
@@ -58,7 +70,9 @@ export const ExtensionRegistriesProvider = ({
<AddedComponentsRegistryContext.Provider value={registries.addedComponentsRegistry}>
<AddedFunctionsRegistryContext.Provider value={registries.addedFunctionsRegistry}>
<ExposedComponentsRegistryContext.Provider value={registries.exposedComponentsRegistry}>
{children}
<CommandPaletteDynamicRegistryContext.Provider value={registries.commandPaletteDynamicRegistry}>
{children}
</CommandPaletteDynamicRegistryContext.Provider>
</ExposedComponentsRegistryContext.Provider>
</AddedFunctionsRegistryContext.Provider>
</AddedComponentsRegistryContext.Provider>
@@ -9,6 +9,7 @@ import { resetLogMock } from './logs/testUtils';
import { AddedComponentsRegistry } from './registry/AddedComponentsRegistry';
import { AddedFunctionsRegistry } from './registry/AddedFunctionsRegistry';
import { AddedLinksRegistry } from './registry/AddedLinksRegistry';
import { CommandPaletteDynamicRegistry } from './registry/CommandPaletteDynamicRegistry';
import { ExposedComponentsRegistry } from './registry/ExposedComponentsRegistry';
import { PluginExtensionRegistries } from './registry/types';
import { useLoadAppPlugins } from './useLoadAppPlugins';
@@ -93,6 +94,7 @@ describe('usePluginComponent()', () => {
exposedComponentsRegistry: new ExposedComponentsRegistry(),
addedLinksRegistry: new AddedLinksRegistry(),
addedFunctionsRegistry: new AddedFunctionsRegistry(),
commandPaletteDynamicRegistry: new CommandPaletteDynamicRegistry(),
};
jest.mocked(useLoadAppPlugins).mockReturnValue({ isLoading: false });
jest.mocked(isGrafanaDevMode).mockReturnValue(false);
@@ -17,6 +17,7 @@ import { resetLogMock } from './logs/testUtils';
import { AddedComponentsRegistry } from './registry/AddedComponentsRegistry';
import { AddedFunctionsRegistry } from './registry/AddedFunctionsRegistry';
import { AddedLinksRegistry } from './registry/AddedLinksRegistry';
import { CommandPaletteDynamicRegistry } from './registry/CommandPaletteDynamicRegistry';
import { ExposedComponentsRegistry } from './registry/ExposedComponentsRegistry';
import { PluginExtensionRegistries } from './registry/types';
import { useLoadAppPlugins } from './useLoadAppPlugins';
@@ -74,6 +75,7 @@ describe('usePluginComponents()', () => {
exposedComponentsRegistry: new ExposedComponentsRegistry(),
addedLinksRegistry: new AddedLinksRegistry(),
addedFunctionsRegistry: new AddedFunctionsRegistry(),
commandPaletteDynamicRegistry: new CommandPaletteDynamicRegistry(),
};
pluginMeta = {
@@ -16,6 +16,7 @@ import { resetLogMock } from './logs/testUtils';
import { AddedComponentsRegistry } from './registry/AddedComponentsRegistry';
import { AddedFunctionsRegistry } from './registry/AddedFunctionsRegistry';
import { AddedLinksRegistry } from './registry/AddedLinksRegistry';
import { CommandPaletteDynamicRegistry } from './registry/CommandPaletteDynamicRegistry';
import { ExposedComponentsRegistry } from './registry/ExposedComponentsRegistry';
import { PluginExtensionRegistries } from './registry/types';
import { useLoadAppPlugins } from './useLoadAppPlugins';
@@ -67,6 +68,7 @@ describe('usePluginFunctions()', () => {
exposedComponentsRegistry: new ExposedComponentsRegistry(),
addedLinksRegistry: new AddedLinksRegistry(),
addedFunctionsRegistry: new AddedFunctionsRegistry(),
commandPaletteDynamicRegistry: new CommandPaletteDynamicRegistry(),
};
resetLogMock(log);
@@ -16,6 +16,7 @@ import { resetLogMock } from './logs/testUtils';
import { AddedComponentsRegistry } from './registry/AddedComponentsRegistry';
import { AddedFunctionsRegistry } from './registry/AddedFunctionsRegistry';
import { AddedLinksRegistry } from './registry/AddedLinksRegistry';
import { CommandPaletteDynamicRegistry } from './registry/CommandPaletteDynamicRegistry';
import { ExposedComponentsRegistry } from './registry/ExposedComponentsRegistry';
import { PluginExtensionRegistries } from './registry/types';
import { useLoadAppPlugins } from './useLoadAppPlugins';
@@ -67,6 +68,7 @@ describe('usePluginLinks()', () => {
exposedComponentsRegistry: new ExposedComponentsRegistry(),
addedLinksRegistry: new AddedLinksRegistry(),
addedFunctionsRegistry: new AddedFunctionsRegistry(),
commandPaletteDynamicRegistry: new CommandPaletteDynamicRegistry(),
};
resetLogMock(log);