Skip to content

Commit

Permalink
remove blacklist state
Browse files Browse the repository at this point in the history
  • Loading branch information
AshrafMd-1 committed Jan 7, 2024
1 parent 3fda4c4 commit d802975
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
12 changes: 4 additions & 8 deletions src/Common/hooks/useFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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(() => {
Expand Down Expand Up @@ -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));
}}
>
Expand Down
13 changes: 7 additions & 6 deletions src/Components/Patient/ManagePatients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<FacilityModel>({
name: "",
Expand Down Expand Up @@ -776,11 +781,7 @@ export const PatientManager = () => {
return {
name,
value: qParams[name] || defaultValue,
onChange: (e: FieldChangeEvent<T>) =>
updateQuery({ [e.name]: e.value }, [
"phone_number",
"emergency_phone_number",
]),
onChange: (e: FieldChangeEvent<T>) => updateQuery({ [e.name]: e.value }),
className: "grow w-full mb-2",
};
};
Expand Down

0 comments on commit d802975

Please sign in to comment.