Skip to content

Commit

Permalink
Fix opensearch theme version
Browse files Browse the repository at this point in the history
Originally, in Advanced setting, there is a setting let you set theme version from `v7` to `v8(beta)`
implying version that do not exist yet.

Change the version label to `v1` as default theme and remove the beta version.
Hide `theme:version` UI from Advanced Setting since we have only one theme avaialble now.

Signed-off-by: Zuocheng Ding <[email protected]>
  • Loading branch information
zuochengding committed Jan 5, 2022
1 parent ac9c837 commit 56bfda5
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 92 deletions.
2 changes: 1 addition & 1 deletion DEVELOPER_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ Do not use setters, they cause more problems than they can solve.
When writing a new component, create a sibling SASS file of the same name and import directly into the **top** of the JS/TS component file. Doing so ensures the styles are never separated or lost on import and allows for better modularization (smaller individual plugin asset footprint).
All SASS (.scss) files will automatically build with the [EUI](https://elastic.github.io/eui/#/guidelines/sass) & OpenSearch Dashboards invisibles (SASS variables, mixins, functions) from the [`globals_[theme].scss` file](src/core/public/core_app/styles/_globals_v7light.scss).
All SASS (.scss) files will automatically build with the [EUI](https://elastic.github.io/eui/#/guidelines/sass) & OpenSearch Dashboards invisibles (SASS variables, mixins, functions) from the [`globals_[theme].scss` file](src/core/public/core_app/styles/_globals_v1light.scss).
While the styles for this component will only be loaded if the component exists on the page,
the styles **will** be global and so it is recommended to use a three letter prefix on your
Expand Down
10 changes: 5 additions & 5 deletions packages/osd-optimizer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@ Any import in a bundle which resolves into another bundles "context" directory,

## Themes

SASS imports in bundles are automatically converted to CSS for one or more themes. In development we build the `v7light` and `v7dark` themes by default to improve build performance. When producing distributable bundles the default shifts to `*` so that the distributable bundles will include all themes, preventing the bundles from needing to be rebuilt when users change the active theme in OpenSearch Dashboards's advanced settings.
SASS imports in bundles are automatically converted to CSS for one or more themes. In development we build the `v1light` and `v1dark` themes by default to improve build performance. When producing distributable bundles the default shifts to `*` so that the distributable bundles will include all themes, preventing the bundles from needing to be rebuilt when users change the active theme in OpenSearch Dashboards's advanced settings.

To customize the themes that are built for development you can specify the `OSD_OPTIMIZER_THEMES` environment variable to one or more theme tags, or use `*` to build styles for all themes. Unfortunately building more than one theme significantly impacts build performance, so try to be strategic about which themes you build.

Currently supported theme tags: `v7light`, `v7dark`, `v8light`, `v8dark`
Currently supported theme tags: `v1light`, `v1dark`

Examples:
```sh
# start OpenSearch Dashboards with only a single theme
OSD_OPTIMIZER_THEMES=v7light yarn start
OSD_OPTIMIZER_THEMES=v1light yarn start

# start OpenSearch Dashboards with dark themes for version 7 and 8
OSD_OPTIMIZER_THEMES=v7dark,v8dark yarn start
# start OpenSearch Dashboards with dark themes for version 1
OSD_OPTIMIZER_THEMES=v1dark yarn start

# start OpenSearch Dashboards with all the themes
OSD_OPTIMIZER_THEMES=* yarn start
Expand Down

This file was deleted.

This file was deleted.

39 changes: 18 additions & 21 deletions packages/osd-optimizer/src/common/theme_tags.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,70 +35,67 @@ import { parseThemeTags } from './theme_tags';
it('returns default tags when passed undefined', () => {
expect(parseThemeTags()).toMatchInlineSnapshot(`
Array [
"v7dark",
"v7light",
"v1dark",
"v1light",
]
`);
});

it('returns all tags when passed *', () => {
expect(parseThemeTags('*')).toMatchInlineSnapshot(`
Array [
"v7dark",
"v7light",
"v8dark",
"v8light",
"v1dark",
"v1light",
]
`);
});

it('returns specific tag when passed a single value', () => {
expect(parseThemeTags('v8light')).toMatchInlineSnapshot(`
expect(parseThemeTags('v1light')).toMatchInlineSnapshot(`
Array [
"v8light",
"v1light",
]
`);
});

it('returns specific tags when passed a comma separated list', () => {
expect(parseThemeTags('v8light, v7dark,v7light')).toMatchInlineSnapshot(`
expect(parseThemeTags('v1dark, v1light')).toMatchInlineSnapshot(`
Array [
"v7dark",
"v7light",
"v8light",
"v1dark",
"v1light",
]
`);
});

it('returns specific tags when passed an array', () => {
expect(parseThemeTags(['v8light', 'v7light'])).toMatchInlineSnapshot(`
expect(parseThemeTags(['v1dark', 'v1light'])).toMatchInlineSnapshot(`
Array [
"v7light",
"v8light",
"v1dark",
"v1light",
]
`);
});

it('throws when an invalid tag is in the array', () => {
expect(() => parseThemeTags(['v8light', 'v7light', 'bar'])).toThrowErrorMatchingInlineSnapshot(
`"Invalid theme tags [bar], options: [v7dark, v7light, v8dark, v8light]"`
expect(() => parseThemeTags(['v1dark', 'v1light', 'bar'])).toThrowErrorMatchingInlineSnapshot(
`"Invalid theme tags [bar], options: [v1dark, v1light]"`
);
});

it('throws when an invalid tags in comma separated list', () => {
expect(() => parseThemeTags('v8light ,v7light,bar,box ')).toThrowErrorMatchingInlineSnapshot(
`"Invalid theme tags [bar, box], options: [v7dark, v7light, v8dark, v8light]"`
expect(() => parseThemeTags('v1dark ,v1light, bar, box')).toThrowErrorMatchingInlineSnapshot(
`"Invalid theme tags [bar, box], options: [v1dark, v1light]"`
);
});

it('returns tags in alphabetical order', () => {
const tags = parseThemeTags(['v7light', 'v8light']);
const tags = parseThemeTags(['v1dark', 'v1light']);
expect(tags).toEqual(tags.slice().sort((a, b) => a.localeCompare(b)));
});

it('returns an immutable array', () => {
expect(() => {
const tags = parseThemeTags('v8light');
const tags = parseThemeTags('v1light');
// @ts-expect-error
tags.push('foo');
}).toThrowErrorMatchingInlineSnapshot(`"Cannot add property 1, object is not extensible"`);
Expand Down
6 changes: 3 additions & 3 deletions packages/osd-optimizer/src/common/theme_tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ const isArrayOfStrings = (input: unknown): input is string[] =>
Array.isArray(input) && input.every((v) => typeof v === 'string');

export type ThemeTags = readonly ThemeTag[];
export type ThemeTag = 'v7light' | 'v7dark' | 'v8light' | 'v8dark';
export const DEFAULT_THEMES = tags('v7light', 'v7dark');
export const ALL_THEMES = tags('v7light', 'v7dark', 'v8light', 'v8dark');
export type ThemeTag = 'v1light' | 'v1dark';
export const DEFAULT_THEMES = tags('v1light', 'v1dark');
export const ALL_THEMES = tags('v1light', 'v1dark');

export function parseThemeTags(input?: any): ThemeTags {
if (!input) {
Expand Down
Loading

0 comments on commit 56bfda5

Please sign in to comment.