From 48287d3e5bb165f91869f6365e21c69128ce2435 Mon Sep 17 00:00:00 2001 From: Birk Johansson Date: Wed, 6 Jul 2022 23:59:16 +0200 Subject: [PATCH 1/3] fix: add debounced data-element search --- .../debounced-search-input.js | 2 +- src/data-workspace/entry-form.js | 3 +- src/data-workspace/filter-field.js | 14 +++++--- .../section-form/section-filter.js | 32 +++++++++++++++++ src/data-workspace/section-form/section.js | 34 ++++--------------- src/shared/index.js | 1 + .../use-debounce.js | 10 +++++- 7 files changed, 59 insertions(+), 37 deletions(-) create mode 100644 src/data-workspace/section-form/section-filter.js rename src/{context-selection/org-unit-selector-bar-item => shared}/use-debounce.js (59%) diff --git a/src/context-selection/org-unit-selector-bar-item/debounced-search-input.js b/src/context-selection/org-unit-selector-bar-item/debounced-search-input.js index e40e266c3..126561be4 100644 --- a/src/context-selection/org-unit-selector-bar-item/debounced-search-input.js +++ b/src/context-selection/org-unit-selector-bar-item/debounced-search-input.js @@ -2,7 +2,7 @@ import i18n from '@dhis2/d2-i18n' import { InputField } from '@dhis2/ui' import PropTypes from 'prop-types' import React, { useEffect, useState } from 'react' -import useDebounce from './use-debounce.js' +import { useDebounce } from '../../shared/index.js' export default function DebouncedSearchInput({ onChange, initialValue }) { const [value, setValue] = useState(initialValue) diff --git a/src/data-workspace/entry-form.js b/src/data-workspace/entry-form.js index 76113bdd1..feb58beda 100644 --- a/src/data-workspace/entry-form.js +++ b/src/data-workspace/entry-form.js @@ -24,8 +24,7 @@ export const EntryForm = ({ dataSet }) => { <> {formType !== FORM_TYPES.CUSTOM && ( )} diff --git a/src/data-workspace/filter-field.js b/src/data-workspace/filter-field.js index f7034ef53..e9cf4779f 100644 --- a/src/data-workspace/filter-field.js +++ b/src/data-workspace/filter-field.js @@ -2,12 +2,17 @@ import i18n from '@dhis2/d2-i18n' import { Button, InputField } from '@dhis2/ui' import classNames from 'classnames' import PropTypes from 'prop-types' -import React from 'react' +import React, { useState } from 'react' +import { useDebounceCallback } from '../shared/index.js' import { FORM_TYPES } from './constants.js' import styles from './entry-form.module.css' -export default function FilterField({ value, setFilterText, formType }) { +export default function FilterField({ onFilterChange, formType }) { + const [filterText, setFilterText] = useState('') const wrapperClasses = classNames(styles.filterWrapper, 'hide-for-print') + + useDebounceCallback(filterText, onFilterChange) + return (
setFilterText(value)} />