Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command Palette: Maintain page state when changing theme #59787

Merged
merged 2 commits into from Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion public/app/core/services/keybindingSrv.ts
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
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);
}
Expand Up @@ -4,6 +4,7 @@ import React from 'react';
import { isIconName, NavModelItem } from '@grafana/data';
import { locationService } from '@grafana/runtime';
import { Icon } from '@grafana/ui';
import { changeTheme } from 'app/core/services/theme';

const SECTION_PAGES = 'Pages';
const SECTION_ACTIONS = 'Actions';
Expand Down Expand Up @@ -82,21 +83,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