The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
UXW-2257 fix theme override after table render (#66620)
Denis Berezin8279532cbb4d
diff --git a/e2e/test/scenarios/onboarding/setup/user_settings.cy.spec.js b/e2e/test/scenarios/onboarding/setup/user_settings.cy.spec.jsindex 9471955a6e4..e97e21eb025 100644--- a/e2e/test/scenarios/onboarding/setup/user_settings.cy.spec.js+++ b/e2e/test/scenarios/onboarding/setup/user_settings.cy.spec.js@@ -287,6 +287,75 @@ describe("user > settings", () => {cy.visit("/account/profile");assertDarkMode();});++ it("should apply user's selected theme instead of browser's OS theme preference", () => {+ cy.visit("/account/profile");++ cy.findByDisplayValue("Use system default").click();+ H.popover().findByText("Light").click();++ assertLightMode();++ H.navigationSidebar().findByText("Our analytics").click();+ H.collectionTable().findByText("Orders").should("exist").click();++ cy.findByTestId("table-body").should("be.visible"); // wait for table to be rendered++ cy.window().then((win) => {+ H.appBar()+ .findByLabelText("Settings")+ .should("exist")+ .then(($button) => {+ cy.wrap(win.getComputedStyle($button[0]).color).should(+ "eq",+ "rgba(7, 23, 34, 0.84)", // text-dark+ );+ });++ cy.findByTestId("viz-type-button").click();+ cy.findByTestId("sidebar-left")+ .findByText("Other charts")+ .then(($text) => {+ cy.wrap(win.getComputedStyle($text[0]).color).should(+ "eq",+ "rgba(7, 23, 34, 0.62)", // text-medium+ );+ });+ });++ H.appBar().findByLabelText("Settings").click();+ H.popover().findByText("Account settings").click();+ cy.findByDisplayValue("Light").click();+ H.popover().findByText("Dark").click();++ H.openNavigationSidebar();+ H.navigationSidebar().findByText("Our analytics").click();+ H.collectionTable().findByText("Orders").should("exist").click();++ cy.findByTestId("table-body").should("be.visible"); // wait for table to be rendered++ cy.window().then((win) => {+ H.appBar()+ .findByLabelText("Settings")+ .should("exist")+ .then(($button) => {+ cy.wrap(win.getComputedStyle($button[0]).color).should(+ "eq",+ "rgba(255, 255, 255, 0.95)", // text-dark+ );+ });++ cy.findByTestId("viz-type-button").click();+ cy.findByTestId("sidebar-left")+ .findByText("Other charts")+ .then(($text) => {+ cy.wrap(win.getComputedStyle($text[0]).color).should(+ "eq",+ "rgba(255, 255, 255, 0.69)", // text-medium+ );+ });+ });+ });});});diff --git a/frontend/src/metabase/app.js b/frontend/src/metabase/app.jsindex 3b61fbbe0de..28524f89ad3 100644--- a/frontend/src/metabase/app.js+++ b/frontend/src/metabase/app.js@@ -37,7 +37,6 @@ import { initializePlugins } from "ee-plugins";import { ModifiedBackend } from "metabase/common/components/dnd/ModifiedBackend";import { createTracker } from "metabase/lib/analytics";import api from "metabase/lib/api";-import { getUserColorScheme } from "metabase/lib/color-scheme";import { initializeEmbedding } from "metabase/lib/embed";import { captureConsoleErrors } from "metabase/lib/errors";import { MetabaseReduxProvider } from "metabase/lib/redux/custom-context";@@ -81,7 +80,7 @@ function _init(reducers, getRoutes, callback) {<MetabaseReduxProvider store={store}><EmotionCacheProvider><DragDropContextProvider backend={ModifiedBackend} context={{ window }}>- <ThemeProvider initialColorScheme={getUserColorScheme()}>+ <ThemeProvider><GlobalStyles /><MetabotProvider><HistoryProvider history={syncedHistory}>diff --git a/frontend/src/metabase/lib/color-scheme.ts b/frontend/src/metabase/lib/color-scheme.tsindex 34bae0dec71..1ef16e9198c 100644--- a/frontend/src/metabase/lib/color-scheme.ts+++ b/frontend/src/metabase/lib/color-scheme.ts@@ -13,3 +13,7 @@ export const getUserColorScheme = (): ColorScheme | undefined => {return window.MetabaseUserColorScheme;}};++export const setUserColorSchemeAfterUpdate = (value: ColorScheme) => {+ window.MetabaseUserColorScheme = value;+};diff --git a/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsx b/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsxindex d3b8e3a3405..3a0038e5a8f 100644--- a/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsx+++ b/frontend/src/metabase/ui/components/theme/ThemeProvider/ThemeProvider.tsx@@ -23,6 +23,10 @@ import type {ColorScheme,ResolvedColorScheme,} from "metabase/lib/color-scheme";+import {+ getUserColorScheme,+ setUserColorSchemeAfterUpdate,+} from "metabase/lib/color-scheme";import { mutateColors } from "metabase/lib/colors/colors";import type { DisplayTheme } from "metabase/public/lib/types";@@ -176,11 +180,13 @@ export const ThemeProvider = (props: ThemeProviderProps) => {key: "color-scheme",value: value,});++ setUserColorSchemeAfterUpdate(value);}, []);return (<ColorSchemeProvider- defaultColorScheme={props.initialColorScheme}+ defaultColorScheme={getUserColorScheme()}forceColorScheme={forceColorScheme}onUpdateColorScheme={handleUpdateColorScheme}>