Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated publish controls UX and fixing issues #1473

Merged
merged 3 commits into from
Oct 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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) => {
Expand All @@ -66,6 +100,18 @@ class PublishControls extends Component {
return null;
}

renderPublishButton() {
return (
<Button
disabled={this.hasChanges === false}
i18nKeyLabel="app.publishChanges"
label="Publish Changes"
onClick={this.handlePublishClick}
status="success"
/>
);
}

render() {
if (this.props.isEnabled) {
return (
Expand All @@ -76,12 +122,7 @@ class PublishControls extends Component {
onClick={this.handleToggleShowChanges}
status="link"
/>
<Button
i18nKeyLabel="app.publishChanges"
label="Publish Changes"
onClick={this.handlePublishClick}
primary={true}
/>
{this.renderPublishButton()}
{this.showDiffs && <hr />}
{this.renderChanges()}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Revisions } from "/lib/collections";
import { Meteor } from "meteor/meteor";
import TranslationProvider from "/imports/plugins/core/ui/client/providers/translationProvider";
import { isRevisionControlEnabled } from "../../lib/api";
import { i18next } from "/client/api";

/**
* Publish container is a stateless container component connected to Meteor data source.
Expand Down Expand Up @@ -35,7 +36,22 @@ export function handlePublishClick(revisions) {
const documentIds = revisions.map((revision) => {
return revision.documentId;
});
Meteor.call("revisions/publish", documentIds);

Meteor.call("revisions/publish", documentIds, (error, result) => {
if (result === true) {
const message = i18next.t("revisions.changedPublished", {
defaultValue: "Changes published successfully"
});

Alerts.toast(message, "success");
} else {
const message = i18next.t("revisions.noChangesPublished", {
defaultValue: "There are no changes to publish"
});

Alerts.toast(message, "warning");
}
});
}
}

Expand All @@ -45,8 +61,22 @@ function composer(props, onData) {

if (subscription.ready()) {
const revisions = Revisions.find({
documentId: {
$in: props.documentIds
"$or": [
{
documentId: {
$in: props.documentIds
}
},
{
"documentData.ancestors": {
$in: props.documentIds
}
}
],
"workflow.status": {
$nin: [
"revision/published"
]
}
}).fetch();

Expand Down
4 changes: 2 additions & 2 deletions imports/plugins/core/revisions/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ Meteor.methods({
let updatedDocuments = 0;

if (revisions) {
for (let revision of revisions) {
for (const revision of revisions) {
const res = Products.update({
_id: revision.documentId
}, {
Expand All @@ -81,6 +81,6 @@ Meteor.methods({
return true;
}

throw new Meteor.Error(403, "Forbidden", "Could not publish product revision");
return false;
}
});
5 changes: 4 additions & 1 deletion private/data/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,10 @@
"unpublishedChanges": "Unpublished Changes",
"publishChanges": "Publish Changes",
"showChanges": "Show Changes",
"hideChanges": "Hide Changes"
"hideChanges": "Hide Changes",
"changedPublished": "Changes published successfully",
"noChanges": "No Changes",
"noChangesPublished": "There are no changes to publish"
},
"address": {
"country": "Country",
Expand Down