Skip to content

Commit

Permalink
fix(utilities): crowdin object filtered fields logic (#196)
Browse files Browse the repository at this point in the history
* fix(utilities): crowdin object filtered fields logic

* fix(utilities): flatten fields in buildPayloadUpdateObject

* fix(lib): cleanup and fix test

* style(test): remove unused imports
  • Loading branch information
thompsonsj authored Oct 20, 2024
1 parent 289af27 commit 2d788e5
Show file tree
Hide file tree
Showing 10 changed files with 1,056 additions and 66 deletions.
35 changes: 35 additions & 0 deletions dev/src/lib/collections/NestedFieldCollection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Block, CollectionConfig } from "payload/types";
import { basicLocalizedFields } from "./fields/basicLocalizedFields";
import { delocalizeFields } from "../utils";
import { lexicalEditorWithBlocks } from "./fields/lexicalEditorWithBlocks";

const BasicBlockTextFields: Block = {
slug: "basicBlock", // required
Expand Down Expand Up @@ -30,6 +31,13 @@ const BasicBlockMixedFields: Block = {
],
};

const BasicBlockLexical: Block = {
slug: "basicBlockLexical",
fields: [
lexicalEditorWithBlocks,
]
}

const TestBlockArrayOfRichText: Block = {
slug: "testBlockArrayOfRichText",
fields: [
Expand Down Expand Up @@ -118,6 +126,33 @@ const NestedFieldCollection: CollectionConfig = {
},
],
},
{
label: "Block Layout Tab",
fields: [
{
name: 'items',
type: 'array',
minRows: 1,
maxRows: 20,
fields: [
{
name: "heading",
type: "text",
localized: true,
},
{
name: 'block',
type: 'blocks',
minRows: 1,
maxRows: 1,
blocks: [
BasicBlockLexical,
]
},
],
},
]
},
{
name: "tabTwo",
label: "Tab Two Label",
Expand Down
28 changes: 28 additions & 0 deletions dev/src/lib/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,34 @@ export interface NestedFieldCollection {
[k: string]: unknown;
}[]
| null;
items?:
| {
heading?: string | null;
block?:
| {
content?: {
root: {
type: string;
children: {
type: string;
version: number;
[k: string]: unknown;
}[];
direction: ('ltr' | 'rtl') | null;
format: 'left' | 'start' | 'center' | 'right' | 'end' | 'justify' | '';
indent: number;
version: number;
};
[k: string]: unknown;
} | null;
id?: string | null;
blockName?: string | null;
blockType: 'basicBlockLexical';
}[]
| null;
id?: string | null;
}[]
| null;
tabTwo: {
tabTwoTitle?: string | null;
tabTwoContent?:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,273 @@
import { NestedFieldCollection } from "../../payload-types";

export const fixture = {
"id": "6712ecd0ce62939a20dea70c",
"arrayField": [],
"layout": [],
"group": {},
"items": [
{
"heading": "Nested Lexical fields are supported",
"block": [
{
"content": {
"root": {
"children": [
{
"children": [
{
"detail": 0,
"format": 0,
"mode": "normal",
"style": "",
"text": "Lexical fields nested within complex layouts - such as this one (a ",
"type": "text",
"version": 1
},
{
"detail": 0,
"format": 16,
"mode": "normal",
"style": "",
"text": "blocks",
"type": "text",
"version": 1
},
{
"detail": 0,
"format": 0,
"mode": "normal",
"style": "",
"text": " field in an ",
"type": "text",
"version": 1
},
{
"detail": 0,
"format": 16,
"mode": "normal",
"style": "",
"text": "array",
"type": "text",
"version": 1
},
{
"detail": 0,
"format": 0,
"mode": "normal",
"style": "",
"text": " item within a ",
"type": "text",
"version": 1
},
{
"detail": 0,
"format": 16,
"mode": "normal",
"style": "",
"text": "tab",
"type": "text",
"version": 1
},
{
"detail": 0,
"format": 0,
"mode": "normal",
"style": "",
"text": "), are supported.",
"type": "text",
"version": 1
}
],
"direction": "ltr",
"format": "",
"indent": 0,
"type": "paragraph",
"version": 1
}
],
"direction": "ltr",
"format": "",
"indent": 0,
"type": "root",
"version": 1
}
},
"id": "6712ecd0a87c5472e08bf255",
"blockType": "basicBlockLexical"
}
],
"id": "6712ecd0a87c5472e08bf253"
},
{
"heading": "Nested Lexical fields are supported - and blocks in that Lexical field are also translated",
"block": [
{
"content": {
"root": {
"children": [
{
"children": [
{
"detail": 0,
"format": 0,
"mode": "normal",
"style": "",
"text": "If you add custom blocks, these will also be translated!",
"type": "text",
"version": 1
}
],
"direction": "ltr",
"format": "",
"indent": 0,
"type": "paragraph",
"version": 1
},
{
"format": "",
"type": "block",
"version": 2,
"fields": {
"id": "6712ec66a81e050bf5f31b43",
"blockName": "",
"blockType": "highlight",
"content": {
"root": {
"children": [
{
"children": [
{
"detail": 0,
"format": 0,
"mode": "normal",
"style": "",
"text": "Note a key difference with regular blocks - all ",
"type": "text",
"version": 1
},
{
"detail": 0,
"format": 16,
"mode": "normal",
"style": "",
"text": "text",
"type": "text",
"version": 1
},
{
"detail": 0,
"format": 0,
"mode": "normal",
"style": "",
"text": ", ",
"type": "text",
"version": 1
},
{
"detail": 0,
"format": 16,
"mode": "normal",
"style": "",
"text": "textarea",
"type": "text",
"version": 1
},
{
"detail": 0,
"format": 0,
"mode": "normal",
"style": "",
"text": " and ",
"type": "text",
"version": 1
},
{
"detail": 0,
"format": 16,
"mode": "normal",
"style": "",
"text": "richText",
"type": "text",
"version": 1
},
{
"detail": 0,
"format": 0,
"mode": "normal",
"style": "",
"text": " fields will be sent to Crowdin regardless of whether or not they are ",
"type": "text",
"version": 1
},
{
"children": [
{
"detail": 0,
"format": 0,
"mode": "normal",
"style": "",
"text": "localized fields",
"type": "text",
"version": 1
}
],
"direction": "ltr",
"format": "",
"indent": 0,
"type": "link",
"version": 2,
"fields": {
"linkType": "custom",
"newTab": false,
"url": "https://payloadcms.com/docs/configuration/localization#field-by-field-localization"
}
},
{
"detail": 0,
"format": 0,
"mode": "normal",
"style": "",
"text": ".",
"type": "text",
"version": 1
}
],
"direction": "ltr",
"format": "",
"indent": 0,
"type": "paragraph",
"version": 1
}
],
"direction": "ltr",
"format": "",
"indent": 0,
"type": "root",
"version": 1
}
},
"heading": {
"title": "Block configuration in Lexical fields"
}
}
}
],
"direction": "ltr",
"format": "",
"indent": 0,
"type": "root",
"version": 1
}
},
"id": "6712ecd0a87c5472e08bf256",
"blockType": "basicBlockLexical"
}
],
"id": "6712ecd0a87c5472e08bf254"
}
],
"tabTwo": {},
"createdAt": "2024-10-18T23:18:40.599Z",
"updatedAt": "2024-10-18T23:18:40.599Z"
} as NestedFieldCollection
Loading

0 comments on commit 2d788e5

Please sign in to comment.