Command Palette: Maintain page state when changing theme (#59787)
* use same function as the change theme keybindings * rename toggleTheme service to just theme
This commit is contained in:
@@ -24,7 +24,7 @@ import { AppChromeService } from '../components/AppChrome/AppChromeService';
|
|||||||
import { HelpModal } from '../components/help/HelpModal';
|
import { HelpModal } from '../components/help/HelpModal';
|
||||||
import { contextSrv } from '../core';
|
import { contextSrv } from '../core';
|
||||||
|
|
||||||
import { toggleTheme } from './toggleTheme';
|
import { toggleTheme } from './theme';
|
||||||
import { withFocusedPanel } from './withFocusedPanelId';
|
import { withFocusedPanel } from './withFocusedPanelId';
|
||||||
|
|
||||||
export class KeybindingSrv {
|
export class KeybindingSrv {
|
||||||
|
|||||||
@@ -7,11 +7,10 @@ import { contextSrv } from '../core';
|
|||||||
|
|
||||||
import { PreferencesService } from './PreferencesService';
|
import { PreferencesService } from './PreferencesService';
|
||||||
|
|
||||||
export async function toggleTheme(runtimeOnly: boolean) {
|
export async function changeTheme(mode: 'dark' | 'light', runtimeOnly?: boolean) {
|
||||||
const currentTheme = config.theme2;
|
|
||||||
const newTheme = createTheme({
|
const newTheme = createTheme({
|
||||||
colors: {
|
colors: {
|
||||||
mode: currentTheme.isDark ? 'light' : 'dark',
|
mode: mode,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -55,3 +54,8 @@ export async function toggleTheme(runtimeOnly: boolean) {
|
|||||||
theme: newTheme.colors.mode,
|
theme: newTheme.colors.mode,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function toggleTheme(runtimeOnly: boolean) {
|
||||||
|
const currentTheme = config.theme2;
|
||||||
|
changeTheme(currentTheme.isDark ? 'light' : 'dark', runtimeOnly);
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import React from 'react';
|
|||||||
import { isIconName, NavModelItem } from '@grafana/data';
|
import { isIconName, NavModelItem } from '@grafana/data';
|
||||||
import { locationService } from '@grafana/runtime';
|
import { locationService } from '@grafana/runtime';
|
||||||
import { Icon } from '@grafana/ui';
|
import { Icon } from '@grafana/ui';
|
||||||
|
import { changeTheme } from 'app/core/services/theme';
|
||||||
|
|
||||||
const SECTION_PAGES = 'Pages';
|
const SECTION_PAGES = 'Pages';
|
||||||
const SECTION_ACTIONS = 'Actions';
|
const SECTION_ACTIONS = 'Actions';
|
||||||
@@ -82,10 +83,7 @@ export default (navBarTree: NavModelItem[]) => {
|
|||||||
name: 'Dark',
|
name: 'Dark',
|
||||||
keywords: 'dark theme',
|
keywords: 'dark theme',
|
||||||
section: '',
|
section: '',
|
||||||
perform: () => {
|
perform: () => changeTheme('dark'),
|
||||||
locationService.push({ search: '?theme=dark' });
|
|
||||||
location.reload();
|
|
||||||
},
|
|
||||||
parent: 'preferences/theme',
|
parent: 'preferences/theme',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -93,10 +91,7 @@ export default (navBarTree: NavModelItem[]) => {
|
|||||||
name: 'Light',
|
name: 'Light',
|
||||||
keywords: 'light theme',
|
keywords: 'light theme',
|
||||||
section: '',
|
section: '',
|
||||||
perform: () => {
|
perform: () => changeTheme('light'),
|
||||||
locationService.push({ search: '?theme=light' });
|
|
||||||
location.reload();
|
|
||||||
},
|
|
||||||
parent: 'preferences/theme',
|
parent: 'preferences/theme',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user