chore(xo-web/scheduling): compute TimePicker max step (#3568)

This commit is contained in:
Julien Fontanet 2018-10-19 16:22:25 +02:00 committed by GitHub
parent 0cd84ee250
commit ec9717dafb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,11 +25,6 @@ const PREVIEW_SLIDER_STYLE = { width: '400px' }
const UNITS = ['minute', 'hour', 'monthDay', 'month', 'weekDay'] const UNITS = ['minute', 'hour', 'monthDay', 'month', 'weekDay']
const MINUTES_RANGE = [1, 30]
const HOURS_RANGE = [1, 12]
const MONTH_DAYS_RANGE = [1, 15]
const MONTHS_RANGE = [1, 6]
const MIN_PREVIEWS = 5 const MIN_PREVIEWS = 5
const MAX_PREVIEWS = 20 const MAX_PREVIEWS = 20
@ -271,15 +266,14 @@ const TimePicker = [
}, },
}, },
computed: { computed: {
step: (_, { value }) => maxStep: ({ optionsValues }) => Math.floor(optionsValues.length / 2),
value.indexOf('/') === 1 ? +value.split('/')[1] : undefined,
optionsValues: (_, { options }) => flatten(options), optionsValues: (_, { options }) => flatten(options),
// '*' or '*/1' => all values // '*' or '*/1' => all values
// '2,7' => [2,7] // '2,7' => [2,7]
// '*/2' => [min + 2 * 0, min + 2 * 1, ..., min + 2 * n <= max] // '*/2' => [min + 2 * 0, min + 2 * 1, ..., min + 2 * n <= max]
tableValue: ({ optionsValues, step }, { value }) => tableValue: ({ optionsValues, step }, { value }) =>
value === '*' || step === 1 step === 1
? optionsValues ? optionsValues
: step !== undefined : step !== undefined
? optionsValues.filter((_, i) => i % step === 0) ? optionsValues.filter((_, i) => i % step === 0)
@ -287,7 +281,13 @@ const TimePicker = [
// '*' => 1 // '*' => 1
// '*/2' => 2 // '*/2' => 2
rangeValue: ({ step }, { value }) => (value === '*' ? 1 : step), // otherwise => undefined
step: (_, { value }) =>
value === '*'
? 1
: value.indexOf('/') === 1
? +value.split('/')[1]
: undefined,
}, },
}), }),
injectState, injectState,
@ -305,14 +305,12 @@ const TimePicker = [
options={props.options} options={props.options}
value={state.tableValue} value={state.tableValue}
/> />
{props.range !== undefined && ( <Range
<Range max={state.maxStep}
max={props.range[1]} min={1}
min={props.range[0]} onChange={effects.onChange}
onChange={effects.onChange} value={state.step}
value={state.rangeValue} />
/>
)}
</CardBlock> </CardBlock>
</Card> </Card>
), ),
@ -324,7 +322,6 @@ TimePicker.propTypes = {
onChange: PropTypes.func.isRequired, onChange: PropTypes.func.isRequired,
optionRenderer: PropTypes.func, optionRenderer: PropTypes.func,
options: PropTypes.array.isRequired, options: PropTypes.array.isRequired,
range: PropTypes.array,
value: PropTypes.string.isRequired, value: PropTypes.string.isRequired,
} }
@ -391,7 +388,6 @@ class DayPicker extends Component {
onChange={this._onChange} onChange={this._onChange}
optionRenderer={weekDayMode ? getDayName : undefined} optionRenderer={weekDayMode ? getDayName : undefined}
options={weekDayMode ? WEEK_DAYS : DAYS} options={weekDayMode ? WEEK_DAYS : DAYS}
range={MONTH_DAYS_RANGE}
value={weekDayMode ? weekDayPattern : monthDayPattern} value={weekDayMode ? weekDayPattern : monthDayPattern}
/> />
) )
@ -463,7 +459,6 @@ export default class Scheduler extends Component {
optionRenderer={getMonthName} optionRenderer={getMonthName}
options={MONTHS} options={MONTHS}
onChange={this._monthChange} onChange={this._monthChange}
range={MONTHS_RANGE}
value={cronPatternArr[PICKTIME_TO_ID['month']]} value={cronPatternArr[PICKTIME_TO_ID['month']]}
/> />
</Col> </Col>
@ -480,7 +475,6 @@ export default class Scheduler extends Component {
<TimePicker <TimePicker
labelId='Hour' labelId='Hour'
options={HOURS} options={HOURS}
range={HOURS_RANGE}
onChange={this._hourChange} onChange={this._hourChange}
value={cronPatternArr[PICKTIME_TO_ID['hour']]} value={cronPatternArr[PICKTIME_TO_ID['hour']]}
/> />
@ -489,7 +483,6 @@ export default class Scheduler extends Component {
<TimePicker <TimePicker
labelId='Minute' labelId='Minute'
options={MINS} options={MINS}
range={MINUTES_RANGE}
onChange={this._minuteChange} onChange={this._minuteChange}
value={cronPatternArr[PICKTIME_TO_ID['minute']]} value={cronPatternArr[PICKTIME_TO_ID['minute']]}
/> />