Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V3-list-block-for-customer-cases #790

Merged
merged 14 commits into from
Oct 17, 2024
6 changes: 6 additions & 0 deletions studioShared/lib/queries/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ export const CUSTOMER_CASE_QUERY = groq`
_type == "richTextBlock" => {
...,
"richText": ${translatedFieldFragment("richText")},
},
_type == "listBlock" => {
"description": ${translatedFieldFragment("description")},
"list": list[] {
"text": ${translatedFieldFragment("text")},
},
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion studioShared/schemas/documents/customerCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { richTextID, titleID } from "studio/schemas/fields/text";
import { titleSlug } from "studio/schemas/schemaTypes/slug";
import { firstTranslation } from "studio/utils/i18n";
import { customerCaseProjectInfo } from "studioShared/schemas/fields/customerCaseProjectInfo";
import listBlock from "studioShared/schemas/objects/listBlock";
import richTextBlock from "studioShared/schemas/objects/richTextBlock";

export const customerCaseID = "customerCase";
Expand Down Expand Up @@ -36,7 +37,7 @@ const customerCase = defineType({
title: "Sections",
description: "Add sections here",
type: "array",
of: [richTextBlock],
of: [richTextBlock, listBlock],
}),
defineField({
name: richTextID,
Expand Down
73 changes: 73 additions & 0 deletions studioShared/schemas/objects/listBlock.ts
Original file line number Diff line number Diff line change
@@ -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,
};
},
},
},
],
},
],
anemne marked this conversation as resolved.
Show resolved Hide resolved
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;