Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DH-14972 Remove setSearch debounce in CommandHistoryViewportUpdater #1351

Merged
merged 1 commit into from
Jun 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions packages/console/src/command-history/CommandHistory.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { ChangeEvent, Component, ReactElement, RefObject } from 'react';
import debounce from 'lodash.debounce';
import {
ContextActions,
ItemList,
Expand Down Expand Up @@ -55,6 +56,7 @@ interface CommandHistoryState {
offset: number;
selectedRanges: Range[];
searchText: string;
debouncedSearchText: string;
}

class CommandHistory extends Component<
Expand All @@ -65,6 +67,8 @@ class CommandHistory extends Component<

static MAX_SELECTION_COUNT = 10000;

static SET_SEARCH_DEBOUNCE_MS = 150;

static menuGroups = {
send: ContextActions.groups.medium + 100,
};
Expand Down Expand Up @@ -189,10 +193,12 @@ class CommandHistory extends Component<
offset: 0,
selectedRanges: [],
searchText: '',
debouncedSearchText: '',
};
}

componentWillUnmount(): void {
this.debouncedSearchChange.cancel();
this.pending.cancel();
}

Expand Down Expand Up @@ -271,6 +277,14 @@ class CommandHistory extends Component<
.catch(log.error);
}

debouncedSearchChange = debounce((): void => {
this.setState(({ searchText }) => ({
debouncedSearchText: searchText,
// clear selected range, as old selection could be filtered from list
selectedRanges: [],
}));
}, CommandHistory.SET_SEARCH_DEBOUNCE_MS);

sendToNotebook(): void {
this.getSelectedCommandText()
.then(commandText => {
Expand Down Expand Up @@ -316,8 +330,8 @@ class CommandHistory extends Component<
}

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

handleViewportUpdate({
Expand Down Expand Up @@ -361,6 +375,7 @@ class CommandHistory extends Component<
actions,
historyActions,
searchText,
debouncedSearchText,
top,
bottom,
items,
Expand Down Expand Up @@ -404,7 +419,7 @@ class CommandHistory extends Component<
table={table}
top={top}
bottom={bottom}
search={searchText}
search={debouncedSearchText}
onUpdate={this.handleViewportUpdate}
/>
<ContextActions actions={actions} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useEffect, useMemo } from 'react';
import debounce from 'lodash.debounce';
import throttle from 'lodash.throttle';
import {
StorageTableViewport,
Expand All @@ -22,8 +21,6 @@ export type CommandHistoryViewportUpdaterProps = {
onUpdate: ViewportUpdateCallback<CommandHistoryStorageItem>;
};

const SET_SEARCH_DEBOUNCE_MS = 150;

const UPDATE_DELAY = 150;

const ROW_BUFFER_PAGES = 3;
Expand All @@ -39,14 +36,6 @@ function CommandHistoryViewportUpdater({
isReversed = false,
onUpdate,
}: CommandHistoryViewportUpdaterProps): null {
const debounceSetSearch = useMemo(
() =>
debounce((searchText?: string) => {
table.setSearch(searchText ?? '');
}, SET_SEARCH_DEBOUNCE_MS),
[table]
);

const throttledUpdateViewport = useMemo(
() =>
throttle((viewport: StorageTableViewport) => {
Expand Down Expand Up @@ -87,9 +76,9 @@ function CommandHistoryViewportUpdater({

useEffect(
function setSearchText() {
debounceSetSearch(search);
table.setSearch(search ?? '');
},
[debounceSetSearch, search]
[table, search]
);
useEffect(
function updateViewport() {
Expand Down