1
1
import React , { useState } from 'react' ;
2
- import { Link } from 'react-router-dom' ;
3
2
import styled from 'styled-components/macro' ;
4
3
import { useGetSearchResultsForMultipleQuery } from '../../graphql/search.generated' ;
5
4
import { EntityType } from '../../types.generated' ;
6
- import { IconStyleType } from '../entity/Entity' ;
7
5
import { ANTD_GRAY } from '../entity/shared/constants' ;
8
6
import { SearchBar } from '../search/SearchBar' ;
9
7
import ClickOutside from '../shared/ClickOutside' ;
10
8
import { useEntityRegistry } from '../useEntityRegistry' ;
9
+ import GloassarySearchResultItem from './GloassarySearchResultItem' ;
11
10
12
11
const GlossarySearchWrapper = styled . div `
13
12
position: relative;
@@ -28,20 +27,10 @@ const ResultsWrapper = styled.div`
28
27
top: 45px;
29
28
` ;
30
29
31
- const SearchResult = styled ( Link ) `
32
- color: #262626;
33
- display: inline-block;
34
- height: 100%;
35
- padding: 6px 8px;
36
- width: 100%;
37
- &:hover {
38
- background-color: ${ ANTD_GRAY [ 3 ] } ;
39
- color: #262626;
40
- }
41
- ` ;
42
-
43
- const IconWrapper = styled . span `
44
- margin-right: 8px;
30
+ const TermNodeName = styled . span `
31
+ margin-top: 12px;
32
+ color: ${ ANTD_GRAY [ 8 ] } ;
33
+ font-weight: bold;
45
34
` ;
46
35
47
36
function GlossarySearch ( ) {
@@ -63,6 +52,21 @@ function GlossarySearch() {
63
52
64
53
const searchResults = data ?. searchAcrossEntities ?. searchResults ;
65
54
55
+ const renderSearchResults = ( ) => (
56
+ < ResultsWrapper >
57
+ < TermNodeName > Glossary Terms</ TermNodeName >
58
+ { searchResults ?. map ( ( result ) => (
59
+ < GloassarySearchResultItem
60
+ key = { result . entity . urn }
61
+ entity = { result . entity }
62
+ entityRegistry = { entityRegistry }
63
+ query = { query }
64
+ onResultClick = { ( ) => setIsSearchBarFocused ( false ) }
65
+ />
66
+ ) ) }
67
+ </ ResultsWrapper >
68
+ ) ;
69
+
66
70
return (
67
71
< GlossarySearchWrapper >
68
72
< ClickOutside onClickOutside = { ( ) => setIsSearchBarFocused ( false ) } >
@@ -84,23 +88,8 @@ function GlossarySearch() {
84
88
entityRegistry = { entityRegistry }
85
89
onFocus = { ( ) => setIsSearchBarFocused ( true ) }
86
90
/>
87
- { isSearchBarFocused && searchResults && ! ! searchResults . length && (
88
- < ResultsWrapper >
89
- { searchResults . map ( ( result ) => {
90
- return (
91
- < SearchResult
92
- to = { `${ entityRegistry . getEntityUrl ( result . entity . type , result . entity . urn ) } ` }
93
- onClick = { ( ) => setIsSearchBarFocused ( false ) }
94
- >
95
- < IconWrapper >
96
- { entityRegistry . getIcon ( result . entity . type , 12 , IconStyleType . ACCENT ) }
97
- </ IconWrapper >
98
- { entityRegistry . getDisplayName ( result . entity . type , result . entity ) }
99
- </ SearchResult >
100
- ) ;
101
- } ) }
102
- </ ResultsWrapper >
103
- ) }
91
+ { isSearchBarFocused && searchResults && ! ! searchResults . length && renderSearchResults ( ) }
92
+
104
93
</ ClickOutside >
105
94
</ GlossarySearchWrapper >
106
95
) ;
0 commit comments