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

(fix) O3-2877: Make the drug search debounce delay value configurable #1680

Merged
merged 8 commits into from
Feb 20, 2024
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useRef, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Layer, Search } from '@carbon/react';
import { useDebounce, useLayoutType } from '@openmrs/esm-framework';
import { useConfig, useDebounce, useLayoutType } from '@openmrs/esm-framework';
import { type DrugOrderBasketItem } from '../../types';
import OrderBasketSearchResults from './order-basket-search-results.component';
import styles from './order-basket-search.scss';
Expand All @@ -14,7 +14,8 @@ export default function DrugSearch({ openOrderForm }: DrugSearchProps) {
const { t } = useTranslation();
const isTablet = useLayoutType() === 'tablet';
const [searchTerm, setSearchTerm] = useState('');
const debouncedSearchTerm = useDebounce(searchTerm);
const { debounceTime } = useConfig();
const debouncedSearchTerm = useDebounce(searchTerm, debounceTime);
denniskigen marked this conversation as resolved.
Show resolved Hide resolved
denniskigen marked this conversation as resolved.
Show resolved Hide resolved
const searchInputRef = useRef(null);

const focusAndClearSearchInput = () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/esm-patient-medications-app/src/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ export const configSchema = {
_default: 99,
_description: 'The maximum number of days for medication dispensing.',
},
debounceDelayInMs: {
_type: 'integer',
denniskigen marked this conversation as resolved.
Show resolved Hide resolved
_description:
'Number of milliseconds to delay the search operation in the drug search input by after the user starts typing. The useDebounce hook delays the search by 500ms by default',
_default: 500,
denniskigen marked this conversation as resolved.
Show resolved Hide resolved
},
};

export interface ConfigObject {
Expand All @@ -40,4 +46,5 @@ export interface ConfigObject {
drugOrderTypeUUID: string;
showPrintButton: boolean;
maxDispenseDurationInDays: number;
debounceDelayInMs: number;
}
Loading