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

🐛 Add application risk filter of "Unassessed" #2032

Merged
merged 4 commits into from
Aug 1, 2024
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
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
2 changes: 1 addition & 1 deletion client/src/app/api/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ export interface Thresholds {
}

export type AssessmentStatus = "empty" | "started" | "complete";
export type Risk = "green" | "yellow" | "red" | "unknown";
export type Risk = "green" | "yellow" | "red" | "unknown" | "unassessed";

export interface InitialAssessment {
application?: Ref;
Expand Down
6 changes: 4 additions & 2 deletions client/src/app/components/RiskLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,19 @@ import { Label } from "@patternfly/react-core";

import { RISK_LIST } from "@app/Constants";
import { Risk } from "@app/api/models";
import { normalizeRisk } from "@app/utils/type-utils";

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

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

const data = RISK_LIST[risk];
const asRisk = normalizeRisk(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 @@ -17,7 +17,12 @@ import {
Modal,
Tooltip,
} from "@patternfly/react-core";
import { PencilAltIcon, TagIcon } from "@patternfly/react-icons";
import {
PencilAltIcon,
TagIcon,
WarningTriangleIcon,
} from "@patternfly/react-icons";

import {
Table,
Thead,
Expand Down Expand Up @@ -59,8 +64,8 @@ import {
tasksReadScopes,
tasksWriteScopes,
} from "@app/rbac";
import { normalizeRisk } from "@app/utils/type-utils";
import { checkAccess } from "@app/utils/rbac-utils";
import WarningTriangleIcon from "@patternfly/react-icons/dist/esm/icons/warning-triangle-icon";

// Hooks
import { useLocalTableControls } from "@app/hooks/table-controls";
Expand Down Expand Up @@ -486,12 +491,13 @@ export const ApplicationsTable: React.FC = () => {
what: t("terms.risk").toLowerCase(),
}) + "...",
selectOptions: [
{ value: "green", label: "Low" },
{ value: "yellow", label: "Medium" },
{ value: "red", label: "High" },
{ value: "unknown", label: "Unknown" },
{ value: "green", label: t("risks.low") },
{ value: "yellow", label: t("risks.medium") },
{ value: "red", label: t("risks.high") },
{ value: "unknown", label: t("risks.unknown") },
{ value: "unassessed", label: t("risks.unassessed") },
],
getItemValue: (item) => item.risk ?? "",
getItemValue: (item) => normalizeRisk(item.risk) ?? "",
},
],
initialItemsPerPage: 10,
Expand Down
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
37 changes: 37 additions & 0 deletions client/src/app/utils/type-utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Risk } from "@app/api/models";

export type KeyWithValueType<T, V> = {
[Key in keyof T]-?: T[Key] extends V ? Key : never;
}[keyof T];
Expand All @@ -10,3 +12,38 @@ export type DisallowCharacters<
export type DiscriminatedArgs<TBoolDiscriminatorKey extends string, TArgs> =
| ({ [key in TBoolDiscriminatorKey]: true } & TArgs)
| { [key in TBoolDiscriminatorKey]?: false };

/**
* Normalize an optional `Risk` or `string` input and return either the matching
* `Risk` or the `defaultValue` (which defaults to `undefined`).
*/
export function normalizeRisk(
risk?: Risk | string,
defaultValue?: Risk
): Risk | undefined {
let normal: Risk | undefined = defaultValue;

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;
}
34 changes: 34 additions & 0 deletions hack/import-questionnaire/assign-risk.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Assign Risk
description: |
Questionnaire that allows the use to select a risk level directly

sections:
- order: 1
name: Assign The RISK
questions:
- order: 1
text: What should be the Risk level of the application?
answers:
- order: 1
text: Unknown
risk: unknown
- order: 2
text: Green / Low
risk: green
- order: 3
text: Yellow / Medium
risk: yellow
- order: 4
text: Red / High
risk: red

thresholds:
red: 1
yellow: 30
unknown: 15

riskMessages:
red: Application requires deep changes in architecture or lifecycle
yellow: Application is Cloud friendly but requires some minor changes
green: Application is Cloud Native
unknown: More information about the application is required
Loading