Skip to content

Commit

Permalink
Revert "[Manual Backport 2.x] Feat (core): Make theme settings user-s…
Browse files Browse the repository at this point in the history
…pecific and user-configurable (opensearch-project#5652) (opensearch-project#6681)"

This reverts commit 815d2bd.

Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed May 7, 2024
1 parent 8382e5c commit a9948e2
Show file tree
Hide file tree
Showing 31 changed files with 308 additions and 1,011 deletions.
1 change: 0 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- [Multiple Datasource] Able to Hide "Local Cluster" option from datasource DropDown ([#5827](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5827))
- [Multiple Datasource] Add api registry and allow it to be added into client config in data source plugin ([#5895](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5895))
- [Multiple Datasource] Refactor client and legacy client to use authentication registry ([#5881](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5881))
- [Theme] Make theme and dark mode settings user/device specific (in local storage), with opt-out ([#5652](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/5652))

### 🐛 Bug Fixes

Expand Down
131 changes: 0 additions & 131 deletions docs/theme.md

This file was deleted.

1 change: 0 additions & 1 deletion src/core/public/osd_bootstrap.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { __osdBootstrap__ } from './';
describe('osd_bootstrap', () => {
beforeAll(() => {
const metadata = {
branding: { darkMode: 'true' },
i18n: { translationsUrl: 'http://localhost' },
vars: { apmConfig: null },
};
Expand Down
5 changes: 0 additions & 5 deletions src/core/public/osd_bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ export async function __osdBootstrap__() {
document.querySelector('osd-injected-metadata')!.getAttribute('data')!
);

const globals: any = typeof window === 'undefined' ? {} : window;
const themeTag: string = globals.__osdThemeTag__ || '';

injectedMetadata.branding.darkMode = themeTag.endsWith('dark');

let i18nError: Error | undefined;
const apmSystem = new ApmSystem(injectedMetadata.vars.apmConfig, injectedMetadata.basePath);

Expand Down
43 changes: 2 additions & 41 deletions src/core/public/ui_settings/ui_settings_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ export class UiSettingsClient implements IUiSettingsClient {
this.defaults = cloneDeep(params.defaults);
this.cache = defaultsDeep({}, this.defaults, cloneDeep(params.initialSettings));

if (
this.cache['theme:enableUserControl']?.userValue ??
this.cache['theme:enableUserControl']?.value
) {
this.cache = defaultsDeep(this.cache, this.getBrowserStoredSettings());
}

params.done$.subscribe({
complete: () => {
this.update$.complete();
Expand Down Expand Up @@ -180,28 +173,6 @@ You can use \`IUiSettingsClient.get("${key}", defaultValue)\`, which will just r
return this.updateErrors$.asObservable();
}

private getBrowserStoredSettings() {
const uiSettingsJSON = window.localStorage.getItem('uiSettings') || '{}';
try {
return JSON.parse(uiSettingsJSON);
} catch (error) {
this.updateErrors$.next(error);
}
return {};
}

private setBrowserStoredSettings(key: string, newVal: any) {
const oldSettings = this.getBrowserStoredSettings();
const newSettings = cloneDeep(oldSettings);
if (newVal === null) {
delete newSettings[key];
} else {
newSettings[key] = { userValue: newVal };
}
window.localStorage.setItem(`uiSettings`, JSON.stringify(newSettings));
return { settings: newSettings };
}

private assertUpdateAllowed(key: string) {
if (this.isOverridden(key)) {
throw new Error(
Expand All @@ -227,18 +198,8 @@ You can use \`IUiSettingsClient.get("${key}", defaultValue)\`, which will just r
this.setLocally(key, newVal);

try {
if (
this.cache['theme:enableUserControl']?.userValue ??
this.cache['theme:enableUserControl']?.value
) {
const { settings } = this.cache[key]?.preferBrowserSetting
? this.setBrowserStoredSettings(key, newVal)
: (await this.api.batchSet(key, newVal)) || {};
this.cache = defaultsDeep({}, defaults, this.getBrowserStoredSettings(), settings);
} else {
const { settings } = (await this.api.batchSet(key, newVal)) || {};
this.cache = defaultsDeep({}, defaults, settings);
}
const { settings } = await this.api.batchSet(key, newVal);
this.cache = defaultsDeep({}, defaults, settings);
this.saved$.next({ key, newValue: newVal, oldValue: initialVal });
return true;
} catch (error) {
Expand Down

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

Loading

0 comments on commit a9948e2

Please sign in to comment.