Skip to content
This repository has been archived by the owner on Jan 31, 2023. It is now read-only.

Add displayDefault to ResultTable #279

Open
daedalus28 opened this issue Aug 1, 2019 · 1 comment
Open

Add displayDefault to ResultTable #279

daedalus28 opened this issue Aug 1, 2019 · 1 comment

Comments

@daedalus28
Copy link
Member

This line: https://github.com/smartprocure/contexture-react/blob/master/src/exampleTypes/ResultTable.js#L288

Replace the x => x with a parameterized default display function. Also pass field as the third param here: https://github.com/smartprocure/contexture-react/blob/master/src/exampleTypes/ResultTable.js#L290

The motivation is to allow end users to customize the default - e.g., to look at field types on schemas to automatically format by type. We could maybe also pass fields or even a "schemaField" equivalent (the destructed props there) as param 4

@daedalus28
Copy link
Member Author

daedalus28 commented Aug 1, 2019

for more context, these were recently written which partially duplicate functionality in ResultTable, but also provide way more intelligent defaults which should drastically reduce the number of times we need a display function:

let fieldFormatters = {
  date: toFullDate,
  number: toNumber,
  mongoId: formatMongoId,
}
let renderSchemaField = _.curry((schemas, schema, record, field) => {
  let schemaField = getSchemaField(schemas, schema, field)
  return schemaField.display
    ? x => schemaField.display(x, record)
    : _.getOr(safeRender, schemaField.typeDefault, fieldFormatters)
})

let renderSchemaLabel = _.curry(
  (schemas, schema, record, field) =>
    getSchemaField(schemas, schema, field).label || _.startCase(field)
)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant