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 filtering for identified risks table #1603

Merged
merged 2 commits into from
Dec 11, 2023
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
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
Loading