-
-
Notifications
You must be signed in to change notification settings - Fork 143
Issue434 - Clear date in DatePickerSingle and DatePickerRange #435
Changes from 5 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2789,6 +2789,9 @@ | |
}, | ||
{ | ||
"name": "string" | ||
}, | ||
{ | ||
"name": "bool" | ||
} | ||
] | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import {DateRangePicker} from 'react-dates'; | ||
import moment from 'moment'; | ||
import PropTypes from 'prop-types'; | ||
import R from 'ramda'; | ||
import React, {Component} from 'react'; | ||
import './css/[email protected]'; | ||
|
||
import convertToMoment from '../utils/convertToMoment'; | ||
|
||
/** | ||
* DatePickerRange is a tailor made component designed for selecting | ||
|
@@ -30,22 +30,15 @@ export default class DatePickerRange extends Component { | |
* - user modifiable attributes | ||
* - moment converted attributes | ||
*/ | ||
const newState = {}; | ||
const momentProps = [ | ||
|
||
const newState = convertToMoment(newProps, [ | ||
'start_date', | ||
'end_date', | ||
'initial_visible_month', | ||
'max_date_allowed', | ||
'min_date_allowed', | ||
]; | ||
momentProps.forEach(prop => { | ||
if (R.type(newProps[prop]) !== 'Undefined') { | ||
newState[prop] = moment(newProps[prop]); | ||
} | ||
if (prop === 'max_date_allowed' && R.has(prop, newState)) { | ||
newState[prop].add(1, 'days'); | ||
} | ||
}); | ||
]); | ||
|
||
this.setState(newState); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ import Tab from './components/Tab.react'; | |
import Store from './components/Store.react'; | ||
import LogoutButton from './components/LogoutButton.react'; | ||
|
||
import './components/css/[email protected]'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving this style dependency to the top level -- jest is not able to handle css files correctly atm |
||
|
||
export { | ||
Checklist, | ||
ConfirmDialog, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import moment from 'moment'; | ||
import R from 'ramda'; | ||
|
||
export default (newProps, momentProps) => { | ||
const dest = {}; | ||
|
||
momentProps.forEach(key => { | ||
const value = newProps[key]; | ||
|
||
switch (R.type(value)) { | ||
case 'Undefined': | ||
return; | ||
case 'Null': | ||
dest[key] = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Common logic between Single and Range + the new |
||
return; | ||
default: | ||
dest[key] = moment(value); | ||
} | ||
|
||
if (key === 'max_date_allowed' && R.has(key, dest)) { | ||
dest[key].add(1, 'days'); | ||
} | ||
}); | ||
|
||
return dest; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import DatePickerRange from '../../src/components/DatePickerRange.react'; | ||
import R from 'ramda'; | ||
import React from 'react'; | ||
import { mount, render } from 'enzyme'; | ||
|
||
test('DatePickerRange renders', () => { | ||
const dps = render(<DatePickerRange />); | ||
|
||
expect(dps.html()).toBeDefined(); | ||
}); | ||
|
||
describe('Date can be set properly', () => { | ||
const defaultProps = { | ||
|
||
}; | ||
|
||
test('null date is not converted by moment', () => { | ||
const props = R.merge(defaultProps, { | ||
end_date: null, | ||
start_date: null | ||
}); | ||
|
||
const dps = mount(<DatePickerRange {...props} />); | ||
|
||
expect(dps.props()).toBeDefined(); | ||
expect(dps.props().end_date).toEqual(props.end_date); | ||
expect(dps.state().end_date).toEqual(null); | ||
expect(dps.props().start_date).toEqual(props.start_date); | ||
expect(dps.state().start_date).toEqual(null); | ||
}); | ||
|
||
test('valid date is not converted by moment', () => { | ||
const props = R.merge(defaultProps, { | ||
end_date: "2019-01-01", | ||
start_date: "2019-01-01" | ||
}); | ||
|
||
const dps = mount(<DatePickerRange {...props} />); | ||
|
||
expect(dps.props()).toBeDefined(); | ||
expect(dps.props().end_date).toEqual(props.end_date); | ||
expect(dps.state().end_date).not.toEqual(null); | ||
expect(dps.props().start_date).toEqual(props.start_date); | ||
expect(dps.state().start_date).not.toEqual(null); | ||
}); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basic tests for range: passing null sets null in the state, otherwise it sets a value (do not care about the exact value atm, just differentiating the 2 cases) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import DatePickerSingle from '../../src/components/DatePickerSingle.react'; | ||
import R from 'ramda'; | ||
import React from 'react'; | ||
import { mount, render } from 'enzyme'; | ||
|
||
test('DatePickerSingle renders', () => { | ||
const dps = render(<DatePickerSingle />); | ||
|
||
expect(dps.html()).toBeDefined(); | ||
}); | ||
|
||
describe('Date can be set properly', () => { | ||
const defaultProps = { | ||
|
||
}; | ||
|
||
test('null date is not converted by moment', () => { | ||
const props = R.merge(defaultProps, { | ||
date: null | ||
}); | ||
|
||
const dps = mount(<DatePickerSingle {...props} />); | ||
|
||
expect(dps.props()).toBeDefined(); | ||
expect(dps.props().date).toEqual(props.date); | ||
expect(dps.state().date).toEqual(null); | ||
}); | ||
|
||
test('valid date is not converted by moment', () => { | ||
const props = R.merge(defaultProps, { | ||
date: "2019-01-01" | ||
}); | ||
|
||
const dps = mount(<DatePickerSingle {...props} />); | ||
|
||
expect(dps.props()).toBeDefined(); | ||
expect(dps.props().date).toEqual(props.date); | ||
expect(dps.state().date).not.toEqual(null); | ||
}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basic tests for single: passing null sets null in the state, otherwise it sets a value (do not care about the exact value atm, just differentiating the 2 cases) |
||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some previous commit the metadata was not updated correctly.