From d802975acb011fcbb56df6796970040a3502f00b Mon Sep 17 00:00:00 2001 From: Ashraf Mohammed Date: Sun, 7 Jan 2024 11:56:16 +0530 Subject: [PATCH] remove blacklist state --- src/Common/hooks/useFilters.tsx | 12 ++++-------- src/Components/Patient/ManagePatients.tsx | 13 +++++++------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/src/Common/hooks/useFilters.tsx b/src/Common/hooks/useFilters.tsx index a5dbd1b90ae..7da5a2c0dac 100644 --- a/src/Common/hooks/useFilters.tsx +++ b/src/Common/hooks/useFilters.tsx @@ -31,13 +31,9 @@ export default function useFilters({ const hasPagination = limit > 0; const [showFilters, setShowFilters] = useState(false); const [qParams, setQueryParams] = useQueryParams(); - const [primaryCacheBlacklist, setPrimaryCacheBlacklist] = - useState(cacheBlacklist); - const updateQuery = (filter: FilterState, cacheBlacklist: string[] = []) => { + const updateQuery = (filter: FilterState) => { filter = hasPagination ? { page: 1, limit, ...filter } : filter; - if (cacheBlacklist.length) - setPrimaryCacheBlacklist(primaryCacheBlacklist.concat(cacheBlacklist)); setQueryParams(Object.assign({}, qParams, filter), { replace: true }); }; const updatePage = (page: number) => { @@ -50,8 +46,8 @@ export default function useFilters({ const removeFilter = (param: string) => removeFilters([param]); useEffect( - () => updateFiltersCache(qParams, primaryCacheBlacklist), - [qParams, primaryCacheBlacklist] + () => updateFiltersCache(qParams, cacheBlacklist), + [qParams, cacheBlacklist] ); useEffect(() => { @@ -184,7 +180,7 @@ export default function useFilters({ id="clear-all-filters" className="rounded-full border border-gray-300 bg-white px-2 py-1 text-xs text-gray-600 hover:text-gray-800" onClick={() => { - updateFiltersCache({}, primaryCacheBlacklist); + updateFiltersCache({}, cacheBlacklist); removeFilters(Object.keys(qParams)); }} > diff --git a/src/Components/Patient/ManagePatients.tsx b/src/Components/Patient/ManagePatients.tsx index d597e1e5252..487b23d796e 100644 --- a/src/Components/Patient/ManagePatients.tsx +++ b/src/Components/Patient/ManagePatients.tsx @@ -99,7 +99,12 @@ export const PatientManager = () => { resultsPerPage, } = useFilters({ limit: 12, - cacheBlacklist: ["name", "patient_no"], + cacheBlacklist: [ + "name", + "patient_no", + "phone_number", + "emergency_phone_number", + ], }); const [selectedFacility, setSelectedFacility] = useState({ name: "", @@ -776,11 +781,7 @@ export const PatientManager = () => { return { name, value: qParams[name] || defaultValue, - onChange: (e: FieldChangeEvent) => - updateQuery({ [e.name]: e.value }, [ - "phone_number", - "emergency_phone_number", - ]), + onChange: (e: FieldChangeEvent) => updateQuery({ [e.name]: e.value }), className: "grow w-full mb-2", }; };