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

Search Page: Flickering Issue on search input field #5515

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Search Page: Flickering Issue on search input field
  • Loading branch information
Ankit-Keshari-Vituity committed Jul 28, 2022
commit db80b95c79d97e839f0b7bc4c0981d9e1eb0ade6
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