chore(utils): Support select_columns with getUserOwnedObjects and split recentActivityObjs (#29459)

This commit is contained in:
Vitor Avila 2024-07-04 13:03:13 -03:00 committed by GitHub
parent 145694d828
commit 4e861cf86e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 40 additions and 20 deletions

View File

@ -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');