Skip to content

Commit 581064c

Browse files
committed
refactor: move valid color overrides to tallymansdk package
- Create tallymansdk.TallymanValidColorOverrides global variable - Add documentation about Metronome color palette - Update API to use tallymansdk.TallymanValidColorOverrides - Remove local validColors map from licenses.go
1 parent 5a11e60 commit 581064c

File tree

2 files changed

+28
-24
lines changed

2 files changed

+28
-24
lines changed

enterprise/coderd/licenses.go

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -418,31 +418,8 @@ func (api *API) postUsageEmbeddableDashboard(rw http.ResponseWriter, r *http.Req
418418
}
419419

420420
// Validate color override names. These must match the colors available in Metronome.
421-
validColors := map[string]struct{}{
422-
"Gray_dark": {},
423-
"Gray_medium": {},
424-
"Gray_light": {},
425-
"Gray_extralight": {},
426-
"White": {},
427-
"Primary_medium": {},
428-
"Primary_light": {},
429-
"UsageLine_0": {},
430-
"UsageLine_1": {},
431-
"UsageLine_2": {},
432-
"UsageLine_3": {},
433-
"UsageLine_4": {},
434-
"UsageLine_5": {},
435-
"UsageLine_6": {},
436-
"UsageLine_7": {},
437-
"UsageLine_8": {},
438-
"UsageLine_9": {},
439-
"Primary_green": {},
440-
"Primary_red": {},
441-
"Progress_bar": {},
442-
"Progress_bar_background": {},
443-
}
444421
for _, override := range req.ColorOverrides {
445-
if _, ok := validColors[override.Name]; !ok {
422+
if _, ok := tallymansdk.TallymanValidColorOverrides[override.Name]; !ok {
446423
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
447424
Message: "Invalid color name.",
448425
Detail: fmt.Sprintf("Color name %q is not a valid Metronome color", override.Name),

enterprise/coderd/usage/tallymansdk/dashboards.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,33 @@ import (
88
"golang.org/x/xerrors"
99
)
1010

11+
// TallymanValidColorOverrides contains the valid color names that can be overridden
12+
// in Metronome dashboards. These correspond to the color palette available in the
13+
// Metronome embedding API.
14+
var TallymanValidColorOverrides = map[string]struct{}{
15+
"Gray_dark": {},
16+
"Gray_medium": {},
17+
"Gray_light": {},
18+
"Gray_extralight": {},
19+
"White": {},
20+
"Primary_medium": {},
21+
"Primary_light": {},
22+
"UsageLine_0": {},
23+
"UsageLine_1": {},
24+
"UsageLine_2": {},
25+
"UsageLine_3": {},
26+
"UsageLine_4": {},
27+
"UsageLine_5": {},
28+
"UsageLine_6": {},
29+
"UsageLine_7": {},
30+
"UsageLine_8": {},
31+
"UsageLine_9": {},
32+
"Primary_green": {},
33+
"Primary_red": {},
34+
"Progress_bar": {},
35+
"Progress_bar_background": {},
36+
}
37+
1138
// DashboardType represents the type of dashboard to embed.
1239
// Corresponds to codersdk.UsageEmbeddableDashboardType.
1340
type DashboardType string

0 commit comments

Comments
 (0)