Skip to content

Commit

Permalink
Fix Historical alert filter ,table filter
Browse files Browse the repository at this point in the history
  • Loading branch information
roshni73 authored and AdityaKhatri committed Dec 4, 2024
1 parent eee48e0 commit f9b12d5
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 27 deletions.
5 changes: 4 additions & 1 deletion src/components/Navbar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useContext } from 'react';
import { useNavigate } from 'react-router-dom';
import {
gql,
useMutation,
Expand Down Expand Up @@ -40,6 +41,7 @@ interface Props {
className?: string;
}
function Navbar(props: Props) {
const navigate = useNavigate();
const { className } = props;
const strings = useTranslation(i18n);
const { isAuthenticated } = useAuth();
Expand All @@ -58,8 +60,9 @@ function Navbar(props: Props) {
onCompleted: (logoutResponse) => {
const response = logoutResponse?.private?.logout;
if (response.ok) {
window.location.reload();
removeUser();
navigate('/login');
window.location.reload();
} else {
alert.show(
strings.logoutFailure,
Expand Down
69 changes: 43 additions & 26 deletions src/views/HistoricalAlerts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
resolveToString,
} from '@ifrc-go/ui/utils';
import {
doesObjectHaveNoData,
isDefined,
isNotDefined,
} from '@togglecorp/fujs';
Expand Down Expand Up @@ -197,40 +198,55 @@ export function Component() {
const variables = useMemo<{
filters: AlertFilter | undefined,
pagination: OffsetPaginationInput,
}>(() => ({
pagination: {
offset,
limit,
},
filters: finalFilter ? {
DISTINCT: true,
infos: {
urgency: finalFilter?.urgency,
severity: finalFilter?.severity,
certainty: finalFilter?.certainty,
category: finalFilter?.category,
}>(() => {
const sentFilter = finalFilter?.startDateBefore || finalFilter?.startDateAfter ? {
range: {
...(finalFilter?.startDateBefore && { end: finalFilter.startDateBefore }),
...(finalFilter?.startDateAfter && { start: finalFilter.startDateAfter }),
},
country: isDefined(finalFilter?.country?.pk)
? { pk: finalFilter.country.pk } : undefined,
admin1: finalFilter?.admin1,
sent: {
range: {
end: finalFilter?.startDateBefore,
start: finalFilter?.startDateAfter,
},
} : undefined;
return {
pagination: {
offset,
limit,
},
} : undefined,
}), [
filters: finalFilter ? {
DISTINCT: true,
infos: {
urgency: finalFilter?.urgency,
severity: finalFilter?.severity,
certainty: finalFilter?.certainty,
category: finalFilter?.category,
},
country: isDefined(finalFilter?.country?.pk)
? { pk: finalFilter.country.pk } : undefined,
admin1: finalFilter?.admin1,
sent: sentFilter,
} : undefined,
};
}, [
limit,
offset,
finalFilter,
]);

const handleApplyFilters = useCallback(() => {
setFinalFilter(rawFilter);
}, [
rawFilter,
]);
if (doesObjectHaveNoData(rawFilter)) {
setFinalFilter(undefined);
} else {
const updatedFilter = {
...rawFilter,
sent: rawFilter.startDateBefore || rawFilter.startDateAfter ? {
range: {
...(rawFilter.startDateBefore && { end: rawFilter.startDateBefore }),
...(rawFilter.startDateAfter && { start: rawFilter.startDateAfter }),
},
} : {},
};
setFinalFilter(updatedFilter);
}
setPage(1);
}, [rawFilter, setPage]);

const handleResetFilters = useCallback(() => {
setFinalFilter(undefined);
Expand Down Expand Up @@ -401,6 +417,7 @@ export function Component() {
errorMessage={alertInfoError?.message}
footerActions={isDefined(data) && (
<Pager
className={styles.pager}
activePage={page}
itemsCount={data?.count}
maxItemsPerPage={limit}
Expand Down
10 changes: 10 additions & 0 deletions src/views/HistoricalAlerts/styles.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
.historical-alerts {
.pager {
button {
flex-shrink: 0 !important;
border-radius: 2rem !important;
padding: 0 var(--go-ui-spacing-sm);
width: fit-content !important;
min-width: 2rem;
line-height: 1;
}
}
.alerts-table {
overflow: auto;

Expand Down
9 changes: 9 additions & 0 deletions src/views/Home/AlertsTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ export function Component() {
activeAdmin1Id,
activeRegionId,
selectedCategoryTypes,
selectedSeverityTypes,
selectedCertaintyTypes,
selectedUrgencyTypes,
startDateFrom,
startDateTo,
} = useContext(AlertDataContext);
Expand Down Expand Up @@ -138,6 +141,9 @@ export function Component() {
region: activeRegionId,
infos: {
category: selectedCategoryTypes,
severity: selectedSeverityTypes,
certainty: selectedCertaintyTypes,
urgency: selectedUrgencyTypes,
},
sent: isDefined(startDateFrom) && isDefined(startDateTo) ? {
range: {
Expand All @@ -154,6 +160,9 @@ export function Component() {
activeAdmin1Id,
activeRegionId,
selectedCategoryTypes,
selectedSeverityTypes,
selectedCertaintyTypes,
selectedUrgencyTypes,
startDateFrom,
startDateTo,
],
Expand Down

0 comments on commit f9b12d5

Please sign in to comment.