Skip to content

Commit

Permalink
Merge pull request #3156 from reactioncommerce/release-1.5.4
Browse files Browse the repository at this point in the history
Release 1.5.4
  • Loading branch information
spencern authored Oct 24, 2017
2 parents d62967b + 040c599 commit e560937
Show file tree
Hide file tree
Showing 57 changed files with 1,799 additions and 648 deletions.
53 changes: 35 additions & 18 deletions imports/plugins/core/checkout/server/methods/workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ import { Logger, Reaction } from "/server/api";

/* eslint no-shadow: 0 */

/**
* @file Methods for Workflow. Run these methods using `Meteor.call()`.
* @example Meteor.call("workflow/pushCartWorkflow", "coreCartWorkflow", "checkoutLogin");
*
* @namespace Methods/Workflow
*/
Meteor.methods({
/**
* workflow/pushCartWorkflow
* @name workflow/pushCartWorkflow
* @memberof Methods/Workflow
* @method
* @example Meteor.call("workflow/pushCartWorkflow", "coreCartWorkflow", "checkoutLogin");
* @summary updates cart workflow status
* @description status in the workflow is stored as the current active
* workflow step.
*
* @description status in the workflow is stored as the current active workflow step.
* first sets, second call moves status to next workflow
* additional calls do nothing
* user permissions to template are verified
Expand Down Expand Up @@ -206,11 +213,12 @@ Meteor.methods({
},

/**
* workflow/revertCartWorkflow
* @description if something was changed on the previous `cartWorkflow` steps
* @name workflow/revertCartWorkflow
* @memberof Methods/Workflow
* @method
* @summary if something was changed on the previous `cartWorkflow` steps,
* we need to revert to this step to renew the order
* @param {String} newWorkflowStatus - name of `cartWorkflow` step, which
* we need to revert
* @param {String} newWorkflowStatus - name of `cartWorkflow` step, which we need to revert
* @todo need tests
* @return {Number|Boolean} cart update results
*/
Expand Down Expand Up @@ -242,18 +250,17 @@ Meteor.methods({
},

/**
* workflow/pushOrderWorkflow
* Push the status as the current workflow step,
* @name workflow/pushOrderWorkflow
* @summary Update the order workflow: Push the status as the current workflow step,
* move the current status to completed worflow steps
*
* Step 1 meteor call to push a new workflow
* @description Step 1 meteor call to push a new workflow
* Meteor.call("workflow/pushOrderWorkflow", "coreOrderWorkflow", "processing", this);
* NOTE: "coreOrderWorkflow", "processing" will be combined into "coreOrderWorkflow/processing"
* and set as the status
*
* NOTE: "coreOrderWorkflow", "processing" will be combined into "coreOrderWorkflow/processing" and set as the status
* Step 2 (this method) of the "workflow/pushOrderWorkflow" flow; Try to update the current status
*
* @summary Update the order workflow
* @method
* @memberof Methods/Workflow
* @param {String} workflow workflow to push to
* @param {String} status - Workflow status
* @param {Order} order - Schemas.Order, an order object
Expand Down Expand Up @@ -284,10 +291,11 @@ Meteor.methods({
},

/**
* workflow/pullOrderWorkflow
* Push the status as the current workflow step,
* move the current status to completed worflow steps
* @name workflow/pullOrderWorkflow
* @description Push the status as the current workflow step, move the current status to completed worflow steps
* @summary Pull a previous order status
* @method
* @memberof Methods/Workflow
* @param {String} workflow workflow to push to
* @param {String} status - Workflow status
* @param {Order} order - Schemas.Order, an order object
Expand All @@ -313,6 +321,15 @@ Meteor.methods({
return result;
},

/**
* @name workflow/pushItemWorkflow
* @method
* @memberof Methods/Workflow
* @param {String} status Workflow status
* @param {Object} order Schemas.Order, an order object
* @param {String[]} itemIds Array of item IDs
* @return {Boolean} true if update was successful
*/
"workflow/pushItemWorkflow": function (status, order, itemIds) {
check(status, String);
check(order, Object);
Expand Down
53 changes: 34 additions & 19 deletions imports/plugins/core/components/lib/components.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
import { compose, setDisplayName } from "recompose";

/**
* @file Reaction Components API
*
* @module components
*/

export const Components = {}; // populated with final wrapped components
export const ComponentsTable = {}; // storage for separate elements of each component


/**
* Register a component and container(s) with a name.
* The raw component can then be extended or replaced.
* @example // Register a component and container(s) with a name.
* // The raw component can then be extended or replaced.
*
* Structure of a component in the list:
* // Structure of a component in the list:
*
* ComponentsTable.MyComponent = {
* name: 'MyComponent',
* hocs: [fn1, fn2],
* rawComponent: React.Component
* }
*
* @name registerComponent
* @method
* @memberof Components
* @param {String} name The name of the component to register.
* @param {React.Component} rawComponent Interchangeable/extendable component.
* @param {Function|Array} hocs The HOCs to wrap around the raw component.
Expand All @@ -43,11 +38,13 @@ export function registerComponent(name, rawComponent, hocs = []) {


/**
* Register containers (HOC) with a name.
* @name registerHOC
* @method
* @summary Register containers (HOC) with a name.
* If some containers already exist for the component, they will be extended.
* @param {String} name The name of the component to register.
* @param {Function|Array} hocs The HOCs to wrap around the raw component.
*
* @memberof Components
* @returns {undefined}
*/
export function registerHOC(name, hocs = []) {
Expand Down Expand Up @@ -81,9 +78,12 @@ export function registerHOC(name, hocs = []) {


/**
* Get a component registered with registerComponent(name, component, ...hocs).
* @name getComponent
* @method
* @summary Get a component registered with registerComponent(name, component, ...hocs).
* @param {String} name The name of the component to get.
* @return {Function|React.Component} A (wrapped) React component
* @memberof Components
*/
export function getComponent(name) {
const component = ComponentsTable[name];
Expand All @@ -99,12 +99,15 @@ export function getComponent(name) {


/**
* Replace a Reaction component with a new component and optionally add one or more higher order components.
* @name replaceComponent
* @method
* @summary Replace a Reaction component with a new component and optionally add one or more higher order components.
* This function keeps track of the previous HOCs and wraps the new HOCs around previous ones
* @param {String} name The name of the component to register.
* @param {React.Component} newComponent Interchangeable/extendable component.
* @param {Function|Array} hocs The HOCs to compose with the raw component.
* @returns {Function|React.Component} A component callable with Components[name]
* @memberof Components
*/
export function replaceComponent(name, newComponent, hocs = []) {
const previousComponent = ComponentsTable[name];
Expand All @@ -120,26 +123,35 @@ export function replaceComponent(name, newComponent, hocs = []) {


/**
* Get the raw UI component without any possible HOCs wrapping it.
* @name getRawComponent
* @method
* @summary Get the raw UI component without any possible HOCs wrapping it.
* @param {String} name The name of the component to get.
* @returns {Function|React.Component} A React component
* @memberof Components
*/
export const getRawComponent = (name) => ComponentsTable[name].rawComponent;


/**
* Get the raw UI component without any possible HOCs wrapping it.
* @name getHOCs
* @method
* @summary Get the raw UI component without any possible HOCs wrapping it.
* @param {String} name The name of the component to get.
* @returns {Function|React.Component} Array of HOCs
* @memberof Components
*/
export const getHOCs = (name) => ComponentsTable[name].hocs;


/**
* Wrap a new component with the HOCs from a different component
* @name copyHOCs
* @method
* @summary Wrap a new component with the HOCs from a different component
* @param {String} sourceComponentName The name of the component to get the HOCs from
* @param {Function|React.Component} targetComponent Component to wrap
* @returns {Function|React.Component} A new component wrapped with the HOCs of the source component
* @memberof Components
*/
export function copyHOCs(sourceComponentName, targetComponent) {
const sourceComponent = ComponentsTable[sourceComponentName];
Expand All @@ -148,9 +160,12 @@ export function copyHOCs(sourceComponentName, targetComponent) {


/**
* Populate the final Components object with the contents of the lookup table.
* @name loadRegisteredComponents
* @method
* @summary Populate the final Components object with the contents of the lookup table.
* This should only be called once on app startup.
* @returns {Object} An object containing all of the registered components
* @memberof Components
**/
export function loadRegisteredComponents() {
Object.keys(ComponentsTable).map((name) => {
Expand Down
6 changes: 0 additions & 6 deletions imports/plugins/core/components/lib/composer/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import hoistStatics from "hoist-non-react-statics";
import _ from "lodash";
import { getDisplayName } from "recompose";

/**
* @file Reaction Components API
*
* @module components
*/

export default function compose(dataLoader, options = {}) {
return function (Child) {
const {
Expand Down
23 changes: 20 additions & 3 deletions imports/plugins/core/components/lib/composer/tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@ import compose from "./compose";

/**
* @file **Reaction Components API** - Most of the React components in the Reaction UI can be replaced or extended with the API outlined here. This allows anyone to create a custom plugin that can easily change the look of the UI and/or extend its functionality without having to edit core Reaction code. See {@link https://docs.reactioncommerce.com/reaction-docs/master/components-api full tutorial and documentation}.
* @module components
*
* @example // Register a component and container(s) with a name.
* // The raw component can then be extended or replaced.
*
* // Structure of a component in the list:
*
* ComponentsTable.MyComponent = {
* name: 'MyComponent',
* hocs: [fn1, fn2],
* rawComponent: React.Component
* }
* @namespace Components
*/

/**
* getTrackerLoader creates a Meteor Tracker to watch dep updates from
* @name getTrackerLoader
* @summary getTrackerLoader creates a Meteor Tracker to watch dep updates from
* the passed in reactiveMapper function
* @param {Function} reactiveMapper data fetching function to bind to a tracker
* @return {Function} composed function
* @memberof Components
* @private
*/
function getTrackerLoader(reactiveMapper) {
return (props, onData, env) => {
Expand All @@ -33,10 +47,13 @@ function getTrackerLoader(reactiveMapper) {


/**
* A higher order component to wrap a reactive function with Meteor's Tracker
* @name composeWithTracker
* @method
* @summary A higher order component to wrap a reactive function with Meteor's Tracker
* @param {Function} reactiveMapper data fetching function to bind to a tracker
* @param {React.Component|Boolean|Object} options can be a custom loader, false (to disable), or a full options object
* @return {Function} composed function
* @memberof Components
*/
export function composeWithTracker(reactiveMapper, options) {
let composeOptions = {};
Expand Down
31 changes: 20 additions & 11 deletions imports/plugins/core/components/lib/hoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ import { Roles } from "meteor/alanning:roles";
import { Accounts, Groups } from "/lib/collections";
import { composeWithTracker } from "./composer";

/**
* @file Reaction Components API
*
* @module components
*/

let Reaction;

if (Meteor.isClient) {
Expand All @@ -20,9 +14,12 @@ if (Meteor.isClient) {


/**
* A wrapper to reactively inject the current user into a component
* @name withCurrentUser
* @method
* @summary A wrapper to reactively inject the current user into a component
* @param {Function|React.Component} component - the component to wrap
* @return {Function} the new wrapped component with a "currentUser" prop
* @memberof Components
*/
export function withCurrentUser(component) {
return composeWithTracker((props, onData) => {
Expand All @@ -32,10 +29,13 @@ export function withCurrentUser(component) {


/**
* A wrapper to reactively inject the current account into a component.
* @name withCurrentAccount
* @method
* @summary A wrapper to reactively inject the current account into a component.
* This assumes you have signed up and are not an anonymous user.
* @param {Function|React.Component} component - the component to wrap
* @return {Function} the new wrapped component with a "currentAccount" prop
* @memberof Components
*/
export function withCurrentAccount(component) {
return composeWithTracker((props, onData) => {
Expand Down Expand Up @@ -64,10 +64,13 @@ export function withCurrentAccount(component) {


/**
* A wrapper to reactively inject the current user's admin status.
* @name withIsAdmin
* @method
* @summary A wrapper to reactively inject the current user's admin status.
* Sets a boolean 'isAdmin' prop on the wrapped component.
* @param {Function|React.Component} component - the component to wrap
* @return {Function} the new wrapped component with an "isAdmin" prop
* @memberof Components
*/
export function withIsAdmin(component) {
return composeWithTracker((props, onData) => {
Expand All @@ -76,11 +79,14 @@ export function withIsAdmin(component) {
}

/**
* A wrapper to reactively inject a user's permission based on group or roles
* @name withPermissions
* @method
* @summary A wrapper to reactively inject a user's permission based on group or roles
* Group access is given to users at that group level and above
* @param {Array|String} roles String or array of strings of permissions to check. default: roles=["guest", "anonymous"]
* @param {String} group Slug title of a group to check against. Group option supercedes roles option. default: group="customer".
* @return {Function} the new wrapped component with a "hasPermissions" prop
* @memberof Components
*/
export function withPermissions({ roles = ["guest", "anonymous"], group }) {
return composeWithTracker((props, onData) => {
Expand Down Expand Up @@ -110,10 +116,13 @@ export function withPermissions({ roles = ["guest", "anonymous"], group }) {


/**
* A wrapper to reactively inject the current user's owner status.
* @name withIsOwner
* @method
* @summary A wrapper to reactively inject the current user's owner status.
* Sets a boolean 'isOwner' prop on the wrapped component.
* @param {Function|React.Component} component - the component to wrap
* @return {Function} the new wrapped component with an "isOwner" prop
* @memberof Components
*/
export function withIsOwner(component) {
return composeWithTracker((props, onData) => {
Expand Down
Loading

0 comments on commit e560937

Please sign in to comment.