Skip to content

Commit

Permalink
fix(dashboard): changing the chart title, except not (apache#10527)
Browse files Browse the repository at this point in the history
* changing slice names in dashboard should not change chart title

* comprehensions > loops
  • Loading branch information
suddjian authored and auxten committed Nov 20, 2020
1 parent 3ecc658 commit 0bf1ae5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class ChartHolder extends React.Component {
...component,
meta: {
...component.meta,
sliceName: nextName,
sliceNameOverride: nextName,
},
},
});
Expand Down Expand Up @@ -255,7 +255,11 @@ class ChartHolder extends React.Component {
dashboardId={dashboardId}
width={chartWidth}
height={chartHeight}
sliceName={component.meta.sliceName || ''}
sliceName={
component.meta.sliceNameOverride ||
component.meta.sliceName ||
''
}
updateSliceName={this.handleUpdateSliceName}
isComponentVisible={isComponentVisible}
handleToggleFullSize={this.handleToggleFullSize}
Expand Down
27 changes: 5 additions & 22 deletions superset/dashboards/dao.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,17 @@ def set_dash_metadata( # pylint: disable=too-many-locals,too-many-branches,too-
) -> None:
positions = data["positions"]
# find slices in the position data
slice_ids = []
slice_id_to_name = {}
for value in positions.values():
if isinstance(value, dict):
try:
slice_id = value["meta"]["chartId"]
slice_ids.append(slice_id)
slice_id_to_name[slice_id] = value["meta"]["sliceName"]
except KeyError:
pass
slice_ids = [
value.get("meta", {}).get("chartId")
for value in positions.values()
if isinstance(value, dict)
]

session = db.session()
current_slices = session.query(Slice).filter(Slice.id.in_(slice_ids)).all()

dashboard.slices = current_slices

# update slice names. this assumes user has permissions to update the slice
# we allow user set slice name be empty string
for slc in dashboard.slices:
try:
new_name = slice_id_to_name[slc.id]
if slc.slice_name != new_name:
slc.slice_name = new_name
session.merge(slc)
session.flush()
except KeyError:
pass

# remove leading and trailing white spaces in the dumped json
dashboard.position_json = json.dumps(
positions, indent=None, separators=(",", ":"), sort_keys=True
Expand Down

0 comments on commit 0bf1ae5

Please sign in to comment.