Skip to content

Commit

Permalink
chore: Support select_columns with getUserOwnedObjects and split getR…
Browse files Browse the repository at this point in the history
…ecentActivityObjs
  • Loading branch information
Vitor-Avila committed Jul 3, 2024
1 parent d5c0506 commit e01f28e
Showing 1 changed file with 35 additions and 20 deletions.
55 changes: 35 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[], select_columns?: string[]) => {
const params = {
order_column: 'changed_on_delta_humanized',
order_direction: 'desc',
page: 0,
page_size: PAGE_SIZE,
filters,
select_columns,
};
if (!filters) delete params.filters;
if (!select_columns) delete params.select_columns;
return rison.encode(params);
};

Expand Down Expand Up @@ -177,9 +179,10 @@ export const getUserOwnedObjects = (
value: `${userId}`,
},
],
select_columns?: string[],
) =>
SupersetClient.get({
endpoint: `/api/v1/${resource}/?q=${getParams(filters)}`,
endpoint: `/api/v1/${resource}/?q=${getParams(filters, select_columns)}`,
}).then(res => res.json?.result);

export const getRecentActivityObjs = (
Expand All @@ -190,28 +193,40 @@ 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 getFilteredChartsandDashboards = (
addDangerToast: (arg1: string, arg2: any) => any,
filters: Filter[],
) => {
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]) => ({
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 createFetchRelated = createFetchResourceMethod('related');
export const createFetchDistinct = createFetchResourceMethod('distinct');

Expand Down

0 comments on commit e01f28e

Please sign in to comment.