Skip to content

Commit

Permalink
feat(translations): update fn works with json and html (#82)
Browse files Browse the repository at this point in the history
* feat(buildhtmlcrowdinobject): include ids and blocktypes in file name

* feat(translations): update fn works with json and html

* docs(engineering): add

* style(*): prettier

* style(utilities): remove comment
  • Loading branch information
thompsonsj authored Jul 12, 2023
1 parent 6ef4331 commit 78c2adc
Show file tree
Hide file tree
Showing 20 changed files with 2,044 additions and 1,570 deletions.
32 changes: 30 additions & 2 deletions dev/src/collections/NestedFieldCollection.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
import { Block, CollectionConfig } from "payload/types";
import { basicLocalizedFields } from "./fields/basicLocalizedFields";

const LocalizedBlock: Block = {
const BasicBlockTextFields: Block = {
slug: "basicBlock", // required
fields: basicLocalizedFields,
};

const BasicBlockRichTextField: Block = {
slug: "basicBlockRichText", // required
fields: [
{
name: "richTextField",
type: "richText",
localized: true,
},
],
};

const BasicBlockMixedFields: Block = {
slug: "basicBlockMixed", // required
fields: [
...basicLocalizedFields,
{
name: "richTextField",
type: "richText",
localized: true,
},
],
};

const TestBlockArrayOfRichText: Block = {
slug: "testBlockArrayOfRichText",
fields: [
Expand Down Expand Up @@ -51,7 +74,12 @@ const NestedFieldCollection: CollectionConfig = {
{
name: "layout", // required
type: "blocks", // required
blocks: [LocalizedBlock, TestBlockArrayOfRichText],
blocks: [
BasicBlockTextFields,
BasicBlockRichTextField,
BasicBlockMixedFields,
TestBlockArrayOfRichText,
],
},
// collapsible
/*{
Expand Down
35 changes: 21 additions & 14 deletions dev/src/tests/files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,17 @@ describe(`CrowdIn file create, update and delete`, () => {
],
},
});
const ids = article.arrayField.map((item) => item.id);
const crowdInFiles = await getFilesByDocumentID(article.id, payload);
expect(crowdInFiles.length).toEqual(3);
expect(
crowdInFiles.find(
(file) => file.name === "arrayField[0].richTextField.html",
(file) => file.name === `arrayField.${ids[0]}.richTextField.html`,
),
).toBeDefined();
expect(
crowdInFiles.find(
(file) => file.name === "arrayField[1].richTextField.html",
(file) => file.name === `arrayField.${ids[1]}.richTextField.html`,
),
).toBeDefined();
expect(
Expand Down Expand Up @@ -201,37 +202,43 @@ describe(`CrowdIn file create, update and delete`, () => {
],
},
});
const firstBlockId = article.layout[0].id;
const blockIds = article.layout.map((item) => item.id);
const blockTypes = article.layout.map((item) => item.blockType);
const arrayIds = article.layout[1].messages.map((item) => item.id);
const crowdInFiles = await getFilesByDocumentID(article.id, payload);
expect(crowdInFiles.length).toEqual(4);
const jsonFile = crowdInFiles.find((file) => file.name === "fields.json");
expect(
crowdInFiles.find(
(file) => file.name === "layout[0].richTextField.html",
(file) =>
file.name ===
`layout.${blockIds[0]}.${blockTypes[0]}.richTextField.html`,
),
).toBeDefined();
expect(
crowdInFiles.find(
(file) => file.name === "layout[1].messages[0].message.html",
(file) =>
file.name ===
`layout.${blockIds[1]}.${blockTypes[1]}.messages.${arrayIds[0]}.message.html`,
),
).toBeDefined();
expect(
crowdInFiles.find(
(file) => file.name === "layout[1].messages[1].message.html",
(file) =>
file.name ===
`layout.${blockIds[1]}.${blockTypes[1]}.messages.${arrayIds[1]}.message.html`,
),
).toBeDefined();
expect(jsonFile).toBeDefined();
expect(jsonFile.fileData.json).toEqual({
layout: [
{
[firstBlockId]: {
basicBlock: {
textareaField: "Test meta description 1",
textField: "Test title 1",
},
layout: {
[blockIds[0]]: {
basicBlock: {
textareaField: "Test meta description 1",
textField: "Test title 1",
},
},
],
},
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export const payloadCreateBlocksRichTextData = {
layout: [
{
richTextField: [
{
children: [
{
text: "Rich text content in block layout at index 0.",
},
],
},
],
blockType: "basicBlockRichText",
},
{
richTextField: [
{
children: [
{
text: "Rich text content in block layout at index 1.",
},
],
},
],
blockType: "basicBlockRichText",
},
],
};
Loading

0 comments on commit 78c2adc

Please sign in to comment.