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,10 +1,11 @@
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';
import { type ConfigObject } from '../../config-schema';

export interface DrugSearchProps {
openOrderForm: (searchResult: DrugOrderBasketItem) => void;
Expand All @@ -14,7 +15,8 @@ export default function DrugSearch({ openOrderForm }: DrugSearchProps) {
const { t } = useTranslation();
const isTablet = useLayoutType() === 'tablet';
const [searchTerm, setSearchTerm] = useState('');
const debouncedSearchTerm = useDebounce(searchTerm);
const { debounceDelayInMs } = useConfig<ConfigObject>();
const debouncedSearchTerm = useDebounce(searchTerm, debounceDelayInMs ?? 300);
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: Type.Number,
_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 300ms by default',
_default: 300,
},
};

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