You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2021/01/09 00:03:40 UTC

[superset] branch fix-datasets-populate updated: added debouncing

This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch fix-datasets-populate
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/fix-datasets-populate by this push:
     new 69f6cd1  added debouncing
69f6cd1 is described below

commit 69f6cd14f8ad81d3fb884e9a060e1978c465e3b6
Author: hughhhh <hu...@gmail.com>
AuthorDate: Fri Jan 8 19:02:24 2021 -0500

    added debouncing
---
 .../src/SqlLab/components/ResultSet.tsx            | 29 +++++++++++++++++++---
 .../src/SqlLab/components/SaveDatasetModal.tsx     |  2 +-
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/superset-frontend/src/SqlLab/components/ResultSet.tsx b/superset-frontend/src/SqlLab/components/ResultSet.tsx
index e580a6e..ff71116 100644
--- a/superset-frontend/src/SqlLab/components/ResultSet.tsx
+++ b/superset-frontend/src/SqlLab/components/ResultSet.tsx
@@ -43,6 +43,28 @@ import { Query } from '../types';
 
 const SEARCH_HEIGHT = 46;
 
+const debounce = (
+  func: { apply: (arg0: any, arg1: IArguments) => void },
+  wait: number,
+  immediate: number,
+) => {
+  let timeout: NodeJS.Timeout | null;
+  return function () {
+    // eslint-disable-next-line @typescript-eslint/no-this-alias
+    const context = this;
+    // eslint-disable-next-line prefer-rest-params
+    const args = arguments;
+    const later = function () {
+      timeout = null;
+      if (!immediate) func.apply(context, args);
+    };
+    const callNow = immediate && !timeout;
+    clearTimeout(timeout);
+    timeout = setTimeout(later, wait);
+    if (callNow) func.apply(context, args);
+  };
+};
+
 enum DatasetRadioState {
   SAVE_NEW = 1,
   OVERWRITE_DATASET = 2,
@@ -86,7 +108,6 @@ interface ResultSetState {
   data: Record<string, any>[];
   showSaveDatasetModal: boolean;
   newSaveDatasetName: string;
-  userDatasetsOwned: DatasetOption[];
   saveDatasetRadioBtnState: number;
   shouldOverwriteDataSet: boolean;
   datasetToOverwrite: Record<string, any>;
@@ -150,8 +171,10 @@ export default class ResultSet extends React.PureComponent<
     this.handleOverwriteDatasetOption = this.handleOverwriteDatasetOption.bind(
       this,
     );
-    this.handleSaveDatasetModalSearch = this.handleSaveDatasetModalSearch.bind(
-      this,
+    this.handleSaveDatasetModalSearch = debounce(
+      this.handleSaveDatasetModalSearch.bind(this),
+      2000,
+      0,
     );
     this.handleFilterAutocompleteOption = this.handleFilterAutocompleteOption.bind(
       this,
diff --git a/superset-frontend/src/SqlLab/components/SaveDatasetModal.tsx b/superset-frontend/src/SqlLab/components/SaveDatasetModal.tsx
index 7e3cd87..e1910fa 100644
--- a/superset-frontend/src/SqlLab/components/SaveDatasetModal.tsx
+++ b/superset-frontend/src/SqlLab/components/SaveDatasetModal.tsx
@@ -30,7 +30,7 @@ interface SaveDatasetModalProps {
   onOk: () => void;
   onHide: () => void;
   handleDatasetNameChange: (e: React.FormEvent<HTMLInputElement>) => void;
-  handleSaveDatasetModalSearch: (searchText: string) => void;
+  handleSaveDatasetModalSearch: (searchText: string) => Promise<void>;
   filterAutocompleteOption: (
     inputValue: string,
     option: { value: string; datasetId: number },