keystone icon indicating copy to clipboard operation
keystone copied to clipboard

Field Groups

Open raveling opened this issue 3 years ago • 1 comments

Grouping fields:

When configuring the Admin UI for users, it can sometimes be helpful to group a series of fields together to provide a related context and thereby improve the editing experience.

Grouping fields can be helpful in situations like:

  • Addresses (street, suburb, postcode, country)
  • SEO (meta title, meta description, meta image)
  • Shipping details (height, length, depth, weight)

Progressive disclosure:

In addition to grouping related fields, providing Admin UI users with a means in which to hide or reveal a group of fields can move complex or less frequently used fields out of the main editing flow and into secondary locations. A progressive disclosure mechanism (e.g. accordion) would make it possible for the user to have more information within reach without causing visual overwhelm.

Before this feature, developers could place related fields in adjacent order on the item form, but the only way to visually signify relatedness, or offer progressive disclosure would involve the creation of a custom field view.

A Field Groups feature would make it easy for a developer to achieve the design intent below in in a low friction manner from within their schema.ts file.

Design intent for a field group feature in Admin UI showing a collapsed and expanded version

raveling avatar Jun 02 '22 01:06 raveling

I would love a feature like that.

fkrauthan avatar Jun 22 '22 03:06 fkrauthan

Definitely would love it

websaid avatar Oct 12 '22 07:10 websaid

A few thoughts around how this might look in configuration... posted here for posterity :blue_book:

Using the .ui object

Option 1

const Post = list({
  ui: {
    groups: {
      attachment: {
        label: 'Attachment',
        description: 'a short description',
        // would need to error if the fields aren't contiguous and in order?
        fields: ['url', 'alt'],
      },
    },
  },
  fields: {
    content: text(),
    url: text(),
    alt: text(),
  },
})

Option 2

const Post = list({
  ui: {
    groups: [{
      from: 'url',
      to: 'alt',
      label: 'Attachment',
      description: 'a short description',
    }],
  },
  fields: {
    content: text(),
    url: text(),
    alt: text(),
  },
})

Not defined at the list level (not .ui)

Option 3

const Post = list({
  fields: {
    content: text(),
    ...group({
      label: 'Attachment',
      description: 'a short description',
      fields: {
        url: text(),
        alt: text(),
      },
    }),
  },
})

What about GraphQL and relationships and database naming

Option 4

const Post = list({
  fields: {
    content: text(),
    url: text(),
    attachment: group({
      label: 'Attachment',
      description: 'a short description',
      fields: {
        url: text(), // TODO: would this be attachment_url?
                     // For relationships? Post.attachment.url?
        alt: text(),
      },
    }),
  },
})

This may or may not be the desired outcome, but this is what I would expect if we put it in fields. This may conflict with some ideas and idioms we have with structured JSON, or maybe it will be idiosyncratically aligned.

Related

  • https://github.com/keystonejs/keystone/issues/7584
  • https://github.com/keystonejs/keystone/issues/195
  • https://github.com/keystonejs/keystone/pull/4805

dcousens avatar Oct 13 '22 05:10 dcousens