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

Avoid submitting duplicate Connected Apps #12481

Merged
merged 1 commit into from
May 22, 2024

Conversation

mkllnk
Copy link
Member

@mkllnk mkllnk commented May 15, 2024

What? Why?

Simple Rails forms prevent double-clicking on submit already. Converting the StimulusReflex interaction to a simple form submit to a controller solves the race condition.

The UX is slightly worse because the whole page is reloaded instead rendering only the connected app panel. But we can solve that when we add more apps and want to activate them independently. By then, we may have good patterns for working with Turbo.

Technically, the new buttons are a form within a form which is invalid HTML, but it works.

What should we test?

  • Activate the connected apps feature.
  • Go to enterprise settings and connected apps.
  • Connect an app.
  • Disconnect an app.

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

The title of the pull request will be included in the release notes.

Dependencies

Documentation updates

Simple Rails forms prevent double-clicking on submit already. Converting
the StimulusReflex interaction to a simple form submit to a controller
solves the race condition.

The UX is slightly worse because the whole page is reloaded instead
rendering only the connected app panel. But we can solve that when we
add more apps and want to activate them independently. By then, we may
have good patterns for working with Turbo.

Technically, the new buttons are a form within a form which is invalid
HTML, but it works.
@mkllnk mkllnk added the technical changes only These pull requests do not contain user facing changes and are grouped in release notes label May 15, 2024
@mkllnk mkllnk self-assigned this May 15, 2024
@mkllnk mkllnk marked this pull request as ready for review May 15, 2024 07:25
Copy link
Member

@dacook dacook 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, glad to have one less reflex! And no changes necessary for feature specs 👌

@@ -6,16 +6,14 @@
%p= t ".tagline"
%div
- if enterprise.connected_apps.empty?
%button{ data: {reflex: "click->Admin::ConnectedApp#create", enterprise_id: enterprise.id} }
= t ".enable"
= button_to t(".enable"), admin_enterprise_connected_apps_path(enterprise.id), method: :post
Copy link
Member

Choose a reason for hiding this comment

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

Technically, the new buttons are a form within a form which is invalid HTML, but it works.

That doesn't seem ideal to me, and might have unexpected drawbacks. But I can't think of a better, so if it works, it works!

I'm guessing if you have other unsaved changes on the Enterprise (from another tab), it will display a confirmation as usual? That could be a little confusing for users, but I think that would be rare and fine for this case.
I'm not sure if the enterprise fields would also be submitted by this button, but even if they are, I expect they'd be silently ignored.

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 may be the cause for the latest bug:

My tests show that it was this commit.

@filipefurtad0
Copy link
Contributor

Hey @mkllnk ,

I was able to reproduce the multiple click scenario on staging-FR, but indeed only as superadmin. The connect button was not immediately disabled, which led to multiple connect attempts, and eventually, an error 500 (not seen in the console, but on Bugsnag only):

https://app.bugsnag.com/open-food-france/coopcircuits/errors/664dc1bdc76ab90008a13f7d?event_id=664dc1bd00ed21d2d87a0000&i=sk&m=nw

The button remains on an endless spinner state:

image

After this, I've staged the PR, and could verify that:

  • the endless spinner remains, for that enterprise (after logging in and logging out)

image

  • I could still click twice on the Share data button -> i.e., I could not observe a difference in the time it took to go to a disabled state...

This becomes an issue, as the button becomes broken and unusable (even after hard refresh and/or login/out). Again, not introduced by this PR, but I can't spot an improvement.

How do you think we should proceed? Is there any significant code improvement you see should be included in master, as is? If so, please feel free to merge. But if not, I guess we need to move it back to In Dev.

@filipefurtad0 filipefurtad0 added feedback-needed and removed pr-staged-fr staging.coopcircuits.fr labels May 22, 2024
@sigmundpetersen
Copy link
Contributor

Was Connected Apps built with StimulusReflex?
Is this the same issue with Endless spinner as on Products page and Reports?

There is also a report on this in #12425

@filipefurtad0
Copy link
Contributor

Was Connected Apps built with StimulusReflex?

Yes, I think so @sigmundpetersen, as on the #12472 PR, there is a specific test case to check for this connection.

So I guess I've stumbled on #12425 indeed. Thanks for pointing it out ✨

@mkllnk
Copy link
Member Author

mkllnk commented May 22, 2024

I was able to reproduce the multiple click scenario on staging-FR, but indeed only as superadmin.

Oh, that's another bug. You shouldn't be able to see that button as super admin unless you are a manager of the enterprise. If you are not a manager of the enterprise, your API key isn't authorised to fetch data from that enterprise and the connection doesn't work.

I'll merge this PR but I will look into the super-admin problem.

@mkllnk mkllnk merged commit 32eb9c5 into openfoodfoundation:master May 22, 2024
56 checks passed
@mkllnk mkllnk deleted the connect-app-once branch May 22, 2024 22:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
technical changes only These pull requests do not contain user facing changes and are grouped in release notes
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Connected App is connecting twice
5 participants