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

feat(ui) Debounce auto-complete in search bar #9205

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions datahub-web-react/src/app/home/HomePageHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useMemo, useState } from 'react';
import { useHistory } from 'react-router';
import { Typography, Image, Row, Button, Tag } from 'antd';
import { debounce } from 'lodash';
import styled, { useTheme } from 'styled-components/macro';
import { RightOutlined } from '@ant-design/icons';
import { ManageAccount } from '../shared/ManageAccount';
Expand All @@ -24,6 +25,7 @@ import { getAutoCompleteInputFromQuickFilter } from '../search/utils/filterUtils
import { useUserContext } from '../context/useUserContext';
import AcrylDemoBanner from './AcrylDemoBanner';
import DemoButton from '../entity/shared/components/styled/DemoButton';
import { HALF_SECOND_IN_MS } from '../entity/shared/tabs/Dataset/Queries/utils/constants';

const Background = styled.div`
width: 100%;
Expand Down Expand Up @@ -176,7 +178,7 @@ export const HomePageHeader = () => {
});
};

const onAutoComplete = (query: string) => {
const onAutoComplete = debounce((query: string) => {
if (query && query.trim() !== '') {
getAutoCompleteResultsForMultiple({
variables: {
Expand All @@ -189,7 +191,7 @@ export const HomePageHeader = () => {
},
});
}
};
}, HALF_SECOND_IN_MS);

const onClickExploreAll = () => {
analytics.event({
Expand Down
6 changes: 4 additions & 2 deletions datahub-web-react/src/app/search/SearchablePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useState } from 'react';
import { useHistory, useLocation } from 'react-router';
import { debounce } from 'lodash';
import * as QueryString from 'query-string';
import { useTheme } from 'styled-components';
import { SearchHeader } from './SearchHeader';
Expand All @@ -17,6 +18,7 @@ import { getAutoCompleteInputFromQuickFilter } from './utils/filterUtils';
import { useQuickFiltersContext } from '../../providers/QuickFiltersContext';
import { useUserContext } from '../context/useUserContext';
import { useSelectedSortOption } from './context/SearchContext';
import { HALF_SECOND_IN_MS } from '../entity/shared/tabs/Dataset/Queries/utils/constants';

const styles = {
children: {
Expand Down Expand Up @@ -93,7 +95,7 @@ export const SearchablePage = ({ onSearch, onAutoComplete, children }: Props) =>
});
};

const autoComplete = (query: string) => {
const autoComplete = debounce((query: string) => {
if (query && query.trim() !== '') {
getAutoCompleteResults({
variables: {
Expand All @@ -105,7 +107,7 @@ export const SearchablePage = ({ onSearch, onAutoComplete, children }: Props) =>
},
});
}
};
}, HALF_SECOND_IN_MS);

// Load correct autocomplete results on initial page load.
useEffect(() => {
Expand Down