From b78ec7be99a31e6e1cb0ee236beaadc8bb254f0a Mon Sep 17 00:00:00 2001 From: rjohanek Date: Mon, 18 Nov 2024 11:36:19 -0500 Subject: [PATCH 1/3] debounce the search and filter api call --- src/components/data_search/DatasetSearchTable.jsx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/data_search/DatasetSearchTable.jsx b/src/components/data_search/DatasetSearchTable.jsx index 188646a0a..a0f025191 100644 --- a/src/components/data_search/DatasetSearchTable.jsx +++ b/src/components/data_search/DatasetSearchTable.jsx @@ -3,7 +3,7 @@ import Tabs from '@mui/material/Tabs'; import useOnMount from '@mui/utils/useOnMount'; import * as React from 'react'; import { Box, Button } from '@mui/material'; -import { useEffect, useState } from 'react'; +import {useEffect, useRef, useState} from 'react'; import { isEmpty } from 'lodash'; import { TerraDataRepo } from '../../libs/ajax/TerraDataRepo'; import { DatasetSearchTableDisplay } from './DatasetSearchTableDisplay'; @@ -211,13 +211,18 @@ export const DatasetSearchTable = (props) => { getExportableDatasets(datasets); }); - useEffect(() => { - const fullQuery = assembleFullQuery(); - try { + const searchAndFilter = useRef( + _.debounce((fullQuery) => { DataSet.searchDatasetIndex(fullQuery).then((filteredDatasets) => { const newFiltered = datasets.filter(value => filteredDatasets.some(item => _.isEqual(item, value))); setFiltered(newFiltered); }); + }, 250)); + + useEffect(() => { + const fullQuery = assembleFullQuery(); + try { + searchAndFilter.current(fullQuery); } catch (error) { Notifications.showError({ text: 'Failed to load Elasticsearch index' }); } }, [filters, searchTerm]); // eslint-disable-line From 174aac23ee39d03a0a2c51d1532074650028f90a Mon Sep 17 00:00:00 2001 From: rjohanek Date: Mon, 18 Nov 2024 11:46:03 -0500 Subject: [PATCH 2/3] spacing changes --- src/components/data_search/DatasetSearchTable.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/data_search/DatasetSearchTable.jsx b/src/components/data_search/DatasetSearchTable.jsx index a0f025191..5a884956f 100644 --- a/src/components/data_search/DatasetSearchTable.jsx +++ b/src/components/data_search/DatasetSearchTable.jsx @@ -3,7 +3,7 @@ import Tabs from '@mui/material/Tabs'; import useOnMount from '@mui/utils/useOnMount'; import * as React from 'react'; import { Box, Button } from '@mui/material'; -import {useEffect, useRef, useState} from 'react'; +import { useEffect, useRef, useState } from 'react'; import { isEmpty } from 'lodash'; import { TerraDataRepo } from '../../libs/ajax/TerraDataRepo'; import { DatasetSearchTableDisplay } from './DatasetSearchTableDisplay'; From 825a5706765f5bc67bd7e085bc773dd9707c9067 Mon Sep 17 00:00:00 2001 From: rjohanek Date: Mon, 18 Nov 2024 14:20:11 -0500 Subject: [PATCH 3/3] change debounce time to 150 --- src/components/data_search/DatasetSearchTable.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/data_search/DatasetSearchTable.jsx b/src/components/data_search/DatasetSearchTable.jsx index 5a884956f..989e8dfc6 100644 --- a/src/components/data_search/DatasetSearchTable.jsx +++ b/src/components/data_search/DatasetSearchTable.jsx @@ -217,7 +217,7 @@ export const DatasetSearchTable = (props) => { const newFiltered = datasets.filter(value => filteredDatasets.some(item => _.isEqual(item, value))); setFiltered(newFiltered); }); - }, 250)); + }, 150)); useEffect(() => { const fullQuery = assembleFullQuery();