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

[59468] Danger Confirmation Dialog implementation #214

Merged
merged 13 commits into from
Dec 20, 2024

Conversation

myabc
Copy link

@myabc myabc commented Dec 11, 2024

Based on FeedbackDialog. Wraps Primer::Alpha::Dialog, providing additional standardised behaviour for scenarios where a user performs a "dangerous" action.

Includes initial Lookbook previews and component tests.

Implements DangerConfirmationDialogFormHelperElement Catalyst controller providing checkbox confirmation behaviour.

What are you trying to accomplish?

Screenshots

https://raw.githubusercontent.com/opf/primer_view_components/d232bfc77ee23bcde7e00ac3bd50c70bc2f4d034/.playwright/screenshots/snapshots.test.ts-snapshots/primer/open_project/danger_confirmation_dialog/default/light.png

Integration

List the issues that this change affects.

https://community.openproject.org/projects/openproject/work_packages/58680

Risk Assessment

  • Low risk the change is small, highly observable, and easily rolled back.
  • Medium risk changes that are isolated, reduced in scope or could impact few users. The change will not impact library availability.
  • High risk changes are those that could impact customers and SLOs, low or no test coverage, low observability, or slow to rollback.

What approach did you choose and why?

Anything you want to highlight for special attention from reviewers?

Accessibility

  • Fixes axe scan violation - This change fixes an existing axe scan violation.
  • No new axe scan violation - This change does not introduce any new axe scan violations.
  • New axe violation - This change introduces a new axe scan violation. Please describe why the violation cannot be resolved below.

Merge checklist

  • Added/updated tests
    • Component tests
    • System tests
  • Added/updated documentation
  • Added/updated previews (Lookbook)
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Additional TODOs/Questions for Discussion

  • Determine how to handle I18n Resolution: leave to caller
  • Test with Rails form builders (?) Resolution: test once upstream

Copy link

changeset-bot bot commented Dec 11, 2024

🦋 Changeset detected

Latest commit: 43e1243

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@openproject/primer-view-components Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

github-actions bot commented Dec 11, 2024

⚠️ Visual differences found

Our visual comparison tests found UI differences. Please review the differences by viewing the files changed tab to ensure that the changes were intentional.

Review visual differences

@myabc myabc force-pushed the feature/58680-danger-confirmation-dialog branch from 843ae27 to 0fb1cb5 Compare December 12, 2024 00:07
Copy link
Collaborator

@HDinger HDinger left a comment

Choose a reason for hiding this comment

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

Hi @myabc

nice job, it looks really good 👍 I only have some minor remarks.

@myabc myabc force-pushed the feature/58680-danger-confirmation-dialog branch 4 times, most recently from e38d4bb to 0ab3d92 Compare December 16, 2024 20:53
@myabc myabc requested a review from HDinger December 16, 2024 21:29
@myabc
Copy link
Author

myabc commented Dec 16, 2024

@HDinger I've addressed most of the issues you raised.

In addition to the couple of questions inline, a couple general questions:

  • Should we use checkbox/Checkbox or check_box/CheckBox? The HTML spec uses checkbox, and is what I would normally prefer. It's one less keystroke for our end users. However the latter would make us consistent with the other Primer components.
  • DangerConfirmationDialog is a pretty long, cumbersome name IMO. "confirmation" is probably redundant, given that our slots also our named confirmation_message and confirmation_dialog. Could we consider going with just (an opinionated) DangerDialog?


def call
render(Primer::BaseComponent.new(**@system_arguments)) do
render(Primer::Alpha::CheckBox.new(**@checkbox_arguments.merge(label: trimmed_content)))
Copy link
Author

Choose a reason for hiding this comment

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

@HDinger As I've implemented it, we build the checkbox label based on (trimmed_)content - this allows for a similar API to the other slots, i.e.:

      dialog.with_show_button { "Click me" }
      dialog.with_confirmation_checkbox { "I confirm this deletion" }

An alternative would be to add a label_text string parameter - either on DangerConfirmationDialog itself - or on the slot. I am not sure "what feels" more idiomatic?

  DangerConfirmationDialog.new(label_text: "I confirm this deletion")
  dialog.with_confirmation_checkbox(label_text: "I confirm this deletion")

Copy link
Author

Choose a reason for hiding this comment

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

Also, do we want to define a I18n.t default for the label? Or is it fine to always leave it to the caller?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently you can write something like dialog.with_confirmation_checkbox which will render a checkbox without any label. So we either have to provide a default or enforce that the user provides a string. Since the default is rather special, we probably have to enforce the the user to pass an argument for now.

With regards to the syntax, I like the dialog.with_confirmation_checkbox { "I confirm this deletion" } notation, but if it is easier to enfoce a text with a named parameter, I am also fine with that.

@myabc myabc force-pushed the feature/58680-danger-confirmation-dialog branch from 161029a to f3848d1 Compare December 16, 2024 21:59
Based on `FeedbackDialog`. Wraps `Primer::Alpha::Dialog`, providing
additional standardised behaviour for scenarios where a user performs
a "dangerous" action.

Includes initial Lookbook previews and component tests.

Implements `DangerConfirmationDialogFormHelperElement` Catalyst
controller providing checkbox confirmation behaviour.

https://community.openproject.org/projects/openproject/work_packages/58680
Adds `confirmation_checkbox` slot to allow the caller to provide custom
labels, including I18n strings.
@myabc myabc force-pushed the feature/58680-danger-confirmation-dialog branch from f3848d1 to d60a8e6 Compare December 16, 2024 22:07
Copy link
Collaborator

@HDinger HDinger left a comment

Choose a reason for hiding this comment

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

I left some remarks and will check what is happening with the snapshots.

.changeset/brave-eggs-obey.md Outdated Show resolved Hide resolved
test/components/component_test.rb Outdated Show resolved Hide resolved

def call
render(Primer::BaseComponent.new(**@system_arguments)) do
render(Primer::Alpha::CheckBox.new(**@checkbox_arguments.merge(label: trimmed_content)))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Currently you can write something like dialog.with_confirmation_checkbox which will render a checkbox without any label. So we either have to provide a default or enforce that the user provides a string. Since the default is rather special, we probably have to enforce the the user to pass an argument for now.

With regards to the syntax, I like the dialog.with_confirmation_checkbox { "I confirm this deletion" } notation, but if it is easier to enfoce a text with a named parameter, I am also fine with that.

@myabc myabc force-pushed the feature/58680-danger-confirmation-dialog branch from 4e56bad to 0d265ad Compare December 17, 2024 11:30
Ensure the the form is actually submittable.
Makes the capitalisation of CheckBox/check_box consistent with other Primer components. Renames the internal `ConfirmationCheckBox` component and slots (`with_confirmation_check_box`) accordinly.
* Teaches `form_arguments` `:builder` and `:name` options. `:builder`
  should be an instance of `ActionView::Helpers::FormBuilder`, which is
  created by the standard Rails `#form_with` and `#form_for` helpers.
* Uses Rails Form Helpers under-the-hood to render form tags, ensuring
  automatic generation of CSRF token, `_method` hidden inputs.
@myabc myabc force-pushed the feature/58680-danger-confirmation-dialog branch from f12553a to 43e1243 Compare December 20, 2024 01:38
@myabc myabc requested a review from HDinger December 20, 2024 01:42
Copy link
Collaborator

@HDinger HDinger left a comment

Choose a reason for hiding this comment

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

Nice job 🌟 I really like the way it can be used 👍

@HDinger HDinger merged commit 4a8aee9 into main Dec 20, 2024
33 checks passed
@HDinger HDinger deleted the feature/58680-danger-confirmation-dialog branch December 20, 2024 07:42
@openprojectci openprojectci mentioned this pull request Dec 20, 2024
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