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/08 22:55:13 UTC

[superset] branch fix-datasets-populate created (now cc06f59)

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

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


      at cc06f59  fix datasets reloading

This branch includes the following new commits:

     new cc06f59  fix datasets reloading

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[superset] 01/01: fix datasets reloading

Posted by hu...@apache.org.
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

commit cc06f59ac82d7817e692bb114ccc748fda87a2e0
Author: hughhhh <hu...@gmail.com>
AuthorDate: Fri Jan 8 17:54:26 2021 -0500

    fix datasets reloading
---
 .../src/SqlLab/components/ResultSet.tsx            | 71 +++++++++++++---------
 1 file changed, 41 insertions(+), 30 deletions(-)

diff --git a/superset-frontend/src/SqlLab/components/ResultSet.tsx b/superset-frontend/src/SqlLab/components/ResultSet.tsx
index 9b60c4d..e580a6e 100644
--- a/superset-frontend/src/SqlLab/components/ResultSet.tsx
+++ b/superset-frontend/src/SqlLab/components/ResultSet.tsx
@@ -23,7 +23,8 @@ import moment from 'moment';
 import { RadioChangeEvent } from 'antd/lib/radio';
 import Button from 'src/components/Button';
 import shortid from 'shortid';
-import { styled, t } from '@superset-ui/core';
+import rison from 'rison';
+import { styled, t, makeApi } from '@superset-ui/core';
 
 import ErrorMessageWithStackTrace from 'src/components/ErrorMessage/ErrorMessageWithStackTrace';
 import { SaveDatasetModal } from 'src/SqlLab/components/SaveDatasetModal';
@@ -124,7 +125,6 @@ export default class ResultSet extends React.PureComponent<
       data: [],
       showSaveDatasetModal: false,
       newSaveDatasetName: this.getDefaultDatasetName(),
-      userDatasetsOwned: [],
       saveDatasetRadioBtnState: DatasetRadioState.SAVE_NEW,
       shouldOverwriteDataSet: false,
       datasetToOverwrite: {},
@@ -162,26 +162,9 @@ export default class ResultSet extends React.PureComponent<
     this.handleExploreBtnClick = this.handleExploreBtnClick.bind(this);
   }
 
-  async componentDidMount() {
+  componentDidMount() {
     // only do this the first time the component is rendered/mounted
     this.reRunQueryIfSessionTimeoutErrorOnMount();
-
-    const appContainer = document.getElementById('app');
-    const bootstrapData = JSON.parse(
-      appContainer?.getAttribute('data-bootstrap') || '{}',
-    );
-
-    if (bootstrapData.user && bootstrapData.user.userId) {
-      const datasets = await getByUser(bootstrapData.user.userId);
-      const userDatasetsOwned = datasets.map(
-        (r: { table_name: string; id: number }) => ({
-          datasetName: r.table_name,
-          datasetId: r.id,
-        }),
-      );
-
-      this.setState({ userDatasetsOwned });
-    }
   }
 
   UNSAFE_componentWillReceiveProps(nextProps: ResultSetProps) {
@@ -317,18 +300,46 @@ export default class ResultSet extends React.PureComponent<
     });
   };
 
-  handleSaveDatasetModalSearch = (searchText: string) => {
+  handleSaveDatasetModalSearch = async (searchText: string) => {
     // Making sure that autocomplete input has a value before rendering the dropdown
     // Transforming the userDatasetsOwned data for SaveModalComponent)
-    const { userDatasetsOwned } = this.state;
-    const userDatasets = !searchText
-      ? []
-      : userDatasetsOwned.map(d => ({
-          value: d.datasetName,
-          datasetId: d.datasetId,
-        }));
-
-    this.setState({ userDatasetOptions: userDatasets });
+    const appContainer = document.getElementById('app');
+    const bootstrapData = JSON.parse(
+      appContainer?.getAttribute('data-bootstrap') || '{}',
+    );
+
+    if (bootstrapData.user && bootstrapData.user.userId) {
+      const queryParams = rison.encode({
+        filters: [
+          {
+            col: 'table_name',
+            opr: 'ct',
+            value: searchText,
+          },
+          {
+            col: 'owners',
+            opr: 'rel_m_m',
+            value: bootstrapData.user.userId,
+          },
+        ],
+        order_column: 'changed_on_delta_humanized',
+        order_direction: 'desc',
+      });
+
+      const response = await makeApi({
+        method: 'GET',
+        endpoint: '/api/v1/dataset',
+      })(`q=${queryParams}`);
+
+      const userDatasetsOwned = response.result.map(
+        (r: { table_name: string; id: number }) => ({
+          value: r.table_name,
+          datasetId: r.id,
+        }),
+      );
+
+      this.setState({ userDatasetOptions: userDatasetsOwned });
+    }
   };
 
   handleFilterAutocompleteOption = (