From 0bf1ae5b533337a05b9b01ca04077827750fc79a Mon Sep 17 00:00:00 2001 From: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com> Date: Fri, 7 Aug 2020 18:06:58 -0700 Subject: [PATCH] fix(dashboard): changing the chart title, except not (#10527) * changing slice names in dashboard should not change chart title * comprehensions > loops --- .../components/gridComponents/ChartHolder.jsx | 8 ++++-- superset/dashboards/dao.py | 27 ++++--------------- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx b/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx index 57a00b5c4c7ec..09a1ae54ac636 100644 --- a/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx +++ b/superset-frontend/src/dashboard/components/gridComponents/ChartHolder.jsx @@ -156,7 +156,7 @@ class ChartHolder extends React.Component { ...component, meta: { ...component.meta, - sliceName: nextName, + sliceNameOverride: nextName, }, }, }); @@ -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} diff --git a/superset/dashboards/dao.py b/superset/dashboards/dao.py index 774e1c8d4add9..3cffe11f7e0ac 100644 --- a/superset/dashboards/dao.py +++ b/superset/dashboards/dao.py @@ -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