-
Notifications
You must be signed in to change notification settings - Fork 605
Add configurable default theme support #4384
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
Open
guillaumebernard84
wants to merge
9
commits into
kubernetes-sigs:main
Choose a base branch
from
guillaumebernard84:default-theme
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+500
−26
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a6294cb
adding default theme system
guillaumebernard84 aa4b6ee
fix theme config page when theme is forced
guillaumebernard84 b6dde83
fixes go linter issue, doc build issue, and frontend test issue
guillaumebernard84 2f42449
fix linter error
guillaumebernard84 27e23bf
Update frontend/src/components/App/Settings/Settings.tsx
guillaumebernard84 621b789
Update frontend/src/components/App/themeSlice.ts
guillaumebernard84 e81736a
Merge branch 'main' into default-theme
guillaumebernard84 d8046e1
fix linter issue
guillaumebernard84 e4e300e
add Copilot suggestions
guillaumebernard84 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| package config_test | ||
|
|
||
| import ( | ||
| "os" | ||
| "testing" | ||
|
|
||
| "github.com/kubernetes-sigs/headlamp/backend/pkg/config" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestParseThemeConfiguration_DefaultLightTheme(t *testing.T) { | ||
| conf, err := config.Parse([]string{"go run ./cmd", "--default-light-theme=corporate-light"}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "corporate-light", conf.DefaultLightTheme) | ||
| assert.Equal(t, "", conf.DefaultDarkTheme) | ||
| assert.Equal(t, "", conf.ForceTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_DefaultDarkTheme(t *testing.T) { | ||
| conf, err := config.Parse([]string{"go run ./cmd", "--default-dark-theme=corporate-dark"}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "", conf.DefaultLightTheme) | ||
| assert.Equal(t, "corporate-dark", conf.DefaultDarkTheme) | ||
| assert.Equal(t, "", conf.ForceTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_BothDefaults(t *testing.T) { | ||
| conf, err := config.Parse([]string{ | ||
| "go run ./cmd", | ||
| "--default-light-theme=corporate-light", | ||
| "--default-dark-theme=corporate-dark", | ||
| }) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "corporate-light", conf.DefaultLightTheme) | ||
| assert.Equal(t, "corporate-dark", conf.DefaultDarkTheme) | ||
| assert.Equal(t, "", conf.ForceTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_ForceTheme(t *testing.T) { | ||
| conf, err := config.Parse([]string{"go run ./cmd", "--force-theme=corporate-branded"}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "", conf.DefaultLightTheme) | ||
| assert.Equal(t, "", conf.DefaultDarkTheme) | ||
| assert.Equal(t, "corporate-branded", conf.ForceTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_ForceWithDefaults(t *testing.T) { | ||
| conf, err := config.Parse([]string{ | ||
| "go run ./cmd", | ||
| "--default-light-theme=light", | ||
| "--default-dark-theme=dark", | ||
| "--force-theme=corporate", | ||
| }) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "light", conf.DefaultLightTheme) | ||
| assert.Equal(t, "dark", conf.DefaultDarkTheme) | ||
| assert.Equal(t, "corporate", conf.ForceTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_FromEnv(t *testing.T) { | ||
| os.Setenv("HEADLAMP_CONFIG_DEFAULT_LIGHT_THEME", "env-light") | ||
| os.Setenv("HEADLAMP_CONFIG_DEFAULT_DARK_THEME", "env-dark") | ||
|
|
||
| defer func() { | ||
| os.Unsetenv("HEADLAMP_CONFIG_DEFAULT_LIGHT_THEME") | ||
| os.Unsetenv("HEADLAMP_CONFIG_DEFAULT_DARK_THEME") | ||
| }() | ||
|
|
||
| conf, err := config.Parse([]string{"go run ./cmd"}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "env-light", conf.DefaultLightTheme) | ||
| assert.Equal(t, "env-dark", conf.DefaultDarkTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_ForceFromEnv(t *testing.T) { | ||
| os.Setenv("HEADLAMP_CONFIG_FORCE_THEME", "env-forced") | ||
| defer os.Unsetenv("HEADLAMP_CONFIG_FORCE_THEME") | ||
|
|
||
| conf, err := config.Parse([]string{"go run ./cmd"}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "env-forced", conf.ForceTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_ArgsOverrideEnv(t *testing.T) { | ||
| os.Setenv("HEADLAMP_CONFIG_DEFAULT_LIGHT_THEME", "env-theme") | ||
| defer os.Unsetenv("HEADLAMP_CONFIG_DEFAULT_LIGHT_THEME") | ||
|
|
||
| conf, err := config.Parse([]string{"go run ./cmd", "--default-light-theme=arg-theme"}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "arg-theme", conf.DefaultLightTheme) | ||
| } | ||
|
|
||
| func TestParseThemeConfiguration_NoConfig(t *testing.T) { | ||
| conf, err := config.Parse([]string{"go run ./cmd"}) | ||
| require.NoError(t, err) | ||
| require.NotNil(t, conf) | ||
|
|
||
| assert.Equal(t, "", conf.DefaultLightTheme) | ||
| assert.Equal(t, "", conf.DefaultDarkTheme) | ||
| assert.Equal(t, "", conf.ForceTheme) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be a boolean? so that default light/dark theme can be forced
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know, it could.
It felt more natural for me to set
--force-theme corporate-lightinstead of--default-light-theme corporate-light --force-themeBut that's a matter of taste. I can change that if you want.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's not a matter of taste. for accessibility reasons there should be an option to force dark or light theme depending on the user preference
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. What behaviour do you want?
--default-light-theme corporate-light --force-theme?--force-light-themeand--force-dark-themeas strings?