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

[57423] Progress modal should always prevent save when there are invalid values #16735

Merged

Conversation

cbliard
Copy link
Member

@cbliard cbliard commented Sep 16, 2024

Ticket

https://community.openproject.org/wp/57423

What are you trying to accomplish?

In progress popover, when inputs are invalid, the modal can still be "saved" when the Save button is pressed multiple time. Nothing is actually changed, but this is still confusing behavior.

Change it so that the popover remains open.

Screenshots

Before:

double.submit.not.blocked.webm

After:

multiple.save.does.not.submit.webm

What approach did you choose and why?

The problem came from the modal form being updated through turbo-stream on submit. In this code path, the rendered modal form did not include the touched fields information, which lead to no fields being touched, meaning it saves without any modifications.

To fix it:

  • include the touched information when rendering the modal

And to clarify the code:

  • on update action:
    • on success, do not render any turbo-stream. The modal will be closed anyway.
    • on error, render turbo-stream directly from the controller instead of using the update template
  • on create action:
    • on error, render turbo-stream directly from the controller instead of using the update template
  • use morph instead of update with turbo-stream to avoid disconnecting and reconnecting stimulus controllers

And as a bonus:

  • fixed an issue with the remaining work not being recalculated if status was changed on the new work package form.
  • fix some test flakiness when checking for progress field focused state

Merge checklist

  • Added/updated tests
  • Added/updated documentation in Lookbook (patterns, previews, etc)
  • Tested major browsers (Chrome, Firefox, Edge, ...)

Merge `progress-preview` and `touched-field-marker` stimulus controllers
together into `preview` controller.

They are sharing some state, the touched status, showing that they need
to be grouped together. It will make it easier to deal with the touched
state later.
@cbliard cbliard force-pushed the bug/57423-prevent-popover-save-on-invalid-progress-values branch from ebdd605 to 61b6f36 Compare September 17, 2024 08:03
Because of the weird way we initialize the fake work package, it could
believe that the status did not change and no recomputation was needed.
This is an edge case, and I'm not satisfied with its design.
@cbliard cbliard force-pushed the bug/57423-prevent-popover-save-on-invalid-progress-values branch from 61b6f36 to c40bd5f Compare September 17, 2024 08:03
When submitting with invalid values, the progress popover was updated
via turbo-stream with a modal which did not include the touched fields.
This caused the fields to be ignored on the second submit, even if they
appeared to be invalid. This was also causing the preview to not work as
expected.

This has been changed:
- the update is done through a turbo-stream morph instead of an update.
  It avoids disconnecting and reconnecting the stimulus controllers.
- the touched fields are now correctly sent to the component for
  rendering. The state is maintained in the stimulus controller instead
  of the hidden fields. Fields are still needed for form submission.
- the fields sent to the server when previewing are exactly the same as
  the ones being sent on submit.
- the turbo_stream commands are sent directly from the controller. None
  are sent if the update completed successfully as the modal will be
  closed by client side javascript anyway.
- the referrer-field is now just the field name instead of the full
  work package key, to reduce noise.
@cbliard cbliard force-pushed the bug/57423-prevent-popover-save-on-invalid-progress-values branch from 284f559 to 0a5765f Compare September 17, 2024 11:49
@cbliard cbliard marked this pull request as ready for review September 17, 2024 12:25
// Turbo supports morphing, by adding the <turbo-frame refresh="morph"> attribute.
// However, it has a bug, and it doesn't morphs when reloading the frame via javascript.
// See https://github.com/hotwired/turbo/issues/1161 . Once the issue is solved, we can remove
// this code and just use <turbo-frame refresh="morph"> instead.
Copy link
Member

Choose a reason for hiding this comment

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

Could it be that this is now fixed with 8.0.10?

See:

https://github.com/hotwired/turbo/releases/tag/v8.0.10
hotwired/turbo#1192

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice! I'll test that.

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems I can't make it work properly. I'll merge this one, and open another PR.

Copy link
Member

@oliverguenther oliverguenther left a comment

Choose a reason for hiding this comment

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

👍 Nice cleanup. I feel like the update flow is now a lot easier. Current behavior fixed as specified in the expected behavior.

There is a small remark on whether the newest update from today might be able to resolve your workaround. I'm fine with merging it before checking.

@cbliard cbliard merged commit 2517cfe into dev Sep 18, 2024
17 checks passed
@cbliard cbliard deleted the bug/57423-prevent-popover-save-on-invalid-progress-values branch September 18, 2024 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants