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

jsdoc: format Invoice React component into @module #3141

Merged
merged 3 commits into from
Oct 24, 2017
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
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
45 changes: 33 additions & 12 deletions imports/plugins/core/orders/client/components/invoice.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,26 @@ import LineItems from "./lineItems";
import InvoiceActions from "./invoiceActions";

/**
* @summary React component for displaying the `invoice` section on the orders sideview
* @param {Object} props - React PropTypes
* @property {Object} invoice - An object representing an invoice
* @property {Object} order - An object representing an order
* @property {Bool} discounts - A boolean indicating whether discounts are enabled
* @property {Array} refunds - An array/list of refunds
* @property {Bool} paymentCaptured - A boolean indicating whether payment has been captured
* @property {Bool} canMakeAdjustments - A boolean indicating whether adjustments could be made on total payment
* @property {Bool} hasRefundingEnabled - A boolean indicating whether payment supports refunds
* @property {Bool} isFetching - A boolean indicating whether refund list is being loaded
* @return {Node} React node containing component for displaying the `invoice` section on the orders sideview
*/
* @file Invoice is a React Component for displaying the `invoice` section on the orders sideview
* @module Invoice
* @extends Components
*/

class Invoice extends Component {
/**
* @name Invoice propTypes
* @type {propTypes}
* @param {Object} props - React PropTypes
* @property {Object} invoice - An object representing an invoice
* @property {Object} order - An object representing an order
* @property {Bool} discounts - A boolean indicating whether discounts are enabled
* @property {Array} refunds - An array/list of refunds
* @property {Bool} paymentCaptured - A boolean indicating whether payment has been captured
* @property {Bool} canMakeAdjustments - A boolean indicating whether adjustments could be made on total payment
* @property {Bool} hasRefundingEnabled - A boolean indicating whether payment supports refunds
* @property {Bool} isFetching - A boolean indicating whether refund list is being loaded
* @return {Node} React node containing component for displaying the `invoice` section on the orders sideview
*/
static propTypes = {
canMakeAdjustments: PropTypes.bool,
discounts: PropTypes.bool,
Expand All @@ -36,6 +43,8 @@ class Invoice extends Component {
}

/**
* @name formatDate()
* @method
* @summary Formats dates
* @param {Number} context - the date to be formatted
* @param {String} block - the preferred format
Expand All @@ -47,6 +56,8 @@ class Invoice extends Component {
}

/**
* @name handleClick()
* @method
* @summary Handle clicking the add discount link
* @param {Event} event - the event that fired
* @returns {null} null
Expand All @@ -59,6 +70,8 @@ class Invoice extends Component {
}

/**
* @name renderDiscountForm()
* @method
* @summary Displays the discount form
* @returns {null} null
*/
Expand All @@ -81,6 +94,8 @@ class Invoice extends Component {
}

/**
* @name renderRefundsInfo()
* @method
* @summary Displays the refund information after the order payment breakdown on the invoice
* @returns {null} null
*/
Expand Down Expand Up @@ -108,6 +123,8 @@ class Invoice extends Component {
}

/**
* @name renderTotal()
* @method
* @summary Displays the total payment form
* @returns {null} null
*/
Expand All @@ -124,6 +141,8 @@ class Invoice extends Component {
}

/**
* @name renderConditionalDisplay()
* @method
* @summary Displays either refunds info or the total payment form
* @returns {null} null
*/
Expand All @@ -148,6 +167,8 @@ class Invoice extends Component {
}

/**
* @name renderInvoice()
* @method
* @summary Displays the invoice form with broken down payment info
* @returns {null} null
*/
Expand Down