Skip to content

Commit

Permalink
Adds support for searching for OrganizationSelector and fix scroll …
Browse files Browse the repository at this point in the history
…for dropdown in sheet (#9620)
  • Loading branch information
rithviknishad authored Dec 31, 2024
1 parent 3855c69 commit f6ba679
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 25 deletions.
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1444,8 +1444,8 @@
"qualification": "Qualification",
"qualification_required": "Qualification is required",
"quantity_approved": "Quantity Approved",
"quantity_required": "Quantity Required",
"quantity_requested": "Quantity Requested",
"quantity_required": "Quantity Required",
"raise_consent_request": "Raise a consent request to fetch patient records over ABDM",
"ration_card__APL": "APL",
"ration_card__BPL": "BPL",
Expand Down Expand Up @@ -1552,6 +1552,7 @@
"schedule_calendar": "Schedule Calendar",
"schedule_information": "Schedule Information",
"scheduled": "Scheduled",
"schedules": "Schedules",
"scribe__reviewing_field": "Reviewing field {{currentField}} / {{totalFields}}",
"scribe_error": "Could not autofill fields",
"search": "Search",
Expand All @@ -1565,7 +1566,6 @@
"search_icd11_placeholder": "Search for ICD-11 Diagnoses",
"search_investigation_placeholder": "Search Investigation & Groups",
"search_medication": "Search Medication",
"search_patient": "Search Patient",
"search_patients": "Search Patients",
"search_resource": "Search Resource",
"searching": "Searching",
Expand Down Expand Up @@ -1676,10 +1676,10 @@
"test_type": "Type of test done",
"tested_on": "Tested on",
"thank_you_for_choosing": "Thank you for choosing our care service",
"time": "Time",
"time_slot": "Time Slot",
"the_request_for_resources_placed_by_yourself_is": "The request for resource (details below) placed by yourself is",
"third_party_software_licenses": "Third Party Software Licenses",
"time": "Time",
"time_slot": "Time Slot",
"title_of_request": "Title of Request",
"titrate_dosage": "Titrate Dosage",
"to": "to",
Expand Down Expand Up @@ -1871,4 +1871,4 @@
"you_need_at_least_a_location_to_create_an_assest": "You need at least a location to create an assest.",
"zoom_in": "Zoom In",
"zoom_out": "Zoom Out"
}
}
4 changes: 2 additions & 2 deletions public/locale/hi.json
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@
"search_for_facility": "सुविधा खोजें",
"search_icd11_placeholder": "ICD-11 निदान खोजें",
"search_investigation_placeholder": "खोज जांच और समूह",
"search_patient": "मरीज खोजें",
"search_patients": "मरीज खोजें",
"search_resource": "संसाधन खोजें",
"select": "चुनना",
"select_date": "तारीख़ चुनें",
Expand Down Expand Up @@ -808,4 +808,4 @@
"you_need_at_least_a_location_to_create_an_assest": "संपत्ति बनाने के लिए आपको कम से कम एक स्थान की आवश्यकता होगी।",
"zoom_in": "ज़ूम इन",
"zoom_out": "ज़ूम आउट"
}
}
4 changes: 2 additions & 2 deletions public/locale/kn.json
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@
"search_for_facility": "ಸೌಲಭ್ಯಕ್ಕಾಗಿ ಹುಡುಕಿ",
"search_icd11_placeholder": "ICD-11 ರೋಗನಿರ್ಣಯಗಳಿಗಾಗಿ ಹುಡುಕಿ",
"search_investigation_placeholder": "ಹುಡುಕಾಟ ತನಿಖೆ ಮತ್ತು ಗುಂಪುಗಳು",
"search_patient": "ರೋಗಿಯನ್ನು ಹುಡುಕಿ",
"search_patients": "ರೋಗಿಯನ್ನು ಹುಡುಕಿ",
"search_resource": "ಹುಡುಕಾಟ ಸಂಪನ್ಮೂಲ",
"select": "ಆಯ್ಕೆ ಮಾಡಿ",
"select_date": "ದಿನಾಂಕವನ್ನು ಆಯ್ಕೆಮಾಡಿ",
Expand Down Expand Up @@ -809,4 +809,4 @@
"you_need_at_least_a_location_to_create_an_assest": "ಆಸ್ತಿಯನ್ನು ರಚಿಸಲು ನಿಮಗೆ ಕನಿಷ್ಠ ಸ್ಥಳದ ಅಗತ್ಯವಿದೆ.",
"zoom_in": "ಜೂಮ್ ಇನ್",
"zoom_out": "ಜೂಮ್ ಔಟ್"
}
}
4 changes: 2 additions & 2 deletions public/locale/ml.json
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@
"search_for_facility": "സൗകര്യത്തിനായി തിരയുക",
"search_icd11_placeholder": "ICD-11 രോഗനിർണയങ്ങൾക്കായി തിരയുക",
"search_investigation_placeholder": "അന്വേഷണവും ഗ്രൂപ്പുകളും",
"search_patient": "രോഗിയെ തിരയുക",
"search_patients": "രോഗിയെ തിരയുക",
"search_resource": "തിരയൽ റിസോഴ്സ്",
"select": "തിരഞ്ഞെടുക്കുക",
"select_date": "തീയതി തിരഞ്ഞെടുക്കുക",
Expand Down Expand Up @@ -809,4 +809,4 @@
"you_need_at_least_a_location_to_create_an_assest": "ഒരു അസസ്‌റ്റ് സൃഷ്‌ടിക്കാൻ നിങ്ങൾക്ക് ഒരു ലൊക്കേഷനെങ്കിലും ആവശ്യമാണ്.",
"zoom_in": "സൂം ഇൻ ചെയ്യുക",
"zoom_out": "സൂം ഔട്ട്"
}
}
4 changes: 2 additions & 2 deletions public/locale/ta.json
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@
"search_for_facility": "வசதியைத் தேடுங்கள்",
"search_icd11_placeholder": "ICD-11 நோய் கண்டறிதல்களைத் தேடவும்",
"search_investigation_placeholder": "தேடல் விசாரணை & குழுக்கள்",
"search_patient": "நோயாளியைத் தேடுங்கள்",
"search_patients": "நோயாளியைத் தேடுங்கள்",
"search_resource": "தேடல் ஆதாரம்",
"select": "தேர்ந்தெடு",
"select_date": "தேதியைத் தேர்ந்தெடுக்கவும்",
Expand Down Expand Up @@ -808,4 +808,4 @@
"you_need_at_least_a_location_to_create_an_assest": "ஒரு அசெஸ்ட்டை உருவாக்க குறைந்தபட்சம் ஒரு இருப்பிடமாவது தேவை.",
"zoom_in": "பெரிதாக்கவும்",
"zoom_out": "பெரிதாக்கவும்"
}
}
5 changes: 4 additions & 1 deletion src/components/ui/autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface AutocompleteProps {
options: AutoCompleteOption[];
value: string;
onChange: (value: string) => void;
onSearch?: (value: string) => void;
placeholder?: string;
noOptionsMessage?: string;
disabled?: boolean;
Expand All @@ -36,14 +37,15 @@ export default function Autocomplete({
options,
value,
onChange,
onSearch,
placeholder = "Select...",
noOptionsMessage = "No options found",
disabled,
}: AutocompleteProps) {
const [open, setOpen] = React.useState(false);

return (
<Popover open={open} onOpenChange={setOpen}>
<Popover open={open} onOpenChange={setOpen} modal={true}>
<PopoverTrigger asChild>
<Button
title={
Expand All @@ -70,6 +72,7 @@ export default function Autocomplete({
<CommandInput
placeholder="Search option..."
disabled={disabled}
onValueChange={onSearch}
className="outline-none border-none ring-0 shadow-none"
/>
<CommandList>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function Calendar({
...classNames,
}}
components={{
IconLeft: () => <ChevronLeftIcon className="h-4 w-4" />,
IconRight: () => <ChevronRightIcon className="h-4 w-4" />,
PreviousMonthButton: () => <ChevronLeftIcon className="h-4 w-4" />,
NextMonthButton: () => <ChevronRightIcon className="h-4 w-4" />,
}}
{...props}
/>
Expand Down
22 changes: 17 additions & 5 deletions src/components/ui/sidebar/app-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,21 @@ interface AppSidebarProps extends React.ComponentProps<typeof Sidebar> {
function generateFacilityLinks(
selectedFacility: UserFacilityModel | null,
t: TFunction,
): NavigationLink[] {
// TODO: switch to UserBase once getcurrentuser serializer is updated
user?: UserModel,
) {
if (!selectedFacility) return [];

const baseUrl = `/facility/${selectedFacility.id}`;
return [
const links: NavigationLink[] = [
{ name: t("facility"), url: baseUrl, icon: "d-hospital" },
{
name: t("appointments"),
url: `${baseUrl}/appointments`,
icon: "d-calendar",
},
{
name: t("Search Patients"),
name: t("search_patients"),
url: `${baseUrl}/patients`,
icon: "d-patient",
},
Expand All @@ -64,11 +66,21 @@ function generateFacilityLinks(
{ name: t("users"), url: `${baseUrl}/users`, icon: "d-people" },
// { name: t("All users"), url: "/users", icon: "d-people" },
{
name: t("Organization"),
name: t("organization"),
url: `${baseUrl}/organization`,
icon: "d-book-open",
},
];

if (user) {
links.push({
name: t("schedules"),
url: `${baseUrl}/users/${user.username}/availability`,
icon: "d-calendar",
});
}

return links;
}

function generateOrganizationLinks(
Expand Down Expand Up @@ -171,7 +183,7 @@ export function AppSidebar({

<SidebarContent>
{facilitySidebar && !selectedOrganization && (
<NavMain links={generateFacilityLinks(selectedFacility, t)} />
<NavMain links={generateFacilityLinks(selectedFacility, t, user)} />
)}
{selectedOrganization && (
<NavMain
Expand Down
3 changes: 3 additions & 0 deletions src/hooks/useSlug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { usePath } from "raviger";

/**
* Returns the slug from the current path.
*
* @deprecated use `usePathParams` instead
* @param prefix The prefix of the slug.
* @returns The slug.
* @example
Expand All @@ -15,6 +17,7 @@ export default function useSlug(prefix: string, fallback?: string) {

/**
* Returns the slugs from the current path.
* * @deprecated use `usePathParams` instead
* @param prefix The prefixes of the slug.
* @returns The slugs
* @example
Expand Down
9 changes: 8 additions & 1 deletion src/pages/Organization/components/OrganizationSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Autocomplete from "@/components/ui/autocomplete";
import { Button } from "@/components/ui/button";
import InputWithError from "@/components/ui/input-with-error";

import useDebouncedState from "@/hooks/useDebouncedState";

import { ORGANIZATION_LEVELS } from "@/common/constants";

import routes from "@/Utils/request/api";
Expand All @@ -32,6 +34,7 @@ interface AutoCompleteOption {
export default function OrganizationSelector(props: OrganizationSelectorProps) {
const { onChange, required } = props;
const [selectedLevels, setSelectedLevels] = useState<Organization[]>([]);
const [searchQuery, setSearchQuery] = useDebouncedState("", 500);

const headers = props.authToken
? {
Expand All @@ -42,11 +45,12 @@ export default function OrganizationSelector(props: OrganizationSelectorProps) {
: {};

const { data: getAllOrganizations } = useQuery<OrganizationResponse>({
queryKey: ["organizations-root"],
queryKey: ["organizations-root", searchQuery],
queryFn: query(routes.organization.list, {
queryParams: {
org_type: "govt",
parent: "",
name: searchQuery || undefined,
},
...headers,
}),
Expand All @@ -58,11 +62,13 @@ export default function OrganizationSelector(props: OrganizationSelectorProps) {
queryKey: [
"organizations-current",
selectedLevels[selectedLevels.length - 1]?.id,
searchQuery,
],
queryFn: query(routes.organization.list, {
queryParams: {
parent: selectedLevels[selectedLevels.length - 1]?.id,
org_type: "govt",
name: searchQuery || undefined,
},
...headers,
}),
Expand Down Expand Up @@ -153,6 +159,7 @@ export default function OrganizationSelector(props: OrganizationSelectorProps) {
onChange={(value: string) =>
handleLevelChange(value, selectedLevels.length)
}
onSearch={setSearchQuery}
/>
</InputWithError>
</div>
Expand Down

0 comments on commit f6ba679

Please sign in to comment.