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

Custom additional action on actions column on index page #1676

Closed
bekicot opened this issue Jun 15, 2020 · 6 comments
Closed

Custom additional action on actions column on index page #1676

bekicot opened this issue Jun 15, 2020 · 6 comments
Assignees
Labels
dashboards how administrate presents fields and displays data feature new functionality that’s not yet implemented

Comments

@bekicot
Copy link
Contributor

bekicot commented Jun 15, 2020

  • What would you like to be able to do? Can you provide some examples?
    Custom additional action on actions column on the index page

  • How could we go about implementing that?
    The simplest way is to move the actions column into partial so that the user can override just the actions column part of the table. Instead of overriding the whole collection partial.
    We also need to update the column heading count to also account for the additional custom action.

Another approach is probably to add ability to add an action button via the dashboard class.

# CarDashboard.rb
ACTIONS = [:start, :stop, :destroy, :show]
# CarController.rb
def start
resource.start!
end
  • Can you think of other approaches to the problem?
    Currently, we can override the whole collection partial. But it will lead to a greater incompatibility upon updating administrate.
@pablobm
Copy link
Collaborator

pablobm commented Jun 25, 2020

I'd prefer two partials: one for the header and another for the record rows, both used from app/views/administrate/application/_collection.html.erb. At least for now, as it will be more forward-compatible. In the future, this may or may not be generated from external info (such as new dashboard field like the one you propose), but for now I feel that would add unnecessary complexity.

How do you feel about this? Would you be able to create a PR that splits the two partials out of that template?

@nickcharlton nickcharlton added dashboards how administrate presents fields and displays data feature new functionality that’s not yet implemented labels Jun 30, 2020
@bekicot
Copy link
Contributor Author

bekicot commented Jul 9, 2020

@pablobm I will find some time this weekend to tackle this one. Please assign this issue to me.

bekicot added a commit to bekicot/administrate that referenced this issue Oct 29, 2020
also move actions into their own partials

close thoughtbot#1676
bekicot added a commit to bekicot/administrate that referenced this issue Oct 29, 2020
also move actions into their own partials

close thoughtbot#1676
bekicot added a commit to bekicot/administrate that referenced this issue Oct 29, 2020
also move actions into their own partials

close thoughtbot#1676
bekicot added a commit to bekicot/administrate that referenced this issue Oct 29, 2020
also move actions into their own partials

close thoughtbot#1676
pablobm added a commit to pablobm/administrate that referenced this issue Jun 10, 2021
Our collection tables show two actions for each record: "Edit" and
"Destroy". What if we want to allow other actions? This involves
overriding the whole collection template, which is messy and adds
friction when upgrading to new versions of Administrate.

We have some examples of this need in our issue tracker. For example:
thoughtbot#1676 More selfishly,
I want to add one such custom action in the changes I'm making to how
the example app handles authorization :-P

This PR splits the collection partial into new partials that can be
more easily overridden by users.
pablobm added a commit to pablobm/administrate that referenced this issue Jun 17, 2021
Our collection tables show two actions for each record: "Edit" and
"Destroy". What if we want to allow other actions? This involves
overriding the whole collection template, which is messy and adds
friction when upgrading to new versions of Administrate.

We have some examples of this need in our issue tracker. For example:
thoughtbot#1676 More selfishly,
I want to add one such custom action in the changes I'm making to how
the example app handles authorization :-P

This PR splits the collection partial into new partials that can be
more easily overridden by users.
pablobm added a commit to pablobm/administrate that referenced this issue Jun 17, 2021
Our collection tables show two actions for each record: "Edit" and
"Destroy". What if we want to allow other actions? This involves
overriding the whole collection template, which is messy and adds
friction when upgrading to new versions of Administrate.

We have some examples of this need in our issue tracker. For example:
thoughtbot#1676 More selfishly,
I want to add one such custom action in the changes I'm making to how
the example app handles authorization :-P

This PR splits the collection partial into new partials that can be
more easily overridden by users.
@audyaver
Copy link

Is there any progress on this? I am trying to add a custom action link to my dashboard and having issues with it.

This is my route:

get 'admin/foo/:id/solr_index', to: 'foo#solr_index', as: 'admin_foo_solr_index_path'

I am adding this link_to to my _collection.html.erb file for foo controller:

<%= link_to(
            t("administrate.actions.solr_index"),
            [namespace, resource, :solr_index]

            ) if show_action? :solr_index, resource %>

And I am getting the following error on the index page:

Showing /xxx/app/views/admin/foo/_collection.html.erb where line #87 raised:

undefined method `admin_foo_solr_index_path' for #<#<Class:0x007fcce47c8720>:0x007fcce4adcd80>

I would appreciate if you could tell me what I am missing here.

@pablobm
Copy link
Collaborator

pablobm commented Aug 8, 2021

@audyaver - In your specific case, I think that Administrate is not the problem. Your route definition looks wrong. You have this:

get 'admin/foo/:id/solr_index', to: 'foo#solr_index', as: 'admin_foo_solr_index_path'

And I think it should be this:

get 'admin/foo/:id/solr_index', to: 'foo#solr_index', as: 'admin_foo_solr_index'

To clarify: without the suffix "_path", as this is added automatically by Rails. In your example, you'd get the route helpers admin_foo_solr_index_path_path and admin_foo_solr_index_path_url, which I don't think is what you want.

@pablobm
Copy link
Collaborator

pablobm commented Aug 8, 2021

Re: this issue in general, there's some progress at #1998, which implements new partials to help with this.

pablobm added a commit to pablobm/administrate that referenced this issue Aug 8, 2021
Our collection tables show two actions for each record: "Edit" and
"Destroy". What if we want to allow other actions? This involves
overriding the whole collection template, which is messy and adds
friction when upgrading to new versions of Administrate.

We have some examples of this need in our issue tracker. For example:
thoughtbot#1676 More selfishly,
I want to add one such custom action in the changes I'm making to how
the example app handles authorization :-P

This PR splits the collection partial into new partials that can be
more easily overridden by users.
pablobm added a commit that referenced this issue Aug 26, 2021
Our collection tables show two actions for each record: "Edit" and
"Destroy". What if we want to allow other actions? This involves
overriding the whole collection template, which is messy and adds
friction when upgrading to new versions of Administrate.

We have some examples of this need in our issue tracker. For example:
#1676 More selfishly,
I want to add one such custom action in the changes I'm making to how
the example app handles authorization :-P

This PR splits the collection partial into new partials that can be
more easily overridden by users.
KingTiger001 added a commit to KingTiger001/admin-Rails-project that referenced this issue Jan 15, 2023
Our collection tables show two actions for each record: "Edit" and
"Destroy". What if we want to allow other actions? This involves
overriding the whole collection template, which is messy and adds
friction when upgrading to new versions of Administrate.

We have some examples of this need in our issue tracker. For example:
thoughtbot/administrate#1676 More selfishly,
I want to add one such custom action in the changes I'm making to how
the example app handles authorization :-P

This PR splits the collection partial into new partials that can be
more easily overridden by users.
@pablobm
Copy link
Collaborator

pablobm commented Apr 6, 2023

This should be fixed now after merging #1998. I have added it to the list of stuff to document.

@pablobm pablobm closed this as completed Apr 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dashboards how administrate presents fields and displays data feature new functionality that’s not yet implemented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants