-
Notifications
You must be signed in to change notification settings - Fork 532
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
Public Facilities Filters #9748
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
faa4abe
WIP: organization filter
Jacobjeevan 099e91e
Merge branch 'develop' into organizationFilter
Jacobjeevan 3abdfd9
Organization Filter
Jacobjeevan 2349c84
Merge branch 'develop' into organizationFilter
Jacobjeevan db940f2
minor fixes
Jacobjeevan bc0560a
Merge branch 'develop' into organizationFilter
Jacobjeevan a57dfa6
Tweak logic to work with levels from BE than hardcoded
Jacobjeevan c4ca814
Merge branch 'develop' into organizationFilter
Jacobjeevan be5bcaa
Update organisation filter and search bar styling on public facilitie…
vinutv 2b62571
Merge branch 'develop' into organizationFilter
Jacobjeevan 5ff2f0f
added query for root level, styling changes
Jacobjeevan 31986af
moved logic to sep file&hook as per cursor suggestion
Jacobjeevan 5537247
coderabbit suggestions
Jacobjeevan 3ca311d
additional styling changes
Jacobjeevan def05a4
mobile responsiveness edits
Jacobjeevan f1f9b55
Merge branch 'develop' into organizationFilter
nihal467 04b8c10
Merge branch 'develop' into organizationFilter
Jacobjeevan 06dba7b
switch to debounced query
Jacobjeevan cfd445c
styling and fixes
Jacobjeevan c3eb888
Merge branch 'develop' into organizationFilter
Jacobjeevan e0f4527
Merge branch 'develop' into organizationFilter
Jacobjeevan 03ee501
disable facility type filter if location is not selected
Jacobjeevan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useEffect, useMemo, useState } from "react"; | ||
|
||
import { FilterState } from "@/hooks/useFilters"; | ||
|
||
import query from "@/Utils/request/query"; | ||
import { Organization } from "@/types/organization/organization"; | ||
import organizationApi from "@/types/organization/organizationApi"; | ||
|
||
interface UseOrganizationLevelProps { | ||
index: number; | ||
skip: boolean; | ||
selectedLevels: Organization[]; | ||
setOrgTypes: React.Dispatch<React.SetStateAction<string[]>>; | ||
onChange: (Filter: FilterState, index?: number) => void; | ||
getParentId: (index: number) => string; | ||
} | ||
|
||
export function useOrganizationLevel({ | ||
index, | ||
skip, | ||
selectedLevels, | ||
setOrgTypes, | ||
onChange, | ||
getParentId, | ||
}: UseOrganizationLevelProps) { | ||
const [levelSearch, setLevelSearch] = useState(""); | ||
|
||
const { data: availableOrgs } = useQuery<{ results: Organization[] }>({ | ||
queryKey: ["organizations-available", getParentId(index), levelSearch], | ||
queryFn: query.debounced(organizationApi.getPublicOrganizations, { | ||
queryParams: { | ||
...(index > 0 && { parent: getParentId(index) }), | ||
...(index === 0 && { level_cache: 1 }), | ||
name: levelSearch || undefined, | ||
}, | ||
}), | ||
enabled: | ||
!skip && | ||
index <= selectedLevels.length && | ||
(index === 0 || selectedLevels[index - 1] !== undefined), | ||
}); | ||
|
||
// Update org types when we get new data for this level | ||
useEffect(() => { | ||
if (selectedLevels[index]) { | ||
const currentOrg = selectedLevels[index]; | ||
if (currentOrg?.metadata?.govt_org_children_type) { | ||
setOrgTypes((prevTypes) => { | ||
const newTypes = [...prevTypes]; | ||
// Update next level type | ||
if (currentOrg.metadata?.govt_org_children_type) { | ||
if (index === newTypes.length) { | ||
newTypes.push(currentOrg.metadata.govt_org_children_type); | ||
} else { | ||
newTypes[index + 1] = currentOrg.metadata.govt_org_children_type; | ||
} | ||
} | ||
return newTypes; | ||
}); | ||
} | ||
} | ||
}, [selectedLevels, setOrgTypes, index]); | ||
|
||
const options = useMemo(() => { | ||
return ( | ||
availableOrgs?.results?.map((org) => ({ | ||
label: org.name, | ||
value: org.id, | ||
})) || [] | ||
); | ||
}, [availableOrgs?.results]); | ||
|
||
const handleChange = (value: string) => { | ||
const selectedOrg = availableOrgs?.results.find((org) => org.id === value); | ||
if (selectedOrg) { | ||
onChange({ organization: selectedOrg.id }, index); | ||
setLevelSearch(""); | ||
} | ||
}; | ||
|
||
const handleSearch = (value: string) => setLevelSearch(value); | ||
|
||
return { | ||
options, | ||
levelSearch, | ||
handleChange, | ||
handleSearch, | ||
availableOrgs, | ||
}; | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add type safety to the handleChange function.
The function assumes the selected organization exists but doesn't handle the case where it might not be found.
📝 Committable suggestion