diff --git a/imports/plugins/core/revisions/client/components/publishControls.js b/imports/plugins/core/revisions/client/components/publishControls.js index 3b0e7497726..57c2ed44e47 100644 --- a/imports/plugins/core/revisions/client/components/publishControls.js +++ b/imports/plugins/core/revisions/client/components/publishControls.js @@ -43,6 +43,10 @@ class PublishControls extends Component { return "app.hideChanges"; } + get hasRevisions() { + return Array.isArray(this.props.revisions) && this.props.revisions.length; + } + get diffs() { return this.props.revisions; } @@ -51,6 +55,36 @@ class PublishControls extends Component { return this.diffs && this.state.showDiffs; } + /** + * Getter hasChanges + * @return {Boolean} one or more revision has changes + */ + get hasChanges() { + // Verify we even have any revision at all + if (this.hasRevisions) { + // Loop through all revisions to determin if they have changes + const diffHasActualChanges = this.props.revisions.map((revision) => { + // We probably do have chnages to publish + // Note: Sometimes "updatedAt" will cause false positives, but just incase, lets + // enable the publish button anyway. + if (Array.isArray(revision.diff) && revision.diff.length) { + return true; + } + + // If all else fails, we will disable the button + return false; + }); + + // If even one revision has changes we should enable the publish button + return diffHasActualChanges.some((element) => { + return element === true; + }); + } + + // No revisions, no publishing + return false; + } + renderChanges() { if (this.showDiffs) { const diffs = this.props.revisions.map((revision) => { @@ -66,6 +100,18 @@ class PublishControls extends Component { return null; } + renderPublishButton() { + return ( +