Skip to content

Commit

Permalink
🐛 Remove color from labels with no backend color assigned
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 committed Nov 16, 2023
1 parent 924ef4e commit e1e6ab5
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions client/src/app/components/labels-from-items/labels-from-items.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,7 @@
import React from "react";
import { LabelGroup, LabelProps } from "@patternfly/react-core";
import { LabelCustomColor } from "../LabelCustomColor";
import { Label, LabelGroup } from "@patternfly/react-core";
import { useTranslation } from "react-i18next";

interface RandomColorLabelProps extends LabelProps {}

export const RandomColorLabel: React.FC<RandomColorLabelProps> = ({
...props
}) => {
const getRandomColor = (() => {
"use strict";

const randomInt = (min: number, max: number) => {
return Math.floor(Math.random() * (max - min + 1)) + min;
};

return () => {
const h = randomInt(0, 360);
const s = randomInt(42, 98);
const l = randomInt(40, 90);
return `hsl(${h},${s}%,${l}%)`;
};
})();

const randomColor = getRandomColor();

return <LabelCustomColor color={randomColor} {...props} />;
};

export function LabelsFromItems<T extends { name: string }>({
items,
noneMessage,
Expand All @@ -41,7 +15,7 @@ export function LabelsFromItems<T extends { name: string }>({
return (
<LabelGroup>
{items.map((item, index) => (
<RandomColorLabel key={index}>{item.name}</RandomColorLabel>
<Label key={index}>{item.name}</Label>
))}
</LabelGroup>
);
Expand Down

0 comments on commit e1e6ab5

Please sign in to comment.