From 726c46c020a65ad109668a0ccd27bac61edfbfb5 Mon Sep 17 00:00:00 2001 From: Akshay Shekhawat Date: Wed, 31 Aug 2022 16:01:14 -0700 Subject: [PATCH] (feature) use query params for initial alert filters --- frontend/src/pages/alerts.tsx | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/frontend/src/pages/alerts.tsx b/frontend/src/pages/alerts.tsx index 4ece1956..54d27c27 100644 --- a/frontend/src/pages/alerts.tsx +++ b/frontend/src/pages/alerts.tsx @@ -7,7 +7,7 @@ import { SidebarLayoutShell } from "components/SidebarLayoutShell" import { AlertList } from "components/Alert/AlertList" import { ALERT_PAGE_LIMIT } from "~/constants" import { getAlerts, updateAlert } from "api/alerts" -import { Status } from "@common/enums" +import { AlertType, RiskScore, Status } from "@common/enums" import { GetServerSideProps } from "next" const Alerts = ({ initParams, initAlerts, initTotalCount }) => { @@ -84,7 +84,7 @@ const Alerts = ({ initParams, initAlerts, initTotalCount }) => { fetching={fetching} pagination totalCount={totalCount} - page={(params.offset / ALERT_PAGE_LIMIT) + 1} + page={params.offset / ALERT_PAGE_LIMIT + 1} /> @@ -94,9 +94,21 @@ const Alerts = ({ initParams, initAlerts, initTotalCount }) => { export const getServerSideProps: GetServerSideProps = async context => { const initParams: GetAlertParams = { - riskScores: [], - status: [Status.OPEN], - alertTypes: [], + riskScores: ((context.query.riskScores as string) || "") + .split(",") + .map(e => e.toUpperCase()) + .filter(e => Object.keys(RiskScore).includes(e)) + .map(e => RiskScore[e]), + status: ((context.query.status as string) || "open") + .split(",") + .map(e => e.toUpperCase()) + .filter(e => Object.keys(Status).includes(e)) + .map(e => Status[e]), + alertTypes: ((context.query.alertTypes as string) || "") + .split(",") + .map(e => e.toUpperCase()) + .filter(e => Object.keys(AlertType).includes(e)) + .map(e => AlertType[e]), offset: 0, limit: ALERT_PAGE_LIMIT, order: "DESC",