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

feat(ui): Added theme profile to log-viewer #21448

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,60 @@ import * as React from 'react';
import {ToggleButton} from '../../../shared/components/toggle-button';

// DarkModeToggleButton is a component that renders a toggle button that toggles dark mode.
export const DarkModeToggleButton = ({prefs}: {prefs: ViewPreferences}) => (
<ToggleButton
title='Dark Mode'
onToggle={() => {
const inverted = prefs.appDetails.darkMode;
// Added a logviewer theme profile

export const DarkModeToggleButton = ({prefs}: {prefs: ViewPreferences}) => {
React.useEffect(() => {
// Only run when theme changes or LogViewerTheme is not initialized
const profile = prefs.appDetails.UseDarkModeInLogViewerForAppTheme;

if (!profile) {
// First time initialization
services.viewPreferences.updatePreferences({
...prefs,
appDetails: {...prefs.appDetails, darkMode: !inverted}
appDetails: {
...prefs.appDetails,
UseDarkModeInLogViewerForAppTheme: {
light: prefs.appDetails.darkMode,
dark: prefs.appDetails.darkMode
}
}
});
}}
toggled={prefs.appDetails.darkMode}
icon='moon'
/>
);
return;
}

// Update darkMode based on saved preference for current theme
const currentThemeDarkMode = profile[prefs.theme as keyof typeof profile];
if (prefs.appDetails.darkMode !== currentThemeDarkMode) {
services.viewPreferences.updatePreferences({
...prefs,
appDetails: {
...prefs.appDetails,
darkMode: currentThemeDarkMode
}
});
}
}, [prefs.theme]);

const handleToggle = () => {
const newDarkMode = !prefs.appDetails.darkMode;
const currentProfile = prefs.appDetails.UseDarkModeInLogViewerForAppTheme || {
light: prefs.appDetails.darkMode,
dark: prefs.appDetails.darkMode
};

services.viewPreferences.updatePreferences({
...prefs,
appDetails: {
...prefs.appDetails,
darkMode: newDarkMode,
UseDarkModeInLogViewerForAppTheme: {
...currentProfile,
[prefs.theme]: newDarkMode
}
}
});
};

return <ToggleButton title='Dark Mode' onToggle={handleToggle} toggled={prefs.appDetails.darkMode} icon='moon' />;
};
1 change: 1 addition & 0 deletions ui/src/app/shared/services/view-preferences-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface AppDetailsPreferences {
zoom: number;
podGroupCount: number;
userHelpTipMsgs: UserMessages[];
UseDarkModeInLogViewerForAppTheme?: {light: boolean; dark: boolean};
}

export interface PodViewPreferences {
Expand Down
Loading