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

enhancement: access to the query on all action blocks #3581

Merged
merged 13 commits into from
Jan 17, 2025

Conversation

Nevelito
Copy link
Contributor

@Nevelito Nevelito commented Jan 13, 2025

Description

Fixes #2935

Grants access to the query object throughout the action, enabling its use when rendering the action view.

Here is an example with a test action:

class Avo::Actions::Test::Query < Avo::BaseAction
  self.name = "Test query access"
  self.message = -> {
    "message #{query.count} selected"
  }
  self.cancel_button_label = -> {
    "cancel_button_label #{query.count} selected"
  }
  self.confirm_button_label = -> {
    "confirm_button_label #{query.count} selected"
  }
  self.standalone = true

  def fields
    field :selected, default: "#{query.count} selected def fields"
  end

  def handle(**args)
    succeed "succeed #{query.count} selected"
  end
end

image

Checklist:

Copy link

codeclimate bot commented Jan 13, 2025

Code Climate has analyzed commit 0ef9f22 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.

Thanks for working on this, @Nevelito!

I've manually tested this PR with the following action code, but it seems there's currently no access to the query object inside the actions.
Let's make sure the query object is accessible within action messages/fields.
Additionally, I've left some code review comments, let me know if you have any questions!

class Avo::Actions::Sub::DummyAction < Avo::BaseAction
  self.name = -> { "Dummy action" }
  self.message = -> { query.first.name }
  self.cancel_button_label = -> { query.first.name }
  self.confirm_button_label = -> { query.first.name }
  self.standalone = true

  def fields
    field :name, default: query.first.name
  end

  def handle(query:, **args)
    succeed query.first.name
  end
end

Comment on lines 12 to 16
before_action :set_query, only: [:show, :handle], if: ->(request) do
# set query will fail in show if user will not select some row
# params[:fields] are set during selecting row or in show view
request.params[:fields].present?
end
Copy link
Contributor

Choose a reason for hiding this comment

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

This approach makes sense for show, but we should ensure that the conditional check does not apply to handle.

@Nevelito Nevelito requested a review from Paul-Bob January 15, 2025 14:25
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.

Thanks for all the work done here @Nevelito it's looking good!

I'll take over from here and adjust the last details before merging.

@Paul-Bob Paul-Bob self-assigned this Jan 15, 2025
@Paul-Bob Paul-Bob changed the title Feature / Access to the selected records on actions feature: access to the query on action view Jan 16, 2025
@adrianthedev adrianthedev changed the title feature: access to the query on action view feature: access to the query on all action blocks Jan 17, 2025
@Paul-Bob Paul-Bob added the Enhancement Not necessarily a feature, but something has improved label Jan 17, 2025
@Paul-Bob Paul-Bob changed the title feature: access to the query on all action blocks enhancement: access to the query on all action blocks Jan 17, 2025
@Paul-Bob Paul-Bob merged commit 09b4270 into avo-hq:main Jan 17, 2025
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Not necessarily a feature, but something has improved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Access to the selected records on actions fields/messages
2 participants