Skip to content

Commit

Permalink
Uses reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina committed Apr 4, 2023
1 parent fe4f17f commit 92a5600
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions superset-frontend/src/dashboard/actions/sliceEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ function fetchAllSlicesFailed(error: string) {
return { type: FETCH_ALL_SLICES_FAILED, payload: { error } };
}

const parseResult = (result: any[]) => {
const slices: { [id: number]: Slice } = {};
result.forEach((slice: any) => {
const parseResult = (result: any[]) =>
result.reduce((slices, slice: any) => {
let form_data = JSON.parse(slice.params);
form_data = {
...form_data,
Expand All @@ -69,28 +68,29 @@ const parseResult = (result: any[]) => {
getDatasourceParameter(slice.datasource_id, slice.datasource_type) ||
form_data.datasource,
};
slices[slice.id] = {
slice_id: slice.id,
slice_url: slice.url,
slice_name: slice.slice_name,
form_data,
datasource_name: slice.datasource_name_text,
datasource_url: slice.datasource_url,
datasource_id: slice.datasource_id,
datasource_type: slice.datasource_type,
changed_on: new Date(slice.changed_on_utc).getTime(),
description: slice.description,
description_markdown: slice.description_markeddown,
viz_type: slice.viz_type,
modified: slice.changed_on_delta_humanized,
changed_on_humanized: slice.changed_on_delta_humanized,
thumbnail_url: slice.thumbnail_url,
owners: slice.owners,
created_by: slice.created_by,
return {
...slices,
[slice.id]: {
slice_id: slice.id,
slice_url: slice.url,
slice_name: slice.slice_name,
form_data,
datasource_name: slice.datasource_name_text,
datasource_url: slice.datasource_url,
datasource_id: slice.datasource_id,
datasource_type: slice.datasource_type,
changed_on: new Date(slice.changed_on_utc).getTime(),
description: slice.description,
description_markdown: slice.description_markeddown,
viz_type: slice.viz_type,
modified: slice.changed_on_delta_humanized,
changed_on_humanized: slice.changed_on_delta_humanized,
thumbnail_url: slice.thumbnail_url,
owners: slice.owners,
created_by: slice.created_by,
},
};
});
return slices;
};
}, {});

export function updateSlices(slices: { [id: number]: Slice }) {
return (dispatch: Dispatch) => {
Expand Down

0 comments on commit 92a5600

Please sign in to comment.