@@ -3,8 +3,8 @@ import { AutoComplete, Empty } from 'antd';
3
3
import React , { useState } from 'react' ;
4
4
import styled from 'styled-components/macro' ;
5
5
import { useEntityRegistry } from '../../useEntityRegistry' ;
6
- import { useGetSearchResultsForMultipleLazyQuery } from '../../../graphql/search.generated' ;
7
- import { Entity , EntityType , SearchResult } from '../../../types.generated' ;
6
+ import { useGetAutoCompleteMultipleResultsLazyQuery } from '../../../graphql/search.generated' ;
7
+ import { Entity , EntityType } from '../../../types.generated' ;
8
8
import { Direction } from '../types' ;
9
9
import { getValidEntityTypes } from '../utils/manageLineageUtils' ;
10
10
import LineageEntityView from './LineageEntityView' ;
@@ -62,8 +62,8 @@ function getPlaceholderText(validEntityTypes: EntityType[], entityRegistry: Enti
62
62
return placeholderText ;
63
63
}
64
64
65
- export function existsInEntitiesToAdd ( result : SearchResult , entitiesAlreadyAdded : Entity [ ] ) {
66
- return ! ! entitiesAlreadyAdded . find ( ( entity ) => entity . urn === result . entity . urn ) ;
65
+ export function existsInEntitiesToAdd ( result : Entity , entitiesAlreadyAdded : Entity [ ] ) {
66
+ return ! ! entitiesAlreadyAdded . find ( ( entity ) => entity . urn === result . urn ) ;
67
67
}
68
68
69
69
interface Props {
@@ -82,33 +82,34 @@ export default function AddEntityEdge({
82
82
entityType,
83
83
} : Props ) {
84
84
const entityRegistry = useEntityRegistry ( ) ;
85
- const [ search , { data : searchData , loading } ] = useGetSearchResultsForMultipleLazyQuery ( ) ;
85
+ const [ getAutoCompleteResults , { data : autoCompleteResults , loading } ] =
86
+ useGetAutoCompleteMultipleResultsLazyQuery ( ) ;
86
87
const [ queryText , setQueryText ] = useState < string > ( '' ) ;
87
88
88
89
const validEntityTypes = getValidEntityTypes ( lineageDirection , entityType ) ;
89
90
90
91
function handleSearch ( text : string ) {
91
92
setQueryText ( text ) ;
92
93
if ( text !== '' ) {
93
- search ( {
94
+ getAutoCompleteResults ( {
94
95
variables : {
95
96
input : {
96
97
types : validEntityTypes ,
97
98
query : text ,
98
- start : 0 ,
99
- count : 15 ,
99
+ limit : 15 ,
100
100
} ,
101
101
} ,
102
102
} ) ;
103
103
}
104
104
}
105
105
106
106
function selectEntity ( urn : string ) {
107
- const selectedEntity = searchData ?. searchAcrossEntities ?. searchResults . find (
108
- ( result ) => result . entity . urn === urn ,
107
+ const resultEntities = autoCompleteResults ?. autoCompleteForMultiple ?. suggestions . flatMap (
108
+ ( suggestion ) => suggestion . entities || [ ] ,
109
109
) ;
110
+ const selectedEntity = resultEntities ?. find ( ( entity ) => entity . urn === urn ) ;
110
111
if ( selectedEntity ) {
111
- setEntitiesToAdd ( ( existingEntities ) => [ ...existingEntities , selectedEntity . entity ] ) ;
112
+ setEntitiesToAdd ( ( existingEntities ) => [ ...existingEntities , selectedEntity ] ) ;
112
113
}
113
114
}
114
115
@@ -120,9 +121,10 @@ export default function AddEntityEdge({
120
121
) ;
121
122
} ;
122
123
123
- const searchResults = searchData ?. searchAcrossEntities ?. searchResults
124
- . filter ( ( result ) => ! existsInEntitiesToAdd ( result , entitiesToAdd ) && result . entity . urn !== entityUrn )
125
- . map ( ( result ) => renderSearchResult ( result . entity ) ) ;
124
+ const searchResults = autoCompleteResults ?. autoCompleteForMultiple ?. suggestions
125
+ . flatMap ( ( suggestion ) => suggestion . entities || [ ] )
126
+ . filter ( ( entity ) => entity && ! existsInEntitiesToAdd ( entity , entitiesToAdd ) && entity . urn !== entityUrn )
127
+ . map ( ( entity ) => renderSearchResult ( entity ) ) ;
126
128
127
129
const placeholderText = getPlaceholderText ( validEntityTypes , entityRegistry ) ;
128
130
@@ -142,7 +144,7 @@ export default function AddEntityEdge({
142
144
filterOption = { false }
143
145
notFoundContent = { ( queryText . length > 3 && < Empty description = "No Assets Found" /> ) || undefined }
144
146
>
145
- { ! searchData && loading && (
147
+ { loading && (
146
148
< AutoComplete . Option value = "loading" >
147
149
< LoadingWrapper >
148
150
< LoadingOutlined />
0 commit comments