Skip to content

Commit

Permalink
V3-list-block-for-customer-cases (#790)
Browse files Browse the repository at this point in the history
* Added block for list component

* removed console.log

* Update studioShared/schemas/objects/listBlock.ts

Co-authored-by: Mathias Oterhals Myklebust <[email protected]>

* Update studioShared/schemas/objects/listBlock.ts

Co-authored-by: Mathias Oterhals Myklebust <[email protected]>

* Update studioShared/schemas/objects/listBlock.ts

Co-authored-by: Mathias Oterhals Myklebust <[email protected]>

* Update studioShared/schemas/objects/listBlock.ts

Co-authored-by: Mathias Oterhals Myklebust <[email protected]>

* Update studioShared/lib/queries/customerCases.ts

Co-authored-by: Mathias Oterhals Myklebust <[email protected]>

* Update studioShared/schemas/objects/listBlock.ts

Co-authored-by: Mathias Oterhals Myklebust <[email protected]>

* Update studioShared/schemas/objects/listBlock.ts

Co-authored-by: Mathias Oterhals Myklebust <[email protected]>

* resolve conflicts

---------

Co-authored-by: Mathias Oterhals Myklebust <[email protected]>
  • Loading branch information
anemne and mathiazom authored Oct 17, 2024
1 parent 2c64fa3 commit 3bef07f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
6 changes: 6 additions & 0 deletions studioShared/lib/queries/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")},
},
}
}
}
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 @@ -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";
Expand Down Expand Up @@ -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,
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,
};
},
},
},
],
},
],
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;

0 comments on commit 3bef07f

Please sign in to comment.