Skip to content

Commit

Permalink
refactor to make it backwards compatible with old history
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Dinh committed Sep 26, 2017
1 parent 34abfed commit 90a2508
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
4 changes: 3 additions & 1 deletion admin/client/App/screens/Revision/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
7 changes: 4 additions & 3 deletions admin/client/App/screens/Revision/components/RevisionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ const RevisionItem = ({
<div style={style}>
{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 (
<div key={revision._id}>
<RevisionListItem active={active} noedit onClick={() => 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}`}
</RevisionListItem>
{active
? <div className="RevisionsItem__table--container">
Expand All @@ -90,7 +91,7 @@ const RevisionItem = ({
<th>Current</th>
<th>Rollback</th>
</tr>
{renderDifferences(revision.data)}
{renderDifferences(revision.data || revision.d)}
</table>
<div>
<Container>
Expand Down
3 changes: 2 additions & 1 deletion admin/client/App/screens/Revision/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions admin/server/api/revision/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
};
2 changes: 1 addition & 1 deletion lib/schemaPlugins/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 90a2508

Please sign in to comment.