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 multi-record support to attributes_table_for #2544

Merged

Conversation

zorab47
Copy link
Contributor

@zorab47 zorab47 commented Oct 8, 2013

Allow multiple records to be displayed in columns using the ActiveAdmin attribute_table_for component, while staying backward compatible with the previous behavior. It also builds a colgroup and col elements to facilitate styling each record's table column, but only when a collection is provided.

The PR is a result of discussions in #2540.

attributes_table_for_collection

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.17%) when pulling 406d7bd on zorab47:multi-record-attributes-table-for into 1f4f90c on gregbell:master.

@seanlinsley
Copy link
Contributor

💙

But do you really think attributes_table_for is a descriptive name of this functionality? I'm in favor of renaming it and deprecating the current method.

@zorab47
Copy link
Contributor Author

zorab47 commented Oct 8, 2013

Were you thinking of something like this?

table_for collection, by: :row do
  field :id
  field :name
end

or maybe this?

table_for collection, display: :attributes do; end
table_for collection, display: :columns do; end
table_for collection, display: :rows do; end # <= the default behavior

What would be the best approach for moving to a new API like this? Provide deprecated aliases for the existing API?

@seanlinsley
Copy link
Contributor

What would display: :attributes do?

I think I'm in favor of display: :rows and display: :columns, but I'll need to sleep on it.

Yeah, the idea is we'd keep aliases for the existing API for at least the next release.

If we're going to merge these, I'm still conflicted on the field vs column & row question...

@zorab47
Copy link
Contributor Author

zorab47 commented Oct 8, 2013

I like to try all possible names to see which would be the best. Display :attributes could be an "alias" for the attributes_table_for, but it would probably be best to drop it entirely.

I think this new API would take the form:

table_for collection do
  column :name
end

table_for collection, display: :columns do
  row :name
end

The calls row and column would be aliases, which helps convey what type table is being constructed. In reality, they are defining an attribute field for the table. And to be the most flexible add another alias as field.

There is still potential for confusion. If a user wants to change the table format to be displayed by rows; she converts all the column calls to row, but then forgets to set the :display option. This may lead to several questions.

@seanlinsley
Copy link
Contributor

Maybe if you're using row or column in the wrong table, we could raise an exception.

On Oct 8, 2013, at 8:12 AM, Charles Maresh [email protected] wrote:

I like to try all possible names to see which would be the best. Display :attributes could be an "alias" for the attributes_table_for, but it would probably be best to drop it entirely.

I think this new API would take the form:

table_for collection do
column :name
end

table_for collection, display: :rows do
row :name
end
The calls row and column would be aliases, which helps convey what type table is being constructed. In reality, they are defining an attribute field for the table. And to be the most flexible add another alias as field.

There is still potential for confusion. If a user wants to change the table format to be displayed by rows; she converts all the column calls to row, but then forgets to set the :display option. This may lead to several questions.


Reply to this email directly or view it on GitHub.

@zorab47
Copy link
Contributor Author

zorab47 commented Oct 8, 2013

A more intuitive solution would be to display the table by columns if all the calls are row and display the table by rows if all the calls are column. Then an error must be raised if there is a mixture of the two calls.

@shekibobo
Copy link
Contributor

I think I'm with @zorab47 on this one.

table_for collection do
  row :id
  row :name
  row :created_at
end

table_for collection do
  column :id
  column :name
  column :created_at
end

Feels much more intuitive. In fact I'm pretty sure I've absent-mindedly tried to do this on multiple occasions.

I'd also vote for columns and rows support, as well, for passing multiple fields in one call.

@seanlinsley
Copy link
Contributor

I'm not sure how we'll deal with the built in selectable_column, id_column and actions, but I like the idea.

It should probably be its own PR though, after this one. Do you agree @zorab47? If so, I'll merge this one.

@zorab47
Copy link
Contributor Author

zorab47 commented Oct 8, 2013

@daxter I'm good with that approach.

@shekibobo
Copy link
Contributor

TIL id_column

@seanlinsley
Copy link
Contributor

Yeah, I don't think id_column is documented anywhere. I found it when spelunking through the code.

seanlinsley added a commit that referenced this pull request Oct 8, 2013
Add multi-record support to attributes_table_for
@seanlinsley seanlinsley merged commit f512d2b into activeadmin:master Oct 8, 2013
@seanlinsley
Copy link
Contributor

Thanks for the contribution! 🐼

@zorab47 zorab47 deleted the multi-record-attributes-table-for branch October 8, 2013 16:07
@seanlinsley
Copy link
Contributor

@zorab47 are you planning on implementing the new table_for? If not I'm more than happy to.

@zorab47
Copy link
Contributor Author

zorab47 commented Oct 8, 2013

@daxter it is your call. I won't have time to dedicate to it until this coming weekend.

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.

4 participants