Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix inconsistent removal of facility filters #7031

Merged
merged 6 commits into from
Jan 23, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Components/Facility/HospitalList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
downloadFacilityDoctors,
downloadFacilityTriage,
} from "../../Redux/actions";
import { lazy } from "react";
import { lazy, useEffect } from "react";
import { AdvancedFilterButton } from "../../CAREUI/interactive/FiltersSlideover";
import CountBlock from "../../CAREUI/display/Count";
import ExportMenu from "../Common/Export";
Expand Down Expand Up @@ -35,6 +35,17 @@ export const HospitalList = () => {
} = useFilters({
limit: 14,
});

useEffect(() => {
if (Object.keys(qParams).length === 0) return;
if (!qParams.state) {
advancedFilter.removeFilters(["district", "local_body"]);
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
}
if (!qParams.district) {
advancedFilter.removeFilters(["local_body"]);
}
}, [advancedFilter, qParams]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still find if (Object.keys(qParams).length === 0) return; line hard to understand why it's there. Maybe would the following be a more readable and correct approach of what you are trying to do?

cc: @Ashesh3

Suggested change
if (Object.keys(qParams).length === 0) return;
if (!qParams.state) {
advancedFilter.removeFilters(["district", "local_body"]);
}
if (!qParams.district) {
advancedFilter.removeFilters(["local_body"]);
}
}, [advancedFilter, qParams]);
if (!qParams.state && (qParams.district || qParams.local_body)) {
advancedFilter.removeFilters(["district", "local_body"]);
}
if (!qParams.district && qParams.local_body) {
advancedFilter.removeFilters(["local_body"]);
}
}, [advancedFilter, qParams]);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion seems good and reads better.

  • If state is not present, but district or local_body is, then remove both
  • If district is not preset but we still have local_body, then remove it.


let manageFacilities: any = null;
const { user_type } = useAuthUser();
const { t } = useTranslation();
Expand Down
Loading