Skip to content

Commit

Permalink
Allow overriding the themeTag temporarily via the query-string
Browse files Browse the repository at this point in the history
Also:
* Fix `getOverrideOrDefault` not correctly returning overridden values

Signed-off-by: Miki <[email protected]>
  • Loading branch information
AMoo-Miki committed Oct 7, 2024
1 parent c5462c3 commit 86c6832
Show file tree
Hide file tree
Showing 12 changed files with 602 additions and 42 deletions.
16 changes: 16 additions & 0 deletions packages/osd-ui-shared-deps/theme_config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
* SPDX-License-Identifier: Apache-2.0
*/

/**
* Types for valid theme versions
*/
type ThemeVersion = 'v7' | 'v8' | 'v9';

/**
* Types for valid theme color-scheme modes
*/
type ThemeMode = 'light' | 'dark';

/**
* Types for valid theme tags (themeVersion + themeMode)
* Note: used by @osd/optimizer
Expand All @@ -16,6 +26,12 @@ export type ThemeTags = readonly ThemeTag[];
*/
export const themeTags: ThemeTags;

/**
* Map of themeTag values to their version and mode
* Note: this is used for ui display
*/
export const themeTagDetailMap: Map<ThemeTag, { version: ThemeVersion; mode: ThemeMode }>;

/**
* Map of themeVersion values to labels
* Note: this is used for ui display
Expand Down
17 changes: 15 additions & 2 deletions packages/osd-ui-shared-deps/theme_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
*/

/**
* The purpose of this file is to centalize theme configuration so it can be used across server,
* The purpose of this file is to centralize theme configuration so it can be used across server,
* client, and dev tooling. DO NOT add dependencies that wouldn't operate in all of these contexts.
*
* Default theme is specified in the uiSettings schema.
* A version (key) and color-scheme mode cannot contain a backtick character.
*/

const THEME_MODES = ['light', 'dark'];
Expand All @@ -23,14 +24,26 @@ const THEME_VERSION_VALUE_MAP = {
...Object.fromEntries(Object.keys(THEME_VERSION_LABEL_MAP).map((v) => [v, v])),
};
const THEME_VERSIONS = Object.keys(THEME_VERSION_LABEL_MAP);
const THEME_TAGS = THEME_VERSIONS.flatMap((v) => THEME_MODES.map((m) => `${v}${m}`));
const THEME_TAGS = [];

const themeTagDetailMap = new Map();
THEME_VERSIONS.forEach((version) => {
THEME_MODES.forEach((mode) => {
const key = `${version}${mode}`;

themeTagDetailMap.set(key, { version, mode });
THEME_TAGS.push(key);
});
});

exports.themeVersionLabelMap = THEME_VERSION_LABEL_MAP;

exports.themeVersionValueMap = THEME_VERSION_VALUE_MAP;

exports.themeTags = THEME_TAGS;

exports.themeTagDetailMap = themeTagDetailMap;

exports.themeCssDistFilenames = THEME_VERSIONS.reduce((map, v) => {
map[v] = THEME_MODES.reduce((acc, m) => {
acc[m] = `osd-ui-shared-deps.${v}.${m}.css`;
Expand Down
1 change: 1 addition & 0 deletions src/core/server/http/http_server.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ function createRawRequestMock(customization: DeepPartial<Request> = {}) {
isAuthenticated: true,
},
headers: {},
query: {},
path,
route: { settings: {} },
url,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 86c6832

Please sign in to comment.