From a342450189db3cb6253d31356b990fcb3e14b360 Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Wed, 21 Aug 2024 09:53:10 +0200 Subject: [PATCH 1/4] feat(benefit): benefit type field --- studio/schemas/documents/benefit.ts | 38 +++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/studio/schemas/documents/benefit.ts b/studio/schemas/documents/benefit.ts index 840c815bc..333aee66b 100644 --- a/studio/schemas/documents/benefit.ts +++ b/studio/schemas/documents/benefit.ts @@ -1,27 +1,45 @@ -import { defineType } from 'sanity'; -import { richText, title } from '../fields/text'; +import { defineField, defineType } from "sanity"; +import { richText, title } from "../fields/text"; export const benefitId = "benefit"; +export const benefitTypeId = "benefitType"; + +const BENEFIT_TYPES = [ + { title: "Gadgets", value: "gadgets" }, + { title: "Bonus", value: "bonus" }, + { title: "Pension", value: "pension" }, + { title: "Salary Growth", value: "salaryGrowth" }, +]; + +const benefitType = defineField({ + name: benefitTypeId, + type: "string", + title: "Benefit Type", + description: + "Choose the type of benefit, or leave blank for generic benefits. Some benefit types include visual graphs that will be displayed together with the text.", + options: { + list: BENEFIT_TYPES, + layout: "dropdown", + }, +}); const benefit = defineType({ name: benefitId, type: "document", title: "Benefit", - fields: [ - title, - richText - ], + fields: [benefitType, title, richText], preview: { select: { title: title.name, + type: benefitType.name, }, - prepare({ title }) { + prepare({ title, type }) { return { title, - subtitle: "Benefit", + subtitle: `Benefit${type ? ` / ${BENEFIT_TYPES.find((o) => o.value === type)?.title ?? "Unknown benefit type"}` : ""}`, }; }, }, -}) +}); -export default benefit; \ No newline at end of file +export default benefit; From ebb4227e29486462ac03ddb255d1acc5f67c4e6c Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Wed, 21 Aug 2024 13:32:03 +0200 Subject: [PATCH 2/4] feat(benefit): add default None option for benefit types --- studio/schemas/documents/benefit.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/studio/schemas/documents/benefit.ts b/studio/schemas/documents/benefit.ts index 333aee66b..73ec57e06 100644 --- a/studio/schemas/documents/benefit.ts +++ b/studio/schemas/documents/benefit.ts @@ -4,7 +4,9 @@ import { richText, title } from "../fields/text"; export const benefitId = "benefit"; export const benefitTypeId = "benefitType"; +const BENEFIT_TYPE_NONE_VALUE = "none"; const BENEFIT_TYPES = [ + { title: "None", value: BENEFIT_TYPE_NONE_VALUE }, { title: "Gadgets", value: "gadgets" }, { title: "Bonus", value: "bonus" }, { title: "Pension", value: "pension" }, @@ -16,11 +18,13 @@ const benefitType = defineField({ type: "string", title: "Benefit Type", description: - "Choose the type of benefit, or leave blank for generic benefits. Some benefit types include visual graphs that will be displayed together with the text.", + "Choose the type of benefit (use None for generic benefits). Some benefit types include visual graphs that will be displayed together with the text.", options: { list: BENEFIT_TYPES, - layout: "dropdown", + layout: BENEFIT_TYPES.length > 5 ? "dropdown" : "radio", }, + initialValue: BENEFIT_TYPE_NONE_VALUE, + validation: (Rule) => Rule.required(), }); const benefit = defineType({ From 2cfef7c3f582c1c00217c207b6a13fdb9ee3a4c2 Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Wed, 21 Aug 2024 14:19:29 +0200 Subject: [PATCH 3/4] refactor(benefit): rename benefit type "None" to "Basic" --- studio/schemas/documents/benefit.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/studio/schemas/documents/benefit.ts b/studio/schemas/documents/benefit.ts index 73ec57e06..d55c4d2e5 100644 --- a/studio/schemas/documents/benefit.ts +++ b/studio/schemas/documents/benefit.ts @@ -4,9 +4,9 @@ import { richText, title } from "../fields/text"; export const benefitId = "benefit"; export const benefitTypeId = "benefitType"; -const BENEFIT_TYPE_NONE_VALUE = "none"; +const BENEFIT_TYPE_BASIC_VALUE = "basic"; const BENEFIT_TYPES = [ - { title: "None", value: BENEFIT_TYPE_NONE_VALUE }, + { title: "Basic", value: BENEFIT_TYPE_BASIC_VALUE }, { title: "Gadgets", value: "gadgets" }, { title: "Bonus", value: "bonus" }, { title: "Pension", value: "pension" }, @@ -18,12 +18,12 @@ const benefitType = defineField({ type: "string", title: "Benefit Type", description: - "Choose the type of benefit (use None for generic benefits). Some benefit types include visual graphs that will be displayed together with the text.", + "Choose the type of benefit. Some benefit types include visual graphs that will be displayed together with the text.", options: { list: BENEFIT_TYPES, layout: BENEFIT_TYPES.length > 5 ? "dropdown" : "radio", }, - initialValue: BENEFIT_TYPE_NONE_VALUE, + initialValue: BENEFIT_TYPE_BASIC_VALUE, validation: (Rule) => Rule.required(), }); From fef485bbd1f4067e73b9df4c29917b22a31ef1ef Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Wed, 21 Aug 2024 14:23:38 +0200 Subject: [PATCH 4/4] feat(benefit): remove "Benefit /" prefix from benefit type list preview --- studio/schemas/documents/benefit.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/studio/schemas/documents/benefit.ts b/studio/schemas/documents/benefit.ts index d55c4d2e5..d1794b83f 100644 --- a/studio/schemas/documents/benefit.ts +++ b/studio/schemas/documents/benefit.ts @@ -38,9 +38,12 @@ const benefit = defineType({ type: benefitType.name, }, prepare({ title, type }) { + const subtitle = + BENEFIT_TYPES.find((o) => o.value === type)?.title ?? + "Unknown benefit type"; return { title, - subtitle: `Benefit${type ? ` / ${BENEFIT_TYPES.find((o) => o.value === type)?.title ?? "Unknown benefit type"}` : ""}`, + subtitle, }; }, },