From f33fb7205dd95fafe0b0eb49c395c4e58ade3e84 Mon Sep 17 00:00:00 2001 From: Shivank Kacker Date: Sun, 4 Aug 2024 22:34:43 +0530 Subject: [PATCH 1/3] Add option to filter users by no home facility --- src/Components/Common/FacilitySelect.tsx | 5 +++++ src/Components/Users/ManageUsers.tsx | 8 ++++++-- src/Components/Users/UserFilter.tsx | 3 ++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Components/Common/FacilitySelect.tsx b/src/Components/Common/FacilitySelect.tsx index 526bf6d68ac..2db115386d0 100644 --- a/src/Components/Common/FacilitySelect.tsx +++ b/src/Components/Common/FacilitySelect.tsx @@ -21,6 +21,7 @@ interface FacilitySelectProps { freeText?: boolean; selected?: FacilityModel | FacilityModel[] | null; setSelected: (selected: FacilityModel | FacilityModel[] | null) => void; + allowNone?: boolean; } export const FacilitySelect = (props: FacilitySelectProps) => { @@ -39,6 +40,7 @@ export const FacilitySelect = (props: FacilitySelectProps) => { facilityType, district, state, + allowNone = false, freeText = false, errors = "", } = props; @@ -66,6 +68,9 @@ export const FacilitySelect = (props: FacilitySelectProps) => { name: text, }); + if (allowNone) + return [{ name: "None", id: "NONE" }, ...(data?.results || [])]; + return data?.results; }, [searchAll, showAll, facilityType, district, exclude_user, freeText], diff --git a/src/Components/Users/ManageUsers.tsx b/src/Components/Users/ManageUsers.tsx index 19bafebd115..e19db0fca6e 100644 --- a/src/Components/Users/ManageUsers.tsx +++ b/src/Components/Users/ManageUsers.tsx @@ -73,7 +73,7 @@ export default function ManageUsers() { const { data: homeFacilityData } = useQuery(routes.getAnyFacility, { pathParams: { id: qParams.home_facility }, - prefetch: !!qParams.home_facility, + prefetch: !!qParams.home_facility && qParams.home_facility !== "NONE", }); const { @@ -556,7 +556,11 @@ export default function ManageUsers() { value( "Home Facility", "home_facility", - qParams.home_facility ? homeFacilityData?.name || "" : "", + qParams.home_facility + ? qParams.home_facility === "NONE" + ? "None" + : homeFacilityData?.name || "" + : "", ), value( "Last Active", diff --git a/src/Components/Users/UserFilter.tsx b/src/Components/Users/UserFilter.tsx index f79968cef4f..75692180628 100644 --- a/src/Components/Users/UserFilter.tsx +++ b/src/Components/Users/UserFilter.tsx @@ -43,7 +43,7 @@ export default function UserFilter(props: any) { useQuery(routes.getAnyFacility, { pathParams: { id: filter.home_facility }, - prefetch: !!filter.home_facility, + prefetch: !!filter.home_facility && filter.home_facility !== "NONE", onResponse: ({ data }) => setFilterState({ home_facility_ref: data }), }); @@ -134,6 +134,7 @@ export default function UserFilter(props: any) {
Home Facility setFilterState({ From 23c717d7d73d1e24286fddbfbca16de3e571edb4 Mon Sep 17 00:00:00 2001 From: Shivank Kacker Date: Wed, 7 Aug 2024 17:35:05 +0530 Subject: [PATCH 2/3] fix NONE filter --- src/Components/Users/UserFilter.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Components/Users/UserFilter.tsx b/src/Components/Users/UserFilter.tsx index 75692180628..593cf3f38ee 100644 --- a/src/Components/Users/UserFilter.tsx +++ b/src/Components/Users/UserFilter.tsx @@ -143,7 +143,11 @@ export default function UserFilter(props: any) { home_facility_ref: selected, }) } - selected={filterState.home_facility_ref} + selected={ + filterState.home_facility === "NONE" + ? { name: "None", id: "NONE" } + : filterState.home_facility_ref + } errors="" multiple={false} /> From 5a5033874aa901e4aeb12932a3241decf41d8e3f Mon Sep 17 00:00:00 2001 From: Shivank Kacker Date: Fri, 23 Aug 2024 17:05:20 +0530 Subject: [PATCH 3/3] i18n --- src/Components/Common/FacilitySelect.tsx | 6 +++++- src/Components/Users/ManageUsers.tsx | 17 ++++++----------- src/Components/Users/UserFilter.tsx | 2 +- src/Locale/en/Users.json | 1 + 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Components/Common/FacilitySelect.tsx b/src/Components/Common/FacilitySelect.tsx index 2db115386d0..d718ef3e781 100644 --- a/src/Components/Common/FacilitySelect.tsx +++ b/src/Components/Common/FacilitySelect.tsx @@ -3,6 +3,7 @@ import AutoCompleteAsync from "../Form/AutoCompleteAsync"; import { FacilityModel } from "../Facility/models"; import request from "../../Utils/request/request"; import routes from "../../Redux/api"; +import { t } from "i18next"; interface FacilitySelectProps { name: string; @@ -69,7 +70,10 @@ export const FacilitySelect = (props: FacilitySelectProps) => { }); if (allowNone) - return [{ name: "None", id: "NONE" }, ...(data?.results || [])]; + return [ + { name: t("no_home_facility"), id: "NONE" }, + ...(data?.results || []), + ]; return data?.results; }, diff --git a/src/Components/Users/ManageUsers.tsx b/src/Components/Users/ManageUsers.tsx index 3d3a8dd1734..a3cb3063577 100644 --- a/src/Components/Users/ManageUsers.tsx +++ b/src/Components/Users/ManageUsers.tsx @@ -198,10 +198,7 @@ export default function ManageUsers() {
-
+
{user.username && (
{user.user_type && ( @@ -340,9 +337,7 @@ export default function ManageUsers() { )}
{user.created_by && ( @@ -563,7 +558,7 @@ export default function ManageUsers() { "home_facility", qParams.home_facility ? qParams.home_facility === "NONE" - ? "None" + ? t("no_home_facility") : homeFacilityData?.name || "" : "", ), @@ -790,7 +785,7 @@ export function UserFacilities(props: { user: any }) { {user?.home_facility_object?.name} diff --git a/src/Components/Users/UserFilter.tsx b/src/Components/Users/UserFilter.tsx index 593cf3f38ee..ff2a81723cd 100644 --- a/src/Components/Users/UserFilter.tsx +++ b/src/Components/Users/UserFilter.tsx @@ -145,7 +145,7 @@ export default function UserFilter(props: any) { } selected={ filterState.home_facility === "NONE" - ? { name: "None", id: "NONE" } + ? { name: t("no_home_facility"), id: "NONE" } : filterState.home_facility_ref } errors="" diff --git a/src/Locale/en/Users.json b/src/Locale/en/Users.json index 32c6ee209c3..01fe031c61a 100644 --- a/src/Locale/en/Users.json +++ b/src/Locale/en/Users.json @@ -4,6 +4,7 @@ "add_new_user": "Add New User", "no_users_found": "No Users Found", "home_facility": "Home Facility", + "no_home_facility" : "No home facility assigned", "clear_home_facility": "Clear Home Facility", "linked_facilities": "Linked Facilities", "no_linked_facilities": "No Linked Facilities",