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 2020/12/12 01:37:49 UTC

[GitHub] [incubator-superset] eschutho commented on a change in pull request #11991: feat: update IDs when importing dashboards

eschutho commented on a change in pull request #11991:
URL: https://github.com/apache/incubator-superset/pull/11991#discussion_r541470286



##########
File path: superset/dashboards/commands/importers/v1/utils.py
##########
@@ -29,6 +29,70 @@
 JSON_KEYS = {"position": "position_json", "metadata": "json_metadata"}
 
 
+def build_uuid_to_id_map(position: Dict[str, Any]) -> Dict[str, int]:
+    return {
+        child["meta"]["uuid"]: child["meta"]["chartId"]
+        for child in position.values()
+        if (
+            isinstance(child, dict)
+            and child["type"] == "CHART"
+            and "uuid" in child["meta"]
+        )
+    }
+
+
+def update_id_refs(config: Dict[str, Any], chart_ids: Dict[str, int]) -> Dict[str, Any]:
+    """Update dashboard metadata to use new IDs"""
+    if not config.get("metadata"):
+        return config
+
+    fixed = config.copy()
+
+    # build map old_id => new_id
+    old_ids = build_uuid_to_id_map(fixed["position"])
+    id_map = {old_id: chart_ids[uuid] for uuid, old_id in old_ids.items()}
+
+    # fix metadata
+    metadata = fixed["metadata"]
+    if "timed_refresh_immune_slices" in metadata:
+        metadata["timed_refresh_immune_slices"] = [
+            id_map[old_id] for old_id in metadata["timed_refresh_immune_slices"]
+        ]
+
+    if "filter_scopes" in metadata:
+        # in filter_scopes the key is a chart ID as a string; we nede to udpate

Review comment:
       nit typos




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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



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