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 option to filter users by no home facility #8247

Merged
merged 4 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions src/Components/Common/FacilitySelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -39,6 +40,7 @@ export const FacilitySelect = (props: FacilitySelectProps) => {
facilityType,
district,
state,
allowNone = false,
freeText = false,
errors = "",
} = props;
Expand Down Expand Up @@ -66,6 +68,9 @@ export const FacilitySelect = (props: FacilitySelectProps) => {
name: text,
});

if (allowNone)
return [{ name: "None", id: "NONE" }, ...(data?.results || [])];
shivankacker marked this conversation as resolved.
Show resolved Hide resolved

return data?.results;
},
[searchAll, showAll, facilityType, district, exclude_user, freeText],
Expand Down
8 changes: 6 additions & 2 deletions src/Components/Users/ManageUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,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 {
Expand Down Expand Up @@ -561,7 +561,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",
Expand Down
9 changes: 7 additions & 2 deletions src/Components/Users/UserFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
});

Expand Down Expand Up @@ -134,6 +134,7 @@ export default function UserFilter(props: any) {
<div className="w-full flex-none">
<FieldLabel>Home Facility</FieldLabel>
<FacilitySelect
allowNone
name="home_facility"
setSelected={(selected) =>
setFilterState({
Expand All @@ -142,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}
/>
Expand Down
Loading