Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
fix: should update last_modified_time in client-side after save dash (a…
Browse files Browse the repository at this point in the history
…pache#11305)

(cherry picked from commit 8863c93)
  • Loading branch information
Grace Guo committed Oct 16, 2020
1 parent 1fa1906 commit 8c77202
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,29 @@ describe('dashboardState reducer', () => {
});

it('should set unsaved changes, max undo history, and editMode to false on save', () => {
const result = dashboardStateReducer(
{ hasUnsavedChanges: true },
{ type: ON_SAVE },
);
expect(result.hasUnsavedChanges).toBe(false);
expect(result.maxUndoHistoryExceeded).toBe(false);
expect(result.editMode).toBe(false);
expect(result.updatedColorScheme).toBe(false);
});

it('should set lastModifiedTime on save', () => {
const lastModifiedTime = new Date().getTime() / 1000;
dashboardStateReducer(
{
lastModifiedTime,
},
{},
);

expect(
dashboardStateReducer({ hasUnsavedChanges: true }, { type: ON_SAVE }),
).toEqual({
hasUnsavedChanges: false,
maxUndoHistoryExceeded: false,
editMode: false,
updatedColorScheme: false,
});
dashboardStateReducer({ hasUnsavedChanges: true }, { type: ON_SAVE })
.lastModifiedTime,
).toBeGreaterThanOrEqual(lastModifiedTime);
});

it('should clear focused filter field', () => {
Expand Down
6 changes: 5 additions & 1 deletion superset-frontend/src/dashboard/components/Header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ const propTypes = {
logEvent: PropTypes.func.isRequired,
hasUnsavedChanges: PropTypes.bool.isRequired,
maxUndoHistoryExceeded: PropTypes.bool.isRequired,
lastModifiedTime: PropTypes.number.isRequired,

// redux
onUndo: PropTypes.func.isRequired,
Expand Down Expand Up @@ -269,6 +270,7 @@ class Header extends React.PureComponent {
dashboardInfo,
refreshFrequency: currentRefreshFrequency,
shouldPersistRefreshFrequency,
lastModifiedTime,
} = this.props;

const scale = CategoricalColorNamespace.getScale(
Expand All @@ -290,7 +292,7 @@ class Header extends React.PureComponent {
label_colors: labelColors,
dashboard_title: dashboardTitle,
refresh_frequency: refreshFrequency,
last_modified_time: dashboardInfo.lastModifiedTime,
last_modified_time: lastModifiedTime,
};

// make sure positions data less than DB storage limitation:
Expand Down Expand Up @@ -345,6 +347,7 @@ class Header extends React.PureComponent {
refreshFrequency,
shouldPersistRefreshFrequency,
setRefreshFrequency,
lastModifiedTime,
} = this.props;

const userCanEdit = dashboardInfo.dash_edit_perm;
Expand Down Expand Up @@ -504,6 +507,7 @@ class Header extends React.PureComponent {
showPropertiesModal={this.showPropertiesModal}
refreshLimit={refreshLimit}
refreshWarning={refreshWarning}
lastModifiedTime={lastModifiedTime}
/>
</div>
</StyledDashboardHeader>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const propTypes = {
showPropertiesModal: PropTypes.func.isRequired,
refreshLimit: PropTypes.number,
refreshWarning: PropTypes.string,
lastModifiedTime: PropTypes.number.isRequired,
};

const defaultProps = {
Expand Down Expand Up @@ -138,6 +139,7 @@ class HeaderActionsDropdown extends React.PureComponent {
isLoading,
refreshLimit,
refreshWarning,
lastModifiedTime,
} = this.props;

const emailTitle = t('Superset Dashboard');
Expand Down Expand Up @@ -166,6 +168,7 @@ class HeaderActionsDropdown extends React.PureComponent {
expandedSlices={expandedSlices}
refreshFrequency={refreshFrequency}
shouldPersistRefreshFrequency={shouldPersistRefreshFrequency}
lastModifiedTime={lastModifiedTime}
customCss={customCss}
colorNamespace={colorNamespace}
colorScheme={colorScheme}
Expand Down
4 changes: 3 additions & 1 deletion superset-frontend/src/dashboard/components/SaveModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const propTypes = {
isMenuItem: PropTypes.bool,
canOverwrite: PropTypes.bool.isRequired,
refreshFrequency: PropTypes.number.isRequired,
lastModifiedTime: PropTypes.number.isRequired,
};

const defaultProps = {
Expand Down Expand Up @@ -106,6 +107,7 @@ class SaveModal extends React.PureComponent {
dashboardId,
refreshFrequency: currentRefreshFrequency,
shouldPersistRefreshFrequency,
lastModifiedTime,
} = this.props;

const scale = CategoricalColorNamespace.getScale(
Expand All @@ -129,7 +131,7 @@ class SaveModal extends React.PureComponent {
saveType === SAVE_TYPE_NEWDASHBOARD ? newDashName : dashboardTitle,
duplicate_slices: this.state.duplicateSlices,
refresh_frequency: refreshFrequency,
last_modified_time: dashboardInfo.lastModifiedTime,
last_modified_time: lastModifiedTime,
};

if (saveType === SAVE_TYPE_NEWDASHBOARD && !newDashName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ function mapStateToProps({
isLoading: isDashboardLoading(charts),
hasUnsavedChanges: !!dashboardState.hasUnsavedChanges,
maxUndoHistoryExceeded: !!dashboardState.maxUndoHistoryExceeded,
lastModifiedTime: dashboardState.lastModifiedTime,
editMode: !!dashboardState.editMode,
slug: dashboardInfo.slug,
metadata: dashboardInfo.metadata,
Expand Down
2 changes: 2 additions & 0 deletions superset-frontend/src/dashboard/reducers/dashboardState.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ export default function dashboardStateReducer(state = {}, action) {
maxUndoHistoryExceeded: false,
editMode: false,
updatedColorScheme: false,
// server-side compare last_modified_time in second level
lastModifiedTime: new Date().getTime() / 1000,
};
},
[SET_UNSAVED_CHANGES]() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ export default function getInitialState(bootstrapData) {
id: dashboard.id,
slug: dashboard.slug,
metadata: dashboard.metadata,
lastModifiedTime: dashboard.last_modified_time,
userId: user_id,
dash_edit_perm: dashboard.dash_edit_perm,
dash_save_perm: dashboard.dash_save_perm,
Expand Down Expand Up @@ -301,6 +300,7 @@ export default function getInitialState(bootstrapData) {
isPublished: dashboard.published,
hasUnsavedChanges: false,
maxUndoHistoryExceeded: false,
lastModifiedTime: dashboard.last_modified_time,
},
dashboardLayout,
messageToasts: [],
Expand Down

0 comments on commit 8c77202

Please sign in to comment.