Title

Global

Methods

# buildFeature(options) → {FeatureType}

Higher Order Function which creates a feature

Parameters:
Name Type Description
options ResourceOptions

View Source admin-bro/src/backend/utils/build-feature/build-feature.ts, line 90

FeatureType
Example
const { buildFeature } = require('admin-bro/@core')

const feature = buildFeature({
  // resource options goes here.
})

# mergeResourceOptions(oldOptions, newOptions) → {ResourceOptions}

Merges 2 ResourceOptions together. Used by features

  • 'id', 'href', 'parent', 'sort' from newOptions override oldOptions
  • 'listProperties', 'showProperties', 'editProperties', 'filterProperties' are joined and made unique
  • all 'properties' from newOptions override properties from oldOptions
  • all 'actions' with their parameters from newOptions override oldOptions except hooks and handler - which are chained.
Parameters:
Name Type Description
oldOptions ResourceOptions
newOptions ResourceOptions

View Source admin-bro/src/backend/utils/build-feature/build-feature.ts, line 35

# populator(records)

Populates all references in records.

Usage

Take a look at an example action handler getting the Product record and populates it. We assume that Product has categoryId and it is marked as a 'reference' (PropertyOptions#reference) to a Category.

const { populator } = require('admin-bro')


// action handler for showing product with categories
const showProductsHandler = async (request, response, context) => {
  const { payload } = request
  const { _admin, currentAdmin } = context
  const ProductResource = _admin.findResource('Product')

  const product = await ProductResource.findOne()
  // product.populated is empty

  const [populatedProduct] = await populator([product])
  // populatedProduct.populated - has a categoryId filled with Category params

  return {
    record: record.toJSON(currentAdmin) // returns RecordJSON with populated field as well
  }
}

Where you might want to use it?

Populator is used in all built-in actions so you don't need to take care of populating fields on your own. Situation changes when you want to create a custom action and use data not from the context but right from the database query.

Parameters:
Name Type Description
records Array.<BaseRecord>
New:
  • In version 3.3

View Source admin-bro/src/backend/utils/populator/populator.ts, line 8

SoftwareBrothers

Proudly built and maintained by SoftwareBrothers

Software House with a passion for both JavaScript and TypeScript.

See what we do See what we believe in

Proudly built and maintained by

SoftwareBrothers