@@ -66,20 +66,16 @@ export function JobSearchBar({
6666 < SearchBar
6767 filters = { filters }
6868 setFilters = { setFilters }
69- createSuggestions = { (
70- previousToken : SearchBarToken | undefined ,
71- previousEquation : SearchBarTokenEquation | undefined ,
72- equationIndex ?: number ,
73- ) =>
74- createSuggestions (
69+ createSuggestions = { ( { previousToken, previousEquation, equationIndex } ) =>
70+ createSuggestions ( {
7571 diracxUrl,
7672 accessToken,
7773 previousToken,
7874 previousEquation,
7975 columns,
8076 searchBody,
81- equationIndex ,
82- )
77+ searchBodyIndex : equationIndex ,
78+ } )
8379 }
8480 allowKeyWordSearch = { false } // Disable keyword search for job monitor
8581 plotTypeSelectorProps = { plotTypeSelectorProps }
@@ -100,20 +96,28 @@ export function JobSearchBar({
10096 * @param searchBodyIndex The index of the search body, which is used to determine the current search context (optional).
10197 * @returns A list of suggestions based on the current tokens and data.
10298 */
103- async function createSuggestions (
104- diracxUrl : string | null ,
105- accessToken : string | undefined ,
106- previousToken : SearchBarToken | undefined ,
107- previousEquation : SearchBarTokenEquation | undefined ,
99+ async function createSuggestions ( {
100+ diracxUrl,
101+ accessToken,
102+ previousToken,
103+ previousEquation,
104+ columns,
105+ searchBody,
106+ searchBodyIndex,
107+ } : {
108+ diracxUrl : string | null ;
109+ accessToken : string | undefined ;
110+ previousToken : SearchBarToken | undefined ;
111+ previousEquation : SearchBarTokenEquation | undefined ;
108112 // eslint-disable-next-line @typescript-eslint/no-explicit-any
109- columns : ColumnDef < Job , any > [ ] ,
110- searchBody : SearchBody ,
111- searchBodyIndex ?: number ,
112- ) : Promise < SearchBarSuggestions > {
113+ columns : ColumnDef < Job , any > [ ] ;
114+ searchBody ? : SearchBody ;
115+ searchBodyIndex ?: number ;
116+ } ) : Promise < SearchBarSuggestions > {
113117 let data : JobSummary [ ] = [ ] ;
114118
115119 const search = [ ...( searchBody ?. search || [ ] ) ] ;
116-
120+ /** The search body index is used to determine the current search context */
117121 const newSearchBody = {
118122 ...searchBody ,
119123 search : search . slice ( 0 , searchBodyIndex ) ,
@@ -146,15 +150,11 @@ async function createSuggestions(
146150 const type = columns . map (
147151 ( column ) => column . meta ?. type || CategoryType . STRING ,
148152 ) as CategoryType [ ] ;
149- const hideSuggestion = columns . map (
150- ( column ) => column . meta ?. isQuasiUnique || false ,
151- ) ;
152153
153154 return {
154155 items : items ,
155156 type,
156157 nature : Array ( items . length ) . fill ( SearchBarTokenNature . CATEGORY ) ,
157- hideSuggestion : hideSuggestion ,
158158 } ;
159159 }
160160
@@ -165,26 +165,35 @@ async function createSuggestions(
165165 items : [ "minute" , "hour" , "day" , "week" , "month" , "year" ] ,
166166 nature : Array ( 6 ) . fill ( SearchBarTokenNature . VALUE ) ,
167167 type : Array ( 6 ) . fill ( CategoryType . DATE ) ,
168- hideSuggestion : Array ( 6 ) . fill ( previousToken . hideSuggestion ) ,
169168 } ;
170169 }
171170
172- if ( ! previousToken . hideSuggestion ) {
171+ const hideSuggestion = columns . some (
172+ ( column ) =>
173+ column . header === previousEquation . items [ 0 ] . label &&
174+ column . meta ?. isQuasiUnique === true ,
175+ ) ;
176+
177+ if ( ! hideSuggestion ) {
173178 // Load the suggestions for the selected category
179+
180+ /**
181+ * The internal name of the category is used to fetch the job summary
182+ */
174183 const category = fromHumanReadableText (
175184 String ( previousEquation . items [ 0 ] . label ) ,
176185 columns ,
177186 ) ;
187+
178188 await fetchJobSummary ( category ) ;
179- const items = data . map (
180- ( item ) => item [ category as keyof JobSummary ] as string ,
189+ const items = data . map ( ( item ) =>
190+ String ( item [ category as keyof JobSummary ] ) ,
181191 ) ;
182192
183193 return {
184194 items : items ,
185195 nature : Array ( items . length ) . fill ( SearchBarTokenNature . VALUE ) ,
186- type : Array ( items . length ) . fill ( CategoryType . STRING ) ,
187- hideSuggestion : Array ( items . length ) . fill ( previousToken . hideSuggestion ) ,
196+ type : Array ( items . length ) . fill ( previousToken . type ) ,
188197 } ;
189198 }
190199 }
@@ -197,58 +206,41 @@ async function createSuggestions(
197206 items : items ,
198207 type : Array ( items . length ) . fill ( CategoryType . STRING ) ,
199208 nature : Array ( items . length ) . fill ( SearchBarTokenNature . OPERATOR ) ,
200- hideSuggestion : Array ( items . length ) . fill (
201- previousToken . hideSuggestion ,
202- ) ,
203209 } ;
204210 case CategoryType . NUMBER :
205211 items = Operators . getNumberOperators ( ) . map ( ( op ) => op . getDisplay ( ) ) ;
206212 return {
207213 items : items ,
208214 type : Array ( items . length ) . fill ( CategoryType . NUMBER ) ,
209215 nature : Array ( items . length ) . fill ( SearchBarTokenNature . OPERATOR ) ,
210- hideSuggestion : Array ( items . length ) . fill (
211- previousToken . hideSuggestion ,
212- ) ,
213216 } ;
214217 case CategoryType . BOOLEAN :
215218 items = Operators . getBooleanOperators ( ) . map ( ( op ) => op . getDisplay ( ) ) ;
216219 return {
217220 items : items ,
218221 type : Array ( items . length ) . fill ( CategoryType . BOOLEAN ) ,
219222 nature : Array ( items . length ) . fill ( SearchBarTokenNature . OPERATOR ) ,
220- hideSuggestion : Array ( items . length ) . fill (
221- previousToken . hideSuggestion ,
222- ) ,
223223 } ;
224224 case CategoryType . DATE :
225225 items = Operators . getDateOperators ( ) . map ( ( op ) => op . getDisplay ( ) ) ;
226226 return {
227227 items : items ,
228228 type : Array ( items . length ) . fill ( CategoryType . DATE ) ,
229229 nature : Array ( items . length ) . fill ( SearchBarTokenNature . OPERATOR ) ,
230- hideSuggestion : Array ( items . length ) . fill (
231- previousToken . hideSuggestion ,
232- ) ,
233230 } ;
234231 case CategoryType . CUSTOM :
235232 items = Operators . getDefaultOperators ( ) . map ( ( op ) => op . getDisplay ( ) ) ;
236233 return {
237234 items : items ,
238235 nature : Array ( items . length ) . fill ( SearchBarTokenNature . OPERATOR ) ,
239236 type : Array ( items . length ) . fill ( CategoryType . CUSTOM ) ,
240- hideSuggestion : Array ( items . length ) . fill (
241- previousToken . hideSuggestion ,
242- ) ,
243237 } ;
244238
245- // We don't want suggestions for the number and in case of a custom token
246239 default :
247240 return {
248241 items : [ ] ,
249242 nature : [ ] ,
250243 type : [ ] ,
251- hideSuggestion : [ ] ,
252244 } ;
253245 }
254246 }
@@ -257,6 +249,5 @@ async function createSuggestions(
257249 items : [ ] ,
258250 nature : [ ] ,
259251 type : [ ] ,
260- hideSuggestion : [ ] ,
261252 } ;
262253}
0 commit comments