Version History (#768)
* Stash. Super rough progress * Stash * 'h' how toggles history panel Add documents.restore endpoint * Add tests for documents.restore endpoint * Document restore endpoint * Tiding, RevisionMenu, remove scroll dep * Add history menu item * Paginate loading * Fixed: Error boundary styling Select first revision faster * Diff summary, styling * Add history loading placeholder Fix move modal not opening * Fixes: Refreshing page on specific revision * documentation for document.revision * Better handle versions with no text changes (will no longer be created)
This commit is contained in:
@ -1,13 +1,33 @@
|
||||
// @flow
|
||||
import * as JSDiff from 'diff';
|
||||
import { Revision } from '../models';
|
||||
import presentUser from './user';
|
||||
|
||||
function counts(changes) {
|
||||
return changes.reduce(
|
||||
(acc, change) => {
|
||||
if (change.added) acc.added += change.value.length;
|
||||
if (change.removed) acc.removed += change.value.length;
|
||||
return acc;
|
||||
},
|
||||
{
|
||||
added: 0,
|
||||
removed: 0,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function present(ctx: Object, revision: Revision, previous?: Revision) {
|
||||
const prev = previous ? previous.text : '';
|
||||
|
||||
function present(ctx: Object, revision: Revision) {
|
||||
return {
|
||||
id: revision.id,
|
||||
documentId: revision.documentId,
|
||||
title: revision.title,
|
||||
text: revision.text,
|
||||
createdAt: revision.createdAt,
|
||||
updatedAt: revision.updatedAt,
|
||||
createdBy: presentUser(ctx, revision.user),
|
||||
diff: counts(JSDiff.diffChars(prev, revision.text)),
|
||||
};
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user