I18n: Add locale to user preference (#49425)

* Add __debug_bin file to gitignore

* Add locale user preference

* undo defaulting to existing JSONData in preferences save
This commit is contained in:
Josh Hunt 2022-06-14 12:53:51 +01:00 committed by GitHub
parent b4c8b6d672
commit 3cebd87bbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 2 deletions

2
.gitignore vendored
View File

@ -99,6 +99,7 @@ debug.test
/packaging/**/*.deb
/packaging/**/*.tar.gz
/packaging/**/*.tar.gz.sha256
pkg/cmd/grafana-server/__debug_bin
# Ignore OSX indexing
.DS_Store
@ -165,4 +166,3 @@ public/locales/_build/
public/locales/**/*.js
deployment_tools_config.json

View File

@ -10,6 +10,7 @@ type Prefs struct {
HomeDashboardUID string `json:"homeDashboardUID,omitempty"`
Timezone string `json:"timezone"`
WeekStart string `json:"weekStart"`
Locale string `json:"locale"`
Navbar pref.NavbarPreference `json:"navbar,omitempty"`
QueryHistory pref.QueryHistoryPreference `json:"queryHistory,omitempty"`
}
@ -27,6 +28,7 @@ type UpdatePrefsCmd struct {
WeekStart string `json:"weekStart"`
Navbar *pref.NavbarPreference `json:"navbar,omitempty"`
QueryHistory *pref.QueryHistoryPreference `json:"queryHistory,omitempty"`
Locale string `json:"locale"`
}
// swagger:model
@ -39,6 +41,7 @@ type PatchPrefsCmd struct {
// Enum: utc,browser
Timezone *string `json:"timezone,omitempty"`
WeekStart *string `json:"weekStart,omitempty"`
Locale *string `json:"locale,omitempty"`
Navbar *pref.NavbarPreference `json:"navbar,omitempty"`
QueryHistory *pref.QueryHistoryPreference `json:"queryHistory,omitempty"`
HomeDashboardUID *string `json:"homeDashboardUID,omitempty"`

View File

@ -80,6 +80,7 @@ func (hs *HTTPServer) getPreferencesFor(ctx context.Context, orgID, userID, team
}
if preference.JSONData != nil {
dto.Locale = preference.JSONData.Locale
dto.Navbar = preference.JSONData.Navbar
dto.QueryHistory = preference.JSONData.QueryHistory
}
@ -117,6 +118,7 @@ func (hs *HTTPServer) updatePreferencesFor(ctx context.Context, orgID, userID, t
OrgID: orgID,
TeamID: teamId,
Theme: dtoCmd.Theme,
Locale: dtoCmd.Locale,
Timezone: dtoCmd.Timezone,
WeekStart: dtoCmd.WeekStart,
HomeDashboardID: dtoCmd.HomeDashboardID,
@ -165,6 +167,7 @@ func (hs *HTTPServer) patchPreferencesFor(ctx context.Context, orgID, userID, te
Timezone: dtoCmd.Timezone,
WeekStart: dtoCmd.WeekStart,
HomeDashboardID: dtoCmd.HomeDashboardID,
Locale: dtoCmd.Locale,
Navbar: dtoCmd.Navbar,
QueryHistory: dtoCmd.QueryHistory,
}

View File

@ -47,6 +47,7 @@ type SavePreferenceCommand struct {
Timezone string `json:"timezone,omitempty"`
WeekStart string `json:"weekStart,omitempty"`
Theme string `json:"theme,omitempty"`
Locale string `json:"locale,omitempty"`
Navbar *NavbarPreference `json:"navbar,omitempty"`
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
}
@ -61,6 +62,7 @@ type PatchPreferenceCommand struct {
Timezone *string `json:"timezone,omitempty"`
WeekStart *string `json:"weekStart,omitempty"`
Theme *string `json:"theme,omitempty"`
Locale *string `json:"locale,omitempty"`
Navbar *NavbarPreference `json:"navbar,omitempty"`
QueryHistory *QueryHistoryPreference `json:"queryHistory,omitempty"`
}
@ -77,6 +79,7 @@ type NavbarPreference struct {
}
type PreferenceJSONData struct {
Locale string `json:"locale"`
Navbar NavbarPreference `json:"navbar"`
QueryHistory QueryHistoryPreference `json:"queryHistory"`
}

View File

@ -92,6 +92,9 @@ func (s *Service) Save(ctx context.Context, cmd *pref.SavePreferenceCommand) err
Theme: cmd.Theme,
Created: time.Now(),
Updated: time.Now(),
JSONData: &pref.PreferenceJSONData{
Locale: cmd.Locale,
},
}
_, err = s.store.Insert(ctx, preference)
if err != nil {
@ -106,8 +109,10 @@ func (s *Service) Save(ctx context.Context, cmd *pref.SavePreferenceCommand) err
preference.Theme = cmd.Theme
preference.Updated = time.Now()
preference.Version += 1
preference.JSONData = &pref.PreferenceJSONData{}
preference.HomeDashboardID = cmd.HomeDashboardID
preference.JSONData = &pref.PreferenceJSONData{
Locale: cmd.Locale,
}
if cmd.Navbar != nil {
preference.JSONData.Navbar = *cmd.Navbar
@ -141,6 +146,13 @@ func (s *Service) Patch(ctx context.Context, cmd *pref.PatchPreferenceCommand) e
exists = true
}
if cmd.Locale != nil {
if preference.JSONData == nil {
preference.JSONData = &pref.PreferenceJSONData{}
}
preference.JSONData.Locale = *cmd.Locale
}
if cmd.Navbar != nil {
if preference.JSONData == nil {
preference.JSONData = &pref.PreferenceJSONData{}