Skip to content

Commit

Permalink
Fixed malfunction of filters (#5362)
Browse files Browse the repository at this point in the history
Co-authored-by: Mohammed Nihal <[email protected]>
  • Loading branch information
patelaryan7751 and nihal467 authored Apr 21, 2023
1 parent da56ceb commit ca1e58d
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 12 deletions.
13 changes: 11 additions & 2 deletions src/Components/Assets/AssetsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const AssetsList = () => {
const [totalCount, setTotalCount] = useState(0);
const [facility, setFacility] = useState<FacilityModel>();
const [asset_type, setAssetType] = useState<string>();
const [facilityName, setFacilityName] = useState<string>();
const [asset_class, setAssetClass] = useState<string>();
const [locationName, setLocationName] = useState<string>();
const [importAssetModalOpen, setImportAssetModalOpen] = useState(false);
Expand Down Expand Up @@ -118,6 +119,14 @@ const AssetsList = () => {
},
[dispatch, fetchData]
);
useEffect(() => {
async function fetchFacilityName() {
if (!qParams.facility) return setFacilityName("");
const res = await dispatch(getAnyFacility(qParams.facility, "facility"));
setFacilityName(res?.data?.name);
}
fetchFacilityName();
}, [dispatch, qParams.facility]);

const fetchFacility = useCallback(
async (status: statusType) => {
Expand Down Expand Up @@ -367,14 +376,14 @@ const AssetsList = () => {
</div>
</div>
</div>
<AssetFilter {...advancedFilter} />
<AssetFilter {...advancedFilter} key={window.location.search} />
{isLoading ? (
<Loading />
) : (
<>
<FilterBadges
badges={({ badge, value }) => [
value("Facility", ["facility", "location"], facility?.name || ""),
value("Facility", "facility", facilityName || ""),
badge("Name/Serial No./QR ID", "search"),
value("Asset Type", "asset_type", asset_type || ""),
value("Asset Class", "asset_class", asset_class || ""),
Expand Down
6 changes: 5 additions & 1 deletion src/Components/ExternalResult/ResultList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,11 @@ export default function ResultList() {
</table>
</div>
<Pagination totalCount={totalCount} />
<ListFilter {...advancedFilter} dataList={lsgWardData} />
<ListFilter
{...advancedFilter}
dataList={lsgWardData}
key={window.location.search}
/>
</div>
);
}
2 changes: 1 addition & 1 deletion src/Components/Facility/HospitalList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export const HospitalList = () => {
</div>
</div>

<FacilityFilter {...advancedFilter} />
<FacilityFilter {...advancedFilter} key={window.location.search} />
<FilterBadges
badges={({ badge, value, kasp }) => [
badge("Facility/District Name", "search"),
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Patient/ManagePatients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ export const PatientManager = () => {
/>
</div>
<div>
<PatientFilter {...advancedFilter} />
<PatientFilter {...advancedFilter} key={window.location.search} />
<NavTabs
onChange={(tab) => updateQuery({ is_active: tab ? "False" : "True" })}
options={[
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Patient/SampleViewAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export default function SampleViewAdmin() {
</div>

<AdvancedFilterButton onClick={() => advancedFilter.setShow(true)} />
<SampleFilter {...advancedFilter} />
<SampleFilter {...advancedFilter} key={window.location.search} />
</div>
<FilterBadges
badges={({ badge, value }) => [
Expand Down
17 changes: 16 additions & 1 deletion src/Components/Resource/BadgesList.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useState, useEffect } from "react";
import { getAnyFacility } from "../../Redux/actions";
import { useDispatch } from "react-redux";
import { SHIFTING_FILTER_ORDER } from "../../Common/constants";

export default function BadgesList(props: any) {
const { appliedFilters, FilterBadges } = props;
Expand Down Expand Up @@ -43,10 +44,24 @@ export default function BadgesList(props: any) {
fetchData();
}, [dispatch, appliedFilters.assigned_facility]);

const getDescShiftingFilterOrder = (ordering: any) => {
let desc = "";
SHIFTING_FILTER_ORDER.map((item: any) => {
if (item.text === ordering) {
desc = item.desc;
}
});
return desc;
};

return (
<FilterBadges
badges={({ badge, value, boolean, dateRange }: any) => [
badge("Ordering", "ordering"),
value(
"Ordering",
"ordering",
getDescShiftingFilterOrder(appliedFilters.ordering)
),
badge("Status", "status"),
boolean("Emergency", "emergency", {
trueValue: "yes",
Expand Down
6 changes: 5 additions & 1 deletion src/Components/Resource/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ export default function ListView() {
</div>
)}
</div>
<ListFilter {...advancedFilter} showResourceStatus={true} />
<ListFilter
{...advancedFilter}
showResourceStatus={true}
key={window.location.search}
/>
</div>
);
}
2 changes: 1 addition & 1 deletion src/Components/Resource/ResourceBoardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default function BoardView() {
)}
</div>
</ScrollingComponent>
<ListFilter {...advancedFilter} />
<ListFilter {...advancedFilter} key={window.location.search} />
</div>
);
}
16 changes: 16 additions & 0 deletions src/Components/Shifting/BadgesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { useState, useEffect } from "react";
import { getUserList, getAnyFacility } from "../../Redux/actions";
import { useDispatch } from "react-redux";
import { useTranslation } from "react-i18next";
import { SHIFTING_FILTER_ORDER } from "../../Common/constants";

export default function BadgesList(props: any) {
const { qParams, FilterBadges } = props;
Expand Down Expand Up @@ -63,6 +64,15 @@ export default function BadgesList(props: any) {
}
fetchData();
}, [dispatch, qParams.assigned_facility]);
const getDescShiftingFilterOrder = (ordering: any) => {
let desc = "";
SHIFTING_FILTER_ORDER.map((item: any) => {
if (item.text === ordering) {
desc = item.desc;
}
});
return desc;
};

return (
<FilterBadges
Expand All @@ -82,6 +92,7 @@ export default function BadgesList(props: any) {
phoneNumber(t("phone_no"), "patient_phone_number"),
badge(t("patient_name"), "patient_name"),
...dateRange(t("created"), "created_date"),
...dateRange(t("modified"), "modified_date"),
badge(t("disease_status"), "disease_status"),
badge(t("breathlessness_level"), "breathlessness_level"),
value(t("assigned_to"), "assigned_to", assignedUsername),
Expand All @@ -96,6 +107,11 @@ export default function BadgesList(props: any) {
"shifting_approving_facility",
approvingFacilityName
),
value(
t("ordering"),
"ordering",
getDescShiftingFilterOrder(qParams.ordering)
),
]}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Shifting/BoardView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default function BoardView() {
)}
</div>
</ScrollingComponent>
<ListFilter {...advancedFilter} />
<ListFilter {...advancedFilter} key={window.location.search} />
</div>
);
}
6 changes: 5 additions & 1 deletion src/Components/Shifting/ListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ export default function ListView() {
</div>
)}
</div>
<ListFilter showShiftingStatus={true} {...advancedFilter} />
<ListFilter
showShiftingStatus={true}
{...advancedFilter}
key={window.location.search}
/>
</Page>
);
}
2 changes: 1 addition & 1 deletion src/Components/Users/ManageUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ export default function ManageUsers() {
{userTypes.length && addUser}
</div>

<UserFilter {...advancedFilter} />
<UserFilter {...advancedFilter} key={window.location.search} />
</div>
</div>

Expand Down
1 change: 1 addition & 0 deletions src/Locale/en/Common.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"no": "No",
"status": "Status",
"created": "Created",
"modified": "Modified",
"updated": "Updated",
"assigned_to": "Assigned to",
"cancel": "Cancel",
Expand Down

0 comments on commit ca1e58d

Please sign in to comment.