From 3bef07f5a383c41901b4beefc725c7187df458f6 Mon Sep 17 00:00:00 2001 From: anemne <63043552+anemne@users.noreply.github.com> Date: Thu, 17 Oct 2024 16:22:23 +0200 Subject: [PATCH] V3-list-block-for-customer-cases (#790) * Added block for list component * removed console.log * Update studioShared/schemas/objects/listBlock.ts Co-authored-by: Mathias Oterhals Myklebust <24361490+mathiazom@users.noreply.github.com> * Update studioShared/schemas/objects/listBlock.ts Co-authored-by: Mathias Oterhals Myklebust <24361490+mathiazom@users.noreply.github.com> * Update studioShared/schemas/objects/listBlock.ts Co-authored-by: Mathias Oterhals Myklebust <24361490+mathiazom@users.noreply.github.com> * Update studioShared/schemas/objects/listBlock.ts Co-authored-by: Mathias Oterhals Myklebust <24361490+mathiazom@users.noreply.github.com> * Update studioShared/lib/queries/customerCases.ts Co-authored-by: Mathias Oterhals Myklebust <24361490+mathiazom@users.noreply.github.com> * Update studioShared/schemas/objects/listBlock.ts Co-authored-by: Mathias Oterhals Myklebust <24361490+mathiazom@users.noreply.github.com> * Update studioShared/schemas/objects/listBlock.ts Co-authored-by: Mathias Oterhals Myklebust <24361490+mathiazom@users.noreply.github.com> * resolve conflicts --------- Co-authored-by: Mathias Oterhals Myklebust <24361490+mathiazom@users.noreply.github.com> --- studioShared/lib/queries/customerCases.ts | 6 ++ .../schemas/documents/customerCase.ts | 3 +- studioShared/schemas/objects/listBlock.ts | 73 +++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 studioShared/schemas/objects/listBlock.ts diff --git a/studioShared/lib/queries/customerCases.ts b/studioShared/lib/queries/customerCases.ts index 98ab66bbf..28fbdb46c 100644 --- a/studioShared/lib/queries/customerCases.ts +++ b/studioShared/lib/queries/customerCases.ts @@ -46,6 +46,12 @@ export const CUSTOMER_CASE_QUERY = groq` "images": images[] { ${INTERNATIONALIZED_IMAGE_FRAGMENT} } + }, + _type == "listBlock" => { + "description": ${translatedFieldFragment("description")}, + "list": list[] { + "text": ${translatedFieldFragment("text")}, + }, } } } diff --git a/studioShared/schemas/documents/customerCase.ts b/studioShared/schemas/documents/customerCase.ts index 1f0ff2abf..b641e7df5 100644 --- a/studioShared/schemas/documents/customerCase.ts +++ b/studioShared/schemas/documents/customerCase.ts @@ -7,6 +7,7 @@ import { titleSlug } from "studio/schemas/schemaTypes/slug"; import { firstTranslation } from "studio/utils/i18n"; import { customerCaseProjectInfo } from "studioShared/schemas/fields/customerCaseProjectInfo"; import imageBlock from "studioShared/schemas/objects/imageBlock"; +import listBlock from "studioShared/schemas/objects/listBlock"; import richTextBlock from "studioShared/schemas/objects/richTextBlock"; export const customerCaseID = "customerCase"; @@ -48,7 +49,7 @@ const customerCase = defineType({ title: "Sections", description: "Add sections here", type: "array", - of: [richTextBlock, imageBlock], + of: [richTextBlock, imageBlock, listBlock], }), defineField({ name: richTextID, diff --git a/studioShared/schemas/objects/listBlock.ts b/studioShared/schemas/objects/listBlock.ts new file mode 100644 index 000000000..465e6a551 --- /dev/null +++ b/studioShared/schemas/objects/listBlock.ts @@ -0,0 +1,73 @@ +import { defineField } from "sanity"; + +import { isInternationalizedString } from "studio/lib/interfaces/global"; +import { firstTranslation } from "studio/utils/i18n"; +const listBlock = defineField({ + name: "listBlock", + title: "List Block", + description: + "This block could be used to add a list of skills, tools, methods etc. used for this project.", + type: "object", + fields: [ + { + name: "description", + title: "Description", + description: + "Please provide a brief sentence describing the list. For example: The following skills were applied in this project:", + type: "internationalizedArrayString", + }, + { + name: "list", + title: "List", + description: + "Add the items to be included in this list (e.g., skills, tools, methods).", + type: "array", + of: [ + { + type: "object", // You need to define it as an object since it's a custom field + title: "List Item", + name: "listItem", + fields: [ + { + name: "text", + title: "Text", + type: "internationalizedArrayString", + }, + ], + preview: { + select: { + item: "text", + }, + prepare({ item }) { + if (!isInternationalizedString(item)) { + throw new TypeError( + `Expected 'item' to be InternationalizedString, was ${typeof item}`, + ); + } + return { + title: firstTranslation(item) ?? undefined, + }; + }, + }, + }, + ], + }, + ], + preview: { + select: { + description: "description", + }, + prepare({ description }) { + if (!isInternationalizedString(description)) { + throw new TypeError( + `Expected 'description' to be InternationalizedString, was ${typeof description}`, + ); + } + return { + title: firstTranslation(description) ?? undefined, + }; + }, + }, +}); + +export default listBlock;