fix(dashboard): normalize recoverable layout preferences on save
Build and publish container images / images (push) Successful in 9m27s
Release container images / release (push) Successful in 20s

This commit is contained in:
Anya Tokugawa committed 2026-11-10 07:36:32 +09:00
1 parent 667776e43f
commit 38b0fe2a94
4 files changed
+43 -4

No files matched your search

+30 -1
View File
@@ -53,6 +53,33 @@ type DashboardLayout struct {
Widgets []DashboardWidget `json:"widgets"`
}
func normalizeDashboard(items []DashboardWidget) ([]DashboardWidget, error) {
if len(items) > 100 {
return nil, ErrTaskInvalid
}
out := make([]DashboardWidget, 0, len(items))
seen := map[string]bool{}
for _, item := range items {
if seen[item.ID] {
continue
}
seen[item.ID] = true
item.Width = max(3, min(12, item.Width))
item.Height = max(2, min(10, item.Height))
if item.ID == "tasks" {
switch item.Tab {
case "inbox", "backlog", "someday", "review", "all", "done":
default:
item.Tab = "inbox"
}
} else {
item.Tab = ""
}
out = append(out, item)
}
return out, ValidateDashboard(out)
}
func (s *Store) Dashboard(ctx context.Context, domain, actor string) (DashboardLayout, error) {
p := DashboardLayout{Widgets: DefaultDashboard()}
if err := taskActor(ctx, s.DB, domain, actor, false); err != nil {
@@ -79,9 +106,11 @@ func (s *Store) SaveDashboard(ctx context.Context, domain, actor string, version
if version < 0 {
return p, ErrTaskInvalid
}
if err := ValidateDashboard(widgets); err != nil {
normalized, err := normalizeDashboard(widgets)
if err != nil {
return p, err
}
widgets = normalized
tx, err := s.DB.BeginTx(ctx, nil)
if err != nil {
return p, err