From 904a03f81a096d21f89ce34a77693c7542b3220f Mon Sep 17 00:00:00 2001 From: Ronald Date: Mon, 1 May 2023 14:13:05 +0200 Subject: [PATCH] Sort revision list by createdAt. refs https://ghost.slack.com/archives/C02G9E68C/p1682941387256079?thread_ts=1682507718.761429&cid=C02G9E68C https://github.com/TryGhost/Team/issues/3123 This commit modifies the revisionList method to sort the revisions array by createdAt property in descending order, instead of reversing the order of the array. This makes the code more intuitive and easier to follow for future developers. Additionally, the published_latest key-value pair is renamed to initial_publish to better reflect its meaning. This key-value pair is added to the revision object at the index where the post status changed from 'draft' to 'published', indicating the initial publication of the post. --- ghost/admin/app/components/modal-post-history.hbs | 2 +- ghost/admin/app/components/modal-post-history.js | 13 +++++++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ghost/admin/app/components/modal-post-history.hbs b/ghost/admin/app/components/modal-post-history.hbs index 5edd143d15..33890d8491 100644 --- a/ghost/admin/app/components/modal-post-history.hbs +++ b/ghost/admin/app/components/modal-post-history.hbs @@ -63,7 +63,7 @@ Latest {{/if}} - {{#if (eq revision.published_latest true)}} + {{#if (eq revision.initial_publish true)}} Published {{/if}} diff --git a/ghost/admin/app/components/modal-post-history.js b/ghost/admin/app/components/modal-post-history.js index e48249e892..b119d5dbf4 100644 --- a/ghost/admin/app/components/modal-post-history.js +++ b/ghost/admin/app/components/modal-post-history.js @@ -52,9 +52,14 @@ export default class ModalPostHistory extends Component { } get revisionList() { - const revisions = this.post.get('postRevisions').toArray().reverse(); - const latestPublishedIndex = revisions.findIndex( - revision => revision.get('postStatus') === 'published' && revision.get('reason') === 'published' + // sort revisions by createdAt date + const revisions = this.post.get('postRevisions').toArray().sort((a, b) => b.get('createdAt') - a.get('createdAt')); + // finds the initial published version + const publishedIndex = revisions.findIndex( + (revision, index, arr) => ( + revision.get('postStatus') === 'published' && + arr[index + 1]?.get('postStatus') === 'draft' + ) ); return revisions.map((revision, index) => { @@ -72,7 +77,7 @@ export default class ModalPostHistory extends Component { }, postStatus: revision.get('postStatus'), reason: revision.get('reason'), - published_latest: latestPublishedIndex !== -1 && latestPublishedIndex === index + initial_publish: publishedIndex !== -1 && index === publishedIndex }; }); }