Skip to content

Commit

Permalink
Fix: Able to set out-of-range refresh interval
Browse files Browse the repository at this point in the history
  • Loading branch information
ranbena committed Jan 6, 2019
1 parent b97b847 commit 8458da0
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions client/app/components/queries/ScheduleDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,6 @@ class ScheduleDialog extends React.Component {
};
}

get counts() {
return range(1, INTERVAL_OPTIONS_MAP[this.state.interval]);
}

get intervals() {
const ret = this.props.refreshOptions
.map((seconds) => {
Expand All @@ -95,6 +91,8 @@ class ScheduleDialog extends React.Component {
});
}

getCounts = interval => range(1, INTERVAL_OPTIONS_MAP[interval])

setTime = (time) => {
this.newSchedule = {
time: moment(time).utc().format(HOUR_FORMAT),
Expand Down Expand Up @@ -128,8 +126,14 @@ class ScheduleDialog extends React.Component {
newSchedule.day_of_week = WEEKDAYS_FULL[0];
}

// reset count if out of new interval count range
let count = this.state.count;
if (this.getCounts(newInterval).indexOf(Number(count)) === -1) {
count = '1';
}

newSchedule.interval = newInterval
? intervalToSeconds(Number(this.state.count), newInterval)
? intervalToSeconds(Number(count), newInterval)
: null;

const [hour, minute] = newSchedule.time ?
Expand All @@ -138,7 +142,7 @@ class ScheduleDialog extends React.Component {

this.setState({
interval: newInterval,
count: newInterval !== IntervalEnum.NEVER ? this.state.count : '1',
count,
hour,
minute,
dayOfWeek: newSchedule.day_of_week
Expand Down Expand Up @@ -210,7 +214,7 @@ class ScheduleDialog extends React.Component {
<div>
{interval !== IntervalEnum.NEVER ? (
<Select value={count} onChange={this.setCount} {...selectProps}>
{this.counts.map(cnt => (
{this.getCounts(this.state.interval).map(cnt => (
<Option value={String(cnt)} key={cnt}>{cnt}</Option>
))}
</Select>
Expand Down

0 comments on commit 8458da0

Please sign in to comment.