Skip to content

Commit

Permalink
restructure alerts page code
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay288 committed Aug 31, 2022
1 parent ef1a554 commit 3caab70
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 448 deletions.
56 changes: 35 additions & 21 deletions frontend/src/components/Alert/AlertList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ enum Order {
interface AlertListProps {
alerts: Alert[]
params: GetAlertParams
setParams: (value: React.SetStateAction<GetAlertParams>) => void
setParams: (t: (e: GetAlertParams) => GetAlertParams) => void
handleUpdateAlert: (
alertId: string,
updateAlertParams: UpdateAlertParams,
Expand All @@ -53,7 +53,6 @@ interface AlertListProps {
pagination?: boolean
totalCount?: number
page?: number
setPage?: React.Dispatch<React.SetStateAction<number>>
}

export const AlertList: React.FC<AlertListProps> = ({
Expand All @@ -64,7 +63,6 @@ export const AlertList: React.FC<AlertListProps> = ({
pagination,
totalCount,
page,
setPage,
handleUpdateAlert,
updating,
}) => {
Expand All @@ -84,15 +82,17 @@ export const AlertList: React.FC<AlertListProps> = ({
riskScore: string,
) => {
if (e.target.checked) {
setParams({
...params,
setParams(oldParams => ({
...oldParams,
riskScores: [...params.riskScores, RiskScore[riskScore]],
})
offset: 0,
}))
} else {
setParams({
...params,
setParams(oldParams => ({
...oldParams,
riskScores: params.riskScores.filter(e => e !== RiskScore[riskScore]),
})
offset: 0,
}))
}
}

Expand All @@ -101,15 +101,16 @@ export const AlertList: React.FC<AlertListProps> = ({
alertType: string,
) => {
if (e.target.checked) {
setParams({
...params,
setParams(oldParams => ({
...oldParams,
alertTypes: [...params.alertTypes, AlertType[alertType]],
})
}))
} else {
setParams({
...params,
setParams(oldParams => ({
...oldParams,
alertTypes: params.alertTypes.filter(e => e !== AlertType[alertType]),
})
offset: 0,
}))
}
}

Expand All @@ -118,12 +119,17 @@ export const AlertList: React.FC<AlertListProps> = ({
status: string,
) => {
if (e.target.checked) {
setParams({ ...params, status: [...params.status, Status[status]] })
setParams(oldParams => ({
...oldParams,
status: [...params.status, Status[status]],
offset: 0,
}))
} else {
setParams({
...params,
setParams(oldParams => ({
...oldParams,
status: params.status.filter(e => e !== Status[status]),
})
offset: 0,
}))
}
}

Expand Down Expand Up @@ -232,7 +238,10 @@ export const AlertList: React.FC<AlertListProps> = ({
defaultValue={Order.DESC}
w="fit-content"
onChange={e =>
setParams({ ...params, order: e.target.value as Order })
setParams(oldParams => ({
...oldParams,
order: e.target.value as Order,
}))
}
>
<option value={Order.DESC}>Highest Risk</option>
Expand Down Expand Up @@ -294,7 +303,12 @@ export const AlertList: React.FC<AlertListProps> = ({
<PaginationComponent
pageSize={ALERT_PAGE_LIMIT}
currentPage={page}
setCurrentPage={setPage}
setCurrentPage={e =>
setParams(oldParams => ({
...oldParams,
offset: (e - 1) * ALERT_PAGE_LIMIT,
}))
}
tableSize={totalCount}
/>
</HStack>
Expand Down
81 changes: 0 additions & 81 deletions frontend/src/components/AlertList/Filters.tsx

This file was deleted.

Loading

0 comments on commit 3caab70

Please sign in to comment.