@@ -256,15 +256,14 @@ export class LibraryContainer extends React.Component<LibraryContainerProps, Lib
256
256
if ( ! this . generatedSections ) return ;
257
257
258
258
clearTimeout ( this . timeout ) ;
259
-
260
- let hasText = text . length > 0 ;
261
-
262
- if ( hasText ) {
263
- // Starting searching immediately after user input,
264
- // but only show change on ui after 300ms
265
- setTimeout ( function ( ) {
266
- if ( this . props . libraryController . searchLibraryItemsHandler ) {
267
- this . props . libraryController . searchLibraryItemsHandler ( text , function ( loadedTypesJsonOnSearch : any ) {
259
+
260
+ // Starting searching immediately after user input,
261
+ // but only show change on ui after 300ms
262
+ setTimeout ( function ( ) {
263
+ let hasText = text . length > 0 ;
264
+ if ( this . props . libraryController . searchLibraryItemsHandler ) {
265
+ this . props . libraryController . searchLibraryItemsHandler ( text . length === 0 ? "r" :text , function ( loadedTypesJsonOnSearch : any ) {
266
+ if ( hasText ) {
268
267
// Generate sections based on layout specification and loaded types filtered by search string
269
268
this . generatedSectionsOnSearch = LibraryUtilities . buildLibrarySectionsFromLayoutSpecs (
270
269
loadedTypesJsonOnSearch , this . layoutSpecsJson ,
@@ -273,23 +272,23 @@ export class LibraryContainer extends React.Component<LibraryContainerProps, Lib
273
272
this . updateSections ( this . generatedSectionsOnSearch ) ;
274
273
275
274
// Set all categories and groups to be expanded
275
+ //this.generatedSectionsOnSearch will contain all the search result nodes in a tree structure
276
276
LibraryUtilities . setItemStateRecursive ( this . generatedSectionsOnSearch , true , true ) ;
277
-
278
- //Due that we are using the React debouncing pattern that using the timeout we need to call the updateSearchViewDelayed() method immediately
279
- //The updateSearchViewDelayed update the Library with the Search results got from callback (search engine results)
280
- //If we don't call it here the call below will be executed firts without the results ready then will be showing wrong results.
281
- this . updateSearchViewDelayed ( text ) ;
282
-
283
- } . bind ( this ) ) ;
284
- } else {
285
- LibraryUtilities . searchItemResursive ( this . generatedSections , text ) ;
286
- }
287
- } . bind ( this ) , 300 ) ;
288
- } else {
289
- // Show change on ui immediately if search text is cleared
290
- LibraryUtilities . setItemStateRecursive ( this . generatedSections , true , false ) ;
291
- }
292
- this . updateSearchViewDelayed ( text ) ;
277
+ }
278
+ else {
279
+ // Show change on ui immediately if search text is cleared (shows Library with the default UI)
280
+ LibraryUtilities . setItemStateRecursive ( this . generatedSections , true , false ) ;
281
+ }
282
+ //The updateSearchViewDelayed updates the Library with the content of this.searchResultItems
283
+ // when using this.generatedSectionsOnSearch will set this.searchResultItems with the results from the external search engine
284
+ // when using this.generatedSections will set this.searchResultItems to empty so will show the default UI view for Library
285
+ this . updateSearchViewDelayed ( text ) ;
286
+ } . bind ( this ) ) ;
287
+ } else {
288
+ LibraryUtilities . searchItemResursive ( this . generatedSections , text ) ;
289
+ this . updateSearchViewDelayed ( text ) ;
290
+ }
291
+ } . bind ( this ) , 300 ) ;
293
292
}
294
293
295
294
updateSearchViewDelayed ( text : string ) {
0 commit comments