You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by cc...@apache.org on 2018/06/22 00:54:38 UTC
[incubator-superset] 23/26: [fix] new dashboard state (#5213)
This is an automated email from the ASF dual-hosted git repository.
ccwilliams pushed a commit to branch dashboard-builder
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
commit da816742329305cab61d3d356467d5080359a66c
Author: Grace Guo <gr...@airbnb.com>
AuthorDate: Wed Jun 20 14:35:27 2018 -0700
[fix] new dashboard state (#5213)
---
.../src/dashboard/reducers/getInitialState.js | 6 ++--
.../assets/src/explore/components/SaveModal.jsx | 2 +-
superset/views/core.py | 37 +++++++++++++++-------
3 files changed, 28 insertions(+), 17 deletions(-)
diff --git a/superset/assets/src/dashboard/reducers/getInitialState.js b/superset/assets/src/dashboard/reducers/getInitialState.js
index e1cb6ba..e529bf4 100644
--- a/superset/assets/src/dashboard/reducers/getInitialState.js
+++ b/superset/assets/src/dashboard/reducers/getInitialState.js
@@ -53,7 +53,7 @@ export default function(bootstrapData) {
// dashboard layout
const { position_json: positionJson } = dashboard;
const shouldConvertToV2 =
- !positionJson || positionJson[DASHBOARD_VERSION_KEY] !== 'v2';
+ positionJson && positionJson[DASHBOARD_VERSION_KEY] !== 'v2';
const layout = shouldConvertToV2
? layoutConverter(dashboard)
@@ -69,7 +69,6 @@ export default function(bootstrapData) {
// find root level chart container node for newly-added slices
const parentId = findFirstParentContainerId(layout);
- let hasUnsavedChanges = false;
const chartQueries = {};
const slices = {};
const sliceIds = new Set();
@@ -112,7 +111,6 @@ export default function(bootstrapData) {
layout[chartHolder.id] = chartHolder;
rowContainer.children.push(chartHolder.id);
chartIdToLayoutId[chartHolder.meta.chartId] = chartHolder.id;
- hasUnsavedChanges = true;
}
}
@@ -173,7 +171,7 @@ export default function(bootstrapData) {
css: dashboard.css || '',
editMode: dashboard.dash_edit_perm && editMode,
showBuilderPane: dashboard.dash_edit_perm && editMode,
- hasUnsavedChanges,
+ hasUnsavedChanges: false,
maxUndoHistoryExceeded: false,
isV2Preview: shouldConvertToV2,
},
diff --git a/superset/assets/src/explore/components/SaveModal.jsx b/superset/assets/src/explore/components/SaveModal.jsx
index 86028c8..79880ea 100644
--- a/superset/assets/src/explore/components/SaveModal.jsx
+++ b/superset/assets/src/explore/components/SaveModal.jsx
@@ -108,7 +108,7 @@ class SaveModal extends React.Component {
.then((data) => {
// Go to new slice url or dashboard url
if (gotodash) {
- window.location = supersetURL(data.dashboard, { edit: 'true' });
+ window.location = supersetURL(data.dashboard);
} else {
window.location = data.slice.slice_url;
}
diff --git a/superset/views/core.py b/superset/views/core.py
index 6bbd7ae..be951a1 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1550,6 +1550,8 @@ class Superset(BaseSupersetView):
dash.owners = [g.user] if g.user else []
dash.dashboard_title = data['dashboard_title']
+
+ is_v2_dash = Superset._is_v2_dash(data['positions'])
if data['duplicate_slices']:
# Duplicating slices as well, mapping old ids to new ones
old_to_new_sliceids = {}
@@ -1559,17 +1561,24 @@ class Superset(BaseSupersetView):
session.add(new_slice)
session.flush()
new_slice.dashboards.append(dash)
- old_to_new_sliceids[slc.id] = new_slice.id
+ old_to_new_sliceids['{}'.format(slc.id)] = \
+ '{}'.format(new_slice.id)
# update chartId of layout entities
- for value in data['positions'].values():
- if (
- isinstance(value, dict) and value.get('meta') and
- value.get('meta').get('chartId')
- ):
- old_id = value.get('meta').get('chartId')
- new_id = old_to_new_sliceids[old_id]
- value['meta']['chartId'] = new_id
+ # in v2_dash positions json data, chartId should be integer,
+ # while in older version slice_id is string type
+ if is_v2_dash:
+ for value in data['positions'].values():
+ if (
+ isinstance(value, dict) and value.get('meta') and
+ value.get('meta').get('chartId')
+ ):
+ old_id = '{}'.format(value.get('meta').get('chartId'))
+ new_id = int(old_to_new_sliceids[old_id])
+ value['meta']['chartId'] = new_id
+ else:
+ for d in data['positions']:
+ d['slice_id'] = old_to_new_sliceids[d['slice_id']]
else:
dash.slices = original_dash.slices
dash.params = original_dash.params
@@ -1599,13 +1608,17 @@ class Superset(BaseSupersetView):
return 'SUCCESS'
@staticmethod
- def _set_dash_metadata(dashboard, data):
- positions = data['positions']
- is_v2_dash = (
+ def _is_v2_dash(positions):
+ return (
isinstance(positions, dict) and
positions.get('DASHBOARD_VERSION_KEY') == 'v2'
)
+ @staticmethod
+ def _set_dash_metadata(dashboard, data):
+ positions = data['positions']
+ is_v2_dash = Superset._is_v2_dash(positions)
+
# @TODO remove upon v1 deprecation
if not is_v2_dash:
positions = data['positions']