Skip to content

Commit

Permalink
Merge branch 'main' into remove-non-inclusive-language
Browse files Browse the repository at this point in the history
  • Loading branch information
angle943 authored Feb 27, 2025
2 parents 2ee1dae + 06748d2 commit 13fea9e
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 24 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/9448.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
breaking:
- Remove `withLongNumerals` in `HttpFetchOptions`. ([#9448](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9448))
10 changes: 10 additions & 0 deletions packages/osd-ui-shared-deps/theme_config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ export const themeVersionLabelMap: Record<string, string>;
*/
export const themeVersionValueMap: Record<string, string>;

/**
* 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
Expand Down
9 changes: 9 additions & 0 deletions packages/osd-ui-shared-deps/theme_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down
14 changes: 4 additions & 10 deletions src/core/public/http/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,20 +192,14 @@ export class Fetch {
if (NDJSON_CONTENT.test(contentType)) {
body = await response.blob();
} else if (JSON_CONTENT.test(contentType)) {
// ToDo: [3.x] Remove withLongNumerals
body =
fetchOptions.withLongNumeralsSupport || fetchOptions.withLongNumerals
? parse(await response.text())
: await response.json();
body = fetchOptions.withLongNumeralsSupport
? parse(await response.text())
: await response.json();
} else {
const text = await response.text();

try {
// ToDo: [3.x] Remove withLongNumerals
body =
fetchOptions.withLongNumeralsSupport || fetchOptions.withLongNumerals
? parse(text)
: JSON.parse(text);
body = fetchOptions.withLongNumeralsSupport ? parse(text) : JSON.parse(text);
} catch (err) {
body = text;
}
Expand Down
3 changes: 0 additions & 3 deletions src/core/public/http/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,6 @@ export interface HttpFetchOptions extends HttpRequestInit {
*/
withLongNumeralsSupport?: boolean;

/** @deprecated use {@link withLongNumeralsSupport} instead */
withLongNumerals?: boolean;

prependOptions?: PrependOptions;
}

Expand Down
2 changes: 2 additions & 0 deletions src/core/server/ui_settings/settings/theme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 3 additions & 9 deletions src/core/server/ui_settings/settings/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, UiSettingsParams> => {
return {
'theme:enableUserControl': {
Expand Down Expand Up @@ -79,7 +73,7 @@ export const getThemeSettings = (): Record<string, UiSettingsParams> => {
? 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: `<p>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.</p><p><a href="{href}">{linkText}</a></p>`,
Expand All @@ -91,7 +85,7 @@ export const getThemeSettings = (): Record<string, UiSettingsParams> => {
requiresPageReload: true,
preferBrowserSetting: true,
category: ['appearance'],
schema: schema.oneOf(THEME_SCHEMA_VALUES.map((v) => schema.literal(v)) as [Type<string>]),
schema: schema.oneOf(themeSchemaValues.map((v) => schema.literal(v)) as [Type<string>]),
},
};
};
5 changes: 3 additions & 2 deletions src/core/server/ui_settings/ui_settings_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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<string>], {
defaultValue: 'Next (preview)',
})
),
Expand Down

0 comments on commit 13fea9e

Please sign in to comment.