-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #524 from dadi/feature/datetime-in-list-view
DateTime formatted in list view
- Loading branch information
Showing
3 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import edit from './FieldDateTimeEdit' | ||
import list from './FieldDateTimeList' | ||
import filter from './FieldDateTimeFilter' | ||
|
||
export {edit, filter} | ||
export {edit, list, filter} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters