Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: ScheduleDialog won't render for "30 days" interval with no time value #3447

Merged
merged 2 commits into from
Feb 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 29 additions & 33 deletions client/app/components/queries/ScheduleDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class ScheduleDialog extends React.Component {

setTime = (time) => {
this.newSchedule = {
time: moment(time).utc().format(HOUR_FORMAT),
time: moment(time)
.utc()
.format(HOUR_FORMAT),
};
};

Expand Down Expand Up @@ -107,18 +109,14 @@ class ScheduleDialog extends React.Component {

newSchedule.interval = newSeconds;

const [hour, minute] = newSchedule.time ?
localizeTime(newSchedule.time).split(':')
: [null, null];
const [hour, minute] = newSchedule.time ? localizeTime(newSchedule.time).split(':') : [null, null];

this.setState({
interval: newInterval,
seconds: newSeconds,
hour,
minute,
dayOfWeek: newSchedule.day_of_week
? WEEKDAYS_SHORT[WEEKDAYS_FULL.indexOf(newSchedule.day_of_week)]
: null,
dayOfWeek: newSchedule.day_of_week ? WEEKDAYS_SHORT[WEEKDAYS_FULL.indexOf(newSchedule.day_of_week)] : null,
});

this.newSchedule = newSchedule;
Expand Down Expand Up @@ -157,29 +155,29 @@ class ScheduleDialog extends React.Component {

render() {
const { dialog } = this.props;
const { interval, minute, hour, seconds, newSchedule: { until } } = this.state;
const {
interval,
minute,
hour,
seconds,
newSchedule: { until },
} = this.state;

return (
<Modal
{...dialog.props}
title="Refresh Schedule"
className="schedule"
onOk={() => this.save()}
>
<Modal {...dialog.props} title="Refresh Schedule" className="schedule" onOk={() => this.save()}>
<div className="schedule-component">
<h5>Refresh every</h5>
<div data-testid="interval">
<Select
className="input"
value={seconds}
onChange={this.setInterval}
dropdownMatchSelectWidth={false}
>
<Option value={null} key="never">Never</Option>
<Select className="input" value={seconds} onChange={this.setInterval} dropdownMatchSelectWidth={false}>
<Option value={null} key="never">
Never
</Option>
{Object.keys(this.intervals).map(int => (
<OptGroup label={capitalize(pluralize(int))} key={int}>
{this.intervals[int].map(([cnt, secs]) => (
<Option value={secs} key={cnt}>{durationHumanize(secs)}</Option>
<Option value={secs} key={cnt}>
{durationHumanize(secs)}
</Option>
))}
</OptGroup>
))}
Expand All @@ -192,7 +190,13 @@ class ScheduleDialog extends React.Component {
<div data-testid="time">
<TimePicker
allowEmpty={false}
defaultValue={moment().hour(hour).minute(minute)}
defaultValue={
hour
? moment()
.hour(hour)
.minute(minute)
: null
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ranbena,

This is the actual fix. Before it was:

defaultValue = {  moment().hour(hour).minute(minute) }

And now it's:

defaultValue = { hour ? moment().hour(hour).minute(minute) : null }

(moment().hour(null) returns current hour as integer)

format={HOUR_FORMAT}
minuteStep={5}
onChange={this.setTime}
Expand All @@ -204,11 +208,7 @@ class ScheduleDialog extends React.Component {
<div className="schedule-component">
<h5>On day</h5>
<div data-testid="weekday">
<Radio.Group
size="medium"
defaultValue={this.state.dayOfWeek}
onChange={this.setWeekday}
>
<Radio.Group size="medium" defaultValue={this.state.dayOfWeek} onChange={this.setWeekday}>
{WEEKDAYS_SHORT.map(day => (
<Radio.Button value={day} key={day} className="input">
{day[0]}
Expand All @@ -222,11 +222,7 @@ class ScheduleDialog extends React.Component {
<div className="schedule-component">
<h5>Ends</h5>
<div className="ends" data-testid="ends">
<Radio.Group
size="medium"
value={!!until}
onChange={this.setUntilToggle}
>
<Radio.Group size="medium" value={!!until} onChange={this.setUntilToggle}>
<Radio value={false}>Never</Radio>
<Radio value>On</Radio>
</Radio.Group>
Expand Down
34 changes: 25 additions & 9 deletions client/app/components/queries/ScheduleDialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ import RefreshScheduleDefault from '../proptypes';
const defaultProps = {
schedule: RefreshScheduleDefault,
refreshOptions: [
60, 300, 600, // 1, 5 ,10 mins
3600, 36000, 82800, // 1, 10, 23 hours
86400, 172800, 518400, // 1, 2, 6 days
604800, 1209600, // 1, 2, 4 weeks
60,
300,
600, // 1, 5 ,10 mins
3600,
36000,
82800, // 1, 10, 23 hours
86400,
172800,
518400, // 1, 2, 6 days
604800,
1209600, // 1, 2, 4 weeks
],
dialog: {
props: {
Expand Down Expand Up @@ -126,6 +133,14 @@ describe('ScheduleDialog', () => {
expect(el).toMatchSnapshot();
});
});

describe('Supports 30 days interval with no time value', () => {
test('Time is none', () => {
const [wrapper] = getWrapper({ interval: 30 * 24 * 3600 });
const el = findByTestID(wrapper, 'time');
expect(el).toMatchSnapshot();
});
});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the test for the bug.

});

describe('Adheres to user permissions', () => {
Expand All @@ -139,11 +154,12 @@ describe('ScheduleDialog', () => {
.simulate('click');

// get dropdown menu items
const options = mount(wrapper
.find('Trigger')
.instance()
.getComponent())
.find('MenuItem');
const options = mount(
wrapper
.find('Trigger')
.instance()
.getComponent(),
).find('MenuItem');

const texts = options.map(node => node.text());
const expected = ['Never', '1 minute', '5 minutes', '1 hour', '2 hours'];
Expand Down
Loading