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

WIP: fix "destroy" links #1688

Closed
wants to merge 3 commits into from
Closed

Conversation

pablobm
Copy link
Collaborator

@pablobm pablobm commented Jun 25, 2020

Fixes #1643

When #1618 was merged, some JS broke. One important piece of functionality that stopped working was "destroy" links.

We were using the JS-driven destroy links that are common in Rails. These work on links with the attribute data-method="delete", and show a confirm() box with text extracted from the attribute data-confirm.

You might be wondering why the specs didn't break... Well, it turns out that Capybara tries to be clever about these special attributes, even when using Rack::Test. As a result, tests passed even though the JS to drive the functionality wasn't working. To avoid this happening again, I have told Capybara to respect_data_method: false.

OK, so how can we fix this? We can fix the JS, but there are two problems:

  1. Remove jquery ujs #1618 wasn't merged entirely arbitrarily. It was the product of our trying to figure out how to best integrate with both the asset pipeline and webpacker, two competing alternatives for handling frontend assets. We are still trying to figure this one out, and I don't think there's going to be a simple answer.
  2. I don't like JS-driven delete buttons anyway! I'm ok with progressive enhancement, but having them depend on JS leads to issues... like this one we had.

So I'm proposing that we change the way that destroy links work, so that they use a "traditional" approach, driven by the backend:

  1. Click on "destroy" link.
  2. View separate confirmation page.
  3. Click "confirm" button.
  4. Redirect back to index page.

This is a first draft, which perhaps should be styled a bit. The confirmation page looks like this at the moment:

Ask if user is sure, provide destroy button

Pending:

  • Discuss: how do we feel generally about this approach?
  • Discuss: this introduces new i18n strings. How do we feel about this? I suspect they should be more more, as the reuse I do here may not work well across languages.
  • Style the new destroy confirmation page.
  • Provide i18n strings for all supported languages.

@nickcharlton
Copy link
Member

Ahh this is an interesting way to approach this problem!

Is it just deletions that have this problem? We don't do anything else which was dependent on ujs?

My initial thought would be that this will make deleting items really slow, and having something else to make mass deletions faster isn't something I think we should worry about right now.

@nickcharlton nickcharlton added bug breakages in functionality that is implemented dashboards how administrate presents fields and displays data frontend-pipeline Webpacker vs Sprockets labels Jun 25, 2020
@pablobm
Copy link
Collaborator Author

pablobm commented Jun 25, 2020

I agree: the UX of this solution is a step backwards compared to the pre-bug solution.

Now, I have these two thoughts:

  1. I don't like relying on ujs. Perhaps I'm a bit old-fashioned, but I do appreciate progressive enhancement.
  2. I think the JS should still be fixed, precisely to provide progressive enhancement and fix the UX, and even improve from what we had before.

Having said that, perhaps we should fix the JS issue first, and consider this PR an additional enhancement that should come later.

@nickcharlton
Copy link
Member

Is the best option — in the interest of unblocking the release — to just revert the removal? I'd like to add the Capybara change from this too though.

@pablobm
Copy link
Collaborator Author

pablobm commented Jun 28, 2020

Yeah, I think you are right. I'd still like to provide a JS-independent solution, but let's solve the problem at hand first. So here's a PR that includes the breaking test and the commit reversal: #1691

@pablobm pablobm mentioned this pull request Jun 28, 2020
@pablobm
Copy link
Collaborator Author

pablobm commented Jun 28, 2020

Oops, didn't notice you already had created a PR. I closed mine now.

@nickcharlton
Copy link
Member

Sorry! I should've mentioned it!

Given other priorities, what do you think of closing this one for now and revising it later on?

@pablobm
Copy link
Collaborator Author

pablobm commented Jul 2, 2020

Yes. I'll come back to this in the future, but I'm ok with closing it for now.

@pablobm pablobm closed this Jul 2, 2020
@pablobm pablobm deleted the fix-js-actions branch June 24, 2021 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug breakages in functionality that is implemented dashboards how administrate presents fields and displays data frontend-pipeline Webpacker vs Sprockets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Destroy link does not work
2 participants