mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
fix(dashboard): use server-side lastModifiedTime for co-edit check (#11614)
* fix: [dashboard][co-edit] Round client-side lastModifiedTime * another try: server-side returns last_updated_time in save_dash response
This commit is contained in:
parent
dda95ed250
commit
b9284d3a3c
@ -131,19 +131,22 @@ describe('dashboardState reducer', () => {
|
||||
expect(result.updatedColorScheme).toBe(false);
|
||||
});
|
||||
|
||||
it('should set lastModifiedTime on save', () => {
|
||||
const lastModifiedTime = new Date().getTime() / 1000;
|
||||
it('should reset lastModifiedTime on save', () => {
|
||||
const initTime = new Date().getTime() / 1000;
|
||||
dashboardStateReducer(
|
||||
{
|
||||
lastModifiedTime,
|
||||
lastModifiedTime: initTime,
|
||||
},
|
||||
{},
|
||||
);
|
||||
|
||||
const lastModifiedTime = Math.round(new Date().getTime() / 1000);
|
||||
expect(
|
||||
dashboardStateReducer({ hasUnsavedChanges: true }, { type: ON_SAVE })
|
||||
.lastModifiedTime,
|
||||
).toBeGreaterThanOrEqual(lastModifiedTime);
|
||||
dashboardStateReducer(
|
||||
{ hasUnsavedChanges: true },
|
||||
{ type: ON_SAVE, lastModifiedTime },
|
||||
).lastModifiedTime,
|
||||
).toBeGreaterThanOrEqual(initTime);
|
||||
});
|
||||
|
||||
it('should clear the focused filter field', () => {
|
||||
|
@ -152,8 +152,8 @@ export function onChange() {
|
||||
}
|
||||
|
||||
export const ON_SAVE = 'ON_SAVE';
|
||||
export function onSave() {
|
||||
return { type: ON_SAVE };
|
||||
export function onSave(lastModifiedTime) {
|
||||
return { type: ON_SAVE, lastModifiedTime };
|
||||
}
|
||||
|
||||
export const SET_REFRESH_FREQUENCY = 'SET_REFRESH_FREQUENCY';
|
||||
@ -161,9 +161,9 @@ export function setRefreshFrequency(refreshFrequency, isPersistent = false) {
|
||||
return { type: SET_REFRESH_FREQUENCY, refreshFrequency, isPersistent };
|
||||
}
|
||||
|
||||
export function saveDashboardRequestSuccess() {
|
||||
export function saveDashboardRequestSuccess(lastModifiedTime) {
|
||||
return dispatch => {
|
||||
dispatch(onSave());
|
||||
dispatch(onSave(lastModifiedTime));
|
||||
// clear layout undo history
|
||||
dispatch(UndoActionCreators.clearHistory());
|
||||
};
|
||||
@ -199,7 +199,7 @@ export function saveDashboardRequest(data, id, saveType) {
|
||||
},
|
||||
})
|
||||
.then(response => {
|
||||
dispatch(saveDashboardRequestSuccess());
|
||||
dispatch(saveDashboardRequestSuccess(response.json.last_modified_time));
|
||||
dispatch(addSuccessToast(t('This dashboard was saved successfully.')));
|
||||
return response;
|
||||
})
|
||||
|
@ -25,7 +25,8 @@ export default function dashboardStateReducer(state = {}, action) {
|
||||
return {
|
||||
...state,
|
||||
...action.newInfo,
|
||||
lastModifiedTime: new Date().getTime() / 1000,
|
||||
// server-side compare last_modified_time in second level
|
||||
lastModifiedTime: Math.round(new Date().getTime() / 1000),
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
|
@ -106,8 +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,
|
||||
// server-side returns last_modified_time for latest change
|
||||
lastModifiedTime: action.lastModifiedTime,
|
||||
};
|
||||
},
|
||||
[SET_UNSAVED_CHANGES]() {
|
||||
|
@ -1085,8 +1085,14 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
|
||||
DashboardDAO.set_dash_metadata(dash, data)
|
||||
session.merge(dash)
|
||||
session.commit()
|
||||
|
||||
# get updated changed_on
|
||||
dash = session.query(Dashboard).get(dashboard_id)
|
||||
last_modified_time = dash.changed_on.replace(microsecond=0).timestamp()
|
||||
session.close()
|
||||
return json_success(json.dumps({"status": "SUCCESS"}))
|
||||
return json_success(
|
||||
json.dumps({"status": "SUCCESS", "last_modified_time": last_modified_time,})
|
||||
)
|
||||
|
||||
@api
|
||||
@has_access_api
|
||||
|
Loading…
Reference in New Issue
Block a user