Preferences: Add theme preference to match system theme (#61986)
* user essentials mob! 🔱 lastFile:pkg/api/preferences.go * user essentials mob! 🔱 * user essentials mob! 🔱 lastFile:packages/grafana-data/src/types/config.ts * user essentials mob! 🔱 lastFile:public/app/core/services/echo/utils.test.ts * user essentials mob! 🔱 * user essentials mob! 🔱 lastFile:public/views/index-template.html * user essentials mob! 🔱 * Restore currentUser.lightTheme for backwards compat * fix types * Apply suggestions from code review Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com> * cleanup * cleanup --------- Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com> Co-authored-by: Joao Silva <joao.silva@grafana.com> Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com>
This commit is contained in:
co-authored by
Christopher Moyer
Ashley Harrison
Joao Silva
parent
be7b90bbd1
commit
d51e7ec7ef
@@ -17,6 +17,7 @@ const (
|
||||
defaultTheme string = ""
|
||||
darkTheme string = "dark"
|
||||
lightTheme string = "light"
|
||||
systemTheme string = "system"
|
||||
)
|
||||
|
||||
// POST /api/preferences/set-home-dash
|
||||
@@ -134,7 +135,7 @@ func (hs *HTTPServer) UpdateUserPreferences(c *contextmodel.ReqContext) response
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) updatePreferencesFor(ctx context.Context, orgID, userID, teamId int64, dtoCmd *dtos.UpdatePrefsCmd) response.Response {
|
||||
if dtoCmd.Theme != lightTheme && dtoCmd.Theme != darkTheme && dtoCmd.Theme != defaultTheme {
|
||||
if dtoCmd.Theme != lightTheme && dtoCmd.Theme != darkTheme && dtoCmd.Theme != defaultTheme && dtoCmd.Theme != systemTheme {
|
||||
return response.Error(400, "Invalid theme", nil)
|
||||
}
|
||||
|
||||
@@ -191,7 +192,7 @@ func (hs *HTTPServer) PatchUserPreferences(c *contextmodel.ReqContext) response.
|
||||
}
|
||||
|
||||
func (hs *HTTPServer) patchPreferencesFor(ctx context.Context, orgID, userID, teamId int64, dtoCmd *dtos.PatchPrefsCmd) response.Response {
|
||||
if dtoCmd.Theme != nil && *dtoCmd.Theme != lightTheme && *dtoCmd.Theme != darkTheme && *dtoCmd.Theme != defaultTheme {
|
||||
if dtoCmd.Theme != nil && *dtoCmd.Theme != lightTheme && *dtoCmd.Theme != darkTheme && *dtoCmd.Theme != defaultTheme && *dtoCmd.Theme != systemTheme {
|
||||
return response.Error(400, "Invalid theme", nil)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user