Skip to content

Commit

Permalink
[form-builder] Add RichDate to input resolver + add converter for dat…
Browse files Browse the repository at this point in the history
…e => richDate
  • Loading branch information
bjoerge committed Sep 20, 2017
1 parent 7737579 commit 0c27459
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,14 @@ export default class InvalidValue extends React.PureComponent {
onFocus={e => e.target.select()}
value={(value && typeof value === 'object') ? JSON.stringify(value, null, 2) : value}
/>
<DefaultButton onClick={this.handleClearClick} color="danger">
Clear
</DefaultButton>
{}
{converters.map(converter => (
<DefaultButton onClick={() => this.handleConvertTo(converter.convert(value))} color="danger">
Convert to {converter.to}: <code>{JSON.stringify(converter.convert(value))}</code>
<DefaultButton onClick={() => this.handleConvertTo(converter.convert(value))} color="primary">
Convert value to {converter.to}
</DefaultButton>
))}
<DefaultButton onClick={this.handleClearClick} color="danger">
Remove value
</DefaultButton>
</Details>
</div>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const FALSEY_STRINGS = ['false', 'no', 'false', '0', 'null']
const BOOL_STRINGS = TRUTHY_STRINGS.concat(FALSEY_STRINGS)

const TRUE = () => true
const is = typeName => val => (val && val._type) === typeName

export default {
string: {
Expand All @@ -15,6 +16,12 @@ export default {
convert: value => TRUTHY_STRINGS.includes(value.toLowerCase()) || !FALSEY_STRINGS.includes(value.toLowerCase())
}
},
date: {
richDate: {
test: is('date'),
convert: value => Object.assign({}, value, {_type: 'richDate'})
}
},
number: {
string: {
test: TRUE,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react'
import customResolver from 'part:@sanity/form-builder/input-resolver?'

import ArrayInput from 'part:@sanity/form-builder/input/array?'
import BooleanInput from 'part:@sanity/form-builder/input/boolean?'
import DateInput from 'part:@sanity/form-builder/input/date?'
import EmailInput from 'part:@sanity/form-builder/input/email?'
import GeoPointInput from 'part:@sanity/form-builder/input/geopoint?'
import NumberInput from 'part:@sanity/form-builder/input/number?'
Expand All @@ -19,6 +19,8 @@ import ImageInput from '../inputs/Image'

import resolveReference from './resolveReference'

const DeprecatedDateInput = RichDateInput

const typeInputMap = {
array: ArrayInput,
object: ObjectInput,
Expand All @@ -27,7 +29,7 @@ const typeInputMap = {
string: StringInput,
text: TextInput,
reference: ReferenceInput,
date: DateInput,
date: DeprecatedDateInput,
richDate: RichDateInput,
email: EmailInput,
file: FileInput,
Expand Down

0 comments on commit 0c27459

Please sign in to comment.