Skip to content

Commit

Permalink
Save outdated charts in dash
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Sep 6, 2023
1 parent dd87e66 commit d9380f6
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 11 deletions.
1 change: 1 addition & 0 deletions superset-frontend/src/dashboard/actions/hydrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -86,6 +86,7 @@ const propTypes = {
datasetsStatus: PropTypes.oneOf(['loading', 'error', 'complete']),
isInView: PropTypes.bool,
emitCrossFilters: PropTypes.bool,
updateSlices: PropTypes.func.isRequired,
};

const defaultProps = {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -373,6 +391,7 @@ class Chart extends React.Component {
}

render() {
console.log(this.props.slice.outdated);
const {
id,
componentId,
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/src/dashboard/containers/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -116,6 +117,7 @@ function mapDispatchToProps(dispatch) {
unsetFocusedFilterField,
refreshChart,
logEvent,
updateSlices,
},
dispatch,
);
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/explore/actions/saveModalActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export const getSlicePayload = (
ownState: null,
}),
),
outdated: false,
};
return payload;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
},
Expand Down
1 change: 1 addition & 0 deletions superset/charts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]:
"viz_type",
"query_context",
"is_managed_externally",
"outdated",
"tags.id",
"tags.name",
"tags.type",
Expand Down

0 comments on commit d9380f6

Please sign in to comment.