thoughtbot / thoughtbot/administrate

Manual sorting of HasMany children list

Open
#2,276 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

nested-resources
Dominant language
JavaScript
Stars
6k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Dear all

The evolutions in the way Administrate handle sorting within the dashboards makes the gem flexible and super useful.
However, there is still a particular case which is not managed and which prevents me from having an administration tool entirely based on the configuration files of Administrator. : being able to reorder manually the list of children within a HasMany relation, based on a specific position attribute.

use case : I have an album template that contains many images. These images must be ordered manually by the person in charge of the album, according to his artistic touch, the story he wishes to tell.

I feel that this feature is probably cumbersome to implement, since it would likely impact pagination and other well-established features and add specific behavior regarding the existing/non existing positions when children's data are imported.
Acts_as_list had a bunch of methods allowing things like this I guess.

However, I have the intuition that such an ordering solution, which corresponds well to a data administration action, would be useful for the management of many data models.

In the case of a "simple" HasMany relationship, it would suffice to pass two pieces of information to the dashboard: specify the classification mode and specify the name of the attribute that contains the position of each child.

  ATTRIBUTE_TYPES = {
    pictures: Field::HasMany.with_options(sortable: true, sortable_index_position: :position),
  }.freeze

A last option could allow to specify the method of interaction allowing to modify the classification if there were several.

I hope this idea will interest some of you :)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Field::HasMany dashboard configuration and review how HasMany children are currently sorted and paginated. Compare the proposed sortable and sortable_index_position options with acts_as_list-style ordering, including imported children and missing positions. Done means a defined, usable way to reorder children manually without breaking existing pagination.

Written by the indexing model from the issue text.

Assessment

Tech stack
rails, ruby
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.