Skip to content

feat: Add switches for auto-start and auto-stop #3358

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

Merged
merged 26 commits into from
Aug 10, 2022

Conversation

presleyp
Copy link
Contributor

@presleyp presleyp commented Aug 2, 2022

Closes #3051

  • Refactors scheduling util functions to separate auto-start from auto-stop since they are now independently enable-able
  • Changes default behavior: if the API gives no schedule, assume that's meaningful and present features as disabled. But if the user disables and re-enables, repopulate the data from the API.
  • Puts auto-start and auto-stop in sections
  • Adds a switch to disable each section

I don't love the useEffect but I'm not sure it's worth refactoring to put more logic in the xservice - open to input.
I'd like to have integration tests but they run into routing problems.

Testing

Given I am on the schedule page
When I turn a switch on,
Then the controls in that section become enabled
When I turn a switch off,
Then the controls in that section become disabled (but its values aren't cleared).

Given I save the form with one or both sections disabled,
When I go back to the form from the Workspace page,
Then I see the previously disabled section is still disabled, and its values are cleared (empty, unchecked, or 0).
When I enable Auto-start,
Then I see the default values (9:30 AM, my current timezone, M-F) selected.
When I enable Auto-stop,
Then I see the default value (8) in the input.

Given I enable both sections, give non-default inputs, and save the form,
When I go back to the form from the Workspace page,
Then I see the sections are still enabled and still show the values I selected.
When I disable the sections and then enable them again,
Then I see the values I selected (not the default values).

@presleyp presleyp marked this pull request as ready for review August 2, 2022 14:58
@presleyp presleyp requested a review from a team as a code owner August 2, 2022 14:58
@presleyp presleyp requested review from johnstcn and a team and removed request for a team August 2, 2022 15:22
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

Looks good to me from the backend perspective!

@Kira-Pilot
Copy link
Member

What do you think about restricting the user from adding '0' here? When a user does that, saves, and then toggles the switch, the default comes back anyway. I wonder if it would cause less confusion to validate against this case in the same way we do with start time.
Screen Shot 2022-08-02 at 12 47 39 PM

Copy link
Member

@Kira-Pilot Kira-Pilot left a comment

Choose a reason for hiding this comment

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

Left some comments but overall I think this looks great!

@ammario ammario self-requested a review August 4, 2022 16:16
@presleyp
Copy link
Contributor Author

presleyp commented Aug 8, 2022

@Kira-Pilot fyi on the border - other uses of Section didn't have a border either, so I just added it in the Section component.

@presleyp
Copy link
Contributor Author

presleyp commented Aug 8, 2022

@Kira-Pilot @ammario I changed auto-stop to disallow 0 if it's enabled, and I'm thinking maybe auto-start should work the same way. Currently it's like, you can't have no days checked if you have a start time, but now that there's a switch I figure the logic should be, you have to have a time and at least one day if the switch is on. Does that sound right to you?

@ammario
Copy link
Member

ammario commented Aug 9, 2022

  • When I toggle the Auto-start or Auto-stop buttons, the old form inputs disappear, which surprises me.
  • I'm seeing a validation error when disabling auto off: Screen Shot 2022-08-09 at 10 30 15 AM

@presleyp
Copy link
Contributor Author

presleyp commented Aug 9, 2022

@ammario I'm working on the validation one, and I've found a resetting bug but I'm not sure it's the same one you're describing. I intend for this behavior to happen:

Given Auto-start is enabled and I've entered days and a time,
When I disable Auto-start,
Then the days and time are cleared.

But I consider this a bug:

Given Auto-start and Auto-stop are enabled and I've entered a number of hours until shutdown,
When I disable Auto-start (not Auto-stop),
Then the number of hours until shutdown is reset to whatever value was pulled from the backend before I set it.

If you think the former case is a problem, let me know!

@ammario
Copy link
Member

ammario commented Aug 9, 2022

@ammario I'm working on the validation one, and I've found a resetting bug but I'm not sure it's the same one you're describing. I intend for this behavior to happen:

Given Auto-start is enabled and I've entered days and a time, When I disable Auto-start, Then the days and time are cleared.

The behavior doesn't surprise me. It's when you enable Auto-start again and then the days and time are reset to system default that surprises me. I would expect the days and time to be set to what they were right before I disabled Auto-start.

But I consider this a bug:

Given Auto-start and Auto-stop are enabled and I've entered a number of hours until shutdown, When I disable Auto-start (not Auto-stop), Then the number of hours until shutdown is reset to whatever value was pulled from the backend before I set it.

If you think the former case is a problem, let me know!

Yes I agree this is a surprising behavior.

@presleyp
Copy link
Contributor Author

presleyp commented Aug 9, 2022

@ammario okay, it sounds like we mostly agree but there may be one place we're not on the same page: say my Auto-start is set to Mondays at 9am. I go to my schedule to add Tuesdays. But before submitting, I turn Auto-start off, and then back on again. This PR will reset your form to Mondays. I think you're saying it should show Mondays and Tuesdays.

My argument for Mondays is that that's your current actual schedule, so when you come back from nothing, you should start there. But I see the argument that you should just go back in time to before you disabled Auto-start. I think implementing it to go back in time to Mondays and Tuesdays will be harder than resetting to Mondays. How strongly do you feel about it?

@ammario
Copy link
Member

ammario commented Aug 9, 2022

I don't feel that strongly about. This PR is an improvement on what exists today so it's mergeable as far as I'm concerned :)

@presleyp
Copy link
Contributor Author

@ammario @Kira-Pilot I'm close to putting up changes that will persist form state while a section is disabled (easier than I expected!) and fix the bug where one section affects the other. But I'm realizing having the form state persisted might be confusing to the user. The values are still visible when I disable, and so for instance the stop section says "Your workspace will shut down after n hours" instead of "Your workspace will not automatically shut down." But if I submit the form with Auto-stop disabled, my workspace will not automatically shut down. What do you think, confusing or fine?

Screen Shot 2022-08-10 at 10 45 35 AM

@Kira-Pilot
Copy link
Member

@ammario @Kira-Pilot What do you think, confusing or fine?

I think that is potentially confusing. Can we just clear the validation when they disable? Something like
formik.setTouched({}, false) ?

@presleyp
Copy link
Contributor Author

@Kira-Pilot removed helper text when a section is disabled so that the grey text isn't lying lol

@presleyp
Copy link
Contributor Author

@Kira-Pilot just kidding, that made the helper text override the error text so I reverted it. I'll make a ticket for figuring out the UX.

const handleToggleAutoStart = async (e: ChangeEvent) => {
form.handleChange(e)
// if enabling from empty values, fill with defaults
if (!form.values.autoStartEnabled && !form.values.startTime) {
Copy link
Member

Choose a reason for hiding this comment

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

are we checking !form.values.startTime here to ensure the user didn't fill something out previously?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, so we don't overwrite your values with defaults.

await form.setFieldValue(name, defaults[name as keyof AutoStartSchedule])
})
await form.setFieldValue("startTime", defaults.startTime)
await form.setFieldValue("timezone", defaults.timezone)
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yay, thanks!

startTime: string
timezone: string

autoStopEnabled: boolean
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I know we chatted about this yesterday, but why are we including autoStartEnabled and autoStopEnabled as form values instead of stateful variables? The API doesn't have a concept of these values, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. I just thought it was a little cleaner this way:

  • validation can go back to being an object instead of a function
  • all fields in the form are handled by the form
  • now that I'm persisting pre-submission form state, the formToRequest functions need to refer to the enabled values to decide whether to send the backend falsey values

And the formToRequest functions just create values to return rather than passing everything through, so there wasn't a real downside to having extra data in the form.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good, thanks!

@Kira-Pilot
Copy link
Member

Two small UI things that do not have to be addressed in this PR:
I noticed a flicker on input border when fields are disabled:
Kapture 2022-08-10 at 16 51 17

Sometimes "Days of Week" gets a blue highlight:
Kapture 2022-08-10 at 16 55 38

These are not blockers!! Just noting for posterity.

@Kira-Pilot
Copy link
Member

Nice job! This was complicated. I left some questions but as far as I'm concerned, this is good to be merged up. Looks great when I run it locally. Thanks for seeing it through!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UX: disabling autostart is difficult
4 participants