Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: should update last_modified_time in client-side after save dash #11305

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -516,6 +519,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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This thing is getting a little too bloated. I'm wondering whether we can refactor and just pass a dashboard object to this component.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. dashboardInfo is read only dashboard metadata. I will consider group other edit-able dashboard metadata into another object.

} = 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