Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • A administrate
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 96
    • Issues 96
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 32
    • Merge requests 32
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • thoughtbot, inc.
  • administrate
  • Issues
  • #130
Closed
Open
Issue created Nov 02, 2015 by Administrator@rootContributor

Generate `SHOW_PAGE_ATTRIBUTES` as an explicit array

Created by: mcmire

Right now, COLLECTION_ATTRIBUTES, SHOW_PAGE_ATTRIBUTES, and FORM_ATTRIBUTES use ATTRIBUTE_TYPES.keys as a base set of attributes. It would follow, then, that in order to re-order fields that appear in a form or table, you re-order the keys in ATTRIBUTE_TYPES. However, this seems a little odd, because ATTRIBUTE_TYPES is a hash, and so the order of its keys should be irrelevant. (It just so happens that hashes in Ruby are now ordered, but they really shouldn't be, and we shouldn't be assuming they are.)

So here's a suggestion: introduce a BASE_ATTRIBUTES constant that all of the other *_ATTRIBUTES constants use. The dashboard generator would have to set this to an explicit array based on the columns the model has, but then we'd encourage people to modify this array instead of ATTRIBUTE_TYPES. While we're at it, it might be useful to place ATTRIBUTE_TYPES first.

So a dashboard class would look like this:

ATTRIBUTE_TYPES = {
  author: Field::BelongsTo.with_options(class_name: "User"),
  content: Field::Text,
  id: Field::Number,
  ...
}

BASE_ATTRIBUTES = [
  :author,
  :content,
  :id,
  ...
]

READ_ONLY_ATTRIBUTES = [
  :id,
  :created_at,
  :updated_at
]

TABLE_ATTRIBUTES = BASE_ATTRIBUTES.first(4)

SHOW_PAGE_ATTRIBUTES = BASE_ATTRIBUTES

FORM_ATTRIBUTES = BASE_ATTRIBUTES - READ_ONLY_ATTRIBUTES
Assignee
Assign to
Time tracking