From 841cfda863b391e926a1421e84a4b1ce267fd633 Mon Sep 17 00:00:00 2001 From: Mike Murray Date: Wed, 5 Oct 2016 14:47:15 -0700 Subject: [PATCH 1/3] Updated publish controls UX and fixing issues - Fix bug causing error in console when publishing nothing. - Disabled the publish button if there is nothing to publish. - Added alert toasts for successful and unsuccessful publish. - Publish controls now properly finds relevant revisions. --- .../client/components/publishControls.js | 53 ++++++++++++++++--- .../client/containers/publishContainer.js | 36 +++++++++++-- .../plugins/core/revisions/server/methods.js | 4 +- private/data/i18n/en.json | 5 +- 4 files changed, 86 insertions(+), 12 deletions(-) diff --git a/imports/plugins/core/revisions/client/components/publishControls.js b/imports/plugins/core/revisions/client/components/publishControls.js index 3b0e7497726..e7713f87aff 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 as 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 ( +