Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(style-theme): add support for custom superset themes #12858

Merged
merged 4 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions superset-frontend/src/SqlLab/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { createStore, compose, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import thunkMiddleware from 'redux-thunk';
import { hot } from 'react-hot-loader/root';
import { supersetTheme, ThemeProvider } from '@superset-ui/core';
import { ThemeProvider } from '@superset-ui/core';
import {
initFeatureFlags,
isFeatureEnabled,
Expand All @@ -41,6 +41,7 @@ import setupApp from '../setup/setupApp';
import './main.less';
import '../../stylesheets/reactable-pagination.less';
import '../components/FilterableTable/FilterableTableStyles.less';
import { theme } from '../preamble';

setupApp();

Expand Down Expand Up @@ -109,7 +110,7 @@ if (sqlLabMenu) {

const Application = () => (
<Provider store={store}>
<ThemeProvider theme={supersetTheme}>
<ThemeProvider theme={theme}>
<App />
</ThemeProvider>
</Provider>
Expand Down
5 changes: 3 additions & 2 deletions superset-frontend/src/addSlice/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
*/
import React from 'react';
import { hot } from 'react-hot-loader/root';
import { supersetTheme, ThemeProvider } from '@superset-ui/core';
import { ThemeProvider } from '@superset-ui/core';
import setupApp from '../setup/setupApp';
import setupPlugins from '../setup/setupPlugins';
import { DynamicPluginProvider } from '../components/DynamicPlugins';
import AddSliceContainer from './AddSliceContainer';
import { initFeatureFlags } from '../featureFlags';
import { theme } from '../preamble';

setupApp();
setupPlugins();
Expand All @@ -36,7 +37,7 @@ const bootstrapData = JSON.parse(
initFeatureFlags(bootstrapData.common.feature_flags);

const App = () => (
<ThemeProvider theme={supersetTheme}>
<ThemeProvider theme={theme}>
<DynamicPluginProvider>
<AddSliceContainer datasources={bootstrapData.datasources} />
</DynamicPluginProvider>
Expand Down
5 changes: 3 additions & 2 deletions superset-frontend/src/dashboard/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@
import { hot } from 'react-hot-loader/root';
import React from 'react';
import { Provider } from 'react-redux';
import { supersetTheme, ThemeProvider } from '@superset-ui/core';
import { ThemeProvider } from '@superset-ui/core';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import { DynamicPluginProvider } from 'src/components/DynamicPlugins';
import setupApp from '../setup/setupApp';
import setupPlugins from '../setup/setupPlugins';
import DashboardContainer from './containers/Dashboard';
import { theme } from '../preamble';

setupApp();
setupPlugins();

const App = ({ store }) => (
<Provider store={store}>
<DndProvider backend={HTML5Backend}>
<ThemeProvider theme={supersetTheme}>
<ThemeProvider theme={theme}>
<DynamicPluginProvider>
<DashboardContainer />
</DynamicPluginProvider>
Expand Down
5 changes: 3 additions & 2 deletions superset-frontend/src/explore/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,23 @@ import { hot } from 'react-hot-loader/root';
import { Provider } from 'react-redux';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
import { supersetTheme, ThemeProvider } from '@superset-ui/core';
import { ThemeProvider } from '@superset-ui/core';
import { DynamicPluginProvider } from 'src/components/DynamicPlugins';
import ToastPresenter from '../messageToasts/containers/ToastPresenter';
import ExploreViewContainer from './components/ExploreViewContainer';
import setupApp from '../setup/setupApp';
import setupPlugins from '../setup/setupPlugins';
import './main.less';
import '../../stylesheets/reactable-pagination.less';
import { theme } from '../preamble';

setupApp();
setupPlugins();

const App = ({ store }) => (
<Provider store={store}>
<DndProvider backend={HTML5Backend}>
<ThemeProvider theme={supersetTheme}>
<ThemeProvider theme={theme}>
<DynamicPluginProvider>
<ExploreViewContainer />
<ToastPresenter />
Expand Down
8 changes: 7 additions & 1 deletion superset-frontend/src/preamble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import { setConfig as setHotLoaderConfig } from 'react-hot-loader';
import 'abortcontroller-polyfill/dist/abortcontroller-polyfill-only';
import moment from 'moment';
import { configure } from '@superset-ui/core';
import { configure, supersetTheme } from '@superset-ui/core';
import ColorScheme from '@superset-ui/core/lib/color/ColorScheme';
import { merge } from 'lodash';
import setupClient from './setup/setupClient';
import setupColors from './setup/setupColors';
import setupFormatters from './setup/setupFormatters';
Expand Down Expand Up @@ -74,3 +75,8 @@ setupColors(extraCategoricalColorSchemes, extraSequentialColorSchemes);

// Setup number formatters
setupFormatters();

export const theme = merge(
supersetTheme,
bootstrapData?.common?.theme_overrides ?? {},
);
6 changes: 3 additions & 3 deletions superset-frontend/src/profile/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import { hot } from 'react-hot-loader/root';
import thunk from 'redux-thunk';
import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
import { Provider } from 'react-redux';
import { supersetTheme, ThemeProvider } from '@superset-ui/core';
import { ThemeProvider } from '@superset-ui/core';
import App from './components/App';
import messageToastReducer from '../messageToasts/reducers';
import { initEnhancer } from '../reduxUtils';
import setupApp from '../setup/setupApp';

import './main.less';
import { theme } from '../preamble';

setupApp();

Expand All @@ -46,7 +46,7 @@ const store = createStore(

const Application = () => (
<Provider store={store}>
<ThemeProvider theme={supersetTheme}>
<ThemeProvider theme={theme}>
<App user={bootstrap.user} />
</ThemeProvider>
</Provider>
Expand Down
5 changes: 3 additions & 2 deletions superset-frontend/src/views/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { Provider as ReduxProvider } from 'react-redux';
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import { QueryParamProvider } from 'use-query-params';
import { initFeatureFlags } from 'src/featureFlags';
import { supersetTheme, ThemeProvider } from '@superset-ui/core';
import { ThemeProvider } from '@superset-ui/core';
import { DynamicPluginProvider } from 'src/components/DynamicPlugins';
import ErrorBoundary from 'src/components/ErrorBoundary';
import Menu from 'src/components/Menu/Menu';
Expand All @@ -47,6 +47,7 @@ import setupApp from '../setup/setupApp';
import setupPlugins from '../setup/setupPlugins';
import Welcome from './CRUD/welcome/Welcome';
import ToastPresenter from '../messageToasts/containers/ToastPresenter';
import { theme } from '../preamble';

setupApp();
setupPlugins();
Expand All @@ -68,7 +69,7 @@ const store = createStore(

const App = () => (
<ReduxProvider store={store}>
<ThemeProvider theme={supersetTheme}>
<ThemeProvider theme={theme}>
<FlashProvider common={common}>
<Router>
<DynamicPluginProvider>
Expand Down
5 changes: 3 additions & 2 deletions superset-frontend/src/views/menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@
*/
import React from 'react';
import ReactDOM from 'react-dom';
import { supersetTheme, ThemeProvider } from '@superset-ui/core';
import { ThemeProvider } from '@superset-ui/core';
import Menu from 'src/components/Menu/Menu';
import { theme } from '../preamble';

const container = document.getElementById('app');
const bootstrapJson = container?.getAttribute('data-bootstrap') ?? '{}';
const bootstrap = JSON.parse(bootstrapJson);
const menu = { ...bootstrap.common.menu_data };
const app = (
<ThemeProvider theme={supersetTheme}>
<ThemeProvider theme={theme}>
<Menu data={menu} />
</ThemeProvider>
);
Expand Down
22 changes: 20 additions & 2 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def _try_json_readsha( # pylint: disable=unused-argument

# EXTRA_CATEGORICAL_COLOR_SCHEMES is used for adding custom categorical color schemes
# example code for "My custom warm to hot" color scheme
# EXTRA_CATEGORICAL_COLOR_SCHEMES = [
# EXTRA_CATEGORICAL_COLOR_SCHEMES = [
# {
# "id": 'myVisualizationColors',
# "description": '',
Expand All @@ -382,11 +382,29 @@ def _try_json_readsha( # pylint: disable=unused-argument
# ['#006699', '#009DD9', '#5AAA46', '#44AAAA', '#DDAA77', '#7799BB', '#88AA77',
# '#552288', '#5AAA46', '#CC7788', '#EEDD55', '#9977BB', '#BBAA44', '#DDCCDD']
# }]
#

# This is merely a default
EXTRA_CATEGORICAL_COLOR_SCHEMES: List[Dict[str, Any]] = []

# THEME_OVERRIDES is used for adding custom theme to superset
# example code for "My theme" custom scheme
# THEME_OVERRIDES = {
# "borderRadius": 4,
# "colors": {
# "primary": {
# "base": 'red',
# },
# "secondary": {
# "base": 'green',
# },
# "grayscale": {
# "base": 'orange',
# }
# }
# }

THEME_OVERRIDES: Dict[str, Any] = {}

# EXTRA_SEQUENTIAL_COLOR_SCHEMES is used for adding custom sequential color schemes
# EXTRA_SEQUENTIAL_COLOR_SCHEMES = [
# {
Expand Down
1 change: 1 addition & 0 deletions superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ def common_bootstrap_payload() -> Dict[str, Any]:
"feature_flags": get_feature_flags(),
"extra_sequential_color_schemes": conf["EXTRA_SEQUENTIAL_COLOR_SCHEMES"],
"extra_categorical_color_schemes": conf["EXTRA_CATEGORICAL_COLOR_SCHEMES"],
"theme_overrides": conf["THEME_OVERRIDES"],
"menu_data": menu_data(),
}

Expand Down