Skip to content

Commit 6637771

Browse files
DYN-6739 Regression Typing Fast in Search
I had to update the onTextChanged() method due that when deleting quickly the text typed inside the SearchTextBox was showing the library with search results (event when the textbox is empty). So I have to reorganize all the code in the onTextChanged() method so that most of the code will be inside the timeout (otherwise there is no way to control the code async execution).
1 parent 20d3b73 commit 6637771

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

src/components/LibraryContainer.tsx

+24-25
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,14 @@ export class LibraryContainer extends React.Component<LibraryContainerProps, Lib
256256
if (!this.generatedSections) return;
257257

258258
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) {
268267
// Generate sections based on layout specification and loaded types filtered by search string
269268
this.generatedSectionsOnSearch = LibraryUtilities.buildLibrarySectionsFromLayoutSpecs(
270269
loadedTypesJsonOnSearch, this.layoutSpecsJson,
@@ -273,23 +272,23 @@ export class LibraryContainer extends React.Component<LibraryContainerProps, Lib
273272
this.updateSections(this.generatedSectionsOnSearch);
274273

275274
// Set all categories and groups to be expanded
275+
//this.generatedSectionsOnSearch will contain all the search result nodes in a tree structure
276276
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);
293292
}
294293

295294
updateSearchViewDelayed(text: string) {

0 commit comments

Comments
 (0)