Skip to content
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

fix(api): return label color data as rgba strings #1898

Merged
merged 2 commits into from
Jun 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions internal/models/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ type Color struct {
Alpha uint8 `json:"alpha"`
}

func (c *Color) ToString() string {
return fmt.Sprintf("rgba(%d,%d,%d,%d)", c.Red, c.Green, c.Blue, c.Alpha)
}

// LabelColors holds color information for labels that should be colored in the UI
// every configured label will have a distinct coloring for each value
type LabelColors struct {
Brightness int32 `json:"brightness"`
Background Color `json:"background"`
Brightness int32 `json:"brightness"`
Background string `json:"background"`
}

// LabelsColorMap is a map of "Label Key" -> "Label Value" -> karmaLabelColors
Expand Down
4 changes: 2 additions & 2 deletions internal/transform/colors.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func parseCustomColor(colorStore models.LabelsColorMap, key, val, customColor st
}
colorStore[key][val] = models.LabelColors{
Brightness: brightness,
Background: bc,
Background: bc.ToString(),
}
}

Expand Down Expand Up @@ -102,7 +102,7 @@ func ColorLabel(colorStore models.LabelsColorMap, key string, val string) {
brightness := rgbToBrightness(bc.Red, bc.Green, bc.Blue)
colorStore[key][val] = models.LabelColors{
Brightness: brightness,
Background: bc,
Background: bc.ToString(),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions ui/src/Components/Labels/FilterInputLabel/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const MockColors = () => {
alertStore.data.colors["foo"] = {
bar: {
brightness: 200,
background: { red: 4, green: 5, blue: 6, alpha: 200 },
background: "rgba(4,5,6,200)",
},
};
};
Expand Down Expand Up @@ -112,7 +112,7 @@ describe("<FilterInputLabel /> style", () => {
MockColors();
const tree = ShallowLabel("=", true, true, 1);
expect(tree.props().style).toMatchObject({
backgroundColor: "rgba(4, 5, 6, 200)",
backgroundColor: "rgba(4,5,6,200)",
});
});

Expand Down
4 changes: 2 additions & 2 deletions ui/src/Components/Labels/FilteringLabel/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe("<FilteringLabel />", () => {
alertStore.data.colors["foo"] = {
bar: {
brightness: 125,
background: { red: 4, green: 5, blue: 6, alpha: 200 },
background: "rgba(4,5,6,200)",
},
};
const tree = MountedFilteringLabel("foo", "bar");
Expand All @@ -76,7 +76,7 @@ describe("<FilteringLabel />", () => {
alertStore.data.colors["foo"] = {
bar: {
brightness: 200,
background: { red: 4, green: 5, blue: 6, alpha: 200 },
background: "rgba(4,5,6,200)",
},
};
const tree = MountedFilteringLabel("foo", "bar");
Expand Down
4 changes: 2 additions & 2 deletions ui/src/Components/Labels/HistoryLabel/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe("<HistoryLabel />", () => {
alertStore.data.colors["foo"] = {
bar: {
brightness: 125,
background: { red: 4, green: 5, blue: 6, alpha: 200 },
background: "rgba(4,5,6,200)",
},
};
const tree = ShallowHistoryLabel("foo", "=", "bar").find(
Expand All @@ -53,7 +53,7 @@ describe("<HistoryLabel />", () => {
alertStore.data.colors["foo"] = {
bar: {
brightness: 200,
background: { red: 4, green: 5, blue: 6, alpha: 200 },
background: "rgba(4,5,6,200)",
},
};
const tree = ShallowHistoryLabel("foo", "=", "bar").find(
Expand Down
4 changes: 2 additions & 2 deletions ui/src/Components/Labels/StaticLabel/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe("<StaticLabel />", () => {
alertStore.data.colors["foo"] = {
bar: {
brightness: 125,
background: { red: 4, green: 5, blue: 6, alpha: 200 },
background: "rgba(4,5,6,200)",
},
};
const tree = MountedStaticLabel();
Expand All @@ -41,7 +41,7 @@ describe("<StaticLabel />", () => {
alertStore.data.colors["foo"] = {
bar: {
brightness: 200,
background: { red: 4, green: 5, blue: 6, alpha: 200 },
background: "rgba(4,5,6,200)",
},
};
const tree = MountedStaticLabel();
Expand Down
9 changes: 1 addition & 8 deletions ui/src/Components/Labels/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@ const GetClassAndStyle = (alertStore, name, value, extraClass, baseClass) => {
} else {
const c = alertStore.data.getColorData(name, value);
if (c) {
// if there's color information use it
data.style["backgroundColor"] = `rgba(${[
c.background.red,
c.background.green,
c.background.blue,
c.background.alpha,
].join(", ")})`;

data.style["backgroundColor"] = c.background;
data.colorClassNames.push(
isBackgroundDark(c.brightness)
? "components-label-dark"
Expand Down
4 changes: 2 additions & 2 deletions ui/src/Components/NavBar/index.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ storiesOf("NavBar", module).add("NavBar", () => {
cluster: {
staging: {
brightness: 205,
background: { red: 246, green: 176, blue: 247, alpha: 255 },
background: "rgba(246,176,247,255)",
},
},
region: {
AF: {
brightness: 111,
background: { red: 115, green: 101, blue: 152, alpha: 255 },
background: "rgba(115,101,152,255)",
},
},
};
Expand Down
14 changes: 7 additions & 7 deletions ui/src/__mocks__/Stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,33 @@ const MockGrid = (alertStore) => {
group: {
group1: {
brightness: 50,
background: { red: 178, green: 55, blue: 247, alpha: 255 },
background: "rgba(178,55,247,255)",
},
group2: {
brightness: 50,
background: { red: 200, green: 100, blue: 66, alpha: 255 },
background: "rgba(200,100,66,255)",
},
group3: {
brightness: 205,
background: { red: 246, green: 176, blue: 247, alpha: 255 },
background: "rgba(246,176,247,255)",
},
group4: {
brightness: 111,
background: { red: 115, green: 101, blue: 152, alpha: 255 },
background: "rgba(115,101,152,255)",
},
},
instance: {
instance1: {
brightness: 50,
background: { red: 111, green: 65, blue: 40, alpha: 255 },
background: "rgba(111,65,40,255)",
},
instance2: {
brightness: 50,
background: { red: 66, green: 99, blue: 66, alpha: 255 },
background: "rgba(66,99,66,255)",
},
instance3: {
brightness: 150,
background: { red: 66, green: 250, blue: 123, alpha: 255 },
background: "rgba(66,250,123,255)",
},
},
};
Expand Down