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

Adds prompt for ICD11 search field #8232 #8233

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export default function AddICD11Diagnosis(props: AddICD11DiagnosisProps) {
)}
optionLabel={(option) => option.label}
optionValue={(option) => option}
minQueryLength={2}
onQuery={(query) => refetch({ query: { query } })}
isLoading={loading}
error={hasError ? t("diagnosis_already_added") : undefined}
Expand Down
76 changes: 43 additions & 33 deletions src/Components/Form/FormFields/Autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type AutocompleteFormFieldProps<T, V> = FormFieldBaseProps<V> & {
optionDescription?: OptionCallback<T, string>;
optionIcon?: OptionCallback<T, React.ReactNode>;
optionDisabled?: OptionCallback<T, boolean>;
minQueryLength?: number;
onQuery?: (query: string) => void;
dropdownIcon?: React.ReactNode | undefined;
isLoading?: boolean;
Expand Down Expand Up @@ -45,6 +46,7 @@ const AutocompleteFormField = <T, V>(
optionValue={props.optionValue}
optionDescription={props.optionDescription}
optionDisabled={props.optionDisabled}
minQueryLength={props.minQueryLength}
onQuery={props.onQuery}
isLoading={props.isLoading}
allowRawInput={props.allowRawInput}
Expand All @@ -69,6 +71,7 @@ type AutocompleteProps<T, V = T> = {
optionDescription?: OptionCallback<T, React.ReactNode>;
optionDisabled?: OptionCallback<T, boolean>;
className?: string;
minQueryLength?: number;
onQuery?: (query: string) => void;
requiredError?: boolean;
isLoading?: boolean;
Expand All @@ -95,6 +98,7 @@ type AutocompleteProps<T, V = T> = {
export const Autocomplete = <T, V>(props: AutocompleteProps<T, V>) => {
const { t } = useTranslation();
const [query, setQuery] = useState(""); // Ensure lower case

useEffect(() => {
props.onQuery?.(query);
}, [query]);
Expand Down Expand Up @@ -136,6 +140,7 @@ export const Autocomplete = <T, V>(props: AutocompleteProps<T, V>) => {
const options = props.allowRawInput ? getOptions() : mappedOptions;

const value = options.find((o) => props.value == o.value);

const filteredOptions =
props.onQuery === undefined
? options.filter((o) => o.search.includes(query))
Expand Down Expand Up @@ -198,43 +203,48 @@ export const Autocomplete = <T, V>(props: AutocompleteProps<T, V>) => {

<DropdownTransition>
<Combobox.Options className="cui-dropdown-base absolute z-10 mt-0.5 origin-top-right">
{filteredOptions.length === 0 && (
{props.minQueryLength && query.length < props.minQueryLength ? (
<div className="p-2 text-sm text-secondary-500">
{`Please enter at least ${props.minQueryLength} characters to search`}
</div>
) : filteredOptions.length === 0 ? (
<div className="p-2 text-sm text-secondary-500">
No options found
</div>
)}
{filteredOptions.map((option, index) => (
<Combobox.Option
id={`${props.id}-option-${option.label}-value-${index}`}
key={`${props.id}-option-${option.label}-value-${index}`}
className={dropdownOptionClassNames}
value={option}
disabled={option.disabled}
>
{({ active }) => (
<div className="flex flex-col">
<div className="flex justify-between">
<span>{option.label}</span>
<span>{option.icon}</span>
</div>
{option.description && (
<div
className={classNames(
"text-sm font-normal",
option.disabled
? "text-secondary-700"
: active
? "text-primary-200"
: "text-secondary-700",
)}
>
{option.description}
) : (
filteredOptions.map((option, index) => (
<Combobox.Option
id={`${props.id}-option-${option.label}-value-${index}`}
key={`${props.id}-option-${option.label}-value-${index}`}
className={dropdownOptionClassNames}
value={option}
disabled={option.disabled}
>
{({ active }) => (
<div className="flex flex-col">
<div className="flex justify-between">
<span>{option.label}</span>
<span>{option.icon}</span>
</div>
)}
</div>
)}
</Combobox.Option>
))}
{option.description && (
<div
className={classNames(
"text-sm font-normal",
option.disabled
? "text-secondary-700"
: active
? "text-primary-200"
: "text-secondary-700",
)}
>
{option.description}
</div>
)}
</div>
)}
</Combobox.Option>
))
)}
</Combobox.Options>
</DropdownTransition>
</div>
Expand Down
Loading