From 60eaf21335c9c7edf8db40b49dd49d563e371e31 Mon Sep 17 00:00:00 2001 From: Scott J Dickerson Date: Tue, 30 Jul 2024 14:40:38 -0400 Subject: [PATCH] More type Risk work - 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 --- client/public/locales/en/translation.json | 3 +- client/src/app/Constants.ts | 6 ++++ client/src/app/components/RiskLabel.tsx | 35 +++++++++++++++++-- .../application-assessment-donut-chart.tsx | 6 ++-- .../app/components/tests/RiskLabel.test.tsx | 3 +- .../application-detail-drawer.tsx | 2 +- .../components/archetype-detail-drawer.tsx | 2 +- .../adoption-candidate-table.tsx | 2 +- 8 files changed, 48 insertions(+), 11 deletions(-) diff --git a/client/public/locales/en/translation.json b/client/public/locales/en/translation.json index 284b900851..51f852fea0 100644 --- a/client/public/locales/en/translation.json +++ b/client/public/locales/en/translation.json @@ -246,7 +246,8 @@ "high": "High", "low": "Low", "medium": "Medium", - "unknown": "Unknown" + "unknown": "Unknown", + "unassessed": "Unassessed" }, "sidebar": { "administrator": "Administration", diff --git a/client/src/app/Constants.ts b/client/src/app/Constants.ts index 80a622ee9f..3a1171c7c6 100644 --- a/client/src/app/Constants.ts +++ b/client/src/app/Constants.ts @@ -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 diff --git a/client/src/app/components/RiskLabel.tsx b/client/src/app/components/RiskLabel.tsx index a12330e1ed..54154b7358 100644 --- a/client/src/app/components/RiskLabel.tsx +++ b/client/src/app/components/RiskLabel.tsx @@ -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 = ({ - risk, + risk = "unknown", }: IRiskLabelProps) => { const { t } = useTranslation(); - const data = RISK_LIST[risk]; + const asRisk = normalizeToRisk(risk); + const data = !asRisk ? undefined : RISK_LIST[asRisk]; return (