2022-05-30 00:26:07 -04:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import styled from 'styled-components/macro';
|
|
|
|
import { useGetSearchResultsForMultipleQuery } from '../../graphql/search.generated';
|
|
|
|
import { EntityType } from '../../types.generated';
|
|
|
|
import { ANTD_GRAY } from '../entity/shared/constants';
|
|
|
|
import { SearchBar } from '../search/SearchBar';
|
|
|
|
import ClickOutside from '../shared/ClickOutside';
|
|
|
|
import { useEntityRegistry } from '../useEntityRegistry';
|
2024-01-29 15:26:14 +05:30
|
|
|
import GloassarySearchResultItem from './GloassarySearchResultItem';
|
2022-05-30 00:26:07 -04:00
|
|
|
|
|
|
|
const GlossarySearchWrapper = styled.div`
|
|
|
|
position: relative;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const ResultsWrapper = styled.div`
|
|
|
|
background-color: white;
|
|
|
|
border-radius: 5px;
|
|
|
|
box-shadow: 0 3px 6px -4px rgb(0 0 0 / 12%), 0 6px 16px 0 rgb(0 0 0 / 8%), 0 9px 28px 8px rgb(0 0 0 / 5%);
|
|
|
|
max-height: 380px;
|
|
|
|
overflow: auto;
|
|
|
|
padding: 8px;
|
|
|
|
position: absolute;
|
|
|
|
max-height: 210px;
|
|
|
|
overflow: auto;
|
|
|
|
width: calc(100% - 24px);
|
|
|
|
left: 12px;
|
|
|
|
top: 45px;
|
|
|
|
`;
|
|
|
|
|
2024-01-29 15:26:14 +05:30
|
|
|
const TermNodeName = styled.span`
|
|
|
|
margin-top: 12px;
|
|
|
|
color: ${ANTD_GRAY[8]};
|
|
|
|
font-weight: bold;
|
2022-05-30 00:26:07 -04:00
|
|
|
`;
|
|
|
|
|
|
|
|
function GlossarySearch() {
|
|
|
|
const [query, setQuery] = useState('');
|
|
|
|
const [isSearchBarFocused, setIsSearchBarFocused] = useState(false);
|
|
|
|
const entityRegistry = useEntityRegistry();
|
|
|
|
|
|
|
|
const { data } = useGetSearchResultsForMultipleQuery({
|
|
|
|
variables: {
|
|
|
|
input: {
|
|
|
|
types: [EntityType.GlossaryTerm, EntityType.GlossaryNode],
|
|
|
|
query,
|
|
|
|
start: 0,
|
|
|
|
count: 50,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
skip: !query,
|
|
|
|
});
|
|
|
|
|
|
|
|
const searchResults = data?.searchAcrossEntities?.searchResults;
|
|
|
|
|
2024-01-29 15:26:14 +05:30
|
|
|
const renderSearchResults = () => (
|
|
|
|
<ResultsWrapper>
|
|
|
|
<TermNodeName>Glossary Terms</TermNodeName>
|
|
|
|
{searchResults?.map((result) => (
|
|
|
|
<GloassarySearchResultItem
|
|
|
|
key={result.entity.urn}
|
|
|
|
entity={result.entity}
|
|
|
|
entityRegistry={entityRegistry}
|
|
|
|
query={query}
|
|
|
|
onResultClick={() => setIsSearchBarFocused(false)}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</ResultsWrapper>
|
|
|
|
);
|
|
|
|
|
2022-05-30 00:26:07 -04:00
|
|
|
return (
|
|
|
|
<GlossarySearchWrapper>
|
|
|
|
<ClickOutside onClickOutside={() => setIsSearchBarFocused(false)}>
|
|
|
|
<SearchBar
|
|
|
|
initialQuery={query || ''}
|
|
|
|
placeholderText="Search Glossary"
|
|
|
|
suggestions={[]}
|
2022-06-06 12:14:54 -04:00
|
|
|
hideRecommendations
|
2022-05-30 00:26:07 -04:00
|
|
|
style={{
|
|
|
|
padding: 12,
|
|
|
|
paddingBottom: 5,
|
|
|
|
}}
|
|
|
|
inputStyle={{
|
|
|
|
height: 30,
|
|
|
|
fontSize: 12,
|
|
|
|
}}
|
|
|
|
onSearch={() => null}
|
|
|
|
onQueryChange={(q) => setQuery(q)}
|
|
|
|
entityRegistry={entityRegistry}
|
|
|
|
onFocus={() => setIsSearchBarFocused(true)}
|
|
|
|
/>
|
2024-01-29 15:26:14 +05:30
|
|
|
{isSearchBarFocused && searchResults && !!searchResults.length && renderSearchResults()}
|
2022-05-30 00:26:07 -04:00
|
|
|
</ClickOutside>
|
|
|
|
</GlossarySearchWrapper>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default GlossarySearch;
|