Skip to content

Commit

Permalink
chore(utils): Support select_columns with getUserOwnedObjects and spl…
Browse files Browse the repository at this point in the history
…it recentActivityObjs (#29459)
  • Loading branch information
Vitor-Avila committed Jul 4, 2024
1 parent 145694d commit 4e861cf
Showing 1 changed file with 40 additions and 20 deletions.
60 changes: 40 additions & 20 deletions superset-frontend/src/views/CRUD/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};

Expand Down Expand Up @@ -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,
Expand All @@ -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');
Expand Down

0 comments on commit 4e861cf

Please sign in to comment.