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

[dashboard] clean up usage for old filter immune metadata #9146

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -19,10 +19,7 @@
export default {
id: 1234,
slug: 'dashboardSlug',
metadata: {
filterImmuneSlices: [],
filterImmuneSliceFields: {},
},
metadata: {},
userId: 'mock_user_id',
dash_edit_perm: true,
dash_save_perm: true,
Expand Down
15 changes: 1 addition & 14 deletions superset-frontend/src/dashboard/reducers/getInitialState.js
Expand Up @@ -101,9 +101,6 @@ export default function(bootstrapData) {
let newSlicesContainer;
let newSlicesContainerWidth = 0;

const filterImmuneSliceFields =
dashboard.metadata.filter_immune_slice_fields || {};
const filterImmuneSlices = dashboard.metadata.filter_immune_slices || [];
const filterScopes = dashboard.metadata.filter_scopes || {};

const chartQueries = {};
Expand Down Expand Up @@ -188,8 +185,6 @@ export default function(bootstrapData) {
});
}

// backward compatible:
// merge scoped filter settings with old global immune settings
const scopesByChartId = Object.keys(columns).reduce((map, column) => {
const scopeSettings = {
...filterScopes[key],
Expand All @@ -198,20 +193,12 @@ export default function(bootstrapData) {
...DASHBOARD_FILTER_SCOPE_GLOBAL,
...scopeSettings[column],
};
const immuneChartIds = new Set(filterImmuneSlices);
Object.keys(filterImmuneSliceFields)
.filter(strChartId =>
filterImmuneSliceFields[strChartId].includes(column),
)
.forEach(strChartId => {
immuneChartIds.add(parseInt(strChartId, 10));
});

return {
...map,
[column]: {
scope,
immune: [...immuneChartIds].concat(immune),
immune,
},
};
}, {});
Expand Down
8 changes: 0 additions & 8 deletions superset/views/core.py
Expand Up @@ -1263,16 +1263,8 @@ def _set_dash_metadata(dashboard, data):

if "timed_refresh_immune_slices" not in md:
md["timed_refresh_immune_slices"] = []

if "filter_scopes" in data:
md.pop("filter_immune_slices", None)
md.pop("filter_immune_slice_fields", None)
md["filter_scopes"] = json.loads(data.get("filter_scopes", "{}"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
md["filter_scopes"] = json.loads(data.get("filter_scopes", "{}"))
md["filter_scopes"] = json.loads(data["filter_scopes"])

not yours, but might as well clean this up

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there might be many dashboards holding NULL value in data.get('filter_scopes').

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since, this is inside the if statement if "filter_scopes" in data:, we don't need to use .get because we know the key is there. For the case you mentioned, I think this should be:

md["filter_scopes"] = json.loads(data["filter_scopes"] or "{}")

For explanation,

data = {"filter_scopes": None}
print(data.get("filter_scopes", "{}")) # prints None

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right! added fix. thank you!

else:
if "filter_immune_slices" not in md:
md["filter_immune_slices"] = []
if "filter_immune_slice_fields" not in md:
md["filter_immune_slice_fields"] = {}
md["expanded_slices"] = data["expanded_slices"]
md["refresh_frequency"] = data.get("refresh_frequency", 0)
default_filters_data = json.loads(data.get("default_filters", "{}"))
Expand Down