You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/04/09 17:17:23 UTC
(superset) branch feat/extension-color-scheme-api created (now 477c06dbf05)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a change to branch feat/extension-color-scheme-api
in repository https://gitbox.apache.org/repos/asf/superset.git
at 477c06dbf05 feat(extensions): expose Superset categorical color schemes to extensions
This branch includes the following new commits:
new 477c06dbf05 feat(extensions): expose Superset categorical color schemes to extensions
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(superset) 01/01: feat(extensions): expose Superset categorical color schemes to extensions
Posted by ru...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch feat/extension-color-scheme-api
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 477c06dbf05eab332832e84c7b2ff3c19aafbf2f
Author: Amin Ghadersohi <am...@gmail.com>
AuthorDate: Thu Apr 9 10:16:28 2026 -0700
feat(extensions): expose Superset categorical color schemes to extensions
Add a `colors` module to superset-core that lets extensions read
Superset's registered categorical color palettes without taking a
direct dependency on @superset-ui/core.
Pattern: ExtensionsStartup injects the live CategoricalSchemeRegistry
singleton into superset-core at startup via
`registerCategoricalSchemeRegistry()`. Extensions then call
`colors.getCategoricalSchemeNames()` / `colors.getSchemeColors(name)`
through the federated `@apache-superset/core` module — the same
singleton, so palettes registered by the host are visible.
Co-Authored-By: Claude Sonnet 4.6 <no...@anthropic.com>
---
.../packages/superset-core/src/colors/index.ts | 68 ++++++++++++++++++++++
.../packages/superset-core/src/index.ts | 1 +
.../src/extensions/ExtensionsStartup.tsx | 13 ++++-
3 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/superset-frontend/packages/superset-core/src/colors/index.ts b/superset-frontend/packages/superset-core/src/colors/index.ts
new file mode 100644
index 00000000000..45bd09c6f25
--- /dev/null
+++ b/superset-frontend/packages/superset-core/src/colors/index.ts
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Minimal interface for the categorical color scheme registry.
+ * Mirrors the public surface of @superset-ui/core's ColorSchemeRegistry.
+ */
+export interface CategoricalScheme {
+ id: string;
+ label?: string;
+ colors: string[];
+}
+
+export interface CategoricalSchemeRegistryLike {
+ keys(): string[];
+ get(name: string): CategoricalScheme | null | undefined;
+}
+
+let _registry: CategoricalSchemeRegistryLike | null = null;
+
+/**
+ * Called by the Superset host app (ExtensionsStartup) to inject the
+ * categorical color scheme registry so extensions can access it without
+ * depending directly on @superset-ui/core.
+ */
+export function registerCategoricalSchemeRegistry(
+ registry: CategoricalSchemeRegistryLike,
+): void {
+ _registry = registry;
+}
+
+/**
+ * Returns the categorical color scheme registry registered by the host app,
+ * or null if not yet injected (e.g. in tests or isolated builds).
+ */
+export function getCategoricalSchemeRegistry(): CategoricalSchemeRegistryLike | null {
+ return _registry;
+}
+
+/**
+ * Returns an alphabetically sorted list of all registered scheme names.
+ */
+export function getCategoricalSchemeNames(): string[] {
+ return _registry?.keys().sort() ?? [];
+}
+
+/**
+ * Returns the color array for a named scheme, or null if not found.
+ */
+export function getSchemeColors(schemeName: string): string[] | null {
+ return _registry?.get(schemeName)?.colors ?? null;
+}
diff --git a/superset-frontend/packages/superset-core/src/index.ts b/superset-frontend/packages/superset-core/src/index.ts
index 75863372409..060362c6905 100644
--- a/superset-frontend/packages/superset-core/src/index.ts
+++ b/superset-frontend/packages/superset-core/src/index.ts
@@ -29,3 +29,4 @@ export * as theme from './theme';
export * as translation from './translation';
export * as components from './components';
export * as utils from './utils';
+export * as colors from './colors';
diff --git a/superset-frontend/src/extensions/ExtensionsStartup.tsx b/superset-frontend/src/extensions/ExtensionsStartup.tsx
index 888f8c4e194..285425e23b5 100644
--- a/superset-frontend/src/extensions/ExtensionsStartup.tsx
+++ b/superset-frontend/src/extensions/ExtensionsStartup.tsx
@@ -19,7 +19,11 @@
import { useEffect, useState } from 'react';
// eslint-disable-next-line no-restricted-syntax
import * as supersetCore from '@apache-superset/core';
-import { FeatureFlag, isFeatureEnabled } from '@superset-ui/core';
+import {
+ FeatureFlag,
+ isFeatureEnabled,
+ getCategoricalSchemeRegistry,
+} from '@superset-ui/core';
import {
authentication,
core,
@@ -45,6 +49,7 @@ declare global {
menus: typeof menus;
sqlLab: typeof sqlLab;
views: typeof views;
+ colors: typeof supersetCore.colors;
};
}
}
@@ -80,6 +85,12 @@ const ExtensionsStartup: React.FC<{ children?: React.ReactNode }> = ({
views,
};
+ // Inject the categorical color scheme registry so extensions can access
+ // Superset's registered palettes without depending on @superset-ui/core.
+ supersetCore.colors.registerCategoricalSchemeRegistry(
+ getCategoricalSchemeRegistry(),
+ );
+
const setup = async () => {
if (isFeatureEnabled(FeatureFlag.EnableExtensions)) {
try {