From 033118ff2f667c23b92714837b36eeb655e413ed Mon Sep 17 00:00:00 2001 From: Talyor Chen Date: Wed, 16 Mar 2022 14:40:59 -0400 Subject: [PATCH 1/4] fix(dashboard): make to show the correct owned objects --- superset-frontend/src/views/CRUD/utils.tsx | 4 ++-- superset-frontend/src/views/CRUD/welcome/ChartTable.tsx | 4 ++-- superset-frontend/src/views/CRUD/welcome/DashboardTable.tsx | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/superset-frontend/src/views/CRUD/utils.tsx b/superset-frontend/src/views/CRUD/utils.tsx index d9d21c8565d17..66ea6b86457f6 100644 --- a/superset-frontend/src/views/CRUD/utils.tsx +++ b/superset-frontend/src/views/CRUD/utils.tsx @@ -167,8 +167,8 @@ export const getUserOwnedObjects = ( const filters = { created: [ { - col: 'created_by', - opr: 'rel_o_m', + col: resource === 'saved_query' ? 'created_by' : 'owners', + opr: resource === 'saved_query' ? 'rel_o_m' : 'rel_m_m', value: `${userId}`, }, ], diff --git a/superset-frontend/src/views/CRUD/welcome/ChartTable.tsx b/superset-frontend/src/views/CRUD/welcome/ChartTable.tsx index cd42ae6210791..a035045318a21 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 e6539b2ad71be..4078e23c2dec8 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') { From 2bd467077a355ed804c8e5007f5f3f76efc1275a Mon Sep 17 00:00:00 2001 From: Talyor Chen Date: Thu, 17 Mar 2022 05:52:30 -0400 Subject: [PATCH 2/4] fix(dashboard): make to filter is reusable --- superset-frontend/src/views/CRUD/utils.tsx | 23 ++++++++----------- .../src/views/CRUD/welcome/Welcome.tsx | 10 ++++++-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/superset-frontend/src/views/CRUD/utils.tsx b/superset-frontend/src/views/CRUD/utils.tsx index 66ea6b86457f6..c67d2f609f1ae 100644 --- a/superset-frontend/src/views/CRUD/utils.tsx +++ b/superset-frontend/src/views/CRUD/utils.tsx @@ -163,20 +163,17 @@ export const getEditedObjects = (userId: string | number) => { export const getUserOwnedObjects = ( userId: string | number, resource: string, -) => { - const filters = { - created: [ - { - col: resource === 'saved_query' ? 'created_by' : 'owners', - opr: resource === 'saved_query' ? 'rel_o_m' : 'rel_m_m', - value: `${userId}`, - }, - ], - }; - return SupersetClient.get({ - endpoint: `/api/v1/${resource}/?q=${getParams(filters.created)}`, + filters = [ + { + 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/Welcome.tsx b/superset-frontend/src/views/CRUD/welcome/Welcome.tsx index eb9fd6eadb1d3..903dcd909cec4 100644 --- a/superset-frontend/src/views/CRUD/welcome/Welcome.tsx +++ b/superset-frontend/src/views/CRUD/welcome/Welcome.tsx @@ -197,7 +197,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); @@ -220,7 +226,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); From 9760c3a3cd798394feb07299122676d253e68af3 Mon Sep 17 00:00:00 2001 From: Taylor Date: Mon, 21 Mar 2022 12:16:16 -0400 Subject: [PATCH 3/4] fix(homepage): make sure the type Array --- superset-frontend/src/views/CRUD/utils.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/views/CRUD/utils.tsx b/superset-frontend/src/views/CRUD/utils.tsx index f785b3994460d..7947354484d67 100644 --- a/superset-frontend/src/views/CRUD/utils.tsx +++ b/superset-frontend/src/views/CRUD/utils.tsx @@ -163,7 +163,7 @@ export const getEditedObjects = (userId: string | number) => { export const getUserOwnedObjects = ( userId: string | number, resource: string, - filters = [ + filters: Array = [ { col: 'created_by', opr: 'rel_o_m', From 3d19365d814dba4eec1465ab4d09e39221da8261 Mon Sep 17 00:00:00 2001 From: Taylor Date: Fri, 25 Mar 2022 13:50:29 -0400 Subject: [PATCH 4/4] fix(homepage): make to display dashboard correctly by owners --- superset-frontend/src/views/CRUD/utils.tsx | 4 ++-- superset-frontend/src/views/CRUD/welcome/Welcome.tsx | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/superset-frontend/src/views/CRUD/utils.tsx b/superset-frontend/src/views/CRUD/utils.tsx index 7947354484d67..760acb8586348 100644 --- a/superset-frontend/src/views/CRUD/utils.tsx +++ b/superset-frontend/src/views/CRUD/utils.tsx @@ -165,8 +165,8 @@ export const getUserOwnedObjects = ( resource: string, filters: Array = [ { - col: 'created_by', - opr: 'rel_o_m', + col: 'owners', + opr: 'rel_m_m', value: `${userId}`, }, ], diff --git a/superset-frontend/src/views/CRUD/welcome/Welcome.tsx b/superset-frontend/src/views/CRUD/welcome/Welcome.tsx index 903dcd909cec4..8d23664f5d2ed 100644 --- a/superset-frontend/src/views/CRUD/welcome/Welcome.tsx +++ b/superset-frontend/src/views/CRUD/welcome/Welcome.tsx @@ -199,8 +199,8 @@ function Welcome({ user, addDangerToast }: WelcomeProps) { // Sets other activity data in parallel with recents api call const ownSavedQueryFilters = [ { - col: 'owners', - opr: 'rel_m_m', + col: 'created_by', + opr: 'rel_o_m', value: `${id}`, }, ];