superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From grace...@apache.org
Subject [incubator-superset] branch dashboard-builder updated: [fix] new dashboard state (#5213)
Date Wed, 20 Jun 2018 21:35:30 GMT
This is an automated email from the ASF dual-hosted git repository.

graceguo pushed a commit to branch dashboard-builder
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/dashboard-builder by this push:
     new c4e07f2  [fix] new dashboard state (#5213)
c4e07f2 is described below

commit c4e07f22117aaa774a5eaf810f1fc6884656c306
Author: Grace Guo <grace.guo@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 f33ceeb..700ab21 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1553,6 +1553,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 = {}
@@ -1562,17 +1564,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
@@ -1602,13 +1611,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']


Mime
View raw message