Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Add definePluginSlot and a reset registry to metabase/plugins (#81926)

Fraserecde907aff47
diff --git a/eslint.config.mjs b/eslint.config.mjs
index 04592318a00..fcba2392316 100644
--- a/eslint.config.mjs
+++ b/eslint.config.mjs
@@ -330,7 +330,6 @@ const configs = [
"metabase/no-color-literals": "error",
"metabase/valid-theme-tokens": "error",
"metabase/no-literal-metabase-strings": "error",
- "metabase/no-oss-reinitialize-import": "error",
"metabase/no-analytics-import-outside-analytics-files": "error",
"metabase/no-module-level-memoize": "error",
"metabase/no-direct-memoize-import": "error",
@@ -1277,6 +1276,26 @@ const configs = [
],
},
},
+ // ============================================
+ // PLUGIN SLOT DECLARATIONS
+ // ============================================
+ {
+ files: [
+ "frontend/src/**/*.{ts,tsx,js,jsx}",
+ "enterprise/frontend/src/**/*.{ts,tsx,js,jsx}",
+ ],
+ ignores: [
+ // metabase/api can't import metabase/plugins under the module rules, so PLUGIN_API is declared and reset by hand.
+ // This is temporary: once plugins can sit below api, the slot uses definePluginSlot and this exemption goes.
+ "frontend/src/metabase/api/client/request-handlers.ts",
+ // TODO(no-plugin-slot-outside-plugins-files): reinitialize() leaves these two alone until their modules adopt definePluginSlot.
+ "frontend/src/metabase/embedding/embedding-iframe-sdk/plugin.ts",
+ "frontend/src/embedding-sdk-bundle/store/auth/auth.ts",
+ ],
+ rules: {
+ "metabase/no-plugin-slot-outside-plugins-files": "error",
+ },
+ },
];
if (shouldLintCssModules) {
diff --git a/frontend/lint/eslint-plugin-metabase/index.js b/frontend/lint/eslint-plugin-metabase/index.js
index e2bab0426ad..67d7b7906a7 100644
--- a/frontend/lint/eslint-plugin-metabase/index.js
+++ b/frontend/lint/eslint-plugin-metabase/index.js
@@ -17,12 +17,12 @@ module.exports = {
"no-literal-metabase-strings": require("./rules/no-literal-metabase-strings"),
"no-locale-with-intl-functions": require("./rules/no-locale-with-intl-functions"),
"no-module-side-effects": require("./rules/no-module-side-effects"),
- "no-oss-reinitialize-import": require("./rules/no-oss-reinitialize-import"),
"no-unconditional-metabase-links-render": require("./rules/no-unconditional-metabase-links-render"),
"no-unordered-test-helpers": require("./rules/no-unordered-test-helpers"),
"no-unsafe-element-filtering": require("./rules/no-unsafe-element-filtering"),
"no-unscoped-text-selectors": require("./rules/no-unscoped-text-selectors"),
"no-analytics-import-outside-analytics-files": require("./rules/no-analytics-import-outside-analytics-files"),
+ "no-plugin-slot-outside-plugins-files": require("./rules/no-plugin-slot-outside-plugins-files"),
"no-unjustified-type-casts": require("./rules/no-unjustified-type-casts"),
"valid-theme-tokens": require("./rules/valid-theme-tokens"),
"no-module-level-memoize": require("./rules/no-module-level-memoize"),
diff --git a/frontend/lint/eslint-plugin-metabase/rules/no-oss-reinitialize-import.js b/frontend/lint/eslint-plugin-metabase/rules/no-oss-reinitialize-import.js
deleted file mode 100644
index fe14fab677b..00000000000
--- a/frontend/lint/eslint-plugin-metabase/rules/no-oss-reinitialize-import.js
+++ /dev/null
@@ -1,60 +0,0 @@
-/**
- * @fileoverview Rule to prevent importing reinitialize functions from OSS plugin files
- */
-
-//------------------------------------------------------------------------------
-// Rule Definition
-//------------------------------------------------------------------------------
-
-const ERROR_MESSAGE =
- 'Direct import of "reinitialize" from OSS plugin files is not allowed. Reinitializing all plugins at once from "metabase/plugins/index.ts" is the way.';
-
-module.exports = {
- meta: {
- type: "problem",
- docs: {
- description:
- "Disallow importing reinitialize functions from OSS plugin files",
- category: "Best Practices",
- recommended: true,
- },
- schema: [],
- messages: {
- noReinitializeImport: ERROR_MESSAGE,
- },
- },
- create(context) {
- const filename = context.filename;
-
- // Allow imports in the main plugins index file
- if (filename.endsWith("metabase/plugins/index.ts")) {
- return {};
- }
-
- return {
- ImportDeclaration(node) {
- const sourceValue = node.source.value;
-
- // Check if importing from an OSS plugin file
- if (
- typeof sourceValue === "string" &&
- sourceValue.startsWith("metabase/plugins/oss/")
- ) {
- // Check if importing 'reinitialize'
- const reinitializeImport = node.specifiers.find(
- (specifier) =>
- specifier.type === "ImportSpecifier" &&
- specifier.imported.name === "reinitialize",
- );
-
- if (reinitializeImport) {
- context.report({
- node: reinitializeImport,
- message: ERROR_MESSAGE,
- });
- }
- }
- },
- };
- },
-};
diff --git a/frontend/lint/eslint-plugin-metabase/rules/no-plugin-slot-outside-plugins-files.js b/frontend/lint/eslint-plugin-metabase/rules/no-plugin-slot-outside-plugins-files.js
new file mode 100644
index 00000000000..bf2c217d8cb
--- /dev/null
+++ b/frontend/lint/eslint-plugin-metabase/rules/no-plugin-slot-outside-plugins-files.js
@@ -0,0 +1,122 @@
+const path = require("path");
+
+const SLOT_NAME = /^PLUGIN_[A-Z0-9_]+$/;
+const SLOT_FACTORY = "definePluginSlot";
+const PLUGINS_FILE = /^plugins\.(ts|tsx|js|jsx)$/;
+
+module.exports = {
+ meta: {
+ type: "problem",
+ docs: {
+ description:
+ "Restrict plugin slot declarations, an exported `PLUGIN_*` binding or a use of `definePluginSlot`, to metabase/plugins/ and to a module's plugins.ts file or plugins/ directory",
+ category: "Best Practices",
+ recommended: true,
+ },
+ schema: [],
+ messages: {
+ slotDeclaration:
+ '`{{name}}` declares a plugin slot, which is only allowed in "metabase/plugins/" or in a module\'s "plugins.ts" file or "plugins/" directory. Declare the slot there and export it through the module\'s index.',
+ slotFactory:
+ '`definePluginSlot` may only be called in "metabase/plugins/" or in a module\'s "plugins.ts" file or "plugins/" directory. Declare the slot there and export it through the module\'s index.',
+ },
+ },
+ create(context) {
+ const filename = context.filename.replaceAll("\\", "/");
+ if (isPluginsFile(filename) || isUnderPluginsDirectory(filename)) {
+ return {};
+ }
+
+ return {
+ VariableDeclarator(node) {
+ if (isSlotDeclaration(node)) {
+ context.report({
+ node: node.id,
+ messageId: "slotDeclaration",
+ data: { name: node.id.name },
+ });
+ }
+ },
+ ExportSpecifier(node) {
+ if (
+ node.parent.source ||
+ node.parent.exportKind === "type" ||
+ node.exportKind === "type"
+ ) {
+ return;
+ }
+
+ const exportedName = node.exported.name ?? node.exported.value;
+ const name = SLOT_NAME.test(exportedName)
+ ? exportedName
+ : node.local.name;
+ if (!SLOT_NAME.test(name)) {
+ return;
+ }
+
+ const variable = context.sourceCode
+ .getScope(node)
+ .set.get(node.local.name);
+ // Imported bindings are re-exports, and directly exported declarations
+ // are already checked by VariableDeclarator.
+ if (
+ variable?.defs.some(
+ (definition) =>
+ definition.type === "Variable" &&
+ !isSlotDeclaration(definition.node),
+ )
+ ) {
+ context.report({
+ node,
+ messageId: "slotDeclaration",
+ data: { name },
+ });
+ }
+ },
+ ImportSpecifier(node) {
+ if (isSlotFactoryImport(node)) {
+ context.report({ node, messageId: "slotFactory" });
+ }
+ },
+ MemberExpression(node) {
+ if (isSlotFactoryAccess(node)) {
+ context.report({ node, messageId: "slotFactory" });
+ }
+ },
+ };
+ },
+};
+
+function isPluginsFile(filename) {
+ return PLUGINS_FILE.test(path.posix.basename(filename));
+}
+
+// Covers metabase/plugins/ itself as well as a module's plugins/ directory.
+function isUnderPluginsDirectory(filename) {
+ return path.posix.dirname(filename).split("/").includes("plugins");
+}
+
+// `export const PLUGIN_X = ...`, whatever the value is.
+function isSlotDeclaration(declarator) {
+ return (
+ declarator.id.type === "Identifier" &&
+ SLOT_NAME.test(declarator.id.name) &&
+ declarator.parent.parent.type === "ExportNamedDeclaration"
+ );
+}
+
+// `import { definePluginSlot }`, under any alias.
+function isSlotFactoryImport(specifier) {
+ const { imported } = specifier;
+ const name = imported.type === "Identifier" ? imported.name : imported.value;
+ return name === SLOT_FACTORY;
+}
+
+// `plugins.definePluginSlot(...)`, which is how a namespace import reaches the factory.
+function isSlotFactoryAccess(member) {
+ return (
+ !member.computed &&
+ member.property.type === "Identifier" &&
+ member.property.name === SLOT_FACTORY
+ );
+}
diff --git a/frontend/lint/tests/no-plugin-slot-outside-plugins-files.unit.spec.js b/frontend/lint/tests/no-plugin-slot-outside-plugins-files.unit.spec.js
new file mode 100644
index 00000000000..bffc9fe456d
--- /dev/null
+++ b/frontend/lint/tests/no-plugin-slot-outside-plugins-files.unit.spec.js
@@ -0,0 +1,251 @@
+import { RuleTester } from "eslint";
+import tseslint from "typescript-eslint";
+
+import rule from "../eslint-plugin-metabase/rules/no-plugin-slot-outside-plugins-files";
+
+const ruleTester = new RuleTester({
+ languageOptions: {
+ parser: tseslint.parser,
+ sourceType: "module",
+ },
+});
+
+const MODULE_FILE = "/repo/frontend/src/metabase/search/slots.ts";
+const MODULE_INDEX = "/repo/frontend/src/metabase/search/index.ts";
+const MODULE_PLUGINS_FILE = "/repo/frontend/src/metabase/search/plugins.ts";
+
+const SLOT_EXPORT = `export const PLUGIN_SEARCH = { isEnabled: () => false };`;
+const SLOT_FROM_FACTORY = `
+ import { definePluginSlot } from "metabase/plugins";
+ export const PLUGIN_SEARCH = definePluginSlot(() => ({}));
+`;
+
+const slotDeclaration = { messageId: "slotDeclaration" };
+const slotFactory = { messageId: "slotFactory" };
+
+const VALID_CASES = [
+ // Where a slot may be declared.
+ {
+ name: "slot under metabase/plugins/",
+ filename: "/repo/frontend/src/metabase/plugins/oss/search.ts",
+ code: `
+ import { definePluginSlot } from "../slot";
+ export const PLUGIN_SEARCH = definePluginSlot(() => ({}));
+ `,
+ },
+ {
+ name: "slot in a module's plugins.ts",
+ filename: MODULE_PLUGINS_FILE,
+ code: SLOT_FROM_FACTORY,
+ },
+ {
+ name: "slot in a module's plugins.tsx",
+ filename: "/repo/frontend/src/metabase/search/plugins.tsx",
+ code: SLOT_EXPORT,
+ },
+ {
+ name: "slot under a module's plugins/ directory",
+ filename: "/repo/frontend/src/metabase/querying/plugins/slots.ts",
+ code: SLOT_EXPORT,
+ },
+ {
+ name: "slot nested under a module's plugins/ directory",
+ filename: "/repo/frontend/src/metabase/querying/plugins/nested/slots.ts",
+ code: SLOT_EXPORT,
+ },
+ {
+ name: "slot in a plugins.ts under a Windows path",
+ filename: "C:\\repo\\frontend\\src\\metabase\\search\\plugins.ts",
+ code: SLOT_FROM_FACTORY,
+ },
+ // What is not a slot declaration.
+ {
+ name: "filling a slot",
+ filename:
+ "/repo/enterprise/frontend/src/metabase-enterprise/audit_app/index.ts",
+ code: `
+ import { PLUGIN_AUDIT } from "metabase/plugins";
+ Object.assign(PLUGIN_AUDIT, { isAiAuditingEnabled: true });
+ PLUGIN_AUDIT.getAiAuditingRoutes = () => null;
+ `,
+ },
+ {
+ name: "re-exporting a slot from a barrel",
+ filename: MODULE_INDEX,
+ code: `export { PLUGIN_SEARCH } from "./plugins";`,
+ },
+ {
+ name: "a PLUGIN_* type",
+ filename: MODULE_FILE,
+ code: `export type PLUGIN_SEARCH = { isEnabled: () => boolean };`,
+ },
+ {
+ name: "re-exporting an imported slot through a local export",
+ filename: MODULE_INDEX,
+ code: `
+ import { PLUGIN_SEARCH } from "./plugins";
+ export { PLUGIN_SEARCH };
+ `,
+ },
+ {
+ name: "re-exporting an imported slot under an alias",
+ filename: MODULE_INDEX,
+ code: `
+ import { PLUGIN_SEARCH as search } from "./plugins";
+ export { search as PLUGIN_SEARCH };
+ `,
+ },
+ {
+ name: "exporting a local type separately",
+ filename: MODULE_FILE,
+ code: `
+ type PLUGIN_SEARCH = { isEnabled: () => boolean };
+ export { PLUGIN_SEARCH };
+ `,
+ },
+ {
+ name: "exporting only the type of a local binding",
+ filename: MODULE_FILE,
+ code: `
+ const PLUGIN_SEARCH = {};
+ export type { PLUGIN_SEARCH };
+ export { type PLUGIN_SEARCH as Search };
+ `,
+ },
+ {
+ name: "a PLUGIN_* const that is not exported",
+ filename: MODULE_FILE,
+ code: `const PLUGIN_LOCAL = {};`,
+ },
+ {
+ name: "exports whose name is not PLUGIN_*",
+ filename: MODULE_FILE,
+ code: `
+ export const PLUGINS_LOADED = true;
+ export const pluginConfig = {};
+ `,
+ },
+ {
+ name: "other imports from metabase/plugins",
+ filename: MODULE_FILE,
+ code: `
+ import { PLUGIN_AUDIT, reinitialize } from "metabase/plugins";
+ import type { PluginAudit } from "metabase/plugins";
+ `,
+ },
+];
+
+const INVALID_CASES = [
+ {
+ name: "slot declared and exported separately",
+ filename: MODULE_FILE,
+ code: `const PLUGIN_SEARCH = {}; export { PLUGIN_SEARCH };`,
+ errors: [slotDeclaration],
+ },
+ {
+ name: "slot exported before its declaration",
+ filename: MODULE_FILE,
+ code: `export { PLUGIN_SEARCH }; const PLUGIN_SEARCH = {};`,
+ errors: [slotDeclaration],
+ },
+ {
+ name: "local binding exported as a slot",
+ filename: MODULE_FILE,
+ code: `const search = {}; export { search as PLUGIN_SEARCH };`,
+ errors: [slotDeclaration],
+ },
+ {
+ name: "slot exported under a different name",
+ filename: MODULE_FILE,
+ code: `const PLUGIN_SEARCH = {}; export { PLUGIN_SEARCH as search };`,
+ errors: [slotDeclaration],
+ },
+ {
+ name: "directly exported slot is only reported once",
+ filename: MODULE_FILE,
+ code: `export const PLUGIN_SEARCH = {}; export { PLUGIN_SEARCH as search };`,
+ errors: [slotDeclaration],
+ },
+ // A slot exported outside a plugins file.
+ {
+ name: "slot exported from a module file",
+ filename: MODULE_FILE,
+ code: SLOT_EXPORT,
+ errors: [slotDeclaration],
+ },
+ {
+ name: "slot exported from a module index",
+ filename: MODULE_INDEX,
+ code: SLOT_EXPORT,
+ errors: [slotDeclaration],
+ },
+ {
+ name: "slot exported with let",
+ filename: MODULE_FILE,
+ code: `export let PLUGIN_SEARCH = {};`,
+ errors: [slotDeclaration],
+ },
+ {
+ name: "slot exported with a type annotation",
+ filename: MODULE_FILE,
+ code: `export const PLUGIN_SEARCH: { isEnabled: () => boolean } = { isEnabled: () => false };`,
+ errors: [slotDeclaration],
+ },
+ {
+ name: "a plugin.ts file is not a plugins file",
+ filename: "/repo/frontend/src/metabase/embedding/plugin.ts",
+ code: SLOT_EXPORT,
+ errors: [slotDeclaration],
+ },
+ {
+ name: "a file name that only contains plugins is not a plugins file",
+ filename: "/repo/frontend/src/metabase/embedding/sdk-plugins.ts",
+ code: SLOT_EXPORT,
+ errors: [slotDeclaration],
+ },
+ {
+ name: "a directory name that only starts with plugins is not a plugins directory",
+ filename: "/repo/frontend/src/metabase/embedding/pluginsx/slots.ts",
+ code: SLOT_EXPORT,
+ errors: [slotDeclaration],
+ },
+ // The slot factory reached outside a plugins file.
+ {
+ name: "definePluginSlot imported",
+ filename: MODULE_FILE,
+ code: `import { definePluginSlot } from "metabase/plugins";`,
+ errors: [slotFactory],
+ },
+ {
+ name: "definePluginSlot imported under an alias",
+ filename: MODULE_FILE,
+ code: `import { definePluginSlot as defineSlot } from "metabase/plugins";`,
+ errors: [slotFactory],
+ },
+ {
+ name: "definePluginSlot imported by string name",
+ filename: MODULE_FILE,
+ code: `import { "definePluginSlot" as defineSlot } from "metabase/plugins";`,
+ errors: [slotFactory],
+ },
+ {
+ name: "definePluginSlot reached through a namespace import",
+ filename: MODULE_FILE,
+ code: `
+ import * as plugins from "metabase/plugins";
+ const slot = plugins.definePluginSlot(() => ({}));
+ `,
+ errors: [slotFactory],
+ },
+ {
+ name: "import and export reported separately",
+ filename: MODULE_FILE,
+ code: SLOT_FROM_FACTORY,
+ errors: [slotFactory, slotDeclaration],
+ },
+];
+
+ruleTester.run("no-plugin-slot-outside-plugins-files", rule, {
+ valid: VALID_CASES,
+ invalid: INVALID_CASES,
+});
diff --git a/frontend/src/metabase/plugins/index.ts b/frontend/src/metabase/plugins/index.ts
index b4399ef58c0..8cdcb6cbcf2 100644
--- a/frontend/src/metabase/plugins/index.ts
+++ b/frontend/src/metabase/plugins/index.ts
@@ -1,4 +1,3 @@
-// Re-export all plugins from OSS modules (excluding reinitialize functions to avoid conflicts)
export {
PLUGIN_AUDIT,
type InsightsLinkProps,
@@ -182,6 +181,7 @@ export { PLUGIN_SECURITY_CENTER } from "./oss/security-center";
export { PLUGIN_AI_CONTROLS, type AiControlsPlugin } from "./oss/ai-controls";
export { PLUGIN_SUPPORT } from "./oss/support";
export { PLUGIN_TENANTS } from "./oss/tenants";
+export { definePluginSlot } from "./slot";
// Re-export types that are used by other files
export type {
@@ -193,90 +193,16 @@ export type {
import { reinitializeRequestHandlers } from "metabase/api/client";
-import { reinitialize as reinitializeAiControls } from "./oss/ai-controls";
-import { reinitialize as reinitializeAudit } from "./oss/audit";
-import { reinitialize as reinitializeAuth } from "./oss/auth";
-import { reinitialize as reinitializeCaching } from "./oss/caching";
-import { reinitialize as reinitializeCollections } from "./oss/collections";
-import { reinitialize as reinitializeContentTranslation } from "./oss/content-translation";
-import { reinitialize as reinitializeContentVerification } from "./oss/content-verification";
-import { reinitialize as reinitializeCore } from "./oss/core";
-import { reinitialize as reinitializeCustomViz } from "./oss/custom-viz";
-import { reinitialize as reinitializeDataApps } from "./oss/data-apps";
-import { reinitialize as reinitializeDatabase } from "./oss/database";
-import { reinitialize as reinitializeDependencies } from "./oss/dependencies";
-import { reinitialize as reinitializeEmbedding } from "./oss/embedding";
-import { reinitialize as reinitializeEmbeddingIframeSdk } from "./oss/embedding-iframe-sdk";
-import { reinitialize as reinitializeEmbeddingIframeSdkSetup } from "./oss/embedding-iframe-sdk-setup";
-import { reinitialize as reinitializeEmbeddingSdk } from "./oss/embedding-sdk";
-import { reinitialize as reinitializeLibrary } from "./oss/library";
-import { reinitialize as reinitializeMetabot } from "./oss/metabot";
-import { reinitialize as reinitializeModelPersistence } from "./oss/model-persistence";
-import { reinitialize as reinitializeModeration } from "./oss/moderation";
-import { reinitialize as reinitializeMonitor } from "./oss/monitor";
-import { reinitialize as reinitializeMultiFactorAuth } from "./oss/multi-factor-auth";
-import { reinitialize as reinitializeNotificationsSdk } from "./oss/notifications-sdk";
-import { reinitialize as reinitializePermissions } from "./oss/permissions";
-import { reinitialize as reinitializeRemoteSync } from "./oss/remote-sync";
-import { reinitialize as reinitializeReplacement } from "./oss/replacement";
-import { reinitialize as reinitializeResourceDownloads } from "./oss/resource-downloads";
-import { reinitialize as reinitializeSchemaViewer } from "./oss/schema-viewer";
-import { reinitialize as reinitializeSecurityCenter } from "./oss/security-center";
-import { reinitialize as reinitializeSemanticSearch } from "./oss/semantic-search";
-import { reinitialize as reinitializeSettings } from "./oss/settings";
-import { reinitialize as reinitializeSmtpOverride } from "./oss/smtp-override";
-import { reinitialize as reinitializeSnippets } from "./oss/snippets";
-import { reinitialize as reinitializeSupport } from "./oss/support";
-import { reinitialize as reinitializeTenants } from "./oss/tenants";
-import { reinitialize as reinitializeTransforms } from "./oss/transforms";
-import { reinitialize as reinitializeUploadManagement } from "./oss/upload-management";
-import { reinitialize as reinitializeWhitelabel } from "./oss/whitelabel";
-import { reinitialize as reinitializeWritableConnection } from "./oss/writable-connection";
+import { resetPluginSlots } from "./slot";
+
/**
* Mostly for test purposes, reinitialize all plugins.
* You don't reinitialize plugins individually because some plugins depend on others,
* so reinitializing them all ensures that dependencies are correctly set up.
*/
export function reinitialize() {
- reinitializeNotificationsSdk();
-
- reinitializeAiControls();
+ resetPluginSlots();
+ // metabase/api can't import metabase/plugins under the module rules, so its slot is reset by hand.
+ // This is temporary: once plugins can sit below api, the slot uses definePluginSlot and this goes.
reinitializeRequestHandlers();
- reinitializeAudit();
- reinitializeAuth();
- reinitializeCaching();
- reinitializeCollections();
- reinitializeContentTranslation();
- reinitializeContentVerification();
- reinitializeCore();
- reinitializeCustomViz();
- reinitializeDataApps();
- reinitializeDatabase();
- reinitializeEmbedding();
- reinitializeEmbeddingIframeSdk();
- reinitializeEmbeddingIframeSdkSetup();
- reinitializeEmbeddingSdk();
- reinitializeLibrary();
- reinitializeMetabot();
- reinitializeModelPersistence();
- reinitializeModeration();
- reinitializeMonitor();
- reinitializeMultiFactorAuth();
- reinitializePermissions();
- reinitializeRemoteSync();
- reinitializeReplacement();
- reinitializeResourceDownloads();
- reinitializeSchemaViewer();
- reinitializeSecurityCenter();
- reinitializeSemanticSearch();
- reinitializeSettings();
- reinitializeSmtpOverride();
- reinitializeSnippets();
- reinitializeSupport();
- reinitializeTenants();
- reinitializeDependencies();
- reinitializeTransforms();
- reinitializeUploadManagement();
- reinitializeWhitelabel();
- reinitializeWritableConnection();
}
diff --git a/frontend/src/metabase/plugins/oss/ai-controls.ts b/frontend/src/metabase/plugins/oss/ai-controls.ts
index b6009db7c43..50e52107a93 100644
--- a/frontend/src/metabase/plugins/oss/ai-controls.ts
+++ b/frontend/src/metabase/plugins/oss/ai-controls.ts
@@ -1,5 +1,7 @@
import type { ReactNode } from "react";
+import { definePluginSlot } from "../slot";
+
export type AiControlsPlugin = {
isEnabled: boolean;
getAiControlsRoutes: () => ReactNode;
@@ -12,11 +14,4 @@ const getDefaultPluginAiControls = (): AiControlsPlugin => ({
getAiControlsNavItems: () => null,
});
-export const PLUGIN_AI_CONTROLS = getDefaultPluginAiControls();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_AI_CONTROLS, getDefaultPluginAiControls());
-}
+export const PLUGIN_AI_CONTROLS = definePluginSlot(getDefaultPluginAiControls);
diff --git a/frontend/src/metabase/plugins/oss/audit.ts b/frontend/src/metabase/plugins/oss/audit.ts
index 660298dfc4f..56efa539bdf 100644
--- a/frontend/src/metabase/plugins/oss/audit.ts
+++ b/frontend/src/metabase/plugins/oss/audit.ts
@@ -12,6 +12,8 @@ import type {
IconName,
} from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
export type MetabotSlashCommandHandler = (args: {
command: SlashCommand;
conversationId: string;
@@ -51,11 +53,4 @@ const getDefaultPluginAudit = () => ({
handleMetabotSlashCommand: ((_args) => false) as MetabotSlashCommandHandler,
});
-export const PLUGIN_AUDIT = getDefaultPluginAudit();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_AUDIT, getDefaultPluginAudit());
-}
+export const PLUGIN_AUDIT = definePluginSlot(getDefaultPluginAudit);
diff --git a/frontend/src/metabase/plugins/oss/auth.ts b/frontend/src/metabase/plugins/oss/auth.ts
index 657c4795e11..5e03bd491b8 100644
--- a/frontend/src/metabase/plugins/oss/auth.ts
+++ b/frontend/src/metabase/plugins/oss/auth.ts
@@ -6,6 +6,7 @@ import {
} from "metabase/plugins/components/PluginPlaceholder";
import type { User, UserId } from "metabase-types/api";
+import { definePluginSlot } from "../slot";
import type { GetAuthProviders } from "../types";
export type AuthSettingsPageTab =
@@ -28,18 +29,24 @@ const getDefaultPluginAuthProviders = () => ({
providers: [] as GetAuthProviders[],
});
-export const PLUGIN_AUTH_PROVIDERS = getDefaultPluginAuthProviders();
+export const PLUGIN_AUTH_PROVIDERS = definePluginSlot(
+ getDefaultPluginAuthProviders,
+);
const getDefaultPluginLdapFormFields = () => ({
LdapUserProvisioning: PluginPlaceholder,
LdapGroupMembershipFilter: PluginPlaceholder,
});
-export const PLUGIN_LDAP_FORM_FIELDS = getDefaultPluginLdapFormFields();
+export const PLUGIN_LDAP_FORM_FIELDS = definePluginSlot(
+ getDefaultPluginLdapFormFields,
+);
const getDefaultPluginIsPasswordUser = (): ((user: User) => boolean)[] => [];
-export const PLUGIN_IS_PASSWORD_USER = getDefaultPluginIsPasswordUser();
+export const PLUGIN_IS_PASSWORD_USER = definePluginSlot(
+ getDefaultPluginIsPasswordUser,
+);
const getDefaultPluginAdminUserFormFields = (): {
FormLoginAttributes: ComponentType<{ userId?: UserId | null }>;
@@ -47,19 +54,6 @@ const getDefaultPluginAdminUserFormFields = (): {
FormLoginAttributes: PluginPlaceholder,
});
-export const PLUGIN_ADMIN_USER_FORM_FIELDS =
- getDefaultPluginAdminUserFormFields();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_AUTH_PROVIDERS, getDefaultPluginAuthProviders());
- Object.assign(PLUGIN_LDAP_FORM_FIELDS, getDefaultPluginLdapFormFields());
- PLUGIN_IS_PASSWORD_USER.length = 0;
- PLUGIN_IS_PASSWORD_USER.push(...getDefaultPluginIsPasswordUser());
- Object.assign(
- PLUGIN_ADMIN_USER_FORM_FIELDS,
- getDefaultPluginAdminUserFormFields(),
- );
-}
+export const PLUGIN_ADMIN_USER_FORM_FIELDS = definePluginSlot(
+ getDefaultPluginAdminUserFormFields,
+);
diff --git a/frontend/src/metabase/plugins/oss/caching.ts b/frontend/src/metabase/plugins/oss/caching.ts
index c76663af7cf..58bd8380144 100644
--- a/frontend/src/metabase/plugins/oss/caching.ts
+++ b/frontend/src/metabase/plugins/oss/caching.ts
@@ -13,6 +13,8 @@ import type {
CardId,
} from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
// Types
export type StrategyLabel =
@@ -191,11 +193,4 @@ const getDefaultPluginCaching = () => ({
PluginPlaceholder as ComponentType<MetricCachingModalProps>,
});
-export const PLUGIN_CACHING = getDefaultPluginCaching();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_CACHING, getDefaultPluginCaching());
-}
+export const PLUGIN_CACHING = definePluginSlot(getDefaultPluginCaching);
diff --git a/frontend/src/metabase/plugins/oss/collections.ts b/frontend/src/metabase/plugins/oss/collections.ts
index 6e0efd15cd6..648f54e6ccb 100644
--- a/frontend/src/metabase/plugins/oss/collections.ts
+++ b/frontend/src/metabase/plugins/oss/collections.ts
@@ -17,6 +17,8 @@ import type {
CollectionId,
} from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
// Types
export type ItemWithCollection = { collection: CollectionEssentials };
@@ -100,7 +102,7 @@ const getDefaultPluginCollections = () => ({
}) => JSX.Element | null,
});
-export const PLUGIN_COLLECTIONS = getDefaultPluginCollections();
+export const PLUGIN_COLLECTIONS = definePluginSlot(getDefaultPluginCollections);
const getDefaultPluginCollectionComponents = () => ({
CollectionAuthorityLevelIcon:
@@ -117,16 +119,6 @@ const getDefaultPluginCollectionComponents = () => ({
PluginPlaceholder as ComponentType<CollectionAuthorityLevelDisplayProps>,
});
-export const PLUGIN_COLLECTION_COMPONENTS =
- getDefaultPluginCollectionComponents();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_COLLECTIONS, getDefaultPluginCollections());
- Object.assign(
- PLUGIN_COLLECTION_COMPONENTS,
- getDefaultPluginCollectionComponents(),
- );
-}
+export const PLUGIN_COLLECTION_COMPONENTS = definePluginSlot(
+ getDefaultPluginCollectionComponents,
+);
diff --git a/frontend/src/metabase/plugins/oss/content-translation.ts b/frontend/src/metabase/plugins/oss/content-translation.ts
index be8acadc659..78c5c9d4fd0 100644
--- a/frontend/src/metabase/plugins/oss/content-translation.ts
+++ b/frontend/src/metabase/plugins/oss/content-translation.ts
@@ -8,6 +8,8 @@ import { PluginPlaceholder } from "metabase/plugins/components/PluginPlaceholder
import type { HoveredObject } from "metabase/viz-core";
import type { EntityToken } from "metabase-types/api/entity";
+import { definePluginSlot } from "../slot";
+
const getDefaultPluginContentTranslation = () => ({
isEnabled: false,
// Unjustified type cast. FIXME
@@ -40,14 +42,6 @@ const getDefaultPluginContentTranslation = () => ({
a.localeCompare(b),
});
-export const PLUGIN_CONTENT_TRANSLATION = getDefaultPluginContentTranslation();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(
- PLUGIN_CONTENT_TRANSLATION,
- getDefaultPluginContentTranslation(),
- );
-}
+export const PLUGIN_CONTENT_TRANSLATION = definePluginSlot(
+ getDefaultPluginContentTranslation,
+);
diff --git a/frontend/src/metabase/plugins/oss/content-verification.ts b/frontend/src/metabase/plugins/oss/content-verification.ts
index 41aa79fdaf3..b703e59e1ed 100644
--- a/frontend/src/metabase/plugins/oss/content-verification.ts
+++ b/frontend/src/metabase/plugins/oss/content-verification.ts
@@ -2,6 +2,8 @@ import type { SearchFilterComponent } from "metabase/common/search/types";
import type { State } from "metabase/redux/store";
import type { CollectionEssentials } from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
export type ModelFilterControlsProps = any;
export type ModelFilterSettings = {
verified: boolean;
@@ -32,15 +34,6 @@ const getDefaultPluginContentVerification = () => ({
MetricFilterControls: (_props: MetricFilterControlsProps) => null,
});
-export const PLUGIN_CONTENT_VERIFICATION =
- getDefaultPluginContentVerification();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(
- PLUGIN_CONTENT_VERIFICATION,
- getDefaultPluginContentVerification(),
- );
-}
+export const PLUGIN_CONTENT_VERIFICATION = definePluginSlot(
+ getDefaultPluginContentVerification,
+);
diff --git a/frontend/src/metabase/plugins/oss/core.ts b/frontend/src/metabase/plugins/oss/core.ts
index 1df5c2f66d6..cc52a145aea 100644
--- a/frontend/src/metabase/plugins/oss/core.ts
+++ b/frontend/src/metabase/plugins/oss/core.ts
@@ -7,6 +7,8 @@ import type { AdminPathKey, State } from "metabase/redux/store";
import type { UiParameter } from "metabase-lib/v1/parameters/types";
import type { Dashboard, DraftDashboardSubscription } from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
import type {
SnippetSidebarContext,
SnippetSidebarMenuOption,
@@ -45,7 +47,9 @@ const getLoadingMessage = (isSlow: boolean | undefined = false) =>
const getDefaultAppInitFunctions = (): (() => void)[] => [];
-export const PLUGIN_APP_INIT_FUNCTIONS = getDefaultAppInitFunctions();
+export const PLUGIN_APP_INIT_FUNCTIONS = definePluginSlot(
+ getDefaultAppInitFunctions,
+);
const getDefaultLandingPage = () => ({
getLandingPage: () => "/",
@@ -53,7 +57,7 @@ const getDefaultLandingPage = () => ({
export const PLUGIN_LANDING_PAGE: {
getLandingPage: () => string | null | undefined;
-} = getDefaultLandingPage();
+} = definePluginSlot(getDefaultLandingPage);
const getDefaultHomepageSetting = () => ({
CustomUrlOption: null,
@@ -61,7 +65,7 @@ const getDefaultHomepageSetting = () => ({
export const PLUGIN_HOMEPAGE_SETTING: {
CustomUrlOption: { label: string; Control: ComponentType } | null;
-} = getDefaultHomepageSetting();
+} = definePluginSlot(getDefaultHomepageSetting);
// dispatch is typed as thunk-capable so EE middlewares can dispatch async thunks
const getDefaultReduxMiddlewares = (): Middleware<
@@ -70,18 +74,23 @@ const getDefaultReduxMiddlewares = (): Middleware<
ThunkDispatch<State, unknown, Action>
>[] => [];
-export const PLUGIN_REDUX_MIDDLEWARES = getDefaultReduxMiddlewares();
+export const PLUGIN_REDUX_MIDDLEWARES = definePluginSlot(
+ getDefaultReduxMiddlewares,
+);
const getDefaultLogoIconComponents = (): ComponentType[] => [];
-export const PLUGIN_LOGO_ICON_COMPONENTS = getDefaultLogoIconComponents();
+export const PLUGIN_LOGO_ICON_COMPONENTS = definePluginSlot(
+ getDefaultLogoIconComponents,
+);
const getDefaultAdminAllowedPathGetters = (): ((
user: any,
) => AdminPathKey[])[] => [];
-export const PLUGIN_ADMIN_ALLOWED_PATH_GETTERS =
- getDefaultAdminAllowedPathGetters();
+export const PLUGIN_ADMIN_ALLOWED_PATH_GETTERS = definePluginSlot(
+ getDefaultAdminAllowedPathGetters,
+);
const getDefaultSelectors = () => ({
canWhitelabel: (_state: State) => false,
@@ -104,11 +113,11 @@ const getDefaultSelectors = () => ({
},
});
-export const PLUGIN_SELECTORS = getDefaultSelectors();
+export const PLUGIN_SELECTORS = definePluginSlot(getDefaultSelectors);
const getDefaultFormWidgets = (): Record<string, ComponentType<any>> => ({});
-export const PLUGIN_FORM_WIDGETS = getDefaultFormWidgets();
+export const PLUGIN_FORM_WIDGETS = definePluginSlot(getDefaultFormWidgets);
const getDefaultSnippetSidebarPlusMenuOptions = (): ((
snippetSidebar: SnippetSidebarContext,
@@ -122,12 +131,15 @@ const getDefaultSnippetSidebarHeaderButtons = (): ((
opts: { className?: string },
) => ReactNode)[] => [];
-export const PLUGIN_SNIPPET_SIDEBAR_PLUS_MENU_OPTIONS =
- getDefaultSnippetSidebarPlusMenuOptions();
-export const PLUGIN_SNIPPET_SIDEBAR_ROW_RENDERERS =
- getDefaultSnippetSidebarRowRenderers();
-export const PLUGIN_SNIPPET_SIDEBAR_HEADER_BUTTONS =
- getDefaultSnippetSidebarHeaderButtons();
+export const PLUGIN_SNIPPET_SIDEBAR_PLUS_MENU_OPTIONS = definePluginSlot(
+ getDefaultSnippetSidebarPlusMenuOptions,
+);
+export const PLUGIN_SNIPPET_SIDEBAR_ROW_RENDERERS = definePluginSlot(
+ getDefaultSnippetSidebarRowRenderers,
+);
+export const PLUGIN_SNIPPET_SIDEBAR_HEADER_BUTTONS = definePluginSlot(
+ getDefaultSnippetSidebarHeaderButtons,
+);
const getDefaultDashboardSubscriptionParametersSectionOverride =
(): PluginDashboardSubscriptionParametersSectionOverride => ({
@@ -135,7 +147,7 @@ const getDefaultDashboardSubscriptionParametersSectionOverride =
});
export const PLUGIN_DASHBOARD_SUBSCRIPTION_PARAMETERS_SECTION_OVERRIDE =
- getDefaultDashboardSubscriptionParametersSectionOverride();
+ definePluginSlot(getDefaultDashboardSubscriptionParametersSectionOverride);
const getDefaultReducers = () => ({
advancedPermissionsPlugin: () => null,
@@ -153,57 +165,10 @@ export const PLUGIN_REDUCERS: {
shared: any;
documents: any;
remoteSyncPlugin: any;
-} = getDefaultReducers();
+} = definePluginSlot(getDefaultReducers);
const getDefaultIsEeBuild = () => ({
isEEBuild: () => false,
});
-export const PLUGIN_IS_EE_BUILD = getDefaultIsEeBuild();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- PLUGIN_APP_INIT_FUNCTIONS.length = 0;
- PLUGIN_APP_INIT_FUNCTIONS.push(...getDefaultAppInitFunctions());
-
- Object.assign(PLUGIN_LANDING_PAGE, getDefaultLandingPage());
- Object.assign(PLUGIN_HOMEPAGE_SETTING, getDefaultHomepageSetting());
-
- PLUGIN_REDUX_MIDDLEWARES.length = 0;
- PLUGIN_REDUX_MIDDLEWARES.push(...getDefaultReduxMiddlewares());
-
- PLUGIN_LOGO_ICON_COMPONENTS.length = 0;
- PLUGIN_LOGO_ICON_COMPONENTS.push(...getDefaultLogoIconComponents());
-
- PLUGIN_ADMIN_ALLOWED_PATH_GETTERS.length = 0;
- PLUGIN_ADMIN_ALLOWED_PATH_GETTERS.push(
- ...getDefaultAdminAllowedPathGetters(),
- );
-
- Object.assign(PLUGIN_SELECTORS, getDefaultSelectors());
- Object.assign(PLUGIN_FORM_WIDGETS, getDefaultFormWidgets());
-
- PLUGIN_SNIPPET_SIDEBAR_PLUS_MENU_OPTIONS.length = 0;
- PLUGIN_SNIPPET_SIDEBAR_PLUS_MENU_OPTIONS.push(
- ...getDefaultSnippetSidebarPlusMenuOptions(),
- );
-
- Object.assign(
- PLUGIN_SNIPPET_SIDEBAR_ROW_RENDERERS,
- getDefaultSnippetSidebarRowRenderers(),
- );
-
- PLUGIN_SNIPPET_SIDEBAR_HEADER_BUTTONS.length = 0;
- PLUGIN_SNIPPET_SIDEBAR_HEADER_BUTTONS.push(
- ...getDefaultSnippetSidebarHeaderButtons(),
- );
-
- Object.assign(
- PLUGIN_DASHBOARD_SUBSCRIPTION_PARAMETERS_SECTION_OVERRIDE,
- getDefaultDashboardSubscriptionParametersSectionOverride(),
- );
- Object.assign(PLUGIN_REDUCERS, getDefaultReducers());
- Object.assign(PLUGIN_IS_EE_BUILD, getDefaultIsEeBuild());
-}
+export const PLUGIN_IS_EE_BUILD = definePluginSlot(getDefaultIsEeBuild);
diff --git a/frontend/src/metabase/plugins/oss/custom-viz.ts b/frontend/src/metabase/plugins/oss/custom-viz.ts
index f0310d9903f..18aa1f0fae6 100644
--- a/frontend/src/metabase/plugins/oss/custom-viz.ts
+++ b/frontend/src/metabase/plugins/oss/custom-viz.ts
@@ -13,6 +13,8 @@ import type {
} from "metabase-types/api";
import { isCustomVizDisplay } from "metabase-types/guards";
+import { definePluginSlot } from "../slot";
+
export type LoadCustomVizPluginForDisplayResult =
| { status: "loaded"; display: VisualizationDisplay }
| { status: "unavailable" }
@@ -95,11 +97,4 @@ const getDefaultPluginCustomViz = () => ({
}>,
});
-export const PLUGIN_CUSTOM_VIZ = getDefaultPluginCustomViz();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_CUSTOM_VIZ, getDefaultPluginCustomViz());
-}
+export const PLUGIN_CUSTOM_VIZ = definePluginSlot(getDefaultPluginCustomViz);
diff --git a/frontend/src/metabase/plugins/oss/data-apps.ts b/frontend/src/metabase/plugins/oss/data-apps.ts
index e2b6ae3dddd..8a104ef466a 100644
--- a/frontend/src/metabase/plugins/oss/data-apps.ts
+++ b/frontend/src/metabase/plugins/oss/data-apps.ts
@@ -2,6 +2,8 @@ import type { ComponentType, ReactNode } from "react";
import { PluginPlaceholder } from "metabase/plugins/components/PluginPlaceholder";
+import { definePluginSlot } from "../slot";
+
export type DataAppsPlugin = {
isEnabled: boolean;
getRoutes: () => ReactNode | null;
@@ -16,11 +18,6 @@ const getDefaultPluginDataApps = (): DataAppsPlugin => ({
MainNavbarSection: PluginPlaceholder,
});
-export const PLUGIN_DATA_APPS: DataAppsPlugin = getDefaultPluginDataApps();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_DATA_APPS, getDefaultPluginDataApps());
-}
+export const PLUGIN_DATA_APPS: DataAppsPlugin = definePluginSlot(
+ getDefaultPluginDataApps,
+);
diff --git a/frontend/src/metabase/plugins/oss/database.ts b/frontend/src/metabase/plugins/oss/database.ts
index e6ed955443a..5bb85253d4f 100644
--- a/frontend/src/metabase/plugins/oss/database.ts
+++ b/frontend/src/metabase/plugins/oss/database.ts
@@ -10,6 +10,8 @@ import type {
TableId,
} from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
const getDefaultPluginDbRouting = () => ({
// Unjustified type cast. FIXME
DatabaseRoutingSection: PluginPlaceholder as ComponentType<{
@@ -27,7 +29,7 @@ const getDefaultPluginDbRouting = () => ({
): "default" | "hidden" | "disabled" => "default",
});
-export const PLUGIN_DB_ROUTING = getDefaultPluginDbRouting();
+export const PLUGIN_DB_ROUTING = definePluginSlot(getDefaultPluginDbRouting);
const getDefaultPluginDatabaseReplication = () => ({
// Unjustified type cast. FIXME
@@ -36,8 +38,9 @@ const getDefaultPluginDatabaseReplication = () => ({
}>,
});
-export const PLUGIN_DATABASE_REPLICATION =
- getDefaultPluginDatabaseReplication();
+export const PLUGIN_DATABASE_REPLICATION = definePluginSlot(
+ getDefaultPluginDatabaseReplication,
+);
const getDefaultPluginTableEditing = () => ({
isEnabled: () => false,
@@ -55,16 +58,6 @@ const getDefaultPluginTableEditing = () => ({
}>,
});
-export const PLUGIN_TABLE_EDITING = getDefaultPluginTableEditing();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_DB_ROUTING, getDefaultPluginDbRouting());
- Object.assign(
- PLUGIN_DATABASE_REPLICATION,
- getDefaultPluginDatabaseReplication(),
- );
- Object.assign(PLUGIN_TABLE_EDITING, getDefaultPluginTableEditing());
-}
+export const PLUGIN_TABLE_EDITING = definePluginSlot(
+ getDefaultPluginTableEditing,
+);
diff --git a/frontend/src/metabase/plugins/oss/dependencies.ts b/frontend/src/metabase/plugins/oss/dependencies.ts
index 0b413931204..c5ad7ebf8a1 100644
--- a/frontend/src/metabase/plugins/oss/dependencies.ts
+++ b/frontend/src/metabase/plugins/oss/dependencies.ts
@@ -4,6 +4,8 @@ import { createContext } from "react";
import { PluginPlaceholder } from "metabase/plugins/components/PluginPlaceholder";
import type { GetDependencyGraphRequest } from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
// Types
export type DependencyGraphPageContextType = {
baseUrl?: string;
@@ -32,11 +34,6 @@ const getDefaultPluginDependencies = (): DependenciesPlugin => ({
}),
});
-export const PLUGIN_DEPENDENCIES = getDefaultPluginDependencies();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_DEPENDENCIES, getDefaultPluginDependencies());
-}
+export const PLUGIN_DEPENDENCIES = definePluginSlot(
+ getDefaultPluginDependencies,
+);
diff --git a/frontend/src/metabase/plugins/oss/embedding-iframe-sdk-setup.ts b/frontend/src/metabase/plugins/oss/embedding-iframe-sdk-setup.ts
index de88144b338..8b9549e6c3a 100644
--- a/frontend/src/metabase/plugins/oss/embedding-iframe-sdk-setup.ts
+++ b/frontend/src/metabase/plugins/oss/embedding-iframe-sdk-setup.ts
@@ -1,5 +1,7 @@
import type { DashboardId } from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
export type SdkIframeEmbedSetupModalProps = {
opened: boolean;
onClose: () => void;
@@ -31,15 +33,6 @@ const getDefaultPluginEmbeddingIframeSdkSetup = () => ({
isEnabled: () => false,
});
-export const PLUGIN_EMBEDDING_IFRAME_SDK_SETUP =
- getDefaultPluginEmbeddingIframeSdkSetup();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(
- PLUGIN_EMBEDDING_IFRAME_SDK_SETUP,
- getDefaultPluginEmbeddingIframeSdkSetup(),
- );
-}
+export const PLUGIN_EMBEDDING_IFRAME_SDK_SETUP = definePluginSlot(
+ getDefaultPluginEmbeddingIframeSdkSetup,
+);
diff --git a/frontend/src/metabase/plugins/oss/embedding-iframe-sdk.ts b/frontend/src/metabase/plugins/oss/embedding-iframe-sdk.ts
index a9c1c4ef016..0f6432797f5 100644
--- a/frontend/src/metabase/plugins/oss/embedding-iframe-sdk.ts
+++ b/frontend/src/metabase/plugins/oss/embedding-iframe-sdk.ts
@@ -1,15 +1,9 @@
+import { definePluginSlot } from "../slot";
+
const getDefaultPluginEmbeddingIframeSdk = () => ({
isEnabled: () => false,
});
-export const PLUGIN_EMBEDDING_IFRAME_SDK = getDefaultPluginEmbeddingIframeSdk();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(
- PLUGIN_EMBEDDING_IFRAME_SDK,
- getDefaultPluginEmbeddingIframeSdk(),
- );
-}
+export const PLUGIN_EMBEDDING_IFRAME_SDK = definePluginSlot(
+ getDefaultPluginEmbeddingIframeSdk,
+);
diff --git a/frontend/src/metabase/plugins/oss/embedding-sdk.ts b/frontend/src/metabase/plugins/oss/embedding-sdk.ts
index 48b4ef8cf86..a91c5e8d505 100644
--- a/frontend/src/metabase/plugins/oss/embedding-sdk.ts
+++ b/frontend/src/metabase/plugins/oss/embedding-sdk.ts
@@ -1,12 +1,9 @@
+import { definePluginSlot } from "../slot";
+
const getDefaultPluginEmbeddingSdk = () => ({
isEnabled: () => false,
});
-export const PLUGIN_EMBEDDING_SDK = getDefaultPluginEmbeddingSdk();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_EMBEDDING_SDK, getDefaultPluginEmbeddingSdk());
-}
+export const PLUGIN_EMBEDDING_SDK = definePluginSlot(
+ getDefaultPluginEmbeddingSdk,
+);
diff --git a/frontend/src/metabase/plugins/oss/embedding.ts b/frontend/src/metabase/plugins/oss/embedding.ts
index 6b75a46cc25..3e3d7445388 100644
--- a/frontend/src/metabase/plugins/oss/embedding.ts
+++ b/frontend/src/metabase/plugins/oss/embedding.ts
@@ -5,6 +5,8 @@ import type { State } from "metabase/redux/store";
import type { EmbeddingEntityType } from "metabase/redux/store/embedding-data-picker";
import type { TableId } from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
export interface SimpleDataPickerProps {
filterByDatabaseId: number | null;
selectedEntity?: TableId;
@@ -21,11 +23,4 @@ const getDefaultPluginEmbedding = () => ({
DataSourceSelector: (_props: DataSourceSelectorProps): ReactNode => null,
});
-export const PLUGIN_EMBEDDING = getDefaultPluginEmbedding();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_EMBEDDING, getDefaultPluginEmbedding());
-}
+export const PLUGIN_EMBEDDING = definePluginSlot(getDefaultPluginEmbedding);
diff --git a/frontend/src/metabase/plugins/oss/library.ts b/frontend/src/metabase/plugins/oss/library.ts
index b8aaa815755..9dbb7093834 100644
--- a/frontend/src/metabase/plugins/oss/library.ts
+++ b/frontend/src/metabase/plugins/oss/library.ts
@@ -26,6 +26,8 @@ import type {
TableId,
} from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
export type CreateLibraryModalProps = {
title?: string;
explanatorySentence?: string;
@@ -178,11 +180,4 @@ const getDefaultPluginLibrary = (): LibraryPlugin => ({
): _type is "library-data" => false,
});
-export const PLUGIN_LIBRARY = getDefaultPluginLibrary();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_LIBRARY, getDefaultPluginLibrary());
-}
+export const PLUGIN_LIBRARY = definePluginSlot(getDefaultPluginLibrary);
diff --git a/frontend/src/metabase/plugins/oss/metabot.ts b/frontend/src/metabase/plugins/oss/metabot.ts
index 7139070535a..92592147a54 100644
--- a/frontend/src/metabase/plugins/oss/metabot.ts
+++ b/frontend/src/metabase/plugins/oss/metabot.ts
@@ -2,6 +2,8 @@ import type { ComponentType } from "react";
import { PluginPlaceholder } from "metabase/plugins/components/PluginPlaceholder";
+import { definePluginSlot } from "../slot";
+
export type MetabaseAIProviderSetupProps = {
onConnect?: VoidFunction;
onCancel?: VoidFunction;
@@ -20,11 +22,4 @@ export const PLUGIN_METABOT: {
isEnabled: boolean;
MetabaseAIProviderSetup: ComponentType<MetabaseAIProviderSetupProps>;
hasMetabaseManagedProviderDetails: () => boolean;
-} = getDefaultPluginMetabot();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_METABOT, getDefaultPluginMetabot());
-}
+} = definePluginSlot(getDefaultPluginMetabot);
diff --git a/frontend/src/metabase/plugins/oss/model-persistence.ts b/frontend/src/metabase/plugins/oss/model-persistence.ts
index 1c390b73c45..2b518be4116 100644
--- a/frontend/src/metabase/plugins/oss/model-persistence.ts
+++ b/frontend/src/metabase/plugins/oss/model-persistence.ts
@@ -2,6 +2,8 @@ import { PluginPlaceholder } from "metabase/plugins/components/PluginPlaceholder
import type Question from "metabase-lib/v1/Question";
import type { ModelCacheRefreshStatus } from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
const getDefaultPluginModelPersistence = () => ({
isModelLevelPersistenceEnabled: () => false,
// Unjustified type cast. FIXME
@@ -14,11 +16,6 @@ const getDefaultPluginModelPersistence = () => ({
}) => JSX.Element,
});
-export const PLUGIN_MODEL_PERSISTENCE = getDefaultPluginModelPersistence();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_MODEL_PERSISTENCE, getDefaultPluginModelPersistence());
-}
+export const PLUGIN_MODEL_PERSISTENCE = definePluginSlot(
+ getDefaultPluginModelPersistence,
+);
diff --git a/frontend/src/metabase/plugins/oss/moderation.ts b/frontend/src/metabase/plugins/oss/moderation.ts
index b7cf6863e3f..f458f4841c2 100644
--- a/frontend/src/metabase/plugins/oss/moderation.ts
+++ b/frontend/src/metabase/plugins/oss/moderation.ts
@@ -12,6 +12,8 @@ import type {
MetabotInfo,
} from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
export type RevisionOrModerationEvent = {
title: string;
timestamp: string;
@@ -40,11 +42,4 @@ const getDefaultPluginModeration = () => ({
PluginPlaceholder as React.ComponentType<{ metabot: MetabotInfo }>,
});
-export const PLUGIN_MODERATION = getDefaultPluginModeration();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_MODERATION, getDefaultPluginModeration());
-}
+export const PLUGIN_MODERATION = definePluginSlot(getDefaultPluginModeration);
diff --git a/frontend/src/metabase/plugins/oss/monitor.ts b/frontend/src/metabase/plugins/oss/monitor.ts
index 8e0cf4d3809..eea2cec67e8 100644
--- a/frontend/src/metabase/plugins/oss/monitor.ts
+++ b/frontend/src/metabase/plugins/oss/monitor.ts
@@ -1,5 +1,7 @@
import type { ComponentType, ReactNode } from "react";
+import { definePluginSlot } from "../slot";
+
type MonitorPlugin = {
isDependencyDiagnosticsEnabled: boolean;
getDependencyDiagnosticsRoutes: () => ReactNode;
@@ -10,7 +12,7 @@ const getDefaultPluginMonitor = (): MonitorPlugin => ({
getDependencyDiagnosticsRoutes: () => null,
});
-export const PLUGIN_MONITOR = getDefaultPluginMonitor();
+export const PLUGIN_MONITOR = definePluginSlot(getDefaultPluginMonitor);
const getDefaultMonitorTools = (): { COMPONENT: ComponentType | null } => ({
COMPONENT: null,
@@ -18,12 +20,4 @@ const getDefaultMonitorTools = (): { COMPONENT: ComponentType | null } => ({
export const PLUGIN_MONITOR_TOOLS: {
COMPONENT: ComponentType | null;
-} = getDefaultMonitorTools();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_MONITOR, getDefaultPluginMonitor());
- Object.assign(PLUGIN_MONITOR_TOOLS, getDefaultMonitorTools());
-}
+} = definePluginSlot(getDefaultMonitorTools);
diff --git a/frontend/src/metabase/plugins/oss/multi-factor-auth.ts b/frontend/src/metabase/plugins/oss/multi-factor-auth.ts
index ba256dc0a32..680ba136ea2 100644
--- a/frontend/src/metabase/plugins/oss/multi-factor-auth.ts
+++ b/frontend/src/metabase/plugins/oss/multi-factor-auth.ts
@@ -4,6 +4,8 @@ import {
} from "metabase/plugins/components/PluginPlaceholder";
import type { MfaMethod } from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
export type AuthChallengeFormProps = {
challengeToken: string;
methods: MfaMethod[];
@@ -19,11 +21,6 @@ const getDefaultPluginMultiFactorAuth = () => ({
unenrolledUsersPage: pluginPlaceholderRoute,
});
-export const PLUGIN_MULTI_FACTOR_AUTH = getDefaultPluginMultiFactorAuth();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_MULTI_FACTOR_AUTH, getDefaultPluginMultiFactorAuth());
-}
+export const PLUGIN_MULTI_FACTOR_AUTH = definePluginSlot(
+ getDefaultPluginMultiFactorAuth,
+);
diff --git a/frontend/src/metabase/plugins/oss/notifications-sdk.ts b/frontend/src/metabase/plugins/oss/notifications-sdk.ts
index 7b19fc6872a..c4d1cbfc52c 100644
--- a/frontend/src/metabase/plugins/oss/notifications-sdk.ts
+++ b/frontend/src/metabase/plugins/oss/notifications-sdk.ts
@@ -2,6 +2,8 @@ import type { ButtonHTMLAttributes } from "react";
import type { ActionIconProps } from "metabase/ui";
+import { definePluginSlot } from "../slot";
+
export type DashboardSubscriptionsButtonProps = ActionIconProps &
ButtonHTMLAttributes<HTMLButtonElement>;
@@ -19,11 +21,6 @@ function getDefaultPluginNotificationsSdk() {
};
}
-export const PLUGIN_NOTIFICATIONS_SDK = getDefaultPluginNotificationsSdk();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_NOTIFICATIONS_SDK, getDefaultPluginNotificationsSdk());
-}
+export const PLUGIN_NOTIFICATIONS_SDK = definePluginSlot(
+ getDefaultPluginNotificationsSdk,
+);
diff --git a/frontend/src/metabase/plugins/oss/permissions.ts b/frontend/src/metabase/plugins/oss/permissions.ts
index b359f538ed3..20660d899e0 100644
--- a/frontend/src/metabase/plugins/oss/permissions.ts
+++ b/frontend/src/metabase/plugins/oss/permissions.ts
@@ -20,6 +20,7 @@ import type {
} from "metabase-types/api";
import { DataPermissionValue } from "metabase-types/api";
+import { definePluginSlot } from "../slot";
import type { PluginGroupManagersType } from "../types";
// These describe the entries EE plugins contribute to the admin permissions
@@ -101,28 +102,37 @@ const getDefaultAdminPermissionsTableFieldsPostAction = (): {
sandboxed: null,
});
-export const PLUGIN_ADMIN_PERMISSIONS_DATABASE_ROUTES =
- getDefaultAdminPermissionsDatabaseRoutes();
-export const PLUGIN_ADMIN_PERMISSIONS_DATABASE_GROUP_ROUTES =
- getDefaultAdminPermissionsDatabaseGroupRoutes();
-export const PLUGIN_ADMIN_PERMISSIONS_DATABASE_POST_ACTIONS =
- getDefaultAdminPermissionsDatabasePostActions();
-export const PLUGIN_ADMIN_PERMISSIONS_DATABASE_ACTIONS =
- getDefaultAdminPermissionsDatabaseActions();
-export const PLUGIN_ADMIN_PERMISSIONS_TABLE_OPTIONS =
- getDefaultAdminPermissionsTableOptions();
-export const PLUGIN_ADMIN_PERMISSIONS_TABLE_ROUTES =
- getDefaultAdminPermissionsTableRoutes();
-export const PLUGIN_ADMIN_PERMISSIONS_TABLE_GROUP_ROUTES =
- getDefaultAdminPermissionsTableGroupRoutes();
-export const PLUGIN_ADMIN_PERMISSIONS_TABLE_FIELDS_OPTIONS =
- getDefaultAdminPermissionsTableFieldsOptions();
+export const PLUGIN_ADMIN_PERMISSIONS_DATABASE_ROUTES = definePluginSlot(
+ getDefaultAdminPermissionsDatabaseRoutes,
+);
+export const PLUGIN_ADMIN_PERMISSIONS_DATABASE_GROUP_ROUTES = definePluginSlot(
+ getDefaultAdminPermissionsDatabaseGroupRoutes,
+);
+export const PLUGIN_ADMIN_PERMISSIONS_DATABASE_POST_ACTIONS = definePluginSlot(
+ getDefaultAdminPermissionsDatabasePostActions,
+);
+export const PLUGIN_ADMIN_PERMISSIONS_DATABASE_ACTIONS = definePluginSlot(
+ getDefaultAdminPermissionsDatabaseActions,
+);
+export const PLUGIN_ADMIN_PERMISSIONS_TABLE_OPTIONS = definePluginSlot(
+ getDefaultAdminPermissionsTableOptions,
+);
+export const PLUGIN_ADMIN_PERMISSIONS_TABLE_ROUTES = definePluginSlot(
+ getDefaultAdminPermissionsTableRoutes,
+);
+export const PLUGIN_ADMIN_PERMISSIONS_TABLE_GROUP_ROUTES = definePluginSlot(
+ getDefaultAdminPermissionsTableGroupRoutes,
+);
+export const PLUGIN_ADMIN_PERMISSIONS_TABLE_FIELDS_OPTIONS = definePluginSlot(
+ getDefaultAdminPermissionsTableFieldsOptions,
+);
export const PLUGIN_ADMIN_PERMISSIONS_TABLE_FIELDS_CONFIRMATIONS =
- getDefaultAdminPermissionsTableFieldsConfirmations();
-export const PLUGIN_ADMIN_PERMISSIONS_TABLE_FIELDS_ACTIONS =
- getDefaultAdminPermissionsTableFieldsActions();
+ definePluginSlot(getDefaultAdminPermissionsTableFieldsConfirmations);
+export const PLUGIN_ADMIN_PERMISSIONS_TABLE_FIELDS_ACTIONS = definePluginSlot(
+ getDefaultAdminPermissionsTableFieldsActions,
+);
export const PLUGIN_ADMIN_PERMISSIONS_TABLE_FIELDS_POST_ACTION =
- getDefaultAdminPermissionsTableFieldsPostAction();
+ definePluginSlot(getDefaultAdminPermissionsTableFieldsPostAction);
const getDefaultDataPermissions = () => ({
permissionsPayloadExtraSelectors: [],
@@ -155,15 +165,19 @@ export const PLUGIN_DATA_PERMISSIONS: {
permission: DataPermission,
) => GroupsPermissions)
| null;
-} = getDefaultDataPermissions();
+} = definePluginSlot(getDefaultDataPermissions);
const getDefaultAdminUserMenuItems = (): Array<
(user: User) => React.ReactNode
> => [];
const getDefaultAdminUserMenuRoutes = (): (() => React.ReactNode)[] => [];
-export const PLUGIN_ADMIN_USER_MENU_ITEMS = getDefaultAdminUserMenuItems();
-export const PLUGIN_ADMIN_USER_MENU_ROUTES = getDefaultAdminUserMenuRoutes();
+export const PLUGIN_ADMIN_USER_MENU_ITEMS = definePluginSlot(
+ getDefaultAdminUserMenuItems,
+);
+export const PLUGIN_ADMIN_USER_MENU_ROUTES = definePluginSlot(
+ getDefaultAdminUserMenuRoutes,
+);
const getDefaultAdvancedPermissions = () => ({
addDatabasePermissionOptions: (
@@ -190,7 +204,9 @@ const getDefaultAdvancedPermissions = () => ({
defaultViewDataPermission: DataPermissionValue.UNRESTRICTED,
});
-export const PLUGIN_ADVANCED_PERMISSIONS = getDefaultAdvancedPermissions();
+export const PLUGIN_ADVANCED_PERMISSIONS = definePluginSlot(
+ getDefaultAdvancedPermissions,
+);
const getDefaultFeatureLevelPermissions = () => ({
getFeatureLevelDataPermissions: ({
@@ -238,8 +254,9 @@ const getDefaultFeatureLevelPermissions = () => ({
databaseDetailsQueryProps: {} as any,
});
-export const PLUGIN_FEATURE_LEVEL_PERMISSIONS =
- getDefaultFeatureLevelPermissions();
+export const PLUGIN_FEATURE_LEVEL_PERMISSIONS = definePluginSlot(
+ getDefaultFeatureLevelPermissions,
+);
const getDefaultAdminPermissionsTabs = () => ({
getRoutes: (): ReactNode => null,
@@ -247,7 +264,9 @@ const getDefaultAdminPermissionsTabs = () => ({
tabs: [] as { name: string; value: string }[],
});
-export const PLUGIN_ADMIN_PERMISSIONS_TABS = getDefaultAdminPermissionsTabs();
+export const PLUGIN_ADMIN_PERMISSIONS_TABS = definePluginSlot(
+ getDefaultAdminPermissionsTabs,
+);
const getDefaultApplicationPermissions = () => ({
getRoutes: (): ReactNode => null,
@@ -259,8 +278,9 @@ const getDefaultApplicationPermissions = () => ({
},
});
-export const PLUGIN_APPLICATION_PERMISSIONS =
- getDefaultApplicationPermissions();
+export const PLUGIN_APPLICATION_PERMISSIONS = definePluginSlot(
+ getDefaultApplicationPermissions,
+);
const getDefaultGroupManagers = (): PluginGroupManagersType => ({
// Unjustified type cast. FIXME
@@ -275,87 +295,4 @@ const getDefaultGroupManagers = (): PluginGroupManagersType => ({
confirmUpdateMembershipAction: null,
});
-export const PLUGIN_GROUP_MANAGERS = getDefaultGroupManagers();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- PLUGIN_ADMIN_PERMISSIONS_DATABASE_ROUTES.length = 0;
- PLUGIN_ADMIN_PERMISSIONS_DATABASE_ROUTES.push(
- ...getDefaultAdminPermissionsDatabaseRoutes(),
- );
-
- PLUGIN_ADMIN_PERMISSIONS_DATABASE_GROUP_ROUTES.length = 0;
- PLUGIN_ADMIN_PERMISSIONS_DATABASE_GROUP_ROUTES.push(
- ...getDefaultAdminPermissionsDatabaseGroupRoutes(),
- );
-
- Object.assign(
- PLUGIN_ADMIN_PERMISSIONS_DATABASE_POST_ACTIONS,
- getDefaultAdminPermissionsDatabasePostActions(),
- );
- Object.assign(
- PLUGIN_ADMIN_PERMISSIONS_DATABASE_ACTIONS,
- getDefaultAdminPermissionsDatabaseActions(),
- );
-
- PLUGIN_ADMIN_PERMISSIONS_TABLE_OPTIONS.length = 0;
- PLUGIN_ADMIN_PERMISSIONS_TABLE_OPTIONS.push(
- ...getDefaultAdminPermissionsTableOptions(),
- );
-
- PLUGIN_ADMIN_PERMISSIONS_TABLE_ROUTES.length = 0;
- PLUGIN_ADMIN_PERMISSIONS_TABLE_ROUTES.push(
- ...getDefaultAdminPermissionsTableRoutes(),
- );
-
- PLUGIN_ADMIN_PERMISSIONS_TABLE_GROUP_ROUTES.length = 0;
- PLUGIN_ADMIN_PERMISSIONS_TABLE_GROUP_ROUTES.push(
- ...getDefaultAdminPermissionsTableGroupRoutes(),
- );
-
- PLUGIN_ADMIN_PERMISSIONS_TABLE_FIELDS_OPTIONS.length = 0;
- PLUGIN_ADMIN_PERMISSIONS_TABLE_FIELDS_OPTIONS.push(
- ...getDefaultAdminPermissionsTableFieldsOptions(),
- );
-
- PLUGIN_ADMIN_PERMISSIONS_TABLE_FIELDS_CONFIRMATIONS.length = 0;
- PLUGIN_ADMIN_PERMISSIONS_TABLE_FIELDS_CONFIRMATIONS.push(
- ...getDefaultAdminPermissionsTableFieldsConfirmations(),
- );
-
- Object.assign(
- PLUGIN_ADMIN_PERMISSIONS_TABLE_FIELDS_ACTIONS,
- getDefaultAdminPermissionsTableFieldsActions(),
- );
- Object.assign(
- PLUGIN_ADMIN_PERMISSIONS_TABLE_FIELDS_POST_ACTION,
- getDefaultAdminPermissionsTableFieldsPostAction(),
- );
-
- Object.assign(PLUGIN_DATA_PERMISSIONS, getDefaultDataPermissions());
-
- PLUGIN_ADMIN_USER_MENU_ITEMS.length = 0;
- PLUGIN_ADMIN_USER_MENU_ITEMS.push(...getDefaultAdminUserMenuItems());
-
- PLUGIN_ADMIN_USER_MENU_ROUTES.length = 0;
- PLUGIN_ADMIN_USER_MENU_ROUTES.push(...getDefaultAdminUserMenuRoutes());
-
- Object.assign(PLUGIN_ADVANCED_PERMISSIONS, getDefaultAdvancedPermissions());
- Object.assign(
- PLUGIN_FEATURE_LEVEL_PERMISSIONS,
- getDefaultFeatureLevelPermissions(),
- );
-
- Object.assign(
- PLUGIN_ADMIN_PERMISSIONS_TABS,
- getDefaultAdminPermissionsTabs(),
- );
-
- Object.assign(
- PLUGIN_APPLICATION_PERMISSIONS,
- getDefaultApplicationPermissions(),
- );
- Object.assign(PLUGIN_GROUP_MANAGERS, getDefaultGroupManagers());
-}
+export const PLUGIN_GROUP_MANAGERS = definePluginSlot(getDefaultGroupManagers);
diff --git a/frontend/src/metabase/plugins/oss/remote-sync.ts b/frontend/src/metabase/plugins/oss/remote-sync.ts
index 591c01cd97a..759929b4f1d 100644
--- a/frontend/src/metabase/plugins/oss/remote-sync.ts
+++ b/frontend/src/metabase/plugins/oss/remote-sync.ts
@@ -20,6 +20,8 @@ import type {
RemoteSyncEntity,
} from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
export type CollectionsNavTreeProps = {
collections: CollectionTreeItem[];
selectedId?: number | string;
@@ -115,11 +117,4 @@ export const PLUGIN_REMOTE_SYNC: {
useHasTransformDirtyChanges: () => boolean;
getIsRemoteSyncReadOnly: (state: State) => boolean;
useRemoteSyncDirtyState: () => RemoteSyncDirtyState;
-} = getDefaultPluginRemoteSync();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_REMOTE_SYNC, getDefaultPluginRemoteSync());
-}
+} = definePluginSlot(getDefaultPluginRemoteSync);
diff --git a/frontend/src/metabase/plugins/oss/replacement.ts b/frontend/src/metabase/plugins/oss/replacement.ts
index 06bddf0e04a..5048f43aef4 100644
--- a/frontend/src/metabase/plugins/oss/replacement.ts
+++ b/frontend/src/metabase/plugins/oss/replacement.ts
@@ -4,6 +4,7 @@ import type { State } from "metabase/redux/store";
import type { SourceReplacementEntry } from "metabase-types/api";
import { PluginPlaceholder } from "../components/PluginPlaceholder";
+import { definePluginSlot } from "../slot";
export type SourceReplacementTriggeredFrom = "table_list" | "dependency_graph";
@@ -44,8 +45,4 @@ const getDefaultReplacementPlugin = (): ReplacementPlugin => ({
TransformToolsMenu: PluginPlaceholder,
});
-export const PLUGIN_REPLACEMENT = getDefaultReplacementPlugin();
-
-export function reinitialize() {
- Object.assign(PLUGIN_REPLACEMENT, getDefaultReplacementPlugin());
-}
+export const PLUGIN_REPLACEMENT = definePluginSlot(getDefaultReplacementPlugin);
diff --git a/frontend/src/metabase/plugins/oss/resource-downloads.ts b/frontend/src/metabase/plugins/oss/resource-downloads.ts
index 823073feb48..676254519be 100644
--- a/frontend/src/metabase/plugins/oss/resource-downloads.ts
+++ b/frontend/src/metabase/plugins/oss/resource-downloads.ts
@@ -1,5 +1,7 @@
import type { EmbedResourceDownloadOptions } from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
const getDefaultPluginResourceDownloads = () => ({
areDownloadsEnabled: (_args: {
downloads?: string | boolean | null;
@@ -9,11 +11,6 @@ const getDefaultPluginResourceDownloads = () => ({
}),
});
-export const PLUGIN_RESOURCE_DOWNLOADS = getDefaultPluginResourceDownloads();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_RESOURCE_DOWNLOADS, getDefaultPluginResourceDownloads());
-}
+export const PLUGIN_RESOURCE_DOWNLOADS = definePluginSlot(
+ getDefaultPluginResourceDownloads,
+);
diff --git a/frontend/src/metabase/plugins/oss/schema-viewer.ts b/frontend/src/metabase/plugins/oss/schema-viewer.ts
index b9b2eadf9e6..a2af528208b 100644
--- a/frontend/src/metabase/plugins/oss/schema-viewer.ts
+++ b/frontend/src/metabase/plugins/oss/schema-viewer.ts
@@ -1,5 +1,7 @@
import type { ReactNode } from "react";
+import { definePluginSlot } from "../slot";
+
type SchemaViewerPlugin = {
isEnabled: boolean;
getDataStudioSchemaViewerRoutes: () => ReactNode;
@@ -10,11 +12,6 @@ const getDefaultPluginSchemaViewer = (): SchemaViewerPlugin => ({
getDataStudioSchemaViewerRoutes: () => null,
});
-export const PLUGIN_SCHEMA_VIEWER = getDefaultPluginSchemaViewer();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_SCHEMA_VIEWER, getDefaultPluginSchemaViewer());
-}
+export const PLUGIN_SCHEMA_VIEWER = definePluginSlot(
+ getDefaultPluginSchemaViewer,
+);
diff --git a/frontend/src/metabase/plugins/oss/security-center.ts b/frontend/src/metabase/plugins/oss/security-center.ts
index c009383a82d..e8d67121589 100644
--- a/frontend/src/metabase/plugins/oss/security-center.ts
+++ b/frontend/src/metabase/plugins/oss/security-center.ts
@@ -6,6 +6,8 @@ import {
} from "metabase/plugins/components/PluginPlaceholder";
import type { PluginRoute } from "metabase/plugins/types";
+import { definePluginSlot } from "../slot";
+
type SecurityCenterNavItemProps = {
currentPath: string;
};
@@ -28,11 +30,4 @@ const getDefaultPlugin = (): SecurityCenterPlugin => ({
SecurityCenterMobileNavItem: PluginPlaceholder,
});
-export const PLUGIN_SECURITY_CENTER = getDefaultPlugin();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_SECURITY_CENTER, getDefaultPlugin());
-}
+export const PLUGIN_SECURITY_CENTER = definePluginSlot(getDefaultPlugin);
diff --git a/frontend/src/metabase/plugins/oss/semantic-search.ts b/frontend/src/metabase/plugins/oss/semantic-search.ts
index 604b4765ad4..f24f638df38 100644
--- a/frontend/src/metabase/plugins/oss/semantic-search.ts
+++ b/frontend/src/metabase/plugins/oss/semantic-search.ts
@@ -1,5 +1,7 @@
import { PluginPlaceholder } from "metabase/plugins/components/PluginPlaceholder";
+import { definePluginSlot } from "../slot";
+
export type SearchSettingsWidgetProps = {
statusPollingInterval?: number;
};
@@ -8,11 +10,6 @@ const getDefaultPluginSemanticSearch = () => ({
SearchSettingsWidget: PluginPlaceholder<SearchSettingsWidgetProps>,
});
-export const PLUGIN_SEMANTIC_SEARCH = getDefaultPluginSemanticSearch();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_SEMANTIC_SEARCH, getDefaultPluginSemanticSearch());
-}
+export const PLUGIN_SEMANTIC_SEARCH = definePluginSlot(
+ getDefaultPluginSemanticSearch,
+);
diff --git a/frontend/src/metabase/plugins/oss/settings.ts b/frontend/src/metabase/plugins/oss/settings.ts
index c490fccccf5..efacd722eef 100644
--- a/frontend/src/metabase/plugins/oss/settings.ts
+++ b/frontend/src/metabase/plugins/oss/settings.ts
@@ -2,6 +2,8 @@ import type { ComponentType } from "react";
import { PluginPlaceholder } from "metabase/plugins/components/PluginPlaceholder";
+import { definePluginSlot } from "../slot";
+
const getDefaultPluginAdminSettings = () => ({
InteractiveEmbeddingSettingsCard: null,
LicenseAndBillingSettings: PluginPlaceholder,
@@ -21,11 +23,4 @@ export const PLUGIN_ADMIN_SETTINGS: {
useUpsellFlow: (props: { campaign: string; location: string }) => {
triggerUpsellFlow: (() => void) | undefined;
};
-} = getDefaultPluginAdminSettings();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_ADMIN_SETTINGS, getDefaultPluginAdminSettings());
-}
+} = definePluginSlot(getDefaultPluginAdminSettings);
diff --git a/frontend/src/metabase/plugins/oss/smtp-override.ts b/frontend/src/metabase/plugins/oss/smtp-override.ts
index 81e1f28939a..c7b87b0b1af 100644
--- a/frontend/src/metabase/plugins/oss/smtp-override.ts
+++ b/frontend/src/metabase/plugins/oss/smtp-override.ts
@@ -2,6 +2,8 @@ import type { ComponentType } from "react";
import { PluginPlaceholder } from "metabase/plugins/components/PluginPlaceholder";
+import { definePluginSlot } from "../slot";
+
const getDefaultPluginSmtpOverride = () => ({
CloudSMTPConnectionCard: PluginPlaceholder,
SMTPOverrideConnectionForm: PluginPlaceholder,
@@ -10,11 +12,4 @@ const getDefaultPluginSmtpOverride = () => ({
export const PLUGIN_SMTP_OVERRIDE: {
CloudSMTPConnectionCard: ComponentType;
SMTPOverrideConnectionForm: ComponentType<{ onClose: () => void }>;
-} = getDefaultPluginSmtpOverride();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_SMTP_OVERRIDE, getDefaultPluginSmtpOverride());
-}
+} = definePluginSlot(getDefaultPluginSmtpOverride);
diff --git a/frontend/src/metabase/plugins/oss/snippets.ts b/frontend/src/metabase/plugins/oss/snippets.ts
index 2bf21bbace1..dab6e197bd8 100644
--- a/frontend/src/metabase/plugins/oss/snippets.ts
+++ b/frontend/src/metabase/plugins/oss/snippets.ts
@@ -9,6 +9,7 @@ import type {
} from "metabase-types/api";
import { PluginPlaceholder } from "../components/PluginPlaceholder";
+import { definePluginSlot } from "../slot";
export type SnippetSidebarMenuOption = {
icon: IconName;
@@ -68,8 +69,6 @@ export const getDefaultPluginSnippetFolders = () => ({
MoveSnippetModal: PluginPlaceholder as ComponentType<MoveSnippetModalProps>,
});
-export const PLUGIN_SNIPPET_FOLDERS = getDefaultPluginSnippetFolders();
-
-export function reinitialize() {
- Object.assign(PLUGIN_SNIPPET_FOLDERS, getDefaultPluginSnippetFolders());
-}
+export const PLUGIN_SNIPPET_FOLDERS = definePluginSlot(
+ getDefaultPluginSnippetFolders,
+);
diff --git a/frontend/src/metabase/plugins/oss/support.ts b/frontend/src/metabase/plugins/oss/support.ts
index c885a8e1187..f0978d9bcc4 100644
--- a/frontend/src/metabase/plugins/oss/support.ts
+++ b/frontend/src/metabase/plugins/oss/support.ts
@@ -3,6 +3,7 @@ import type { ComponentType } from "react";
import type { ModalComponentProps } from "metabase/common/components/ModalRoute";
import { PluginPlaceholder } from "../components/PluginPlaceholder";
+import { definePluginSlot } from "../slot";
const getDefaultPluginSupport = () => ({
isEnabled: false,
@@ -14,11 +15,4 @@ export const PLUGIN_SUPPORT: {
isEnabled: boolean;
SupportSettings: ComponentType;
GrantAccessModal: ComponentType<ModalComponentProps>;
-} = getDefaultPluginSupport();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_SUPPORT, getDefaultPluginSupport());
-}
+} = definePluginSlot(getDefaultPluginSupport);
diff --git a/frontend/src/metabase/plugins/oss/tenants.ts b/frontend/src/metabase/plugins/oss/tenants.ts
index db0e0e742f9..6d552f5a7d7 100644
--- a/frontend/src/metabase/plugins/oss/tenants.ts
+++ b/frontend/src/metabase/plugins/oss/tenants.ts
@@ -21,6 +21,7 @@ import {
PluginPlaceholder,
pluginPlaceholderRoute,
} from "../components/PluginPlaceholder";
+import { definePluginSlot } from "../slot";
import type { PluginRoute } from "../types";
export type CreatedTenantData = {
@@ -222,11 +223,4 @@ export const PLUGIN_TENANTS: {
sharedTenantCollections: Collection[] | undefined;
regularCollections: CollectionTreeItem[];
}) => CollectionTreeItem[];
-} = getDefaultPluginTenants();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_TENANTS, getDefaultPluginTenants());
-}
+} = definePluginSlot(getDefaultPluginTenants);
diff --git a/frontend/src/metabase/plugins/oss/transforms.ts b/frontend/src/metabase/plugins/oss/transforms.ts
index 324bfc0d96f..4a9b36dc072 100644
--- a/frontend/src/metabase/plugins/oss/transforms.ts
+++ b/frontend/src/metabase/plugins/oss/transforms.ts
@@ -8,6 +8,8 @@ import {
import type { PluginRoute } from "metabase/plugins/types";
import type { PythonTransformSourceDraft, Transform } from "metabase-types/api";
+import { definePluginSlot } from "../slot";
+
// Types
export type TransformPickerItem = OmniPickerItem & {
model: "transform";
@@ -70,7 +72,7 @@ const getDefaultPluginTransforms = (): TransformsPlugin => ({
TransformsUpsellPage: PluginPlaceholder,
});
-export const PLUGIN_TRANSFORMS = getDefaultPluginTransforms();
+export const PLUGIN_TRANSFORMS = definePluginSlot(getDefaultPluginTransforms);
const getDefaultPluginTransformsPython = (): PythonTransformsPlugin => ({
isEnabled: false,
@@ -86,12 +88,6 @@ const getDefaultPluginTransformsPython = (): PythonTransformsPlugin => ({
sharedLibImportPath: "",
});
-export const PLUGIN_TRANSFORMS_PYTHON = getDefaultPluginTransformsPython();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_TRANSFORMS, getDefaultPluginTransforms());
- Object.assign(PLUGIN_TRANSFORMS_PYTHON, getDefaultPluginTransformsPython());
-}
+export const PLUGIN_TRANSFORMS_PYTHON = definePluginSlot(
+ getDefaultPluginTransformsPython,
+);
diff --git a/frontend/src/metabase/plugins/oss/upload-management.ts b/frontend/src/metabase/plugins/oss/upload-management.ts
index 4a172a29395..86f934b87d9 100644
--- a/frontend/src/metabase/plugins/oss/upload-management.ts
+++ b/frontend/src/metabase/plugins/oss/upload-management.ts
@@ -4,6 +4,8 @@ import { StorageSetupProvider } from "metabase/common/components/upsells/Storage
import { PluginPlaceholder } from "metabase/plugins/components/PluginPlaceholder";
import { _FileUploadErrorModal } from "metabase/status/components/FileUploadStatusLarge/FileUploadErrorModal";
+import { definePluginSlot } from "../slot";
+
type GdriveConnectionModalProps = {
isModalOpen: boolean;
onClose: () => void;
@@ -28,11 +30,6 @@ const getDefaultPluginUploadManagement = () => ({
StorageSetupProvider,
});
-export const PLUGIN_UPLOAD_MANAGEMENT = getDefaultPluginUploadManagement();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_UPLOAD_MANAGEMENT, getDefaultPluginUploadManagement());
-}
+export const PLUGIN_UPLOAD_MANAGEMENT = definePluginSlot(
+ getDefaultPluginUploadManagement,
+);
diff --git a/frontend/src/metabase/plugins/oss/whitelabel.ts b/frontend/src/metabase/plugins/oss/whitelabel.ts
index e33db8cad6e..8fe3171be0b 100644
--- a/frontend/src/metabase/plugins/oss/whitelabel.ts
+++ b/frontend/src/metabase/plugins/oss/whitelabel.ts
@@ -1,15 +1,10 @@
import { PluginPlaceholder } from "metabase/plugins/components/PluginPlaceholder";
+import { definePluginSlot } from "../slot";
+
const getDefaultPluginWhitelabel = () => ({
WhiteLabelBrandingSettingsPage: PluginPlaceholder,
WhiteLabelConcealSettingsPage: PluginPlaceholder,
});
-export const PLUGIN_WHITELABEL = getDefaultPluginWhitelabel();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_WHITELABEL, getDefaultPluginWhitelabel());
-}
+export const PLUGIN_WHITELABEL = definePluginSlot(getDefaultPluginWhitelabel);
diff --git a/frontend/src/metabase/plugins/oss/writable-connection.ts b/frontend/src/metabase/plugins/oss/writable-connection.ts
index fc510df4020..13f8a67f130 100644
--- a/frontend/src/metabase/plugins/oss/writable-connection.ts
+++ b/frontend/src/metabase/plugins/oss/writable-connection.ts
@@ -3,6 +3,7 @@ import type { ComponentType, ReactNode } from "react";
import type { Database } from "metabase-types/api";
import { PluginPlaceholder } from "../components/PluginPlaceholder";
+import { definePluginSlot } from "../slot";
export type WritableConnectionInfoSectionProps = {
database: Database;
@@ -14,11 +15,6 @@ const getDefaultWritableConnection = () => ({
PluginPlaceholder<WritableConnectionInfoSectionProps>,
});
-export const PLUGIN_WRITABLE_CONNECTION = getDefaultWritableConnection();
-
-/**
- * @internal Do not call directly. Use the main reinitialize function from metabase/plugins instead.
- */
-export function reinitialize() {
- Object.assign(PLUGIN_WRITABLE_CONNECTION, getDefaultWritableConnection());
-}
+export const PLUGIN_WRITABLE_CONNECTION = definePluginSlot(
+ getDefaultWritableConnection,
+);
diff --git a/frontend/src/metabase/plugins/slot-reset.unit.spec.ts b/frontend/src/metabase/plugins/slot-reset.unit.spec.ts
new file mode 100644
index 00000000000..22faf815a9f
--- /dev/null
+++ b/frontend/src/metabase/plugins/slot-reset.unit.spec.ts
@@ -0,0 +1,26 @@
+import { definePluginSlot, resetPluginSlots } from "./slot";
+
+describe("resetPluginSlots", () => {
+ it.each(["toString", "constructor", "hasOwnProperty"])(
+ "should remove an added own property named %s",
+ (key) => {
+ const slot = definePluginSlot(() => ({}));
+ Object.assign(slot, { [key]: () => "enterprise" });
+
+ resetPluginSlots();
+
+ expect(Object.hasOwn(slot, key)).toBe(false);
+ expect(Object.keys(slot)).toEqual([]);
+ },
+ );
+
+ it("should restore an own default that shadows an inherited property", () => {
+ const slot = definePluginSlot(() => ({ toString: () => "default" }));
+ slot.toString = () => "enterprise";
+
+ resetPluginSlots();
+
+ expect(Object.hasOwn(slot, "toString")).toBe(true);
+ expect(slot.toString()).toBe("default");
+ });
+});
diff --git a/frontend/src/metabase/plugins/slot.ts b/frontend/src/metabase/plugins/slot.ts
new file mode 100644
index 00000000000..c193db0b93e
--- /dev/null
+++ b/frontend/src/metabase/plugins/slot.ts
@@ -0,0 +1,44 @@
+const resets: (() => void)[] = [];
+
+/**
+ * Define a plugin slot with OSS defaults and register it for reinitialize().
+ *
+ * Declare slots once at module scope in the owner's plugins.ts or plugins/
+ * directory, and export them through the owner's index.ts.
+ *
+ * getDefaults runs at declaration and on every reset. It must return a fresh
+ * mutable plain object with enumerable string-keyed properties, or an array
+ * of contributions. Allocate fresh mutable nested values too. Keep the factory
+ * free of side effects and independent of other slots: reset order is not a
+ * dependency contract.
+ *
+ * Plugins fill the slot at boot. Consumers read its properties at call time
+ * rather than capturing them at module scope. Reset preserves the slot's own
+ * identity, but replaces its properties or array contents; nested references
+ * are not preserved.
+ */
+export function definePluginSlot<T extends object>(getDefaults: () => T): T {
+ const slot = getDefaults();
+ resets.push(() => resetPluginSlot(slot, getDefaults()));
+ return slot;
+}
+
+export function resetPluginSlots() {
+ for (const reset of resets) {
+ reset();
+ }
+}
+
+// Mutate in place so that existing references to the slot stay valid.
+function resetPluginSlot<T extends object>(slot: T, defaults: T) {
+ if (Array.isArray(slot) && Array.isArray(defaults)) {
+ slot.splice(0, slot.length, ...defaults);
+ return;
+ }
+ for (const key of Object.keys(slot)) {
+ if (!Object.hasOwn(defaults, key)) {
+ Reflect.deleteProperty(slot, key);
+ }
+ }
+ Object.assign(slot, defaults);
+}
diff --git a/frontend/src/metabase/plugins/slot.unit.spec.ts b/frontend/src/metabase/plugins/slot.unit.spec.ts
new file mode 100644
index 00000000000..20367d0eea7
--- /dev/null
+++ b/frontend/src/metabase/plugins/slot.unit.spec.ts
@@ -0,0 +1,53 @@
+import { reinitialize } from "metabase/plugins";
+
+import { definePluginSlot } from "./slot";
+
+describe("definePluginSlot", () => {
+ it("should return the defaults", () => {
+ const slot = definePluginSlot(() => ({ enabled: false, label: "default" }));
+
+ expect(slot).toEqual({ enabled: false, label: "default" });
+ });
+
+ it("should restore the defaults and remove added keys on reinitialize", () => {
+ const slot = definePluginSlot(() => ({ enabled: false, label: "default" }));
+
+ slot.enabled = true;
+ slot.label = "changed";
+ Object.assign(slot, { extra: "added" });
+ reinitialize();
+
+ expect(slot).toEqual({ enabled: false, label: "default" });
+ expect(Object.keys(slot)).toEqual(["enabled", "label"]);
+ });
+
+ it("should reset every slot", () => {
+ const first = definePluginSlot(() => ({ value: 1 }));
+ const second = definePluginSlot(() => ({ value: 2 }));
+
+ first.value = 10;
+ second.value = 20;
+ reinitialize();
+
+ expect(first.value).toBe(1);
+ expect(second.value).toBe(2);
+ });
+
+ it("should reset an array slot in place", () => {
+ const slot = definePluginSlot((): string[] => []);
+
+ slot.push("a", "b");
+ reinitialize();
+
+ expect(slot).toEqual([]);
+ });
+
+ it("should reset a nested value that was mutated", () => {
+ const slot = definePluginSlot((): { items: string[] } => ({ items: [] }));
+
+ slot.items.push("mutated");
+ reinitialize();
+
+ expect(slot.items).toEqual([]);
+ });
+});