Skip to content

Commit

Permalink
More type Risk work
Browse files Browse the repository at this point in the history
  - Add "unassessed" as an office `Risk` type option

  - Updated `RiskLabel` to handle undefined and arbitrary
    strings as risk inputs.  Consumers of the component
    don't need to worry about the prop quite as much anymore.

  - Where a string risk was getting looked at, force to
    lower case first so all the constants match up.

Signed-off-by: Scott J Dickerson <[email protected]>
  • Loading branch information
sjd78 committed Jul 30, 2024
1 parent 3578c9b commit 60eaf21
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 11 deletions.
3 changes: 2 additions & 1 deletion client/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@
"high": "High",
"low": "Low",
"medium": "Medium",
"unknown": "Unknown"
"unknown": "Unknown",
"unassessed": "Unassessed"
},
"sidebar": {
"administrator": "Administration",
Expand Down
6 changes: 6 additions & 0 deletions client/src/app/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ export const RISK_LIST: RiskListType = {
labelColor: "grey",
sortFactor: 4,
},
unassessed: {
i18Key: "risks.unassessed",
hexColor: black.value,
labelColor: "grey",
sortFactor: 5,
},
};

// Proposed action
Expand Down
35 changes: 32 additions & 3 deletions client/src/app/components/RiskLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,44 @@ import { RISK_LIST } from "@app/Constants";
import { Risk } from "@app/api/models";

export interface IRiskLabelProps {
risk: Risk;
risk?: Risk | string;
}

function normalizeToRisk(risk?: Risk | string): Risk | undefined {
let normal: Risk | undefined = undefined;

switch (risk) {
case "green":
normal = "green";
break;

case "yellow":
normal = "yellow";
break;

case "red":
normal = "red";
break;

case "unassessed":
normal = "unassessed";
break;

case "unknown":
normal = "unknown";
break;
}

return normal;
}

export const RiskLabel: React.FC<IRiskLabelProps> = ({
risk,
risk = "unknown",
}: IRiskLabelProps) => {
const { t } = useTranslation();

const data = RISK_LIST[risk];
const asRisk = normalizeToRisk(risk);
const data = !asRisk ? undefined : RISK_LIST[asRisk];

return (
<Label color={data ? data.labelColor : "grey"}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ export const getChartDataFromCategories = (
.flatMap((f) => f.answers)
.filter((f) => f.selected === true)
.forEach((f) => {
switch (f.risk) {
case "GREEN":
switch (f.risk.toLowerCase()) {
case "green":
green++;
break;
case "yellow":
amber++;
break;
case "RED":
case "red":
red++;
break;
default:
Expand Down
3 changes: 2 additions & 1 deletion client/src/app/components/tests/RiskLabel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ describe("RiskLabel", () => {
expect(screen.getByText("risks.unknown")).toBeInTheDocument();
});
it("Not defined risk", () => {
const { container } = render(<RiskLabel risk={"ANYTHING_ELSE" as any} />);
const { container } = render(<RiskLabel risk={"ANYTHING_ELSE"} />);
expect(container.firstChild).toHaveClass("pf-v5-c-label");
expect(screen.getByText("ANYTHING_ELSE")).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ const TabDetailsContent: React.FC<{
{t("terms.riskFromApplication")}
</Title>
<Text component="small" cy-data="comments">
<RiskLabel risk={application?.risk || "unknown"} />
<RiskLabel risk={application?.risk} />
</Text>
</TextContent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ const ArchetypeDetailDrawer: React.FC<IArchetypeDetailDrawerProps> = ({
{t("terms.riskFromArchetype")}
</Title>
<Text component="small" cy-data="comments">
<RiskLabel risk={archetype?.risk || "unknown"} />
<RiskLabel risk={archetype?.risk} />
</Text>
</TextContent>
</Tab>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ const AdoptionCandidateTable: React.FC<AdoptionCandidateTableProps> = () => {
{item?.review?.effortEstimate ?? "N/A"}
</Td>
<Td {...getTdProps({ columnKey: "risk" })}>
<RiskLabel risk={item.application.risk || "unknown"} />
<RiskLabel risk={item.application.risk} />
</Td>
</TableRowContentWithControls>
</Tr>
Expand Down

0 comments on commit 60eaf21

Please sign in to comment.