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

Add if option to conditionally hide a collection action #48

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

guewen
Copy link

@guewen guewen commented Feb 4, 2025

Here's a way to conditionally hide collection actions.
It may be useful to check permissions or even to hide actions depending on the current scope/filters as we have access to the current params[:q] and params[:scope].

Closes #41

@guewen
Copy link
Author

guewen commented Feb 4, 2025

Hi @workgena, thanks for this useful gem!

I proposed this PR and another one (#47), any chance to have them in a release once reviewed / tests ok?

I was not able to run tests locally (undefined method assets' for an instance of Rails::Application::Configurationwhen runningrake setup`), so I'm not sure tests actually pass.

@workgena
Copy link
Contributor

@guewen Thank you for PR.

I'm not actively working with ActiveAdmin nowadays, so I would need more time to see how it works. I have this page open in the browser as a reminder.

@guewen
Copy link
Author

guewen commented Feb 13, 2025

Hi, thanks for answering @workgena!

I finally resorted to only using activeadmin's DSL only, which was enough for my needs, something such as (a bit simplified here):

  sidebar I18n.t('active_admin.actions.batch_export.sidebar.title'),
          only: :index do
    if params[:q] || params[:scope]
      para(I18n.t('active_admin.actions.batch_export.sidebar.help'))

      if can?(:export_csv, Order)
        div(
          link_to(I18n.t('active_admin.actions.batch_export.buttons.csv'),
                  batch_export_csv_admin_orders_path(params.slice(:q, :scope).permit!),
                  method: :post,
                  class: 'button btn')
        )
      end
    else
      para(I18n.t('active_admin.actions.batch_export.sidebar.help_no_filter'))
    end
  end

  collection_action :batch_export_csv, method: :post do
    ExportOrdersCsvJob.perform_async(batch_action_collection.pluck(:id), current_user.id)
  end

So I'm finally not using your gem. If you prefer, I can close my pull requests, but I'd happily follow up if there is more interest for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use of if proc
2 participants