Skip to content

Commit

Permalink
Command Palette: Maintain page state when changing theme (#59787) (#5…
Browse files Browse the repository at this point in the history
…9841)

* use same function as the change theme keybindings

* rename toggleTheme service to just theme

(cherry picked from commit 46adfb5)
  • Loading branch information
ashharrison90 committed Dec 12, 2022
1 parent 2b220ad commit d370327
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion public/app/core/services/keybindingSrv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { AppChromeService } from '../components/AppChrome/AppChromeService';
import { HelpModal } from '../components/help/HelpModal';
import { contextSrv } from '../core';

import { toggleTheme } from './toggleTheme';
import { toggleTheme } from './theme';
import { withFocusedPanel } from './withFocusedPanelId';

export class KeybindingSrv {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import { contextSrv } from '../core';

import { PreferencesService } from './PreferencesService';

export async function toggleTheme(runtimeOnly: boolean) {
const currentTheme = config.theme2;
export async function changeTheme(mode: 'dark' | 'light', runtimeOnly?: boolean) {
const newTheme = createTheme({
colors: {
mode: currentTheme.isDark ? 'light' : 'dark',
mode: mode,
},
});

Expand Down Expand Up @@ -55,3 +54,8 @@ export async function toggleTheme(runtimeOnly: boolean) {
theme: newTheme.colors.mode,
});
}

export async function toggleTheme(runtimeOnly: boolean) {
const currentTheme = config.theme2;
changeTheme(currentTheme.isDark ? 'light' : 'dark', runtimeOnly);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { flatMapDeep } from 'lodash';

import { NavModelItem } from '@grafana/data';
import { locationService } from '@grafana/runtime';
import { changeTheme } from 'app/core/services/theme';

import { alertingCommandPaletteStaticActions } from './alerting.static.actions';

Expand Down Expand Up @@ -40,21 +41,15 @@ export default (navBarTree: NavModelItem[]) => {
name: 'Dark',
keywords: 'dark theme',
section: '',
perform: () => {
locationService.push({ search: '?theme=dark' });
location.reload();
},
perform: () => changeTheme('dark'),
parent: 'preferences/theme',
},
{
id: 'preferences/light-theme',
name: 'Light',
keywords: 'light theme',
section: '',
perform: () => {
locationService.push({ search: '?theme=light' });
location.reload();
},
perform: () => changeTheme('light'),
parent: 'preferences/theme',
},
];
Expand Down

0 comments on commit d370327

Please sign in to comment.