Skip to content

Commit

Permalink
Merge pull request #524 from dadi/feature/datetime-in-list-view
Browse files Browse the repository at this point in the history
DateTime formatted in list view
  • Loading branch information
eduardoboucas committed Oct 11, 2018
2 parents 91bda30 + e76c625 commit 5a4260f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
3 changes: 2 additions & 1 deletion frontend/components/FieldDateTime/FieldDateTime.jsx
@@ -1,4 +1,5 @@
import edit from './FieldDateTimeEdit'
import list from './FieldDateTimeList'
import filter from './FieldDateTimeFilter'

export {edit, filter}
export {edit, list, filter}
39 changes: 39 additions & 0 deletions frontend/components/FieldDateTime/FieldDateTimeList.jsx
@@ -0,0 +1,39 @@
'use strict'

import {h, Component} from 'preact'
import proptypes from 'proptypes'

import DateTime from 'lib/datetime'

/**
* Component for rendering API fields of type String on a list view.
*/
export default class FieldDateTimeList extends Component {
static propTypes = {
/**
* App config.
*/
config: proptypes.object,

/**
* The field schema.
*/
schema: proptypes.object

/**
* The field value.
*/
value: proptypes.string
}

render() {
const {config, schema, value} = this.props

// If there's no value, we return `null`.
if (!value) return null

const dateTimeObj = new DateTime(value)

return (dateTimeObj.isValid() && dateTimeObj.format(config.formats.date.long)) || value
}
}
1 change: 1 addition & 0 deletions frontend/containers/DocumentList/DocumentList.jsx
Expand Up @@ -512,6 +512,7 @@ class DocumentList extends Component {
if (FieldComponentList) {
return (
<FieldComponentList
config={state.app.config}
collection={collection}
currentApi={api}
schema={schema}
Expand Down

0 comments on commit 5a4260f

Please sign in to comment.