Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ids in metadata_json on import #294

Merged
merged 2 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions superset/superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand 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"]
Expand All @@ -631,13 +649,24 @@ 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"]
):
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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions superset/tests/import_export_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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): {}}),
}
)

Expand All @@ -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)
Expand Down