diff --git a/studio/schemas/documents/compensations.ts b/studio/schemas/documents/compensations.ts index 2f715f8fd..d8e08701c 100644 --- a/studio/schemas/documents/compensations.ts +++ b/studio/schemas/documents/compensations.ts @@ -5,6 +5,9 @@ import offices from "../objects/offices"; import { title } from "../fields/text"; import { benefitId } from "./benefit"; +// smallest number of offices where ellipsis (...) will be used in preview +const OFFICES_PREVIEW_ELLIPSIS_LIMIT = 5; + export const compensationsId = "compensations"; const compensations = defineType({ @@ -33,8 +36,29 @@ const compensations = defineType({ ], preview: { select: { - title: "office.basicTitle", subtitle: "basicTitle", + // https://www.sanity.io/docs/previews-list-views#62febb15a63a + ...[...Array(OFFICES_PREVIEW_ELLIPSIS_LIMIT).keys()].reduce( + (o, i) => ({ ...o, [`office${i}`]: `offices.${i}.basicTitle` }), + {}, + ), + }, + prepare({ subtitle, ...officesMap }) { + const offices = Object.values(officesMap).filter( + (o) => o !== undefined, + ); + let title; + if (offices.length >= OFFICES_PREVIEW_ELLIPSIS_LIMIT) { + title = + offices.slice(0, OFFICES_PREVIEW_ELLIPSIS_LIMIT - 1).join(", ") + + ", ..."; + } else { + title = offices.join(", "); + } + return { + title, + subtitle, + }; }, }, });