From e4b6466246de58818738387730053c6dbb5ceef0 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Thu, 25 Oct 2018 10:05:36 -0700 Subject: [PATCH 1/4] [dashboard][bugfix][save as] re-direct to copied dashboard upon saveas --- .../src/dashboard/actions/dashboardState.js | 1 - .../src/dashboard/actions/sliceEntities.js | 32 ++++++++++--------- .../src/dashboard/components/SaveModal.jsx | 11 ++----- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/superset/assets/src/dashboard/actions/dashboardState.js b/superset/assets/src/dashboard/actions/dashboardState.js index 883a508c0faaa..de32e2a978505 100644 --- a/superset/assets/src/dashboard/actions/dashboardState.js +++ b/superset/assets/src/dashboard/actions/dashboardState.js @@ -132,7 +132,6 @@ export function saveDashboardRequest(data, id, saveType) { SupersetClient.post({ endpoint: `/superset/${path}/${id}/`, postPayload: { data }, - parseMethod: null, }) .then(response => Promise.all([ diff --git a/superset/assets/src/dashboard/actions/sliceEntities.js b/superset/assets/src/dashboard/actions/sliceEntities.js index 33e3507c1a69f..1c43d34060561 100644 --- a/superset/assets/src/dashboard/actions/sliceEntities.js +++ b/superset/assets/src/dashboard/actions/sliceEntities.js @@ -3,7 +3,10 @@ import { SupersetClient } from '@superset-ui/core'; import { addDangerToast } from '../../messageToasts/actions'; import { t } from '../../locales'; -import { getDatasourceParameter } from '../../modules/utils'; +import { + getDatasourceParameter, + getClientErrorObject, +} from '../../modules/utils'; export const SET_ALL_SLICES = 'SET_ALL_SLICES'; export function setAllSlices(slices) { @@ -64,22 +67,21 @@ export function fetchAllSlices(userId) { return dispatch(setAllSlices(slices)); }) - .catch(error => - Promise.all([ - dispatch( - fetchAllSlicesFailed( - error.error || - error.statusText || - t('Could not fetch all saved charts'), + .catch(errorResponse => + getClientErrorObject(errorResponse).then(({ error }) => + Promise.all([ + dispatch( + fetchAllSlicesFailed( + error || t('Could not fetch all saved charts'), + ), ), - ), - dispatch( - addDangerToast( - t('Sorry there was an error fetching saved charts: ') + - error.error || error.statusText, + dispatch( + addDangerToast( + t('Sorry there was an error fetching saved charts: ') + error, + ), ), - ), - ]), + ]), + ), ); } diff --git a/superset/assets/src/dashboard/components/SaveModal.jsx b/superset/assets/src/dashboard/components/SaveModal.jsx index 13863a24c259d..2219643206cc2 100644 --- a/superset/assets/src/dashboard/components/SaveModal.jsx +++ b/superset/assets/src/dashboard/components/SaveModal.jsx @@ -93,14 +93,9 @@ class SaveModal extends React.PureComponent { t('You must pick a name for the new dashboard'), ); } else { - this.onSave(data, dashboardId, saveType).then(([resp]) => { - if ( - saveType === SAVE_TYPE_NEWDASHBOARD && - resp && - resp.json && - resp.json.id - ) { - window.location = `/superset/dashboard/${resp.json.id}/`; + this.onSave(data, dashboardId, saveType).then(([{ json }]) => { + if (saveType === SAVE_TYPE_NEWDASHBOARD && json && json.id) { + window.location = `/superset/dashboard/${json.id}/`; } }); this.modal.close(); From 7626429688e4973dab8e7e5b8319552fb4fa8587 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Thu, 25 Oct 2018 10:12:10 -0700 Subject: [PATCH 2/4] [dashboard][save modal] safer destructuring --- .../assets/src/dashboard/components/SaveModal.jsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/superset/assets/src/dashboard/components/SaveModal.jsx b/superset/assets/src/dashboard/components/SaveModal.jsx index 2219643206cc2..13863a24c259d 100644 --- a/superset/assets/src/dashboard/components/SaveModal.jsx +++ b/superset/assets/src/dashboard/components/SaveModal.jsx @@ -93,9 +93,14 @@ class SaveModal extends React.PureComponent { t('You must pick a name for the new dashboard'), ); } else { - this.onSave(data, dashboardId, saveType).then(([{ json }]) => { - if (saveType === SAVE_TYPE_NEWDASHBOARD && json && json.id) { - window.location = `/superset/dashboard/${json.id}/`; + this.onSave(data, dashboardId, saveType).then(([resp]) => { + if ( + saveType === SAVE_TYPE_NEWDASHBOARD && + resp && + resp.json && + resp.json.id + ) { + window.location = `/superset/dashboard/${resp.json.id}/`; } }); this.modal.close(); From 22d803326e51a0516196d4cb8b2c45a1ecaf0599 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Thu, 25 Oct 2018 10:16:11 -0700 Subject: [PATCH 3/4] [dashboard][save as] simplify Promise resolution --- superset/assets/src/dashboard/actions/dashboardState.js | 3 +-- superset/assets/src/dashboard/components/SaveModal.jsx | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/superset/assets/src/dashboard/actions/dashboardState.js b/superset/assets/src/dashboard/actions/dashboardState.js index de32e2a978505..2ff139fcdb714 100644 --- a/superset/assets/src/dashboard/actions/dashboardState.js +++ b/superset/assets/src/dashboard/actions/dashboardState.js @@ -135,12 +135,11 @@ export function saveDashboardRequest(data, id, saveType) { }) .then(response => Promise.all([ - Promise.resolve(response), dispatch(saveDashboardRequestSuccess()), dispatch( addSuccessToast(t('This dashboard was saved successfully.')), ), - ]), + ]).then(() => Promise.resolve(response)), ) .catch(response => getClientErrorObject(response).then(({ error }) => diff --git a/superset/assets/src/dashboard/components/SaveModal.jsx b/superset/assets/src/dashboard/components/SaveModal.jsx index 13863a24c259d..2e3d94973f895 100644 --- a/superset/assets/src/dashboard/components/SaveModal.jsx +++ b/superset/assets/src/dashboard/components/SaveModal.jsx @@ -93,7 +93,7 @@ class SaveModal extends React.PureComponent { t('You must pick a name for the new dashboard'), ); } else { - this.onSave(data, dashboardId, saveType).then(([resp]) => { + this.onSave(data, dashboardId, saveType).then(resp => { if ( saveType === SAVE_TYPE_NEWDASHBOARD && resp && From 9bf0c515ff657550de47d766d112e2debfafbb38 Mon Sep 17 00:00:00 2001 From: Chris Williams Date: Thu, 25 Oct 2018 11:26:19 -0700 Subject: [PATCH 4/4] [dashboard] simply fetch slices error --- .../src/dashboard/actions/sliceEntities.js | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/superset/assets/src/dashboard/actions/sliceEntities.js b/superset/assets/src/dashboard/actions/sliceEntities.js index 1c43d34060561..31a03db0d23d2 100644 --- a/superset/assets/src/dashboard/actions/sliceEntities.js +++ b/superset/assets/src/dashboard/actions/sliceEntities.js @@ -68,20 +68,18 @@ export function fetchAllSlices(userId) { return dispatch(setAllSlices(slices)); }) .catch(errorResponse => - getClientErrorObject(errorResponse).then(({ error }) => - Promise.all([ - dispatch( - fetchAllSlicesFailed( - error || t('Could not fetch all saved charts'), - ), + getClientErrorObject(errorResponse).then(({ error }) => { + dispatch( + fetchAllSlicesFailed( + error || t('Could not fetch all saved charts'), ), - dispatch( - addDangerToast( - t('Sorry there was an error fetching saved charts: ') + error, - ), + ); + dispatch( + addDangerToast( + t('Sorry there was an error fetching saved charts: ') + error, ), - ]), - ), + ); + }), ); }