Skip to content

Commit

Permalink
🐛 Add filtering for identified risks table (#1603)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibolton336 authored Dec 11, 2023
1 parent a40777f commit 0c1d91a
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/public/locales/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,7 @@
"rootPath": "Root path",
"scheduled": "Scheduled",
"select": "Select",
"section": "Section",
"settingsAllowApps": "Allow reviewing applications without running an assessment first",
"showLess": "Show less",
"showMore": "Show more",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { Link } from "react-router-dom";
import { Paths } from "@app/Paths";
import spacing from "@patternfly/react-styles/css/utilities/Spacing/spacing";
import RiskIcon from "@app/components/risk-icon/risk-icon";
import { FilterToolbar, FilterType } from "@app/components/FilterToolbar";

export interface IIdentifiedRisksTableProps {
assessmentRefs?: IdRef[];
Expand Down Expand Up @@ -152,6 +153,7 @@ export const IdentifiedRisksTable: React.FC<IIdentifiedRisksTableProps> = ({
},
variant: "compact",
isPaginationEnabled: true,
isFilterEnabled: true,
isSortEnabled: true,
hasActionsColumn: false,
getSortValues: (item) => ({
Expand All @@ -173,6 +175,86 @@ export const IdentifiedRisksTable: React.FC<IIdentifiedRisksTableProps> = ({
],
isExpansionEnabled: true,
expandableVariant: "single",
filterCategories: [
{
key: "questionnaireName",
title: t("terms.questionnaire"),
type: FilterType.multiselect,
placeholderText:
t("actions.filterBy", {
what: t("terms.questionnaire").toLowerCase(),
}) + "...",
getItemValue: (item) => item.questionnaireName || "",
selectOptions: [
...new Set(
tableData.map((item) => item.questionnaireName).filter(Boolean)
),
].map((name) => ({ key: name, value: name })),
},
{
key: "section",
title: t("terms.section"),
type: FilterType.multiselect,
placeholderText:
t("actions.filterBy", {
what: t("terms.section").toLowerCase(),
}) + "...",
getItemValue: (item) => item.section || "",
selectOptions: [
...new Set(tableData.map((item) => item.section).filter(Boolean)),
].map((name) => ({ key: name, value: name })),
},
{
key: "question",
title: t("terms.question"),
type: FilterType.multiselect,
placeholderText:
t("actions.filterBy", {
what: t("terms.question").toLowerCase(),
}) + "...",
getItemValue: (item) => item.question.text || "",
selectOptions: [
...new Set(
tableData.map((item) => item.question.text).filter(Boolean)
),
].map((name) => ({ key: name, value: name })),
},
{
key: "answer",
title: t("terms.answer"),
type: FilterType.multiselect,
placeholderText:
t("actions.filterBy", {
what: t("terms.answer").toLowerCase(),
}) + "...",
getItemValue: (item) => item.answer.text || "",
selectOptions: [
...new Set(tableData.map((item) => item.answer.text).filter(Boolean)),
].map((name) => ({ key: name, value: name })),
},
{
key: "risk",
title: t("terms.risk"),
type: FilterType.multiselect,
placeholderText:
t("actions.filterBy", { what: t("terms.risk").toLowerCase() }) +
"...",
getItemValue: (item: ITableRowData) => {
const riskKey = item.answer.risk;
const riskValue =
riskLevelMapping[riskKey as keyof typeof riskLevelMapping];
return riskValue.toString();
},
selectOptions: [
{ key: "3", value: "High" },
{ key: "2", value: "Medium" },
{ key: "1", value: "Low" },
{ key: "0", value: "Unknown" },
],
},
],
initialItemsPerPage: 10,
isSelectionEnabled: false,
});

const {
Expand All @@ -181,6 +263,7 @@ export const IdentifiedRisksTable: React.FC<IIdentifiedRisksTableProps> = ({
propHelpers: {
toolbarProps,
paginationToolbarItemProps,
filterToolbarProps,
paginationProps,
tableProps,
getThProps,
Expand All @@ -196,6 +279,8 @@ export const IdentifiedRisksTable: React.FC<IIdentifiedRisksTableProps> = ({
<>
<Toolbar {...toolbarProps}>
<ToolbarContent>
<FilterToolbar<ITableRowData, string> {...filterToolbarProps} />

<ToolbarItem {...paginationToolbarItemProps}>
<SimplePagination
idPrefix={`${"identified-risks-table"}}`}
Expand Down

0 comments on commit 0c1d91a

Please sign in to comment.