Skip to content

Commit

Permalink
feat(compensations): offices array preview
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Aug 30, 2024
1 parent 7dc5ec1 commit 06766d8
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion studio/schemas/documents/compensations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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<string>(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,
};
},
},
});
Expand Down

0 comments on commit 06766d8

Please sign in to comment.