From 475220904edf3f1afc9b861e4756ce1d61e99253 Mon Sep 17 00:00:00 2001 From: Peter Dinh Date: Mon, 25 Sep 2017 17:48:32 -0700 Subject: [PATCH] refactor to make it backwards compatible with old history --- admin/client/App/screens/Revision/actions.js | 4 +++- .../client/App/screens/Revision/components/RevisionItem.js | 7 ++++--- admin/client/App/screens/Revision/reducer.js | 3 ++- admin/server/api/revision/get.js | 1 + lib/schemaPlugins/history.js | 2 +- 5 files changed, 11 insertions(+), 6 deletions(-) diff --git a/admin/client/App/screens/Revision/actions.js b/admin/client/App/screens/Revision/actions.js index af5a7a94f5..149ae52e80 100644 --- a/admin/client/App/screens/Revision/actions.js +++ b/admin/client/App/screens/Revision/actions.js @@ -64,9 +64,11 @@ export const selectRevision = revision => { export const applyChanges = router => { return (dispatch, getState) => { const state = getState(); + const { selectedRevision } = state.revisions; const { currentList } = state.lists; const { id } = state.item; - const { data, _id: rollbackId } = state.revisions.selectedRevision; + const data = selectedRevision.data || selectedRevision.d; + const { _id: rollbackId } = selectedRevision; const { currentItem } = state.revisions; const redirectUrl = `${Keystone.adminPath}/${currentList.path}/${id}`; const file = { diff --git a/admin/client/App/screens/Revision/components/RevisionItem.js b/admin/client/App/screens/Revision/components/RevisionItem.js index ebd60ac717..bcc0419dfd 100644 --- a/admin/client/App/screens/Revision/components/RevisionItem.js +++ b/admin/client/App/screens/Revision/components/RevisionItem.js @@ -76,11 +76,12 @@ const RevisionItem = ({
{revisions.map(revision => { const active = selectedRevision._id === revision._id; - const { first, last } = revision.user.name; + const user = revision.user || revision.u; + const { first, last } = user; return (
selectRevision(revision)}> - {moment(revision.time).format('YYYY-MM-DD hh:mm:ssa')} by {`${first} ${last}`} + {moment(revision.time || revision.t).format('YYYY-MM-DD hh:mm:ssa')} by {`${first} ${last}`} {active ?
@@ -90,7 +91,7 @@ const RevisionItem = ({ Current Rollback - {renderDifferences(revision.data)} + {renderDifferences(revision.data || revision.d)}
diff --git a/admin/client/App/screens/Revision/reducer.js b/admin/client/App/screens/Revision/reducer.js index aa069376e1..edaae25459 100644 --- a/admin/client/App/screens/Revision/reducer.js +++ b/admin/client/App/screens/Revision/reducer.js @@ -16,7 +16,8 @@ export default (state = { case LOAD_REVISIONS: return { ...state, error: null, ready: false }; case DATA_LOADING_SUCCESS: - const currentItem = action.payload.pop().data; + const popped = action.payload.pop(); + const currentItem = popped.data || popped.d; return { ...state, revisions: action.payload, error: null, ready: true, currentItem }; case DATA_LOADING_ERROR: if (action.payload) { diff --git a/admin/server/api/revision/get.js b/admin/server/api/revision/get.js index c139b743f5..9df2865ccc 100644 --- a/admin/server/api/revision/get.js +++ b/admin/server/api/revision/get.js @@ -9,6 +9,7 @@ module.exports = (req, res) => { revisions.find({ id }) .populate('user', 'name') + .populate('u', 'name') .then(items => res.json(items)) .catch(err => res.json(err)); }; diff --git a/lib/schemaPlugins/history.js b/lib/schemaPlugins/history.js index 771a88bcd6..33791f5fb9 100644 --- a/lib/schemaPlugins/history.js +++ b/lib/schemaPlugins/history.js @@ -59,7 +59,7 @@ module.exports = function history () { }); - list.schema.pre('save', function (next) { + list.schema.pre('save', function (next) { if (this.isModified()) { this.__rev = (typeof this.__rev === 'number') ? this.__rev + 1 : 1;