diff --git a/cypress/e2e/assets_spec/asset_homepage.cy.ts b/cypress/e2e/assets_spec/asset_homepage.cy.ts index 61f7d8a52c0..a2c1c7734d2 100644 --- a/cypress/e2e/assets_spec/asset_homepage.cy.ts +++ b/cypress/e2e/assets_spec/asset_homepage.cy.ts @@ -27,6 +27,7 @@ describe("Asset Tab", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/assets"); }); @@ -90,7 +91,7 @@ describe("Asset Tab", () => { assetPage.selectImportOption(); assetPage.selectImportFacility("Dummy Facility 1"); assetPage.importAssetFile(); - assetPage.selectImportLocation("Camera Locations"); + assetPage.selectImportLocation("Camera Loc"); assetPage.clickImportAsset(); }); diff --git a/cypress/e2e/assets_spec/assets_creation.cy.ts b/cypress/e2e/assets_spec/assets_creation.cy.ts index 3e7b24eeca6..dde4e0d0e8b 100644 --- a/cypress/e2e/assets_spec/assets_creation.cy.ts +++ b/cypress/e2e/assets_spec/assets_creation.cy.ts @@ -19,6 +19,7 @@ describe("Asset", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/assets"); }); diff --git a/cypress/e2e/assets_spec/assets_manage.cy.ts b/cypress/e2e/assets_spec/assets_manage.cy.ts index 164bc239253..92a4f5be9b8 100644 --- a/cypress/e2e/assets_spec/assets_manage.cy.ts +++ b/cypress/e2e/assets_spec/assets_manage.cy.ts @@ -29,6 +29,7 @@ describe("Asset", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/assets"); }); diff --git a/cypress/e2e/death_report_spec/death_report.cy.ts b/cypress/e2e/death_report_spec/death_report.cy.ts index a9e7eb657d8..c051e1ee776 100644 --- a/cypress/e2e/death_report_spec/death_report.cy.ts +++ b/cypress/e2e/death_report_spec/death_report.cy.ts @@ -11,6 +11,7 @@ describe("Death Report", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/"); cy.intercept("**/api/v1/patient/**").as("getPatients"); cy.get("#facility-patients").contains("Patients").click({ force: true }); diff --git a/cypress/e2e/external_results_spec/external_result.cy.ts b/cypress/e2e/external_results_spec/external_result.cy.ts index 38f7c31373a..deb92ae5171 100644 --- a/cypress/e2e/external_results_spec/external_result.cy.ts +++ b/cypress/e2e/external_results_spec/external_result.cy.ts @@ -16,6 +16,7 @@ describe("Edit Profile Testing", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/external_results"); }); diff --git a/cypress/e2e/external_results_spec/filter.cy.ts b/cypress/e2e/external_results_spec/filter.cy.ts index 8654bb49e63..577b6a46d98 100644 --- a/cypress/e2e/external_results_spec/filter.cy.ts +++ b/cypress/e2e/external_results_spec/filter.cy.ts @@ -8,6 +8,7 @@ describe("External Results Filters", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/external_results"); cy.contains("Filters").click(); }); diff --git a/cypress/e2e/facility_spec/facility_creation.cy.ts b/cypress/e2e/facility_spec/facility_creation.cy.ts index cc2d1b7f921..9fe78f84256 100644 --- a/cypress/e2e/facility_spec/facility_creation.cy.ts +++ b/cypress/e2e/facility_spec/facility_creation.cy.ts @@ -217,6 +217,7 @@ describe("Facility Creation", () => { .should("be.visible"); // verify the facility homepage cy.visit("/facility"); + cy.clearAllFilters(); manageUserPage.typeFacilitySearch(facilityName); facilityPage.verifyFacilityBadgeContent(facilityName); manageUserPage.assertFacilityInCard(facilityName); diff --git a/cypress/e2e/facility_spec/inventory.cy.ts b/cypress/e2e/facility_spec/inventory.cy.ts index c28035dd885..79077d6e6a6 100644 --- a/cypress/e2e/facility_spec/inventory.cy.ts +++ b/cypress/e2e/facility_spec/inventory.cy.ts @@ -13,6 +13,7 @@ describe("Inventory Management Section", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/"); cy.viewport(1280, 720); }); diff --git a/cypress/e2e/facility_spec/locations.cy.ts b/cypress/e2e/facility_spec/locations.cy.ts index cac9adbdde1..f8006b126d4 100644 --- a/cypress/e2e/facility_spec/locations.cy.ts +++ b/cypress/e2e/facility_spec/locations.cy.ts @@ -9,6 +9,7 @@ describe("Location Management Section", () => { beforeEach(() => { cy.viewport(1280, 720); cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/"); cy.intercept("GET", "**/api/v1/facility/**").as("getFacilities"); cy.get("[id='facility-details']").first().click(); diff --git a/cypress/e2e/patient_spec/patient_crud.cy.ts b/cypress/e2e/patient_spec/patient_crud.cy.ts index 57bae83a880..b9843c1556d 100644 --- a/cypress/e2e/patient_spec/patient_crud.cy.ts +++ b/cypress/e2e/patient_spec/patient_crud.cy.ts @@ -27,6 +27,7 @@ describe("Patient Creation with consultation", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/patients"); }); diff --git a/cypress/e2e/patient_spec/patient_manage.cy.ts b/cypress/e2e/patient_spec/patient_manage.cy.ts index e8d381286aa..89d00b6bb9f 100644 --- a/cypress/e2e/patient_spec/patient_manage.cy.ts +++ b/cypress/e2e/patient_spec/patient_manage.cy.ts @@ -15,6 +15,7 @@ describe("Patient", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/patients"); }); diff --git a/cypress/e2e/resource_spec/filter.cy.ts b/cypress/e2e/resource_spec/filter.cy.ts index e4db00050e1..c457f867ed4 100644 --- a/cypress/e2e/resource_spec/filter.cy.ts +++ b/cypress/e2e/resource_spec/filter.cy.ts @@ -8,12 +8,13 @@ describe("Resource filter", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/resource"); - cy.contains("Filters").click(); }); it("filter by origin facility", () => { cy.intercept(/\/api\/v1\/getallfacilities/).as("facilities_filter"); + cy.contains("Filters").click(); cy.get("[name='origin_facility']") .type("Dummy Facility 1") .wait("@facilities_filter"); @@ -23,6 +24,7 @@ describe("Resource filter", () => { it("filter by resource approval facility", () => { cy.intercept(/\/api\/v1\/getallfacilities/).as("facilities_filter"); + cy.contains("Filters").click(); cy.get("[name='approving_facility']") .type("Dummy Shifting Center") .wait("@facilities_filter"); @@ -32,6 +34,7 @@ describe("Resource filter", () => { it("filter by assigned facility", () => { cy.intercept(/\/api\/v1\/getallfacilities/).as("facilities_filter"); + cy.contains("Filters").click(); cy.get("[name='assigned_facility']").type("Dummy Shifting Center"); cy.wait("@facilities_filter"); cy.get("[role='option']").first().click(); @@ -45,26 +48,27 @@ describe("Resource filter", () => { "DESC Modified Date", "ASC Created Date", ].forEach((option) => { + cy.contains("Filters").click(); cy.get("div [id='ordering'] > div > button").click(); cy.get("li").contains(option).click(); cy.intercept(/\/api\/v1\/resource/).as("resource_filter"); cy.contains("Apply").click().wait("@resource_filter"); - cy.contains("Filters").click(); }); }); it("filter by emergency case", () => { ["yes", "no"].forEach((option) => { + cy.contains("Filters").click(); cy.get("div [id='emergency'] > div > button").click(); cy.get("li").contains(option).click(); cy.intercept(/\/api\/v1\/resource/).as("resource_filter"); cy.contains("Apply").click().wait("@resource_filter"); - cy.contains("Filters").click(); }); }); it("filter by created date", () => { cy.intercept(/\/api\/v1\/resource/).as("resource_filter"); + cy.contains("Filters").click(); cy.get("input[name='created_date_start']").click(); cy.get("#date-1").click(); cy.get("#date-1").click(); @@ -74,6 +78,7 @@ describe("Resource filter", () => { it("filter by modified date", () => { cy.intercept(/\/api\/v1\/resource/).as("resource_filter"); + cy.contains("Filters").click(); cy.get("input[name='modified_date_start']").click(); cy.get("#date-1").click(); cy.get("#date-1").click(); @@ -82,8 +87,7 @@ describe("Resource filter", () => { }); afterEach(() => { - cy.contains("Filters").click({ force: true }); - cy.contains("Clear").click(); + cy.clearAllFilters(); cy.saveLocalStorage(); }); }); diff --git a/cypress/e2e/resource_spec/resources.cy.ts b/cypress/e2e/resource_spec/resources.cy.ts index acf179db120..a774023059f 100644 --- a/cypress/e2e/resource_spec/resources.cy.ts +++ b/cypress/e2e/resource_spec/resources.cy.ts @@ -17,6 +17,7 @@ describe("Resource Page", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/resource"); }); diff --git a/cypress/e2e/sample_test_spec/filter.cy.ts b/cypress/e2e/sample_test_spec/filter.cy.ts index 8fe8fa50b81..a015d1ba7c5 100644 --- a/cypress/e2e/sample_test_spec/filter.cy.ts +++ b/cypress/e2e/sample_test_spec/filter.cy.ts @@ -8,6 +8,7 @@ describe("Sample Filter", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/sample"); cy.contains("Advanced Filters").click(); }); diff --git a/cypress/e2e/sample_test_spec/sample_test.cy.ts b/cypress/e2e/sample_test_spec/sample_test.cy.ts index ec12abbfdfb..1a134fffdac 100644 --- a/cypress/e2e/sample_test_spec/sample_test.cy.ts +++ b/cypress/e2e/sample_test_spec/sample_test.cy.ts @@ -8,6 +8,7 @@ describe("Sample List", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/sample"); }); diff --git a/cypress/e2e/shifting_spec/filter.cy.ts b/cypress/e2e/shifting_spec/filter.cy.ts index 3790198a4db..a142a657013 100644 --- a/cypress/e2e/shifting_spec/filter.cy.ts +++ b/cypress/e2e/shifting_spec/filter.cy.ts @@ -11,6 +11,7 @@ describe("Shifting section filter", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/shifting"); shiftingPage.advancedFilterButton().click(); }); diff --git a/cypress/e2e/shifting_spec/shifting.cy.ts b/cypress/e2e/shifting_spec/shifting.cy.ts index bc78e55f175..9cdecc59990 100644 --- a/cypress/e2e/shifting_spec/shifting.cy.ts +++ b/cypress/e2e/shifting_spec/shifting.cy.ts @@ -8,6 +8,7 @@ describe("Shifting Page", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/shifting"); }); diff --git a/cypress/e2e/users_spec/user_creation.cy.ts b/cypress/e2e/users_spec/user_creation.cy.ts index 9090f72505a..55d4b3bef1a 100644 --- a/cypress/e2e/users_spec/user_creation.cy.ts +++ b/cypress/e2e/users_spec/user_creation.cy.ts @@ -63,6 +63,7 @@ describe("User Creation", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/users"); }); diff --git a/cypress/e2e/users_spec/user_homepage.cy.ts b/cypress/e2e/users_spec/user_homepage.cy.ts index 060132105e6..3a633bd65a4 100644 --- a/cypress/e2e/users_spec/user_homepage.cy.ts +++ b/cypress/e2e/users_spec/user_homepage.cy.ts @@ -19,6 +19,7 @@ describe("User Homepage", () => { beforeEach(() => { cy.restoreLocalStorage(); + cy.clearLocalStorage(/filters--.+/); cy.awaitUrl("/users"); }); diff --git a/cypress/e2e/users_spec/user_manage.cy.ts b/cypress/e2e/users_spec/user_manage.cy.ts index 9fe3aea75f9..35818751526 100644 --- a/cypress/e2e/users_spec/user_manage.cy.ts +++ b/cypress/e2e/users_spec/user_manage.cy.ts @@ -27,6 +27,9 @@ describe("Manage User", () => { beforeEach(() => { cy.restoreLocalStorage(); + console.log(localStorage); + cy.clearLocalStorage(/filters--.+/); + console.log(localStorage); cy.awaitUrl("/users"); }); diff --git a/cypress/pageobject/Asset/AssetCreation.ts b/cypress/pageobject/Asset/AssetCreation.ts index 93bbc87c9ab..60e3f3ece2d 100644 --- a/cypress/pageobject/Asset/AssetCreation.ts +++ b/cypress/pageobject/Asset/AssetCreation.ts @@ -239,7 +239,7 @@ export class AssetPage { } selectjsonexportbutton() { - cy.intercept("GET", "**/api/v1/asset/?json=true**").as("getJsonexport"); + cy.intercept("GET", "**/api/v1/asset/?**json=true**").as("getJsonexport"); cy.get("#export-json-option").click(); cy.wait("@getJsonexport").then(({ request, response }) => { expect(response.statusCode).to.eq(200); @@ -248,7 +248,7 @@ export class AssetPage { } selectcsvexportbutton() { - cy.intercept("GET", "**/api/v1/asset/?csv=true**").as("getCsvexport"); + cy.intercept("GET", "**/api/v1/asset/?**csv=true**").as("getCsvexport"); cy.get("#export-csv-option").click(); cy.wait("@getCsvexport").then(({ request, response }) => { expect(response.statusCode).to.eq(200); diff --git a/cypress/pageobject/Asset/AssetFilters.ts b/cypress/pageobject/Asset/AssetFilters.ts index a16b61f4fc5..9a8d9781786 100644 --- a/cypress/pageobject/Asset/AssetFilters.ts +++ b/cypress/pageobject/Asset/AssetFilters.ts @@ -40,7 +40,20 @@ export class AssetFilters { cy.intercept("GET", "**/api/v1/asset/**").as("clearAssets"); cy.get("#clear-filter").click(); cy.wait("@clearAssets").its("response.statusCode").should("eq", 200); - cy.url().should("match", /\/assets$/); + cy.location("pathname").should("match", /\/assets$/); + cy.url().then((url) => { + const queryParams = new URL(url).searchParams; + let allEmpty = true; + const blacklistedKeys = ["page", "limit", "offset"]; + + queryParams.forEach((value, key) => { + if (value !== "" && !blacklistedKeys.includes(key)) { + allEmpty = false; + } + }); + + expect(allEmpty).to.be.true; + }); } clickadvancefilter() { cy.intercept("GET", "**/api/v1/getallfacilities/**").as("advancefilter"); diff --git a/cypress/support/commands.ts b/cypress/support/commands.ts index 2dd8c477233..0c491814102 100644 --- a/cypress/support/commands.ts +++ b/cypress/support/commands.ts @@ -109,3 +109,7 @@ Cypress.Commands.add("getAttached", (selector) => { }) .then(() => cy.wrap($el)); }); + +Cypress.Commands.add("clearAllFilters", () => { + return cy.get("#clear-all-filters").click(); +}); diff --git a/cypress/support/index.ts b/cypress/support/index.ts index a4db7ef3f92..ea1a9b73a0b 100644 --- a/cypress/support/index.ts +++ b/cypress/support/index.ts @@ -12,6 +12,8 @@ declare global { url: string, disableLoginVerification?: boolean ): Chainable; + getAttached(selector: string): Chainable; + clearAllFilters(): Chainable; } } } diff --git a/cypress/tsconfig.json b/cypress/tsconfig.json index ff9ee273356..9c019786170 100644 --- a/cypress/tsconfig.json +++ b/cypress/tsconfig.json @@ -2,7 +2,7 @@ "compilerOptions": { "baseUrl": "../node_modules", "target": "es5", - "lib": ["es5", "dom"], + "lib": ["es5", "dom", "es2015", "es2016", "es2017", "es2018", "es2019", "es2020"], "types": ["cypress"], "typeRoots": ["./support"], "resolveJsonModule": true diff --git a/src/Common/hooks/useFilters.tsx b/src/Common/hooks/useFilters.tsx index 129a696041b..a62180c8a29 100644 --- a/src/Common/hooks/useFilters.tsx +++ b/src/Common/hooks/useFilters.tsx @@ -1,5 +1,5 @@ import { useQueryParams } from "raviger"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useTranslation } from "react-i18next"; import GenericFilterBadge from "../../CAREUI/display/FilterBadge"; import PaginationComponent from "../../Components/Common/Pagination"; @@ -37,6 +37,25 @@ export default function useFilters({ limit = 14 }: { limit?: number }) { const removeFilters = (keys: string[]) => updateQuery(keys.reduce((acc, key) => ({ ...acc, [key]: "" }), qParams)); + useEffect(() => { + const localFilters = JSON.parse( + localStorage.getItem("filters--" + window.location.pathname) || "{}" + ); + const blacklistLocalFilters = ["page", "limit", "offset"]; + const newFilters = { ...localFilters, ...qParams }; + const filteredNewFilters = blacklistLocalFilters.reduce( + (acc, key) => ({ ...acc, [key]: undefined }), + newFilters + ); + + localStorage.setItem( + "filters--" + window.location.pathname, + JSON.stringify(filteredNewFilters) + ); + + updateQuery(newFilters); + }, [qParams]); + const FilterBadge = ({ name, value, paramKey }: FilterBadgeProps) => { if (Array.isArray(paramKey)) return ( @@ -131,11 +150,36 @@ export default function useFilters({ limit = 14 }: { limit?: number }) { }) => { const compiledBadges = badges(badgeUtils); const { t } = useTranslation(); + + const activeFilters = compiledBadges.reduce((acc, badge) => { + const { paramKey } = badge; + + if (Array.isArray(paramKey)) { + const active = paramKey.filter((key) => qParams[key]); + if (active) acc.concat(active); + } else { + if (qParams[paramKey]) acc.push(paramKey); + } + + return acc; + }, [] as string[]); + return (
{compiledBadges.map((props) => ( ))} + {activeFilters.length >= 1 && ( + + )} {children}
); @@ -201,6 +245,7 @@ export default function useFilters({ limit = 14 }: { limit?: number }) { show: showFilters, setShow: setShowFilters, filter: qParams, + removeFilters, onChange: (filter: FilterState) => { updateQuery(filter); setShowFilters(false); diff --git a/src/Components/Assets/AssetFilter.tsx b/src/Components/Assets/AssetFilter.tsx index 98f7f52e1e1..9aeac85e734 100644 --- a/src/Components/Assets/AssetFilter.tsx +++ b/src/Components/Assets/AssetFilter.tsx @@ -1,5 +1,5 @@ import { useState, useEffect, useCallback } from "react"; -import { navigate, useQueryParams } from "raviger"; +import { useQueryParams } from "raviger"; import { FacilitySelect } from "../Common/FacilitySelect"; import { FacilityModel } from "../Facility/models"; import { LocationSelect } from "../Common/LocationSelect"; @@ -19,7 +19,7 @@ const getDate = (value: any) => value && dayjs(value).isValid() && dayjs(value).toDate(); function AssetFilter(props: any) { - const { filter, onChange, closeFilter } = props; + const { filter, onChange, closeFilter, removeFilters } = props; const [facility, setFacility] = useState({ name: "" }); const [asset_type, setAssetType] = useState( filter.asset_type ? filter.asset_type : "" @@ -54,16 +54,16 @@ function AssetFilter(props: any) { }, [facility.id, qParams.facility, qParams.location]); const clearFilter = useCallback(() => { - setFacility({ name: "" }); - setAssetType(""); - setAssetStatus(""); - setAssetClass(""); - setFacilityId(""); - setLocationId(""); + removeFilters([ + "facility", + "asset_type", + "asset_class", + "status", + "location", + "warranty_amc_end_of_validity_before", + "warranty_amc_end_of_validity_after", + ]); closeFilter(); - const searchQuery = qParams?.search && `?search=${qParams?.search}`; - if (searchQuery) navigate(`/assets${searchQuery}`); - else navigate("/assets"); }, [qParams]); const applyFilter = () => { diff --git a/src/Components/ExternalResult/ListFilter.tsx b/src/Components/ExternalResult/ListFilter.tsx index 75358196ffd..898fe9ecb31 100644 --- a/src/Components/ExternalResult/ListFilter.tsx +++ b/src/Components/ExternalResult/ListFilter.tsx @@ -1,6 +1,5 @@ import { useState } from "react"; import useMergeState from "../../Common/hooks/useMergeState"; -import { navigate } from "raviger"; import { useTranslation } from "react-i18next"; import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover"; import TextFormField from "../Form/FormFields/TextFormField"; @@ -27,7 +26,7 @@ const getDate = (value: any) => value && dayjs(value).isValid() && dayjs(value).toDate(); export default function ListFilter(props: any) { - const { filter, onChange, closeFilter, dataList } = props; + const { filter, onChange, closeFilter, dataList, removeFilters } = props; const [wardList, setWardList] = useState([]); const [lsgList, setLsgList] = useState([]); const [wards, setWards] = useState([]); @@ -198,10 +197,11 @@ export default function ListFilter(props: any) { advancedFilter={props} onApply={applyFilter} onClear={() => { - navigate("/external_results"); - setFilterState(clearFilterState); - setSelectedLsgs([]); - setWards([]); + removeFilters([ + ...Object.keys(clearFilterState), + "wards", + "local_bodies", + ]); closeFilter(); }} > diff --git a/src/Components/ExternalResult/ResultList.tsx b/src/Components/ExternalResult/ResultList.tsx index 9aa365c7303..8fddc7cadc9 100644 --- a/src/Components/ExternalResult/ResultList.tsx +++ b/src/Components/ExternalResult/ResultList.tsx @@ -284,6 +284,13 @@ export default function ResultList() { +
+ {qParams.local_bodies && + dataList.lsgList.map((x) => lsgWardBadge("LSG", x, "local_bodies"))} + {qParams.wards && + dataList.wardList.map((x) => lsgWardBadge("Ward", x, "wards"))} +
+ [ badge("Name", "name"), @@ -294,10 +301,7 @@ export default function ResultList() { badge("SRF ID", "srf_id"), ]} /> -
- {dataList.lsgList.map((x) => lsgWardBadge("LSG", x, "local_bodies"))} - {dataList.wardList.map((x) => lsgWardBadge("Ward", x, "wards"))} -
+
diff --git a/src/Components/Facility/FacilityFilter/index.tsx b/src/Components/Facility/FacilityFilter/index.tsx index fd6edd664d1..e9270ec7a63 100644 --- a/src/Components/Facility/FacilityFilter/index.tsx +++ b/src/Components/Facility/FacilityFilter/index.tsx @@ -1,4 +1,3 @@ -import { navigate } from "raviger"; import { FACILITY_TYPES } from "../../../Common/constants"; import useMergeState from "../../../Common/hooks/useMergeState"; import FiltersSlideover from "../../../CAREUI/interactive/FiltersSlideover"; @@ -18,7 +17,7 @@ const clearFilterState = { function FacilityFilter(props: any) { const { t } = useTranslation(); - const { filter, onChange, closeFilter } = props; + const { filter, onChange, closeFilter, removeFilters } = props; const [filterState, setFilterState] = useMergeState({ state: filter.state || "", @@ -66,8 +65,7 @@ function FacilityFilter(props: any) { advancedFilter={props} onApply={applyFilter} onClear={() => { - navigate("/facility"); - setFilterState(clearFilterState); + removeFilters(Object.keys(clearFilterState)); closeFilter(); }} > diff --git a/src/Components/Patient/PatientFilter.tsx b/src/Components/Patient/PatientFilter.tsx index 10b170f4547..0599cb2625b 100644 --- a/src/Components/Patient/PatientFilter.tsx +++ b/src/Components/Patient/PatientFilter.tsx @@ -1,7 +1,5 @@ import dayjs from "dayjs"; -import { navigate } from "raviger"; import { useCallback, useEffect } from "react"; -import { useDispatch } from "react-redux"; import CareIcon from "../../CAREUI/icons/CareIcon"; import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover"; import { @@ -19,6 +17,7 @@ import { getAnyFacility, getDistrict, } from "../../Redux/actions"; +import { useDispatch } from "react-redux"; import { dateQueryString } from "../../Utils/utils"; import { DateRange } from "../Common/DateRangeInputV2"; import { FacilitySelect } from "../Common/FacilitySelect"; @@ -41,7 +40,7 @@ const getDate = (value: any) => export default function PatientFilter(props: any) { const { kasp_enabled, kasp_string } = useConfig(); - const { filter, onChange, closeFilter } = props; + const { filter, onChange, closeFilter, removeFilters } = props; const [filterState, setFilterState] = useMergeState({ district: filter.district || "", @@ -337,8 +336,7 @@ export default function PatientFilter(props: any) { advancedFilter={props} onApply={applyFilter} onClear={() => { - navigate("/patients"); - setFilterState(clearFilterState); + removeFilters(Object.keys(clearFilterState)); closeFilter(); }} > diff --git a/src/Components/Patient/SampleFilters.tsx b/src/Components/Patient/SampleFilters.tsx index db22e54ac80..44af9a6a4d5 100644 --- a/src/Components/Patient/SampleFilters.tsx +++ b/src/Components/Patient/SampleFilters.tsx @@ -4,7 +4,6 @@ import { SAMPLE_TEST_RESULT, SAMPLE_TYPE_CHOICES, } from "../../Common/constants"; -import { navigate } from "raviger"; import { FacilitySelect } from "../Common/FacilitySelect"; import { FacilityModel } from "../Facility/models"; import { getAnyFacility } from "../../Redux/actions"; @@ -25,7 +24,7 @@ const clearFilterState = { }; export default function UserFilter(props: any) { - const { filter, onChange, closeFilter } = props; + const { filter, onChange, closeFilter, removeFilters } = props; const [filterState, setFilterState] = useMergeState({ status: filter.status || "", @@ -74,8 +73,7 @@ export default function UserFilter(props: any) { advancedFilter={props} onApply={applyFilter} onClear={() => { - navigate("/sample"); - setFilterState(clearFilterState); + removeFilters(Object.keys(clearFilterState)); closeFilter(); }} > diff --git a/src/Components/Resource/ListFilter.tsx b/src/Components/Resource/ListFilter.tsx index afe48eedfd0..e232e404520 100644 --- a/src/Components/Resource/ListFilter.tsx +++ b/src/Components/Resource/ListFilter.tsx @@ -2,7 +2,6 @@ import { FacilitySelect } from "../Common/FacilitySelect"; import { RESOURCE_FILTER_ORDER } from "../../Common/constants"; import { RESOURCE_CHOICES } from "../../Common/constants"; import useMergeState from "../../Common/hooks/useMergeState"; -import { navigate } from "raviger"; import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover"; import { FieldLabel } from "../Form/FormFields/FormField"; import CircularProgress from "../Common/components/CircularProgress"; @@ -35,7 +34,7 @@ const getDate = (value: any) => value && dayjs(value).isValid() && dayjs(value).toDate(); export default function ListFilter(props: any) { - const { filter, onChange, closeFilter } = props; + const { filter, onChange, closeFilter, removeFilters } = props; const [filterState, setFilterState] = useMergeState({ origin_facility: filter.origin_facility || "", origin_facility_ref: null, @@ -140,8 +139,7 @@ export default function ListFilter(props: any) { advancedFilter={props} onApply={applyFilter} onClear={() => { - navigate("/resource"); - setFilterState(clearFilterState); + removeFilters(Object.keys(clearFilterState)); closeFilter(); }} > diff --git a/src/Components/Shifting/ListFilter.tsx b/src/Components/Shifting/ListFilter.tsx index ef366d5b038..8d54ec91ce7 100644 --- a/src/Components/Shifting/ListFilter.tsx +++ b/src/Components/Shifting/ListFilter.tsx @@ -18,7 +18,6 @@ import DateRangeFormField from "../Form/FormFields/DateRangeFormField"; import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover"; import { SelectFormField } from "../Form/FormFields/SelectFormField"; import PhoneNumberFormField from "../Form/FormFields/PhoneNumberFormField"; -import { navigate } from "raviger"; import useConfig from "../../Common/hooks/useConfig"; import useMergeState from "../../Common/hooks/useMergeState"; @@ -58,7 +57,7 @@ const getDate = (value: any) => export default function ListFilter(props: any) { const { kasp_enabled, kasp_string, wartime_shifting } = useConfig(); - const { filter, onChange, closeFilter } = props; + const { filter, onChange, closeFilter, removeFilters } = props; const { t } = useTranslation(); @@ -221,8 +220,7 @@ export default function ListFilter(props: any) { advancedFilter={props} onApply={applyFilter} onClear={() => { - navigate("/shifting"); - setFilterState(clearFilterState); + removeFilters(Object.keys(clearFilterState)); closeFilter(); }} > diff --git a/src/Components/Users/UserFilter.tsx b/src/Components/Users/UserFilter.tsx index 4544fb8893a..ed65030f8a7 100644 --- a/src/Components/Users/UserFilter.tsx +++ b/src/Components/Users/UserFilter.tsx @@ -1,4 +1,3 @@ -import { navigate } from "raviger"; import DistrictSelect from "../Facility/FacilityFilter/DistrictSelect"; import { parsePhoneNumber } from "../../Utils/utils"; import TextFormField from "../Form/FormFields/TextFormField"; @@ -19,7 +18,7 @@ const parsePhoneNumberForFilterParam = (phoneNumber: string) => { }; export default function UserFilter(props: any) { - const { filter, onChange, closeFilter } = props; + const { filter, onChange, closeFilter, removeFilters } = props; const [filterState, setFilterState] = useMergeState({ first_name: filter.first_name || "", last_name: filter.last_name || "", @@ -84,8 +83,7 @@ export default function UserFilter(props: any) { advancedFilter={props} onApply={applyFilter} onClear={() => { - navigate("/users"); - setFilterState(clearFilterState); + removeFilters(Object.keys(clearFilterState)); closeFilter(); }} > diff --git a/src/Locale/en/Common.json b/src/Locale/en/Common.json index c455e3a989a..31528afa390 100644 --- a/src/Locale/en/Common.json +++ b/src/Locale/en/Common.json @@ -158,5 +158,6 @@ "edit": "Edit", "clear_selection": "Clear selection", "select_date": "Select date", - "DD/MM/YYYY": "DD/MM/YYYY" -} \ No newline at end of file + "DD/MM/YYYY": "DD/MM/YYYY", + "clear_all_filters": "Clear All Filters" +}