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

vavila pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 4e861cf86e chore(utils): Support select_columns with 
getUserOwnedObjects and split recentActivityObjs (#29459)
4e861cf86e is described below

commit 4e861cf86e2a9ac92f79d2720fe5c22f34449d20
Author: Vitor Avila <[email protected]>
AuthorDate: Thu Jul 4 13:03:13 2024 -0300

    chore(utils): Support select_columns with getUserOwnedObjects and split 
recentActivityObjs (#29459)
---
 superset-frontend/src/views/CRUD/utils.tsx | 60 ++++++++++++++++++++----------
 1 file changed, 40 insertions(+), 20 deletions(-)

diff --git a/superset-frontend/src/views/CRUD/utils.tsx 
b/superset-frontend/src/views/CRUD/utils.tsx
index 22e312d910..7b9274a904 100644
--- a/superset-frontend/src/views/CRUD/utils.tsx
+++ b/superset-frontend/src/views/CRUD/utils.tsx
@@ -126,15 +126,17 @@ const createFetchResourceMethod =
   };
 
 export const PAGE_SIZE = 5;
-const getParams = (filters?: Filter[]) => {
+const getParams = (filters?: Filter[], selectColumns?: string[]) => {
   const params = {
     order_column: 'changed_on_delta_humanized',
     order_direction: 'desc',
     page: 0,
     page_size: PAGE_SIZE,
     filters,
+    select_columns: selectColumns,
   };
   if (!filters) delete params.filters;
+  if (!selectColumns) delete params.select_columns;
   return rison.encode(params);
 };
 
@@ -177,11 +179,42 @@ export const getUserOwnedObjects = (
       value: `${userId}`,
     },
   ],
+  selectColumns?: string[],
 ) =>
   SupersetClient.get({
-    endpoint: `/api/v1/${resource}/?q=${getParams(filters)}`,
+    endpoint: `/api/v1/${resource}/?q=${getParams(filters, selectColumns)}`,
   }).then(res => res.json?.result);
 
+export const getFilteredChartsandDashboards = (
+  addDangerToast: (arg1: string, arg2: any) => any,
+  filters: Filter[],
+  dashboardSelectColumns?: string[],
+  chartSelectColumns?: string[],
+) => {
+  const newBatch = [
+    SupersetClient.get({
+      endpoint: `/api/v1/chart/?q=${getParams(filters, chartSelectColumns)}`,
+    }),
+    SupersetClient.get({
+      endpoint: `/api/v1/dashboard/?q=${getParams(
+        filters,
+        dashboardSelectColumns,
+      )}`,
+    }),
+  ];
+  return Promise.all(newBatch)
+    .then(([chartRes, dashboardRes]) => ({
+      other: [...chartRes.json.result, ...dashboardRes.json.result],
+    }))
+    .catch(errMsg => {
+      addDangerToast(
+        t('There was an error fetching the filtered charts and dashboards:'),
+        errMsg,
+      );
+      return { other: [] };
+    });
+};
+
 export const getRecentActivityObjs = (
   userId: string | number,
   recent: string,
@@ -190,26 +223,13 @@ export const getRecentActivityObjs = (
 ) =>
   SupersetClient.get({ endpoint: recent }).then(recentsRes => {
     const res: any = {};
-    const newBatch = [
-      SupersetClient.get({
-        endpoint: `/api/v1/chart/?q=${getParams(filters)}`,
-      }),
-      SupersetClient.get({
-        endpoint: `/api/v1/dashboard/?q=${getParams(filters)}`,
-      }),
-    ];
-    return Promise.all(newBatch)
-      .then(([chartRes, dashboardRes]) => {
-        res.other = [...chartRes.json.result, ...dashboardRes.json.result];
+    return getFilteredChartsandDashboards(addDangerToast, filters).then(
+      ({ other }) => {
+        res.other = other;
         res.viewed = recentsRes.json.result;
         return res;
-      })
-      .catch(errMsg =>
-        addDangerToast(
-          t('There was an error fetching your recent activity:'),
-          errMsg,
-        ),
-      );
+      },
+    );
   });
 
 export const createFetchRelated = createFetchResourceMethod('related');

Reply via email to