From 455cf41a0c4c83df112cbd419d77a776d7f3935e Mon Sep 17 00:00:00 2001 From: Ida Marie Andreassen Date: Mon, 4 Nov 2024 13:34:57 +0100 Subject: [PATCH] Refactor and improve studio flow for resultblock --- studioShared/lib/interfaces/customerCases.ts | 11 +++++------ studioShared/lib/interfaces/resultBlock.ts | 1 + studioShared/lib/queries/customerCases.ts | 15 ++++++++------- studioShared/schemas/documents/customerCase.ts | 7 ++++++- studioShared/schemas/objects/resultBlock.ts | 4 +++- studioShared/schemas/objects/sections.ts | 2 -- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/studioShared/lib/interfaces/customerCases.ts b/studioShared/lib/interfaces/customerCases.ts index 4e8f7e8d3..40b4ca5f7 100644 --- a/studioShared/lib/interfaces/customerCases.ts +++ b/studioShared/lib/interfaces/customerCases.ts @@ -29,13 +29,12 @@ export interface CustomerCaseBase { image: IImage; } -export type BaseCustomerCaseSection = - | RichTextBlock - | ImageBlock - | QuoteBlock - | ResultBlock; +export type BaseCustomerCaseSection = RichTextBlock | ImageBlock | QuoteBlock; -export type CustomerCaseSection = BaseCustomerCaseSection | SplitSection; +export type CustomerCaseSection = + | BaseCustomerCaseSection + | SplitSection + | ResultBlock; export interface CustomerCase extends CustomerCaseBase { projectInfo: CustomerCaseProjectInfo; diff --git a/studioShared/lib/interfaces/resultBlock.ts b/studioShared/lib/interfaces/resultBlock.ts index b8fe47c2e..9da579f50 100644 --- a/studioShared/lib/interfaces/resultBlock.ts +++ b/studioShared/lib/interfaces/resultBlock.ts @@ -1,6 +1,7 @@ interface ResultListItem { result: string; description: string; + _key: string; } export interface ResultBlock { diff --git a/studioShared/lib/queries/customerCases.ts b/studioShared/lib/queries/customerCases.ts index f5503e04b..71412e949 100644 --- a/studioShared/lib/queries/customerCases.ts +++ b/studioShared/lib/queries/customerCases.ts @@ -48,13 +48,6 @@ export const BASE_SECTIONS_FRAGMENT = groq` "quote": ${translatedFieldFragment("quote")}, "author": ${translatedFieldFragment("author")}, }, - _type == "resultBlock" => { - "resultBlockTitle": ${translatedFieldFragment("resultBlockTitle")}, - "resultList": resultList[] { - result, - "description": ${translatedFieldFragment("description")}, - } - } `; export const CUSTOMER_CASE_QUERY = groq` @@ -81,6 +74,14 @@ export const CUSTOMER_CASE_QUERY = groq` ${BASE_SECTIONS_FRAGMENT} } }, + _type == "resultBlock" => { + "resultBlockTitle": ${translatedFieldFragment("resultBlockTitle")}, + "resultList": resultList[] { + _key, + result, + "description": ${translatedFieldFragment("description")}, + } + }, ${BASE_SECTIONS_FRAGMENT} }, "featuredCases": featuredCases[] -> { diff --git a/studioShared/schemas/documents/customerCase.ts b/studioShared/schemas/documents/customerCase.ts index 180f295f8..f868494c3 100644 --- a/studioShared/schemas/documents/customerCase.ts +++ b/studioShared/schemas/documents/customerCase.ts @@ -8,12 +8,17 @@ import { titleSlug } from "studio/schemas/schemaTypes/slug"; import { buildDraftId, buildPublishedId } from "studio/utils/documentUtils"; import { firstTranslation } from "studio/utils/i18n"; import { customerCaseProjectInfo } from "studioShared/schemas/fields/customerCaseProjectInfo"; +import resultBlock from "studioShared/schemas/objects/resultBlock"; import { baseCustomerCaseSections } from "studioShared/schemas/objects/sections"; import splitSection from "studioShared/schemas/objects/splitSection"; export const customerCaseID = "customerCase"; -export const customerCaseSections = [...baseCustomerCaseSections, splitSection]; +export const customerCaseSections = [ + ...baseCustomerCaseSections, + splitSection, + resultBlock, +]; const customerCase = defineType({ name: customerCaseID, diff --git a/studioShared/schemas/objects/resultBlock.ts b/studioShared/schemas/objects/resultBlock.ts index fbb2ad0b4..e5f058266 100644 --- a/studioShared/schemas/objects/resultBlock.ts +++ b/studioShared/schemas/objects/resultBlock.ts @@ -44,8 +44,9 @@ const resultBlock = defineField({ preview: { select: { item: "description", + subtitle: "result", }, - prepare({ item }) { + prepare({ item, subtitle }) { if (item !== undefined && !isInternationalizedString(item)) { throw new TypeError( `Expected 'title' to be InternationalizedString, was ${typeof item}`, @@ -56,6 +57,7 @@ const resultBlock = defineField({ item !== undefined ? (firstTranslation(item) ?? undefined) : undefined, + subtitle: subtitle, }; }, }, diff --git a/studioShared/schemas/objects/sections.ts b/studioShared/schemas/objects/sections.ts index 2378d22a6..3158f7214 100644 --- a/studioShared/schemas/objects/sections.ts +++ b/studioShared/schemas/objects/sections.ts @@ -1,7 +1,6 @@ import imageBlock from "./imageBlock"; import listBlock from "./listBlock"; import quoteBlock from "./quoteBlock"; -import resultBlock from "./resultBlock"; import richTextBlock from "./richTextBlock"; export const baseCustomerCaseSections = [ @@ -9,5 +8,4 @@ export const baseCustomerCaseSections = [ imageBlock, listBlock, quoteBlock, - resultBlock, ];