Class: Orders

Orders


new Orders()

React component consuming a Order Data Entity collection to feed a grid.

React component consuming a Order Data Entity collection to feed a grid
Author:
Source:

Extends

  • React.Component

Members


entity

Entity name which this component represents to.

Entity name which this component represents to
Source:

foundation

access to foundation instance.

access to foundation instance
Source:

onAddDocEventListener

listen to add Order Data Entity change event on Data API.

listen to add Order Data Entity change event on Data API
Source:

onDeleteDocEventListener

listen to delete Order Data Entity change event on Data API.

listen to delete Order Data Entity change event on Data API
Source:

onEditDocEventListener

listen to edit Order Data Entity change event on Data API.

listen to edit Order Data Entity change event on Data API
Source:

pagination

default pagination to list data.

default pagination to list data
Source:

state

component state.

component state
Source:

Methods


<async, static> componentDidMount()

Called immediately after a component is mounted. Setting state here will trigger re-rendering.

Once component is monted we are now ready to start listen to changes on Order data entity and get a list of order in database to fill out the state.orders
Source:
Example
componentDidMount() {
  const { Order } = this.foundation.data

  this.onAddDocEventListener = Order.on(
    'add',
    handlerOnAddDocEventListener.bind(this)
  )

  this.onEditDocEventListener = Order.on(
    'edit',
    handlerOnEditDocEventListener.bind(this)
  )

  this.onDeleteDocEventListener = Order.on(
    'delete',
    handlerOnDeleteDocEventListener.bind(this)
  )

  const { error, data } = await Order.find({}, { ...this.pagination })
  if (!error) {
    this.setState({ orders: orders.data })
  }
}

<static> componentWillUnmount()

Called immediately before a component is destroyed. Perform any necessary cleanup in this method, such as cancelled network requests, or cleaning up any DOM elements created in componentDidMount.

lets stop listen to Order Data State Change Events
Source:
Example
componentWillUnmount() {
  const { Order } = this.foundation.data
  Order.stopListenTo(this.onAddDocEventListener)
  Order.stopListenTo(this.onEditDocEventListener)
  Order.stopListenTo(this.onDeleteDocEventListener)
}

<static> handleDeleteOrder(event, __id)

Event handler that Deletes a order

Once component is monted we are now ready to start listen to changes on Order data entity and get a list of order in database to fill out the state.orders
Parameters:
Name Type Description
event event The HTML event triggered on User interation
__id number The primaryKey value of the record willing to be deleted
Source:
Example
handleDeleteOrder(e, ___id) {
  const { Order } = this.foundation.data
  e.preventDefault()
  swal({
    title: 'Are you sure?',
    text: 'Once deleted, you will not be able to recover this!',
    icon: 'warning',
    buttons: true,
    dangerMode: true
  }).then(async (willDelete) => {
    if (willDelete) {
      const r = await Order.delete(___id)
      if (r.error) {
        swal('Database error', e.error.message, 'error')
        return
      }
      swal('Poof! The order has been deleted!', {
        icon: 'success'
      })
      return <Redirect to = '/dashboard' / >
    } else {
      swal('The Order is safe!')
    }
  })
}

// <a color='primary' href='#' onClick={e => this.handleDeleteOrder(e, doc.__id)}>[delete]</a>

<async, static> render()

Component render function.

Renders a grid of Orders
Source: