Skip to content

Commit

Permalink
Merge pull request #4238 from reactioncommerce/feat-4237-mikemurray-r…
Browse files Browse the repository at this point in the history
…emove-revisions

Performance/Refactor remove revision control
  • Loading branch information
aldeed authored May 22, 2018
2 parents a1ca3cd + 0e1421e commit accc6b7
Show file tree
Hide file tree
Showing 106 changed files with 278 additions and 3,674 deletions.
1 change: 0 additions & 1 deletion imports/collections/defineCollections.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export default function defineCollections(db, collections) {
Orders: db.collection("Orders"),
Packages: db.collection("Packages"),
Products: db.collection("Products"),
Revisions: db.collection("Revisions"),
roles: db.collection("roles"),
SellerShops: db.collection("SellerShops"),
Shipping: db.collection("Shipping"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@ import { Components } from "@reactioncommerce/reaction-components";
import {
Button,
FlatButton,
IconButton,
Divider,
DropDownMenu,
MenuItem,
Switch,
Icon
} from "/imports/plugins/core/ui/client/components";
import SimpleDiff from "./simpleDiff";
import { Translatable } from "/imports/plugins/core/ui/client/providers";

/** TMP **/
Expand Down Expand Up @@ -176,19 +171,6 @@ class PublishControls extends Component {
return false;
}

renderChanges() {
if (this.showDiffs) {
const diffs = this.props.revisions.map((revision) => <SimpleDiff diff={revision.diff} key={revision._id} />);

return (
<div>
{diffs}
</div>
);
}
return null;
}

renderDeletionStatus() {
if (this.hasChanges) {
if (this.primaryRevision && this.primaryRevision.documentData.isDeleted) {
Expand Down Expand Up @@ -232,48 +214,6 @@ class PublishControls extends Component {
);
}

renderMoreOptionsButton() {
return (
<DropDownMenu
buttonElement={<IconButton icon={"fa fa-ellipsis-v"}/>}
handleMenuItemChange={this.handleAction}
>
<MenuItem label="Administrator" value="administrator" />
<MenuItem label="Customer" value="customer" />
<Divider />
<MenuItem
i18nKeyLabel="app.public"
icon="fa fa-unlock"
label="Public"
selectLabel="Public"
value="public"
/>
<MenuItem
i18nKeyLabel="app.private"
label="Private"
icon="fa fa-lock"
selectLabel="Public"
value="private"
/>
<Divider />
<MenuItem
disabled={this.hasChanges === false}
i18nKeyLabel="revisions.discardChanges"
icon="fa fa-undo"
label="Discard Changes"
value="discard"
/>
<Divider />
<MenuItem
i18nKeyLabel="app.archive"
icon="fa fa-trash-o"
label="Archive"
value="archive"
/>
</DropDownMenu>
);
}

renderViewControls() {
if (this.props.showViewAsControls) {
let tooltip = "Private";
Expand Down Expand Up @@ -304,19 +244,6 @@ class PublishControls extends Component {
return null;
}

renderUndoButton() {
return (
<FlatButton
disabled={this.hasChanges === false}
tooltip="Discard Changes"
i18nKeyTooltip="revisions.discardChanges"
icon={"fa fa-undo"}
value="discard"
onClick={this.handleAction}
/>
);
}

renderArchiveButton() {
return (
<FlatButton
Expand Down Expand Up @@ -378,20 +305,14 @@ class PublishControls extends Component {
}

render() {
if (this.props.isEnabled) {
return (
<Components.ToolbarGroup lastChild={true}>
{this.renderDeletionStatus()}
{this.renderUndoButton()}
{this.renderArchiveButton()}
{this.renderViewControls()}
{this.renderPublishButton()}
{/* this.renderMoreOptionsButton() */}
</Components.ToolbarGroup>
);
}

return null;
return (
<Components.ToolbarGroup lastChild={true}>
{this.renderDeletionStatus()}
{this.renderArchiveButton()}
{this.renderViewControls()}
{this.renderPublishButton()}
</Components.ToolbarGroup>
);
}
}

Expand Down
83 changes: 83 additions & 0 deletions imports/plugins/core/catalog/client/containers/publishContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import { composeWithTracker } from "@reactioncommerce/reaction-components";
import PublishControls from "../components/publishControls";
import { Meteor } from "meteor/meteor";
import TranslationProvider from "/imports/plugins/core/ui/client/providers/translationProvider";
import { Reaction, i18next } from "/client/api";

/*
* PublishContainer is a container component connected to Meteor data source.
*/
class PublishContainer extends Component {
publishToCatalog(collection, documentIds) {
Meteor.call(`catalog/publish/${collection}`, documentIds, (error, result) => {
if (result) {
Alerts.toast(i18next.t("admin.catalogProductPublishSuccess", { defaultValue: "Product published to catalog" }), "success");
} else if (error) {
Alerts.toast(error.message, "error");
}
});
}

handlePublishClick = () => {
const productIds = this.props.documents
.filter((doc) => doc.type === "simple")
.map((doc) => doc._id);

this.publishToCatalog("products", productIds);
}

handlePublishActions = (event, action) => {
if (action === "archive" && this.props.onAction) {
this.props.onAction(event, action, this.props.documentIds);
}
}

render() {
return (
<TranslationProvider>
<PublishControls
documentIds={this.props.documentIds}
documents={this.props.documents}
isEnabled={this.props.isEnabled}
onPublishClick={this.handlePublishClick}
onAction={this.handlePublishActions}
onVisibilityChange={this.props.onVisibilityChange}
isPreview={this.props.isPreview}
/>
</TranslationProvider>
);
}
}

PublishContainer.propTypes = {
documentIds: PropTypes.arrayOf(PropTypes.string),
documents: PropTypes.arrayOf(PropTypes.object),
isEnabled: PropTypes.bool,
isPreview: PropTypes.bool,
onAction: PropTypes.func,
onPublishSuccess: PropTypes.func,
onVisibilityChange: PropTypes.func,
product: PropTypes.object
};

function composer(props, onData) {
const viewAs = Reaction.getUserPreferences("reaction-dashboard", "viewAs", "administrator");

if (Array.isArray(props.documentIds) && props.documentIds.length) {
onData(null, {
documentIds: props.documentIds,
documents: props.documents,
isPreview: viewAs === "customer"
});

return;
}

onData(null, {
isPreview: viewAs === "customer"
});
}

export default composeWithTracker(composer)(PublishContainer);
Loading

0 comments on commit accc6b7

Please sign in to comment.