Skip to content

Commit

Permalink
(feature) use query params for initial alert filters
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay288 committed Aug 31, 2022
1 parent 3caab70 commit 726c46c
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions frontend/src/pages/alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }) => {
Expand Down Expand Up @@ -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}
/>
</Box>
</VStack>
Expand All @@ -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",
Expand Down

0 comments on commit 726c46c

Please sign in to comment.