Skip to content

Commit 2601146

Browse files
authored
fix: DH-14972 Remove setSearch debounce in CommandHistoryViewportUpdater (#1351)
There was an issue with Enterprise command history, where `applyFilters` method was called on the history table after `setViewport`, because of the `setSearch` debounce. Fixed by moving the debounce to the parent component.
1 parent b086e9c commit 2601146

2 files changed

Lines changed: 20 additions & 16 deletions

File tree

packages/console/src/command-history/CommandHistory.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { ChangeEvent, Component, ReactElement, RefObject } from 'react';
2+
import debounce from 'lodash.debounce';
23
import {
34
ContextActions,
45
ItemList,
@@ -55,6 +56,7 @@ interface CommandHistoryState {
5556
offset: number;
5657
selectedRanges: Range[];
5758
searchText: string;
59+
debouncedSearchText: string;
5860
}
5961

6062
class CommandHistory extends Component<
@@ -65,6 +67,8 @@ class CommandHistory extends Component<
6567

6668
static MAX_SELECTION_COUNT = 10000;
6769

70+
static SET_SEARCH_DEBOUNCE_MS = 150;
71+
6872
static menuGroups = {
6973
send: ContextActions.groups.medium + 100,
7074
};
@@ -189,10 +193,12 @@ class CommandHistory extends Component<
189193
offset: 0,
190194
selectedRanges: [],
191195
searchText: '',
196+
debouncedSearchText: '',
192197
};
193198
}
194199

195200
componentWillUnmount(): void {
201+
this.debouncedSearchChange.cancel();
196202
this.pending.cancel();
197203
}
198204

@@ -271,6 +277,14 @@ class CommandHistory extends Component<
271277
.catch(log.error);
272278
}
273279

280+
debouncedSearchChange = debounce((): void => {
281+
this.setState(({ searchText }) => ({
282+
debouncedSearchText: searchText,
283+
// clear selected range, as old selection could be filtered from list
284+
selectedRanges: [],
285+
}));
286+
}, CommandHistory.SET_SEARCH_DEBOUNCE_MS);
287+
274288
sendToNotebook(): void {
275289
this.getSelectedCommandText()
276290
.then(commandText => {
@@ -316,8 +330,8 @@ class CommandHistory extends Component<
316330
}
317331

318332
handleSearchChange(e: ChangeEvent<HTMLInputElement>): void {
319-
// clear selected range, as old selection could be filtered from list
320-
this.setState({ searchText: e.target.value, selectedRanges: [] });
333+
this.setState({ searchText: e.target.value });
334+
this.debouncedSearchChange();
321335
}
322336

323337
handleViewportUpdate({
@@ -361,6 +375,7 @@ class CommandHistory extends Component<
361375
actions,
362376
historyActions,
363377
searchText,
378+
debouncedSearchText,
364379
top,
365380
bottom,
366381
items,
@@ -404,7 +419,7 @@ class CommandHistory extends Component<
404419
table={table}
405420
top={top}
406421
bottom={bottom}
407-
search={searchText}
422+
search={debouncedSearchText}
408423
onUpdate={this.handleViewportUpdate}
409424
/>
410425
<ContextActions actions={actions} />

packages/console/src/command-history/CommandHistoryViewportUpdater.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { useEffect, useMemo } from 'react';
2-
import debounce from 'lodash.debounce';
32
import throttle from 'lodash.throttle';
43
import {
54
StorageTableViewport,
@@ -22,8 +21,6 @@ export type CommandHistoryViewportUpdaterProps = {
2221
onUpdate: ViewportUpdateCallback<CommandHistoryStorageItem>;
2322
};
2423

25-
const SET_SEARCH_DEBOUNCE_MS = 150;
26-
2724
const UPDATE_DELAY = 150;
2825

2926
const ROW_BUFFER_PAGES = 3;
@@ -39,14 +36,6 @@ function CommandHistoryViewportUpdater({
3936
isReversed = false,
4037
onUpdate,
4138
}: CommandHistoryViewportUpdaterProps): null {
42-
const debounceSetSearch = useMemo(
43-
() =>
44-
debounce((searchText?: string) => {
45-
table.setSearch(searchText ?? '');
46-
}, SET_SEARCH_DEBOUNCE_MS),
47-
[table]
48-
);
49-
5039
const throttledUpdateViewport = useMemo(
5140
() =>
5241
throttle((viewport: StorageTableViewport) => {
@@ -87,9 +76,9 @@ function CommandHistoryViewportUpdater({
8776

8877
useEffect(
8978
function setSearchText() {
90-
debounceSetSearch(search);
79+
table.setSearch(search ?? '');
9180
},
92-
[debounceSetSearch, search]
81+
[table, search]
9382
);
9483
useEffect(
9584
function updateViewport() {

0 commit comments

Comments
 (0)