Skip to content

Commit e6a681a

Browse files
DYN-6739 Regression Typing Fast in Search (#224)
* DYN-6739 Regression Typing Fast in Search When typing fast in the TextSearch box was getting wrong results or the results were not in the same order than Dynamo InCanvasSearch, It was happening due that we are implementing the React Debounce pattern (this patters allows the user to continue typing while we are searching ) but we were missing to update the results immediately after getting the results so I added a call to this.updateSearchViewDelayed() method immediately after getting the results. * 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). * DYN-6739 Regression Typing Fast in Search Updating comments so my changes will be more clear
1 parent 2028438 commit e6a681a

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

src/components/LibraryContainer.tsx

+24-19
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,15 @@ 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+
//searchLibraryItemsHandler is the callback that needs to be set when creating the library
266+
this.props.libraryController.searchLibraryItemsHandler(text.length === 0? "r":text, function (loadedTypesJsonOnSearch: any) {
267+
if (hasText) {
268268
// Generate sections based on layout specification and loaded types filtered by search string
269269
this.generatedSectionsOnSearch = LibraryUtilities.buildLibrarySectionsFromLayoutSpecs(
270270
loadedTypesJsonOnSearch, this.layoutSpecsJson,
@@ -273,17 +273,22 @@ export class LibraryContainer extends React.Component<LibraryContainerProps, Lib
273273
this.updateSections(this.generatedSectionsOnSearch);
274274

275275
// Set all categories and groups to be expanded
276+
//this.generatedSectionsOnSearch will contain all the search result nodes in a tree structure
276277
LibraryUtilities.setItemStateRecursive(this.generatedSectionsOnSearch, true, true);
277-
}.bind(this));
278-
} else {
279-
LibraryUtilities.searchItemResursive(this.generatedSections, text);
280-
}
281-
}.bind(this), 300);
282-
} else {
283-
// Show change on ui immediately if search text is cleared
284-
LibraryUtilities.setItemStateRecursive(this.generatedSections, true, false);
285-
}
286-
this.updateSearchViewDelayed(text);
278+
}
279+
else {
280+
// Show change on ui immediately if search text is cleared (shows Library with the default UI)
281+
LibraryUtilities.setItemStateRecursive(this.generatedSections, true, false);
282+
}
283+
//The updateSearchViewDelayed() method updates the Library with the search results
284+
//Needs to be done inside the callback because the callback is executed in a async way otherwise we don't have control when this method will be executed
285+
this.updateSearchViewDelayed(text);
286+
}.bind(this));
287+
} else {
288+
LibraryUtilities.searchItemResursive(this.generatedSections, text);
289+
this.updateSearchViewDelayed(text);
290+
}
291+
}.bind(this), 300);
287292
}
288293

289294
updateSearchViewDelayed(text: string) {

0 commit comments

Comments
 (0)