Open daedalus28 opened 5 years ago
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)
)
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 passfield
as the third param here: https://github.com/smartprocure/contexture-react/blob/master/src/exampleTypes/ResultTable.js#L290The 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