Skip to content

Commit

Permalink
Fix multi-select dropdown for facilities in user creation module (#8086)
Browse files Browse the repository at this point in the history
* Fix multi-select dropdown for facilities in user creation module

* if NOptions is undefined then all the facilities will be shown.If not then that particular number will be shown.

* Apply suggestions from code review

---------

Co-authored-by: Mohammed Nihal <[email protected]>
Co-authored-by: Rithvik Nishad <[email protected]>
  • Loading branch information
3 people authored Jul 9, 2024
1 parent a76b958 commit 0f5b54c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/Components/Common/FacilitySelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface FacilitySelectProps {
district?: string;
state?: string;
showAll?: boolean;
showNOptions?: number;
showNOptions?: number | undefined;
freeText?: boolean;
selected?: FacilityModel | FacilityModel[] | null;
setSelected: (selected: FacilityModel | FacilityModel[] | null) => void;
Expand All @@ -34,7 +34,7 @@ export const FacilitySelect = (props: FacilitySelectProps) => {
searchAll,
disabled = false,
showAll = true,
showNOptions = 10,
showNOptions,
className = "",
facilityType,
district,
Expand Down Expand Up @@ -65,6 +65,7 @@ export const FacilitySelect = (props: FacilitySelectProps) => {
data?.results?.push({
name: text,
});

return data?.results;
},
[searchAll, showAll, facilityType, district, exclude_user, freeText],
Expand Down
14 changes: 9 additions & 5 deletions src/Components/Form/AutoCompleteAsync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ interface Props {
onChange: (selected: any) => void;
optionLabel?: (option: any) => string;
optionLabelChip?: (option: any) => string;
showNOptions?: number;
showNOptions?: number | undefined;
multiple?: boolean;
compareBy?: string;
debounceTime?: number;
Expand All @@ -40,7 +40,7 @@ const AutoCompleteAsync = (props: Props) => {
onChange,
optionLabel = (option: any) => option.label,
optionLabelChip = (option: any) => option.label,
showNOptions = 10,
showNOptions,
multiple = false,
compareBy,
debounceTime = 300,
Expand All @@ -62,8 +62,13 @@ const AutoCompleteAsync = (props: Props) => {
() =>
debounce(async (query: string) => {
setLoading(true);
const data = await fetchData(query);
setData(data?.slice(0, showNOptions) || []);
const data = (await fetchData(query)) || [];

if (showNOptions !== undefined) {
setData(data.slice(0, showNOptions));
} else {
setData(data);
}
setLoading(false);
}, debounceTime),
[fetchData, showNOptions, debounceTime],
Expand Down Expand Up @@ -102,7 +107,6 @@ const AutoCompleteAsync = (props: Props) => {
onChange={({ target }) => setQuery(target.value)}
onFocus={props.onFocus}
onBlur={() => {
setQuery("");
props.onBlur?.();
}}
autoComplete="off"
Expand Down

0 comments on commit 0f5b54c

Please sign in to comment.