diff --git a/CHANGELOG.md b/CHANGELOG.md index c42f9ef6..bd13da20 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ - Reduce the size of docker image ([#272](https://github.com/src-d/sourced-ui/issues/272)) +### Fixed + +- Update ids in dashboard metadata on import ([#288](https://github.com/src-d/sourced-ui/issues/288)) + ## [v0.7.0](https://github.com/src-d/sourced-ui/releases/tag/v0.7.0) - 2019-09-26 ### Changed diff --git a/superset/superset/models/core.py b/superset/superset/models/core.py index 681f5087..591c796e 100755 --- a/superset/superset/models/core.py +++ b/superset/superset/models/core.py @@ -600,8 +600,13 @@ def alter_positions(dashboard, old_to_new_slc_id_dict): old_to_new_slc_id_dict = {} new_filter_immune_slices = [] new_timed_refresh_immune_slices = [] + new_filter_immune_slice_fields = {} new_expanded_slices = {} + new_default_filters = {} i_params_dict = dashboard_to_import.params_dict + old_default_filters = None + if "default_filters" in i_params_dict: + old_default_filters = json.loads(i_params_dict["default_filters"]) remote_id_slice_map = { slc.params_dict["remote_id"]: slc for slc in session.query(Slice).all() @@ -621,6 +626,19 @@ def alter_positions(dashboard, old_to_new_slc_id_dict): # update json metadata that deals with slice ids new_slc_id_str = "{}".format(new_slc_id) old_slc_id_str = "{}".format(slc.id) + + """ Updates slice_ids in the position json. + + Sample metadata_json data: + { + "filter_immune_slices": [id1, id2], + "timed_refresh_immune_slices": [id1, id2], + "filter_immune_slice_fields": { id1: [...], ... }, + "expanded_slices": { id1: [...], ... }, + "default_filters": "{\"id1\": {...}}" + ... + } + """ if ( "filter_immune_slices" in i_params_dict and old_slc_id_str in i_params_dict["filter_immune_slices"] @@ -631,6 +649,13 @@ def alter_positions(dashboard, old_to_new_slc_id_dict): and old_slc_id_str in i_params_dict["timed_refresh_immune_slices"] ): new_timed_refresh_immune_slices.append(new_slc_id_str) + if ( + "filter_immune_slice_fields" in i_params_dict + and old_slc_id_str in i_params_dict["filter_immune_slice_fields"] + ): + new_filter_immune_slice_fields[new_slc_id_str] = i_params_dict[ + "filter_immune_slice_fields" + ][old_slc_id_str] if ( "expanded_slices" in i_params_dict and old_slc_id_str in i_params_dict["expanded_slices"] @@ -638,6 +663,10 @@ def alter_positions(dashboard, old_to_new_slc_id_dict): new_expanded_slices[new_slc_id_str] = i_params_dict["expanded_slices"][ old_slc_id_str ] + if old_default_filters and old_slc_id_str in old_default_filters: + new_default_filters[new_slc_id_str] = old_default_filters[ + old_slc_id_str + ] # override the dashboard existing_dashboard = None @@ -666,6 +695,14 @@ def alter_positions(dashboard, old_to_new_slc_id_dict): dashboard_to_import.alter_params( timed_refresh_immune_slices=new_timed_refresh_immune_slices ) + if new_filter_immune_slice_fields: + dashboard_to_import.alter_params( + filter_immune_slice_fields=new_filter_immune_slice_fields + ) + if new_default_filters: + dashboard_to_import.alter_params( + default_filters=json.dumps(new_default_filters) + ) new_slices = ( session.query(Slice) diff --git a/superset/tests/import_export_tests.py b/superset/tests/import_export_tests.py index 7db87b35..b5625890 100644 --- a/superset/tests/import_export_tests.py +++ b/superset/tests/import_export_tests.py @@ -402,10 +402,13 @@ def test_import_dashboard_2_slices(self): { "remote_id": 10003, "filter_immune_slices": ["{}".format(e_slc.id)], + "timed_refresh_immune_slices": ["{}".format(e_slc.id)], + "filter_immune_slice_fields": {"{}".format(e_slc.id): []}, "expanded_slices": { "{}".format(e_slc.id): True, "{}".format(b_slc.id): False, }, + "default_filters": json.dumps({"{}".format(e_slc.id): {}}), } ) @@ -422,10 +425,13 @@ def test_import_dashboard_2_slices(self): expected_json_metadata = { "remote_id": 10003, "filter_immune_slices": ["{}".format(i_e_slc.id)], + "timed_refresh_immune_slices": ["{}".format(i_e_slc.id)], + "filter_immune_slice_fields": {"{}".format(i_e_slc.id): []}, "expanded_slices": { "{}".format(i_e_slc.id): True, "{}".format(i_b_slc.id): False, }, + "default_filters": json.dumps({"{}".format(i_e_slc.id): {}}), } self.assertEquals( expected_json_metadata, json.loads(imported_dash.json_metadata)