From ec9717dafba5299a504476c867d11d165a3b1410 Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Fri, 19 Oct 2018 16:22:25 +0200 Subject: [PATCH] chore(xo-web/scheduling): compute TimePicker max step (#3568) --- packages/xo-web/src/common/scheduling.js | 37 ++++++++++-------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/packages/xo-web/src/common/scheduling.js b/packages/xo-web/src/common/scheduling.js index 5a6a8bfdd..d95d9d32c 100644 --- a/packages/xo-web/src/common/scheduling.js +++ b/packages/xo-web/src/common/scheduling.js @@ -25,11 +25,6 @@ const PREVIEW_SLIDER_STYLE = { width: '400px' } 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 MAX_PREVIEWS = 20 @@ -271,15 +266,14 @@ const TimePicker = [ }, }, computed: { - step: (_, { value }) => - value.indexOf('/') === 1 ? +value.split('/')[1] : undefined, + maxStep: ({ optionsValues }) => Math.floor(optionsValues.length / 2), optionsValues: (_, { options }) => flatten(options), // '*' or '*/1' => all values // '2,7' => [2,7] // '*/2' => [min + 2 * 0, min + 2 * 1, ..., min + 2 * n <= max] tableValue: ({ optionsValues, step }, { value }) => - value === '*' || step === 1 + step === 1 ? optionsValues : step !== undefined ? optionsValues.filter((_, i) => i % step === 0) @@ -287,7 +281,13 @@ const TimePicker = [ // '*' => 1 // '*/2' => 2 - rangeValue: ({ step }, { value }) => (value === '*' ? 1 : step), + // otherwise => undefined + step: (_, { value }) => + value === '*' + ? 1 + : value.indexOf('/') === 1 + ? +value.split('/')[1] + : undefined, }, }), injectState, @@ -305,14 +305,12 @@ const TimePicker = [ options={props.options} value={state.tableValue} /> - {props.range !== undefined && ( - - )} + ), @@ -324,7 +322,6 @@ TimePicker.propTypes = { onChange: PropTypes.func.isRequired, optionRenderer: PropTypes.func, options: PropTypes.array.isRequired, - range: PropTypes.array, value: PropTypes.string.isRequired, } @@ -391,7 +388,6 @@ class DayPicker extends Component { onChange={this._onChange} optionRenderer={weekDayMode ? getDayName : undefined} options={weekDayMode ? WEEK_DAYS : DAYS} - range={MONTH_DAYS_RANGE} value={weekDayMode ? weekDayPattern : monthDayPattern} /> ) @@ -463,7 +459,6 @@ export default class Scheduler extends Component { optionRenderer={getMonthName} options={MONTHS} onChange={this._monthChange} - range={MONTHS_RANGE} value={cronPatternArr[PICKTIME_TO_ID['month']]} /> @@ -480,7 +475,6 @@ export default class Scheduler extends Component { @@ -489,7 +483,6 @@ export default class Scheduler extends Component {