diff --git a/packages/osd-ui-shared-deps/theme_config.d.ts b/packages/osd-ui-shared-deps/theme_config.d.ts index ff88a4965aca..ecb3a77c0d79 100644 --- a/packages/osd-ui-shared-deps/theme_config.d.ts +++ b/packages/osd-ui-shared-deps/theme_config.d.ts @@ -28,6 +28,16 @@ export const themeVersionLabelMap: Record; */ export const themeVersionValueMap: Record; +/** + * List of theme schema values + */ +export const themeSchemaValues: string[]; + +/** + * List of theme options + */ +export const themeOptions: string[]; + /** * Theme CSS distributable filenames by themeVersion and themeMode * Note: used by bootstrap template diff --git a/packages/osd-ui-shared-deps/theme_config.js b/packages/osd-ui-shared-deps/theme_config.js index 0ccd422e321d..7abc3f6bfa81 100644 --- a/packages/osd-ui-shared-deps/theme_config.js +++ b/packages/osd-ui-shared-deps/theme_config.js @@ -25,12 +25,21 @@ const THEME_VERSION_VALUE_MAP = { const THEME_VERSIONS = Object.keys(THEME_VERSION_LABEL_MAP); const THEME_TAGS = THEME_VERSIONS.flatMap((v) => THEME_MODES.map((m) => `${v}${m}`)); +// Setup theme options to be backwards compatible with the fact that v8 was persisted with its +// label rather than with the correct themeVersion value +const THEME_SCHEMA_VALUES = THEME_VERSIONS.concat(THEME_VERSION_LABEL_MAP.v8); +const THEME_OPTIONS = THEME_VERSIONS.map((v) => (v !== 'v8' ? v : THEME_VERSION_LABEL_MAP.v8)); + exports.themeVersionLabelMap = THEME_VERSION_LABEL_MAP; exports.themeVersionValueMap = THEME_VERSION_VALUE_MAP; exports.themeTags = THEME_TAGS; +exports.themeSchemaValues = THEME_SCHEMA_VALUES; + +exports.themeOptions = THEME_OPTIONS; + exports.themeCssDistFilenames = THEME_VERSIONS.reduce((map, v) => { map[v] = THEME_MODES.reduce((acc, m) => { acc[m] = `osd-ui-shared-deps.${v}.${m}.css`; diff --git a/src/core/server/ui_settings/settings/theme.test.ts b/src/core/server/ui_settings/settings/theme.test.ts index 05c07372d1a7..5e6ea67aefc5 100644 --- a/src/core/server/ui_settings/settings/theme.test.ts +++ b/src/core/server/ui_settings/settings/theme.test.ts @@ -57,6 +57,8 @@ describe('theme settings', () => { it('should only accept valid values', () => { expect(() => validate('v7')).not.toThrow(); + expect(() => validate('v8')).not.toThrow(); + expect(() => validate('v9')).not.toThrow(); expect(() => validate('Next (preview)')).not.toThrow(); expect(() => validate('v12')).toThrowErrorMatchingInlineSnapshot(` "types that failed validation: diff --git a/src/core/server/ui_settings/settings/theme.ts b/src/core/server/ui_settings/settings/theme.ts index 8e7813943003..c81a10f38be3 100644 --- a/src/core/server/ui_settings/settings/theme.ts +++ b/src/core/server/ui_settings/settings/theme.ts @@ -30,17 +30,11 @@ import { schema } from '@osd/config-schema'; import { i18n } from '@osd/i18n'; -import { themeVersionLabelMap } from '@osd/ui-shared-deps'; +import { themeVersionLabelMap, themeSchemaValues, themeOptions } from '@osd/ui-shared-deps'; import type { Type } from '@osd/config-schema'; import { UiSettingsParams } from '../../../types'; import { DEFAULT_THEME_VERSION } from '../ui_settings_config'; -// Setup theme options to be backwards compatible with the fact that v8 was persisted with its -// label rather than with the correct themeVersion value -const THEME_VERSIONS = Object.keys(themeVersionLabelMap); -const THEME_SCHEMA_VALUES = THEME_VERSIONS.concat(themeVersionLabelMap.v8); -const THEME_OPTIONS = THEME_VERSIONS.map((v) => (v !== 'v8' ? v : themeVersionLabelMap.v8)); - export const getThemeSettings = (): Record => { return { 'theme:enableUserControl': { @@ -79,7 +73,7 @@ export const getThemeSettings = (): Record => { ? themeVersionLabelMap[DEFAULT_THEME_VERSION] : DEFAULT_THEME_VERSION, type: 'select', - options: THEME_OPTIONS, + options: themeOptions, optionLabels: themeVersionLabelMap, description: i18n.translate('core.ui_settings.params.themeVersionText', { defaultMessage: `

Switch between the themes used for the current and next versions of OpenSearch Dashboards. A page refresh is required for the setting to be applied.

{linkText}

`, @@ -91,7 +85,7 @@ export const getThemeSettings = (): Record => { requiresPageReload: true, preferBrowserSetting: true, category: ['appearance'], - schema: schema.oneOf(THEME_SCHEMA_VALUES.map((v) => schema.literal(v)) as [Type]), + schema: schema.oneOf(themeSchemaValues.map((v) => schema.literal(v)) as [Type]), }, }; }; diff --git a/src/core/server/ui_settings/ui_settings_config.ts b/src/core/server/ui_settings/ui_settings_config.ts index 4be80102e9d7..32dc9fb9dd36 100644 --- a/src/core/server/ui_settings/ui_settings_config.ts +++ b/src/core/server/ui_settings/ui_settings_config.ts @@ -28,7 +28,8 @@ * under the License. */ -import { schema, TypeOf } from '@osd/config-schema'; +import { schema, TypeOf, Type } from '@osd/config-schema'; +import { themeOptions } from '@osd/ui-shared-deps'; import { ConfigDeprecationProvider } from 'src/core/server'; import { ServiceConfigDescriptor } from '../internal_types'; @@ -59,7 +60,7 @@ const configSchema = schema.object({ defaults: schema.object({ 'theme:darkMode': schema.maybe(schema.boolean({ defaultValue: false })), 'theme:version': schema.maybe( - schema.oneOf([schema.literal('v7'), schema.literal('Next (preview)')], { + schema.oneOf(themeOptions.map((option) => schema.literal(option)) as [Type], { defaultValue: 'Next (preview)', }) ),