This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch sc_74253
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/sc_74253 by this push:
     new d9380f60c9 Save outdated charts in dash
d9380f60c9 is described below

commit d9380f60c91986d945e91e432f79591f92960273
Author: Beto Dealmeida <[email protected]>
AuthorDate: Tue Sep 5 21:06:33 2023 -0700

    Save outdated charts in dash
---
 superset-frontend/src/dashboard/actions/hydrate.js  |  1 +
 .../dashboard/components/gridComponents/Chart.jsx   | 21 ++++++++++++++++++++-
 .../src/dashboard/containers/Chart.jsx              |  2 ++
 .../src/explore/actions/saveModalActions.js         |  1 +
 .../explore/components/ExploreChartPanel/index.jsx  | 12 ++----------
 superset/charts/api.py                              |  1 +
 6 files changed, 27 insertions(+), 11 deletions(-)

diff --git a/superset-frontend/src/dashboard/actions/hydrate.js 
b/superset-frontend/src/dashboard/actions/hydrate.js
index 699c2041c8..5a8ac3a036 100644
--- a/superset-frontend/src/dashboard/actions/hydrate.js
+++ b/superset-frontend/src/dashboard/actions/hydrate.js
@@ -152,6 +152,7 @@ export const hydrateDashboard =
         owners: slice.owners,
         modified: slice.modified,
         changed_on: new Date(slice.changed_on).getTime(),
+        outdated: slice.outdated,
       };
 
       sliceIds.add(key);
diff --git 
a/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx 
b/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx
index a99061c707..8b797356fa 100644
--- a/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx
+++ b/superset-frontend/src/dashboard/components/gridComponents/Chart.jsx
@@ -19,7 +19,7 @@
 import cx from 'classnames';
 import React from 'react';
 import PropTypes from 'prop-types';
-import { styled, t, logging } from '@superset-ui/core';
+import { SupersetClient, styled, t, logging } from '@superset-ui/core';
 import { debounce, isEqual } from 'lodash';
 import { withRouter } from 'react-router-dom';
 
@@ -86,6 +86,7 @@ const propTypes = {
   datasetsStatus: PropTypes.oneOf(['loading', 'error', 'complete']),
   isInView: PropTypes.bool,
   emitCrossFilters: PropTypes.bool,
+  updateSlices: PropTypes.func.isRequired,
 };
 
 const defaultProps = {
@@ -219,6 +220,23 @@ class Chart extends React.Component {
       const descriptionHeight = this.getDescriptionHeight();
       this.setState({ descriptionHeight });
     }
+
+    if (this.props.slice.outdated) {
+      const { slice, updateSlices } = this.props;
+      SupersetClient.put({
+        endpoint: `/api/v1/chart/${slice.slice_id}`,
+        headers: { 'Content-Type': 'application/json' },
+        body: JSON.stringify({
+          query_context: slice.query_context,
+          params: JSON.stringify(slice.form_data),
+          outdated: false,
+        }),
+      }).then(response =>
+        updateSlices({
+          [slice.slice_id]: { ...slice, ...response.json.result },
+        }),
+      );
+    }
   }
 
   componentWillUnmount() {
@@ -373,6 +391,7 @@ class Chart extends React.Component {
   }
 
   render() {
+    console.log(this.props.slice.outdated);
     const {
       id,
       componentId,
diff --git a/superset-frontend/src/dashboard/containers/Chart.jsx 
b/superset-frontend/src/dashboard/containers/Chart.jsx
index 1e50602b06..b212eba389 100644
--- a/superset-frontend/src/dashboard/containers/Chart.jsx
+++ b/superset-frontend/src/dashboard/containers/Chart.jsx
@@ -24,6 +24,7 @@ import {
   unsetFocusedFilterField,
 } from 'src/dashboard/actions/dashboardState';
 import { updateComponents } from 'src/dashboard/actions/dashboardLayout';
+import { updateSlices } from 'src/dashboard/actions/sliceEntities';
 import { changeFilter } from 'src/dashboard/actions/dashboardFilters';
 import {
   addSuccessToast,
@@ -116,6 +117,7 @@ function mapDispatchToProps(dispatch) {
       unsetFocusedFilterField,
       refreshChart,
       logEvent,
+      updateSlices,
     },
     dispatch,
   );
diff --git a/superset-frontend/src/explore/actions/saveModalActions.js 
b/superset-frontend/src/explore/actions/saveModalActions.js
index 8c864eceac..0b87ce78d2 100644
--- a/superset-frontend/src/explore/actions/saveModalActions.js
+++ b/superset-frontend/src/explore/actions/saveModalActions.js
@@ -114,6 +114,7 @@ export const getSlicePayload = (
         ownState: null,
       }),
     ),
+    outdated: false,
   };
   return payload;
 };
diff --git 
a/superset-frontend/src/explore/components/ExploreChartPanel/index.jsx 
b/superset-frontend/src/explore/components/ExploreChartPanel/index.jsx
index 4fa45501f9..f2e9fcfdda 100644
--- a/superset-frontend/src/explore/components/ExploreChartPanel/index.jsx
+++ b/superset-frontend/src/explore/components/ExploreChartPanel/index.jsx
@@ -178,16 +178,8 @@ const ExploreChartPanel = ({
   const updateChart = useCallback(
     async function overwriteChart() {
       if (slice.outdated) {
-        await SupersetClient.put({
-          endpoint: `/api/v1/chart/${slice.slice_id}`,
-          headers: { 'Content-Type': 'application/json' },
-          body: JSON.stringify({
-            query_context: slice.query_context,
-            params: JSON.stringify(slice.form_data),
-            outdated: false,
-          }),
-        });
-        // TODO: update slice in the parent and trigger render
+        await actions.updateSlice(slice, slice.slice_name);
+        // TODO (betodealmeida): better refresh logic
         window.location.reload();
       }
     },
diff --git a/superset/charts/api.py b/superset/charts/api.py
index d8ca3d6c15..3d7633a401 100644
--- a/superset/charts/api.py
+++ b/superset/charts/api.py
@@ -146,6 +146,7 @@ class ChartRestApi(BaseSupersetModelRestApi):
         "viz_type",
         "query_context",
         "is_managed_externally",
+        "outdated",
         "tags.id",
         "tags.name",
         "tags.type",

Reply via email to