schemasanity

Display all properties of an array of objects in Sanity.io


In a Sanity project, I've created a schema containing an array of objects.

In Sanity Studio, this appears as a list of those objects' first property, but I really need to see at least 2 properties for it to be meaningful.

I can't find a way to do this. Is it possible?

Below is my schema. It represents a blog article which holds an array of translations. Each translation is defined by a language and a reference to another article.

// sanity\schemas\documents\article.ts

import { defineArrayMember, defineField, defineType } from "sanity"
import translation from "../objects/translation";

export default defineType({
    title: 'Article',
    name: 'article',
    type: 'document',
    fields: [
        defineField({ title: 'Title', name: 'title', type: 'string' }),
        defineField({ title: 'Translations', name: 'translations', type: 'array', of: [defineArrayMember(translation)] }),
// sanity\schemas\objects\translation.ts

import { defineField, defineType } from "sanity"

export default defineType({
    title: 'Translation',
    name: 'translation',
    type: 'object',
    fields: [
        defineField({ title: 'Language', name: 'language', type: 'string' }),
        defineField({ title: 'Article', name: 'article', type: 'reference', to: [{ type: 'article' }] }),
    ]
});

This is how it shows up:

enter image description here

I would like to see "fr - title of the article in french".

Note that I'd like to do this for other fields too, so I'm not looking for a package to handle internationalisation. Is it doable?


Solution

  • Found the answer: https://www.sanity.io/docs/previews-list-views

    I hadn't realised this applies to lists within fields too, not just lists of documents. Adding the "preview" property at the root of my schema did the trick:

    preview: {
      select: {
        title: 'field1',
        subtitle: 'field2'
      }
    }