From 29cba2b00cc4a68bf89740e34e3b107384616380 Mon Sep 17 00:00:00 2001 From: smileydev <47900232+prosdev0107@users.noreply.github.com> Date: Mon, 21 Mar 2022 17:51:10 -0400 Subject: [PATCH] fix(dashboard): make to show the correct owned objects (#19223) * fix(dashboard): make to show the correct owned objects * fix(dashboard): make to filter is reusable * fix(homepage): make sure the type Array --- superset-frontend/src/views/CRUD/utils.tsx | 23 ++++++++----------- .../src/views/CRUD/welcome/ChartTable.tsx | 4 ++-- .../src/views/CRUD/welcome/DashboardTable.tsx | 4 ++-- .../src/views/CRUD/welcome/Welcome.tsx | 10 ++++++-- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/superset-frontend/src/views/CRUD/utils.tsx b/superset-frontend/src/views/CRUD/utils.tsx index c6c5282738..6606fd459f 100644 --- a/superset-frontend/src/views/CRUD/utils.tsx +++ b/superset-frontend/src/views/CRUD/utils.tsx @@ -164,20 +164,17 @@ export const getEditedObjects = (userId: string | number) => { export const getUserOwnedObjects = ( userId: string | number, resource: string, -) => { - const filters = { - created: [ - { - col: 'created_by', - opr: 'rel_o_m', - value: `${userId}`, - }, - ], - }; - return SupersetClient.get({ - endpoint: `/api/v1/${resource}/?q=${getParams(filters.created)}`, + filters: Array = [ + { + col: 'created_by', + opr: 'rel_o_m', + value: `${userId}`, + }, + ], +) => + SupersetClient.get({ + endpoint: `/api/v1/${resource}/?q=${getParams(filters)}`, }).then(res => res.json?.result); -}; export const getRecentAcitivtyObjs = ( userId: string | number, diff --git a/superset-frontend/src/views/CRUD/welcome/ChartTable.tsx b/superset-frontend/src/views/CRUD/welcome/ChartTable.tsx index cd42ae6210..a035045318 100644 --- a/superset-frontend/src/views/CRUD/welcome/ChartTable.tsx +++ b/superset-frontend/src/views/CRUD/welcome/ChartTable.tsx @@ -126,8 +126,8 @@ function ChartTable({ if (filterName === 'Mine') { filters.push({ - id: 'created_by', - operator: 'rel_o_m', + id: 'owners', + operator: 'rel_m_m', value: `${user?.userId}`, }); } else if (filterName === 'Favorite') { diff --git a/superset-frontend/src/views/CRUD/welcome/DashboardTable.tsx b/superset-frontend/src/views/CRUD/welcome/DashboardTable.tsx index e6539b2ad7..4078e23c2d 100644 --- a/superset-frontend/src/views/CRUD/welcome/DashboardTable.tsx +++ b/superset-frontend/src/views/CRUD/welcome/DashboardTable.tsx @@ -136,8 +136,8 @@ function DashboardTable({ const filters = []; if (filterName === 'Mine') { filters.push({ - id: 'created_by', - operator: 'rel_o_m', + id: 'owners', + operator: 'rel_m_m', value: `${user?.userId}`, }); } else if (filterName === 'Favorite') { diff --git a/superset-frontend/src/views/CRUD/welcome/Welcome.tsx b/superset-frontend/src/views/CRUD/welcome/Welcome.tsx index 28ad652965..bf4675f583 100644 --- a/superset-frontend/src/views/CRUD/welcome/Welcome.tsx +++ b/superset-frontend/src/views/CRUD/welcome/Welcome.tsx @@ -202,7 +202,13 @@ function Welcome({ user, addDangerToast }: WelcomeProps) { ); // Sets other activity data in parallel with recents api call - + const ownSavedQueryFilters = [ + { + col: 'owners', + opr: 'rel_m_m', + value: `${id}`, + }, + ]; getUserOwnedObjects(id, 'dashboard') .then(r => { setDashboardData(r); @@ -225,7 +231,7 @@ function Welcome({ user, addDangerToast }: WelcomeProps) { setLoadedCount(loadedCount => loadedCount + 1); addDangerToast(t('There was an issues fetching your chart: %s', err)); }); - getUserOwnedObjects(id, 'saved_query') + getUserOwnedObjects(id, 'saved_query', ownSavedQueryFilters) .then(r => { setQueryData(r); setLoadedCount(loadedCount => loadedCount + 1);