Skip to content

Commit

Permalink
fix(ui): Flickering Issue on search input field (datahub-project#5515)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankit-Keshari-Vituity authored and maggiehays committed Aug 1, 2022
1 parent c1c0f37 commit 56a797f
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions datahub-web-react/src/app/search/SearchablePage.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React, { useEffect } from 'react';
import React, { useEffect, useState } from 'react';
import { useHistory, useLocation } from 'react-router';
import * as QueryString from 'query-string';
import { useTheme } from 'styled-components';
import { SearchHeader } from './SearchHeader';
import { useEntityRegistry } from '../useEntityRegistry';
import { EntityType } from '../../types.generated';
import { useGetAutoCompleteMultipleResultsLazyQuery } from '../../graphql/search.generated';
import {
GetAutoCompleteMultipleResultsQuery,
useGetAutoCompleteMultipleResultsLazyQuery,
} from '../../graphql/search.generated';
import { navigateToSearchUrl } from './utils/navigateToSearchUrl';
import { useGetAuthenticatedUser } from '../useGetAuthenticatedUser';
import analytics, { EventType } from '../analytics';
Expand Down Expand Up @@ -44,6 +47,13 @@ export const SearchablePage = ({ onSearch, onAutoComplete, children }: Props) =>

const [getAutoCompleteResults, { data: suggestionsData }] = useGetAutoCompleteMultipleResultsLazyQuery();
const user = useGetAuthenticatedUser()?.corpUser;
const [newSuggestionData, setNewSuggestionData] = useState<GetAutoCompleteMultipleResultsQuery | undefined>();

useEffect(() => {
if (suggestionsData !== undefined) {
setNewSuggestionData(suggestionsData);
}
}, [suggestionsData]);

const search = (query: string, type?: EntityType) => {
if (!query || query.trim().length === 0) {
Expand Down Expand Up @@ -94,9 +104,9 @@ export const SearchablePage = ({ onSearch, onAutoComplete, children }: Props) =>
initialQuery={currentQuery as string}
placeholderText={themeConfig.content.search.searchbarMessage}
suggestions={
(suggestionsData &&
suggestionsData?.autoCompleteForMultiple &&
suggestionsData.autoCompleteForMultiple.suggestions) ||
(newSuggestionData &&
newSuggestionData?.autoCompleteForMultiple &&
newSuggestionData.autoCompleteForMultiple.suggestions) ||
[]
}
onSearch={onSearch || search}
Expand Down

0 comments on commit 56a797f

Please sign in to comment.