Skip to content

Commit

Permalink
Refactor and improve studio flow for resultblock
Browse files Browse the repository at this point in the history
  • Loading branch information
idamand committed Nov 4, 2024
1 parent 1828466 commit 455cf41
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 17 deletions.
11 changes: 5 additions & 6 deletions studioShared/lib/interfaces/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions studioShared/lib/interfaces/resultBlock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
interface ResultListItem {
result: string;
description: string;
_key: string;
}

export interface ResultBlock {
Expand Down
15 changes: 8 additions & 7 deletions studioShared/lib/queries/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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[] -> {
Expand Down
7 changes: 6 additions & 1 deletion studioShared/schemas/documents/customerCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion studioShared/schemas/objects/resultBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand All @@ -56,6 +57,7 @@ const resultBlock = defineField({
item !== undefined
? (firstTranslation(item) ?? undefined)
: undefined,
subtitle: subtitle,
};
},
},
Expand Down
2 changes: 0 additions & 2 deletions studioShared/schemas/objects/sections.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import imageBlock from "./imageBlock";
import listBlock from "./listBlock";
import quoteBlock from "./quoteBlock";
import resultBlock from "./resultBlock";
import richTextBlock from "./richTextBlock";

export const baseCustomerCaseSections = [
richTextBlock,
imageBlock,
listBlock,
quoteBlock,
resultBlock,
];

0 comments on commit 455cf41

Please sign in to comment.