From 6a346def90df2f339fd0334a328b5dc7ee9c9dfe Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Fri, 12 Jan 2024 21:35:36 +0530 Subject: [PATCH 1/6] add blacklisting logic --- src/Common/hooks/useFilters.tsx | 38 +++++++++++++------- src/Components/Assets/AssetsList.tsx | 1 + src/Components/ExternalResult/ResultList.tsx | 6 +++- src/Components/Facility/HospitalList.tsx | 1 + src/Components/Patient/ManagePatients.tsx | 6 ++++ src/Components/Patient/SampleViewAdmin.tsx | 3 ++ src/Components/Shifting/BoardView.tsx | 1 + src/Components/Shifting/ListView.tsx | 2 +- src/Components/Users/ManageUsers.tsx | 5 ++- 9 files changed, 48 insertions(+), 15 deletions(-) diff --git a/src/Common/hooks/useFilters.tsx b/src/Common/hooks/useFilters.tsx index 117a14ba418..264a3eba7bd 100644 --- a/src/Common/hooks/useFilters.tsx +++ b/src/Common/hooks/useFilters.tsx @@ -1,4 +1,4 @@ -import { QueryParam, setQueryParamsOptions, useQueryParams } from "raviger"; +import { useQueryParams } from "raviger"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import GenericFilterBadge from "../../CAREUI/display/FilterBadge"; @@ -8,6 +8,7 @@ import { classNames } from "../../Utils/utils"; export type FilterState = Record; export type FilterParamKeys = string | string[]; + interface FilterBadgeProps { name: string; value?: string; @@ -18,24 +19,28 @@ interface FilterBadgeProps { * A custom hook wrapped around raviger's `useQueryParams` hook to ease handling * of pagination and filters. */ -export default function useFilters({ limit = 14 }: { limit?: number }) { +export default function useFilters({ + limit = 14, + cacheBlacklist = [], +}: { + limit?: number; + cacheBlacklist?: string[]; +}) { const { t } = useTranslation(); const { kasp_string } = useConfig(); const hasPagination = limit > 0; const [showFilters, setShowFilters] = useState(false); - const [qParams, _setQueryParams] = useQueryParams(); - - const setQueryParams = ( - query: QueryParam, - options?: setQueryParamsOptions - ) => { - _setQueryParams(query, options); - updateFiltersCache(query); - }; + const [qParams, setQueryParams] = useQueryParams(); const updateQuery = (filter: FilterState) => { filter = hasPagination ? { page: 1, limit, ...filter } : filter; - setQueryParams(Object.assign({}, qParams, filter), { replace: true }); + const updatedQParams = { ...qParams }; + for (const key of cacheBlacklist) { + delete updatedQParams[key]; + } + setQueryParams(Object.assign({}, updatedQParams, filter), { + replace: true, + }); }; const updatePage = (page: number) => { if (!hasPagination) return; @@ -46,6 +51,15 @@ export default function useFilters({ limit = 14 }: { limit?: number }) { }; const removeFilter = (param: string) => removeFilters([param]); + useEffect(() => { + const updatedQParams = { ...qParams }; + + for (const key of cacheBlacklist) { + delete updatedQParams[key]; + } + updateFiltersCache(updatedQParams); + }, [qParams, cacheBlacklist]); + useEffect(() => { const cache = getFiltersCache(); const qParamKeys = Object.keys(qParams); diff --git a/src/Components/Assets/AssetsList.tsx b/src/Components/Assets/AssetsList.tsx index 3fc9c9f9f14..bc0abbd4c2a 100644 --- a/src/Components/Assets/AssetsList.tsx +++ b/src/Components/Assets/AssetsList.tsx @@ -38,6 +38,7 @@ const AssetsList = () => { resultsPerPage, } = useFilters({ limit: 18, + cacheBlacklist: ["search"], }); const [assets, setAssets] = useState([{} as AssetData]); const [isLoading, setIsLoading] = useState(false); diff --git a/src/Components/ExternalResult/ResultList.tsx b/src/Components/ExternalResult/ResultList.tsx index 9a04fcf38b6..f644c2b54e0 100644 --- a/src/Components/ExternalResult/ResultList.tsx +++ b/src/Components/ExternalResult/ResultList.tsx @@ -18,6 +18,7 @@ import useQuery from "../../Utils/request/useQuery"; import { parsePhoneNumber } from "../../Utils/utils"; import useAuthUser from "../../Common/hooks/useAuthUser"; import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; + const Loading = lazy(() => import("../Common/Loading")); export default function ResultList() { @@ -29,7 +30,10 @@ export default function ResultList() { FilterBadges, advancedFilter, resultsPerPage, - } = useFilters({ limit: 14 }); + } = useFilters({ + limit: 14, + cacheBlacklist: ["mobile_number", "name"], + }); const [showDialog, setShowDialog] = useState(false); const [selectedFacility, setSelectedFacility] = useState({ name: "", diff --git a/src/Components/Facility/HospitalList.tsx b/src/Components/Facility/HospitalList.tsx index 075ad8de39e..e173f78e20e 100644 --- a/src/Components/Facility/HospitalList.tsx +++ b/src/Components/Facility/HospitalList.tsx @@ -34,6 +34,7 @@ export const HospitalList = () => { resultsPerPage, } = useFilters({ limit: 14, + cacheBlacklist: ["search"], }); let manageFacilities: any = null; const { user_type } = useAuthUser(); diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index 0f9a6656f67..6f1fa4cafeb 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -99,6 +99,12 @@ export const PatientManager = () => { resultsPerPage, } = useFilters({ limit: 12, + cacheBlacklist: [ + "name", + "patient_no", + "phone_number", + "emergency_phone_number", + ], }); const [selectedFacility, setSelectedFacility] = useState({ name: "", diff --git a/src/Components/Patient/SampleViewAdmin.tsx b/src/Components/Patient/SampleViewAdmin.tsx index 085616adfac..5aca767e480 100644 --- a/src/Components/Patient/SampleViewAdmin.tsx +++ b/src/Components/Patient/SampleViewAdmin.tsx @@ -26,6 +26,7 @@ import CountBlock from "../../CAREUI/display/Count"; import CareIcon from "../../CAREUI/icons/CareIcon"; import { AdvancedFilterButton } from "../../CAREUI/interactive/FiltersSlideover"; import Page from "../Common/components/Page"; + const Loading = lazy(() => import("../Common/Loading")); export default function SampleViewAdmin() { @@ -38,6 +39,7 @@ export default function SampleViewAdmin() { resultsPerPage, } = useFilters({ limit: 10, + cacheBlacklist: ["patient_name", "district_name"], }); const dispatch: any = useDispatch(); const initialData: any[] = []; @@ -58,6 +60,7 @@ export default function SampleViewAdmin() { const res = await dispatch(getAnyFacility(qParams.facility)); setFacilityName(res?.data?.name); } + fetchData(); }, [dispatch, qParams.facility]); diff --git a/src/Components/Shifting/BoardView.tsx b/src/Components/Shifting/BoardView.tsx index 9c96daa0e59..ed29a16b8d5 100644 --- a/src/Components/Shifting/BoardView.tsx +++ b/src/Components/Shifting/BoardView.tsx @@ -29,6 +29,7 @@ const ScrollingComponent = withScrolling("div"); export default function BoardView() { const { qParams, updateQuery, FilterBadges, advancedFilter } = useFilters({ limit: -1, + cacheBlacklist: ["patient_name"], }); const { wartime_shifting } = useConfig(); diff --git a/src/Components/Shifting/ListView.tsx b/src/Components/Shifting/ListView.tsx index ec11f4cf91f..45a484af933 100644 --- a/src/Components/Shifting/ListView.tsx +++ b/src/Components/Shifting/ListView.tsx @@ -36,7 +36,7 @@ export default function ListView() { FilterBadges, advancedFilter, resultsPerPage, - } = useFilters({}); + } = useFilters({ cacheBlacklist: ["patient_name"] }); const [modalFor, setModalFor] = useState({ externalId: undefined, diff --git a/src/Components/Users/ManageUsers.tsx b/src/Components/Users/ManageUsers.tsx index 750603ccf6f..f6df186d4be 100644 --- a/src/Components/Users/ManageUsers.tsx +++ b/src/Components/Users/ManageUsers.tsx @@ -44,7 +44,10 @@ export default function ManageUsers() { FilterBadges, advancedFilter, resultsPerPage, - } = useFilters({ limit: 18 }); + } = useFilters({ + limit: 18, + cacheBlacklist: ["username"], + }); let manageUsers: any = null; const [expandSkillList, setExpandSkillList] = useState(false); const [expandFacilityList, setExpandFacilityList] = useState(false); From ec730a7f930b3c00a96d6d053d3d58fac48b0ed5 Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Fri, 12 Jan 2024 21:41:15 +0530 Subject: [PATCH 2/6] update useFilter --- src/Common/hooks/useFilters.tsx | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/Common/hooks/useFilters.tsx b/src/Common/hooks/useFilters.tsx index 264a3eba7bd..7e0db465031 100644 --- a/src/Common/hooks/useFilters.tsx +++ b/src/Common/hooks/useFilters.tsx @@ -1,4 +1,4 @@ -import { useQueryParams } from "raviger"; +import { QueryParam, setQueryParamsOptions, useQueryParams } from "raviger"; import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import GenericFilterBadge from "../../CAREUI/display/FilterBadge"; @@ -30,17 +30,23 @@ export default function useFilters({ const { kasp_string } = useConfig(); const hasPagination = limit > 0; const [showFilters, setShowFilters] = useState(false); - const [qParams, setQueryParams] = useQueryParams(); + const [qParams, _setQueryParams] = useQueryParams(); + + const setQueryParams = ( + query: QueryParam, + options?: setQueryParamsOptions + ) => { + const updatedQParams = { ...query }; + for (const param of cacheBlacklist) { + delete updatedQParams[param]; + } + _setQueryParams(query, options); + updateFiltersCache(updatedQParams); + }; const updateQuery = (filter: FilterState) => { filter = hasPagination ? { page: 1, limit, ...filter } : filter; - const updatedQParams = { ...qParams }; - for (const key of cacheBlacklist) { - delete updatedQParams[key]; - } - setQueryParams(Object.assign({}, updatedQParams, filter), { - replace: true, - }); + setQueryParams(Object.assign({}, qParams, filter), { replace: true }); }; const updatePage = (page: number) => { if (!hasPagination) return; @@ -51,15 +57,6 @@ export default function useFilters({ }; const removeFilter = (param: string) => removeFilters([param]); - useEffect(() => { - const updatedQParams = { ...qParams }; - - for (const key of cacheBlacklist) { - delete updatedQParams[key]; - } - updateFiltersCache(updatedQParams); - }, [qParams, cacheBlacklist]); - useEffect(() => { const cache = getFiltersCache(); const qParamKeys = Object.keys(qParams); From 5e8e3499270620ddb2798363316cbcc4c125011f Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Tue, 16 Jan 2024 19:12:34 +0530 Subject: [PATCH 3/6] add space --- src/Common/hooks/useFilters.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Common/hooks/useFilters.tsx b/src/Common/hooks/useFilters.tsx index 7e0db465031..a6ffa6ba007 100644 --- a/src/Common/hooks/useFilters.tsx +++ b/src/Common/hooks/useFilters.tsx @@ -37,6 +37,7 @@ export default function useFilters({ options?: setQueryParamsOptions ) => { const updatedQParams = { ...query }; + for (const param of cacheBlacklist) { delete updatedQParams[param]; } From 7b3e2f304044faaef125433faef18a977e5ea515 Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed <98876115+AshrafMd-1@users.noreply.github.com> Date: Tue, 16 Jan 2024 19:46:27 +0530 Subject: [PATCH 4/6] Update useFilters.tsx --- src/Common/hooks/useFilters.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Common/hooks/useFilters.tsx b/src/Common/hooks/useFilters.tsx index a6ffa6ba007..7e0db465031 100644 --- a/src/Common/hooks/useFilters.tsx +++ b/src/Common/hooks/useFilters.tsx @@ -37,7 +37,6 @@ export default function useFilters({ options?: setQueryParamsOptions ) => { const updatedQParams = { ...query }; - for (const param of cacheBlacklist) { delete updatedQParams[param]; } From bfe681efcaf5b6e0e4d1faf47e7e977a4c731845 Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed <98876115+AshrafMd-1@users.noreply.github.com> Date: Tue, 16 Jan 2024 20:01:59 +0530 Subject: [PATCH 5/6] Update useFilters.tsx --- src/Common/hooks/useFilters.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Common/hooks/useFilters.tsx b/src/Common/hooks/useFilters.tsx index 7e0db465031..41fc91dfd5f 100644 --- a/src/Common/hooks/useFilters.tsx +++ b/src/Common/hooks/useFilters.tsx @@ -37,9 +37,11 @@ export default function useFilters({ options?: setQueryParamsOptions ) => { const updatedQParams = { ...query }; + for (const param of cacheBlacklist) { delete updatedQParams[param]; } + _setQueryParams(query, options); updateFiltersCache(updatedQParams); }; From 39881b3f19fb3606d13fdef466c338ee31c921cc Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Tue, 16 Jan 2024 20:16:08 +0530 Subject: [PATCH 6/6] lint --- src/Common/hooks/useFilters.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Common/hooks/useFilters.tsx b/src/Common/hooks/useFilters.tsx index 41fc91dfd5f..dd08a2442a5 100644 --- a/src/Common/hooks/useFilters.tsx +++ b/src/Common/hooks/useFilters.tsx @@ -37,11 +37,11 @@ export default function useFilters({ options?: setQueryParamsOptions ) => { const updatedQParams = { ...query }; - + for (const param of cacheBlacklist) { delete updatedQParams[param]; } - + _setQueryParams(query, options); updateFiltersCache(updatedQParams); };