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

feature: action dynamic backdrop option #3379

Merged

Conversation

thiagoyoussef
Copy link
Contributor

Description

Fixes #3326
Related PR: avo-hq/docs.avohq.io#303

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Screenshots & recording

https://www.loom.com/share/970418f8279244f7b4feb97e2617bff5?sid=f44ba85f-55c0-4809-a464-cc1328f628a2

Manual review steps

By default, action modals use a dynamic backdrop. Added a self.dynamic_backdrop = false action option in case you want to prevent the user from closing the modal when clicking on the backdrop.

class Avo::Actions::DummyAction < Avo::BaseAction
  self.name = "Dummy action"
  self.dynamic_backdrop = false

  def handle(query:, fields:, current_user:, resource:, **args)
    # Do something here
    succeed 'Yup'
  end
end

Questions

I saw that other action options like no_confirmation and standalone doesn't have tests.

  1. Should I add tests for a simple feature like this one?

PS: It's not laziness, I'm assuming it's not worth it in this context.


I left a usage example on the Avo::Actions::ExportCsv action:

class Avo::Actions::ExportCsv < Avo::BaseAction
  ...
  self.dynamic_backdrop = false
  ...
end
  1. Should I remove it?

I decided to use the name dynamic_backdrop instead of ⁠close_on_backdrop_click. Usually dynamic/static is used to indicate the backdrop behavior.
3) Do you prefer to keep it ⁠close_on_backdrop_click ?


  1. Should I add dynamic_backdrop option on the action generator?

Copy link

codeclimate bot commented Nov 2, 2024

Code Climate has analyzed commit a565cba and detected 0 issues on this pull request.

View more on Code Climate.

Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

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

Thank you for this contribution @thiagoyoussef!

I'll address all your bullet point questions and let a code review.

I saw that other action options like no_confirmation and standalone doesn't have tests.
Should I add tests for a simple feature like this one?
Yes, tests are crucial. When we identify missing tests, we normally implement them.

The no_confirmation option is tested in this test case. In this scenario, invoking the action triggers the expected response without requiring any user confirmation.

The standalone option is also covered. For actions marked as standalone, no record selection is necessary to execute them. This behavior is validated across several test cases, specifically those that run Dummy action without selecting any records.

Lastly, if a specific option name doesn't appear in the test titles, it doesn't necessarily mean it's untested. Many options are implicitly covered by existing test cases, even if not directly named.

I left a usage example on the Avo::Actions::ExportCsv action:
Should I remove it?

No, it's ok, we can use that action to test this option.

I decided to use the name dynamic_backdrop instead of ⁠close_on_backdrop_click. Usually dynamic/static is used to indicate the backdrop behavior.
3) Do you prefer to keep it ⁠close_on_backdrop_click ?

Got it, naming is sensible, I like dynamic_backdrop but close_on_backdrop_click seems more expressive, anyway dynamic_backdrop sounds good, do you have any other suggestions? @adrianthedev WDYT about naming here?

Let’s keep this option name for now and revisit it after gathering more feedback.

Should I add dynamic_backdrop option on the action generator?

No, it's all good. We considered adding more options to the templates, but it can quickly lead to cluttered configuration in each generated file. This can feel overwhelming, especially for new users who just want to create a simple action when starting with Avo. Let's focus on ensuring that this option is documented and easy to find.

Thank you again for this contribution @thiagoyoussef, I also left some code review with a duplication removal suggestion and a question about whether the new backdrop target is necessary.

Comment on lines 4 to 5
data-modal-target="modal"
data-modal-dynamic-backdrop-value="<%= dynamic_backdrop %>"
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove duplicated

Suggested change
data-modal-target="modal"
data-modal-dynamic-backdrop-value="<%= dynamic_backdrop %>"
data-modal-dynamic-backdrop-value="<%= dynamic_backdrop %>"


close() {
if (event.target === this.backdropTarget && !this.dynamicBackdropValue) return
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this check?: event.target === this.backdropTarget

Wouldn't this work?

Suggested change
if (event.target === this.backdropTarget && !this.dynamicBackdropValue) return
if (!this.dynamicBackdropValue) return

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to check if the event comes from the backdrop. If we don't, it would also prevent the user from closing the modal on the cancel button.

@adrianthedev
Copy link
Collaborator

How about self.click_backdrop_to_close_modal?

@thiagoyoussef
Copy link
Contributor Author

@Paul-Bob thank you for the code review! Will make the changes 😄

@thiagoyoussef
Copy link
Contributor Author

thiagoyoussef commented Nov 4, 2024

How about self.click_backdrop_to_close_modal?

Great, it's very clear!

Do I change it to click_backdrop_to_close_modal then?

Maybe close_modal_on_backdrop_click?

Should I keep using dynamic_backdrop on the modal component prop?

@Paul-Bob
Copy link
Contributor

Paul-Bob commented Nov 4, 2024

Great, it's very clear!
Do I change it to click_backdrop_to_close_modal then?
Maybe close_modal_on_backdrop_click?

close_modal_on_backdrop_click is a good suggestion, let's apply it.

Should I keep using dynamic_backdrop on the modal component prop?

Let's stick to one name for this option across all files and components. This will make it easier to find and manage, like when you're doing a quick global search to see all the places where it's used.

@thiagoyoussef thiagoyoussef force-pushed the feature/action-dynamic-backdrop-option branch from 05ced39 to a565cba Compare November 4, 2024 17:41
Copy link
Contributor

@Paul-Bob Paul-Bob left a comment

Choose a reason for hiding this comment

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

Thank you @thiagoyoussef!

@Paul-Bob Paul-Bob merged commit 40abfed into avo-hq:main Nov 5, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

action modal not closable
3 participants