You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2018/06/23 01:58:53 UTC

[GitHub] williaster closed pull request #5273: [Fix] import/export dash in V2

williaster closed pull request #5273: [Fix] import/export dash in V2
URL: https://github.com/apache/incubator-superset/pull/5273
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/models/core.py b/superset/models/core.py
index bd5fc9dcff..4e195ae41d 100644
--- a/superset/models/core.py
+++ b/superset/models/core.py
@@ -418,7 +418,7 @@ def import_obj(cls, dashboard_to_import, import_time=None):
         def alter_positions(dashboard, old_to_new_slc_id_dict):
             """ Updates slice_ids in the position json.
 
-            Sample position json:
+            Sample position json v1:
             [{
                 "col": 5,
                 "row": 10,
@@ -426,16 +426,59 @@ def alter_positions(dashboard, old_to_new_slc_id_dict):
                 "size_y": 2,
                 "slice_id": "3610"
             }]
+
+            Sample position json v2:
+            {
+                "DASHBOARD_VERSION_KEY": "v2",
+                "DASHBOARD_ROOT_ID": {
+                    "type": "DASHBOARD_ROOT_TYPE",
+                    "id": "DASHBOARD_ROOT_ID",
+                    "children": ["DASHBOARD_GRID_ID"]
+                },
+                "DASHBOARD_GRID_ID": {
+                    "type": "DASHBOARD_GRID_TYPE",
+                    "id": "DASHBOARD_GRID_ID",
+                    "children": ["DASHBOARD_CHART_TYPE-2"]
+                },
+                "DASHBOARD_CHART_TYPE-2": {
+                    "type": "DASHBOARD_CHART_TYPE",
+                    "id": "DASHBOARD_CHART_TYPE-2",
+                    "children": [],
+                    "meta": {
+                        "width": 4,
+                        "height": 50,
+                        "chartId": 118
+                    }
+                },
+            }
             """
-            position_array = dashboard.position_array
-            for position in position_array:
-                if 'slice_id' not in position:
-                    continue
-                old_slice_id = int(position['slice_id'])
-                if old_slice_id in old_to_new_slc_id_dict:
-                    position['slice_id'] = '{}'.format(
-                        old_to_new_slc_id_dict[old_slice_id])
-            dashboard.position_json = json.dumps(position_array)
+            position_data = json.loads(dashboard.position_json)
+            is_v2_dash = (
+                isinstance(position_data, dict) and
+                position_data.get('DASHBOARD_VERSION_KEY') == 'v2'
+            )
+            if is_v2_dash:
+                position_json = position_data.values()
+                for value in position_json:
+                    if (isinstance(value, dict) and value.get('meta') and
+                            value.get('meta').get('chartId')):
+                        old_slice_id = value.get('meta').get('chartId')
+
+                        if old_slice_id in old_to_new_slc_id_dict:
+                            value['meta']['chartId'] = (
+                                old_to_new_slc_id_dict[old_slice_id]
+                            )
+                dashboard.position_json = json.dumps(position_data)
+            else:
+                position_array = dashboard.position_array
+                for position in position_array:
+                    if 'slice_id' not in position:
+                        continue
+                    old_slice_id = int(position['slice_id'])
+                    if old_slice_id in old_to_new_slc_id_dict:
+                        position['slice_id'] = '{}'.format(
+                            old_to_new_slc_id_dict[old_slice_id])
+                dashboard.position_json = json.dumps(position_array)
 
         logging.info('Started import of the dashboard: {}'
                      .format(dashboard_to_import.to_json()))


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org