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

add support to cache filter options #6695

Merged
merged 16 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions cypress/e2e/assets_spec/asset_homepage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe("Asset Tab", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
khavinshankar marked this conversation as resolved.
Show resolved Hide resolved
cy.awaitUrl("/assets");
});

Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/assets_spec/assets_creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe("Asset", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/assets");
});

Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/assets_spec/assets_manage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe("Asset", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/assets");
});

Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/death_report_spec/death_report.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/external_results_spec/external_result.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe("Edit Profile Testing", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/external_results");
});

Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/external_results_spec/filter.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe("External Results Filters", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/external_results");
cy.contains("Filters").click();
});
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/facility_spec/facility.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe("Facility Creation", () => {
beforeEach(() => {
cy.viewport(1280, 720);
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/facility");
});

Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/facility_spec/inventory.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe("Inventory Management Section", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/");
cy.viewport(1280, 720);
});
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/facility_spec/locations.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/patient_spec/patient_crud.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe("Patient Creation with consultation", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/patients");
});

Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/patient_spec/patient_manage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe("Patient", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/patients");
});

Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/resource_spec/filter.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe("Resource filter", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/resource");
cy.contains("Filters").click();
});
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/resource_spec/resources.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe("Resource Page", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/resource");
});

Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/sample_test_spec/filter.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe("Sample Filter", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/sample");
cy.contains("Advanced Filters").click();
});
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/sample_test_spec/sample_test.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe("Sample List", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/sample");
});

Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/shifting_spec/filter.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe("Shifting section filter", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/shifting");
shiftingPage.advancedFilterButton().click();
});
Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/shifting_spec/shifting.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ describe("Shifting Page", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/shifting");
});

Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/users_spec/user_creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe("User Creation", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/users");
});

Expand Down
1 change: 1 addition & 0 deletions cypress/e2e/users_spec/user_homepage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe("User Homepage", () => {

beforeEach(() => {
cy.restoreLocalStorage();
cy.clearLocalStorage(/filters--.+/);
cy.awaitUrl("/users");
});

Expand Down
3 changes: 3 additions & 0 deletions cypress/e2e/users_spec/user_manage.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ describe("Manage User", () => {

beforeEach(() => {
cy.restoreLocalStorage();
console.log(localStorage);
cy.clearLocalStorage(/filters--.+/);
console.log(localStorage);
cy.awaitUrl("/users");
});

Expand Down
21 changes: 20 additions & 1 deletion src/Common/hooks/useFilters.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 (
Expand Down
Loading