@localazy/strapi-plugin 0.1.14 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.strapi-updater.json +4 -0
- package/package.json +2 -2
- package/server/controllers/localazy-transfer-controller.js +22 -25
- package/server/services/strapi-i18n-service.js +22 -7
- package/server/services/strapi-localazy-i18n-service.js +28 -2
- package/server/tests/fixtures/parsed-localazy-entry-to-create-entry-lesson-dz.js +45 -35
- package/server/tests/fixtures/parsed-localazy-entry-to-create-entry-page-dz.js +658 -0
- package/server/tests/fixtures/strapi-plugin-all-models.js +5623 -671
- package/server/utils/__tests__/parsed-localazy-entry-to-create-entry.test.js +64 -75
- package/server/utils/__tests__/parsed-localazy-entry-to-update-entry.test.js +13 -0
- package/server/utils/__tests__/pick-entries.test.js +8 -8
- package/server/utils/__tests__/populate-create-update-entry-with-base-entry.test.js +15 -0
- package/server/utils/flatten-object.js +7 -2
- package/server/utils/parsed-localazy-entry-to-create-entry.js +65 -40
- package/server/utils/parsed-localazy-entry-to-update-entry.js +8 -0
- package/server/utils/pick-entries.js +10 -122
- package/server/utils/populate-create-update-entry-with-base-entry.js +0 -4
- package/server/utils/transfer-setup-utils.js +35 -0
- package/test/helpers/mocks.js +9 -0
- package/server/tests/fixtures/parsed-localazy-entry-to-create-entry-sample-json-dz.js +0 -4675
|
@@ -5,7 +5,7 @@ const allModels = require("../../tests/fixtures/strapi-plugin-all-models");
|
|
|
5
5
|
const simpleMenuWithMediaModel = require("../../tests/fixtures/parsed-localazy-entry-to-create-entry-restaurant-simple-menu");
|
|
6
6
|
const cookbookModel = require("../../tests/fixtures/parsed-localazy-entry-to-create-entry-cookbook");
|
|
7
7
|
const lessonDZModel = require("../../tests/fixtures/parsed-localazy-entry-to-create-entry-lesson-dz");
|
|
8
|
-
const
|
|
8
|
+
const pageDZModel = require("../../tests/fixtures/parsed-localazy-entry-to-create-entry-page-dz");
|
|
9
9
|
|
|
10
10
|
describe("parsed-localazy-entry-to-create-entry.js", () => {
|
|
11
11
|
it("should return transformed 'restaurant-simple-menu' entry to strapi create entry structure", () => {
|
|
@@ -123,24 +123,23 @@ describe("parsed-localazy-entry-to-create-entry.js", () => {
|
|
|
123
123
|
expect(result).toEqual(expected);
|
|
124
124
|
});
|
|
125
125
|
|
|
126
|
-
it("should return transformed 'lesson' entry including Dynamic Zones to strapi create entry structure", () => {
|
|
126
|
+
it("should return transformed 'lesson' entry including Dynamic Zones to strapi create entry structure (for existing entry)", () => {
|
|
127
127
|
// EXECUTE
|
|
128
128
|
const result = parsedLocalazyEntryToCreateEntry(
|
|
129
129
|
allModels,
|
|
130
130
|
lessonDZModel.parsedLocalazyEntry,
|
|
131
131
|
lessonDZModel.baseEntry,
|
|
132
132
|
lessonDZModel.uid,
|
|
133
|
-
lessonDZModel.locale
|
|
134
133
|
);
|
|
135
134
|
|
|
136
135
|
// VERIFY
|
|
137
136
|
const expected = {
|
|
138
137
|
createEntry: {
|
|
139
|
-
title: "Test:
|
|
138
|
+
title: "Test: Přidání",
|
|
140
139
|
description: "Otestujte si své dovednosti, které jsme se naučili v předchozí lekci.",
|
|
141
140
|
lesson_type: [
|
|
142
141
|
{
|
|
143
|
-
title: "
|
|
142
|
+
title: "Zvolte správnou odpověď",
|
|
144
143
|
__component: "lesson.quiz",
|
|
145
144
|
questions: [
|
|
146
145
|
{
|
|
@@ -152,7 +151,7 @@ describe("parsed-localazy-entry-to-create-entry.js", () => {
|
|
|
152
151
|
__component: "lesson.survey-question",
|
|
153
152
|
},
|
|
154
153
|
{
|
|
155
|
-
question: "Kolik
|
|
154
|
+
question: "Kolik šálků je na fotografii?",
|
|
156
155
|
__component: "lesson.survey-question",
|
|
157
156
|
},
|
|
158
157
|
],
|
|
@@ -172,7 +171,6 @@ describe("parsed-localazy-entry-to-create-entry.js", () => {
|
|
|
172
171
|
],
|
|
173
172
|
},
|
|
174
173
|
],
|
|
175
|
-
locale: "cs",
|
|
176
174
|
},
|
|
177
175
|
dynamicZoneComponentKeys: [
|
|
178
176
|
{
|
|
@@ -185,85 +183,76 @@ describe("parsed-localazy-entry-to-create-entry.js", () => {
|
|
|
185
183
|
expect(result).toEqual(expected);
|
|
186
184
|
});
|
|
187
185
|
|
|
188
|
-
it("should return transformed '
|
|
186
|
+
it("should return transformed 'page' entry including Dynamic Zones to strapi create entry structure (for non-existing entry)", () => {
|
|
189
187
|
// EXECUTE
|
|
190
|
-
const
|
|
188
|
+
const { createEntry } = parsedLocalazyEntryToCreateEntry(
|
|
191
189
|
allModels,
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
190
|
+
pageDZModel.parsedLocalazyEntry,
|
|
191
|
+
pageDZModel.baseEntry,
|
|
192
|
+
pageDZModel.uid,
|
|
193
|
+
pageDZModel.locale,
|
|
195
194
|
);
|
|
196
195
|
|
|
197
196
|
// VERIFY
|
|
198
197
|
const expected = {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
{
|
|
208
|
-
name: "Položka 2",
|
|
209
|
-
__component: "restaurant.menu-item",
|
|
210
|
-
description: "Nějaký další popis",
|
|
211
|
-
},
|
|
212
|
-
],
|
|
213
|
-
dynamic_property: [
|
|
214
|
-
{
|
|
215
|
-
image_title: "Nějaký název obrázku",
|
|
216
|
-
__component: "food.gallery-item",
|
|
217
|
-
image_description: "Nějaký popis obrázku",
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
name: "Přísada I",
|
|
221
|
-
__component: "food.recipe-ingredient",
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
name: "První položka CB",
|
|
225
|
-
__component: "food.cookbook-item",
|
|
226
|
-
author_name: "Já",
|
|
227
|
-
ingredients: [
|
|
228
|
-
{
|
|
229
|
-
name: "První Ingr DZ",
|
|
230
|
-
__component: "food.recipe-ingredient",
|
|
231
|
-
},
|
|
232
|
-
],
|
|
233
|
-
gallery: [
|
|
234
|
-
{
|
|
235
|
-
image_title: "Obrázek G Jedna",
|
|
236
|
-
__component: "food.gallery-item",
|
|
237
|
-
image_description: "Obrázek G Popis Jedna",
|
|
238
|
-
},
|
|
239
|
-
],
|
|
240
|
-
},
|
|
241
|
-
{
|
|
242
|
-
name: "Druhá přísada",
|
|
243
|
-
__component: "food.recipe-ingredient",
|
|
244
|
-
},
|
|
245
|
-
],
|
|
198
|
+
title: "Software IP Intelligence",
|
|
199
|
+
slug: "ip-intelligence-software",
|
|
200
|
+
path: "/ip-intelligence software",
|
|
201
|
+
seo: {
|
|
202
|
+
__component: "seo.seo",
|
|
203
|
+
title: "Software IP Intelligence",
|
|
204
|
+
description: "Popis stránky IP Intelligence Software.",
|
|
205
|
+
canonical: "ip-intelligence-software",
|
|
246
206
|
},
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
{
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
207
|
+
hero: {
|
|
208
|
+
__component: "global.hero",
|
|
209
|
+
preTitle: "Inteligentní software před IP",
|
|
210
|
+
title: "Inteligentní software před IP",
|
|
211
|
+
text: "Text softwaru Hero Pre-IP Intelligence",
|
|
212
|
+
animatedText: {
|
|
213
|
+
__component: "hero.animated-text",
|
|
214
|
+
items: [
|
|
215
|
+
{
|
|
216
|
+
text: "hej",
|
|
217
|
+
__component: "hero.animated-text-items",
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
text: "Člověk",
|
|
221
|
+
__component: "hero.animated-text-items",
|
|
222
|
+
},
|
|
223
|
+
{
|
|
224
|
+
text: "Úžasné",
|
|
225
|
+
__component: "hero.animated-text-items",
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
text: "Práce!",
|
|
229
|
+
__component: "hero.animated-text-items",
|
|
230
|
+
},
|
|
231
|
+
],
|
|
259
232
|
},
|
|
233
|
+
},
|
|
234
|
+
components: [
|
|
235
|
+
undefined,
|
|
260
236
|
{
|
|
261
|
-
|
|
262
|
-
|
|
237
|
+
items: [
|
|
238
|
+
{
|
|
239
|
+
text: "Funkce One",
|
|
240
|
+
__component: "global.feature",
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
text: "Funkce dva",
|
|
244
|
+
__component: "global.feature",
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
text: "Funkce tři",
|
|
248
|
+
__component: "global.feature",
|
|
249
|
+
},
|
|
250
|
+
],
|
|
263
251
|
},
|
|
264
|
-
]
|
|
252
|
+
],
|
|
253
|
+
locale: "cs",
|
|
265
254
|
};
|
|
266
255
|
|
|
267
|
-
expect(
|
|
256
|
+
expect(createEntry).toEqual(expected);
|
|
268
257
|
});
|
|
269
258
|
});
|
|
@@ -11,7 +11,20 @@ const {
|
|
|
11
11
|
locale,
|
|
12
12
|
} = require("../../tests/fixtures/parsed-localazy-entry-to-update-entry");
|
|
13
13
|
|
|
14
|
+
const mocks = require("../../../test/helpers/mocks");
|
|
15
|
+
|
|
14
16
|
describe("parsed-localazy-entry-to-update-entry.js", () => {
|
|
17
|
+
Object.defineProperty(global, "strapi", {
|
|
18
|
+
value: mocks.strapi,
|
|
19
|
+
});
|
|
20
|
+
jest.spyOn(mocks.strapi.entityService, "findOne").mockImplementation(() => {
|
|
21
|
+
return {
|
|
22
|
+
id: 24,
|
|
23
|
+
title: "Pro každý den v roce",
|
|
24
|
+
localizations: [],
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
15
28
|
it("should return transformed 'cookbook' entry to strapi update entry structure", async () => {
|
|
16
29
|
// EXECUTE
|
|
17
30
|
const result = await parsedLocalazyEntryToUpdateEntry(
|
|
@@ -893,19 +893,19 @@ describe("pick entries test suite", () => {
|
|
|
893
893
|
"api::lesson.lesson[1].start_time": "2022-09-28T09:00:00.000Z",
|
|
894
894
|
"api::lesson.lesson[1].duration": "03:00:00.000",
|
|
895
895
|
"api::lesson.lesson[1].description": "## Description\n\nIn this lesson, we'll learn about addition and what rules to follow...",
|
|
896
|
-
"api::lesson.lesson[1].lesson_type[1].__component": "lesson.lecture",
|
|
897
|
-
"api::lesson.lesson[1].lesson_type[1].content": "You need to follow these rules:\na) add one number to the other\nb) do not subtract nor multiply\nc) ...",
|
|
896
|
+
"api::lesson.lesson[1].lesson_type[1;lesson.lecture].__component": "lesson.lecture",
|
|
897
|
+
"api::lesson.lesson[1].lesson_type[1;lesson.lecture].content": "You need to follow these rules:\na) add one number to the other\nb) do not subtract nor multiply\nc) ...",
|
|
898
898
|
};
|
|
899
899
|
|
|
900
900
|
const pickPaths = [
|
|
901
901
|
"api::lesson.lesson.title",
|
|
902
902
|
"api::lesson.lesson.description",
|
|
903
|
-
"api::lesson.lesson.lesson_type[
|
|
904
|
-
"api::lesson.lesson.lesson_type[
|
|
905
|
-
"api::lesson.lesson.lesson_type[
|
|
906
|
-
"api::lesson.lesson.lesson_type[
|
|
907
|
-
"api::lesson.lesson.lesson_type[
|
|
908
|
-
"api::lesson.lesson.lesson_type[
|
|
903
|
+
"api::lesson.lesson.lesson_type[lecture].content",
|
|
904
|
+
"api::lesson.lesson.lesson_type[survey].description",
|
|
905
|
+
"api::lesson.lesson.lesson_type[survey].questions.question",
|
|
906
|
+
"api::lesson.lesson.lesson_type[quiz].title",
|
|
907
|
+
"api::lesson.lesson.lesson_type[quiz].questions.question",
|
|
908
|
+
"api::lesson.lesson.lesson_type[quiz].answers.correct_answer",
|
|
909
909
|
"api::lesson.lesson.id",
|
|
910
910
|
];
|
|
911
911
|
|
|
@@ -13,7 +13,22 @@ const lessonWithDZsModel = require("../../tests/fixtures/populate-create-update-
|
|
|
13
13
|
|
|
14
14
|
const populateCreateUpdateEntryWithBaseEntry = require("../populate-create-update-entry-with-base-entry");
|
|
15
15
|
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
const mocks = require("../../../test/helpers/mocks");
|
|
19
|
+
|
|
16
20
|
describe("populate-create-update-entry-with-base-entry.js", () => {
|
|
21
|
+
Object.defineProperty(global, "strapi", {
|
|
22
|
+
value: mocks.strapi,
|
|
23
|
+
});
|
|
24
|
+
jest.spyOn(mocks.strapi.entityService, "findOne").mockImplementation(() => {
|
|
25
|
+
return {
|
|
26
|
+
id: 24,
|
|
27
|
+
title: "Pro každý den v roce",
|
|
28
|
+
localizations: [],
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
17
32
|
it("should populate a 'restaurant-simple-flat' correctly", async () => {
|
|
18
33
|
const populatedEntry = await populateCreateUpdateEntryWithBaseEntry(
|
|
19
34
|
allModels,
|
|
@@ -22,8 +22,13 @@ const flattenObject = (object, prefix = "") => {
|
|
|
22
22
|
const flattenedArray = object[objectKey].reduce(
|
|
23
23
|
(accumulator, item, index) => {
|
|
24
24
|
// No id should use the index of the array item
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
let key = `${objectKey}[${item.id || index}]`;
|
|
26
|
+
// is Dynamic Zone
|
|
27
|
+
if (item.id && item.__component) {
|
|
28
|
+
key = `${objectKey}[${item.id};${item.__component}]`;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
accumulator[key] = flattenObject(item);
|
|
27
32
|
return accumulator;
|
|
28
33
|
},
|
|
29
34
|
{}
|
|
@@ -19,13 +19,13 @@ const parsedLocalazyEntryToCreateEntry = (
|
|
|
19
19
|
const toCreateEntry = (
|
|
20
20
|
entry,
|
|
21
21
|
model,
|
|
22
|
-
baseEntry,
|
|
23
22
|
// eslint-disable-next-line no-unused-vars
|
|
24
23
|
key = "",
|
|
25
24
|
prefix = "",
|
|
26
25
|
component = "",
|
|
27
26
|
isRepeatableComponent = false,
|
|
28
27
|
isDZ = false,
|
|
28
|
+
isInsideDZ = false,
|
|
29
29
|
) => {
|
|
30
30
|
if (Array.isArray(entry)) {
|
|
31
31
|
// is array
|
|
@@ -41,13 +41,13 @@ const parsedLocalazyEntryToCreateEntry = (
|
|
|
41
41
|
if (baseEntryRepeateableGroup !== undefined) {
|
|
42
42
|
const localizedEntryRepeatableItemPosition = baseEntryRepeateableGroup.findIndex((repeatableItem) => !!repeatableItem && repeatableItem.id === baseEntryRepeatableItemId);
|
|
43
43
|
if (localizedEntryRepeatableItemPosition > -1) {
|
|
44
|
-
toCreateEntry(value, model,
|
|
44
|
+
toCreateEntry(value, model, localizedEntryRepeatableItemPosition, `${prefix}.${localizedEntryRepeatableItemPosition}`, component);
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
if (component && !isRepeatableComponent) {
|
|
50
|
-
toCreateEntry(value, model,
|
|
50
|
+
toCreateEntry(value, model, `${prefix}`, `${prefix}`);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
if (!component && isRepeatableComponent) {
|
|
@@ -66,7 +66,6 @@ const parsedLocalazyEntryToCreateEntry = (
|
|
|
66
66
|
toCreateEntry(
|
|
67
67
|
value,
|
|
68
68
|
dzEntryComponentModel,
|
|
69
|
-
baseEntry,
|
|
70
69
|
localizedEntryRepeatableItemPosition,
|
|
71
70
|
`${prefix}.${localizedEntryRepeatableItemPosition}`,
|
|
72
71
|
dzEntryComponent,
|
|
@@ -78,6 +77,29 @@ const parsedLocalazyEntryToCreateEntry = (
|
|
|
78
77
|
}
|
|
79
78
|
}
|
|
80
79
|
});
|
|
80
|
+
} else if (isDZ) {
|
|
81
|
+
Object.entries(entry).forEach(([dzEntryIdWithComponent, value]) => {
|
|
82
|
+
let [dzEntryId, dzEntryComponent] = dzEntryIdWithComponent.split(";");
|
|
83
|
+
dzEntryId = parseInt(dzEntryId);
|
|
84
|
+
const baseEntryDZEntry = get(baseEntry, prefix).find((v) => (v.id === dzEntryId) && (v.__component === dzEntryComponent));
|
|
85
|
+
if (baseEntryDZEntry !== undefined) {
|
|
86
|
+
const dzEntryComponentModel = findModel(models, dzEntryComponent);
|
|
87
|
+
toCreateEntry(
|
|
88
|
+
value,
|
|
89
|
+
dzEntryComponentModel,
|
|
90
|
+
dzEntryId,
|
|
91
|
+
`${prefix}.${dzEntryId}`,
|
|
92
|
+
dzEntryComponent,
|
|
93
|
+
true,
|
|
94
|
+
false, // we're already inside, so it's falsy
|
|
95
|
+
true,
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Don't do anything if `baseEntryDZEntry` is `undefined` - it means that the entry was deleted
|
|
100
|
+
* That also automatically presumes that deal with `undefined` `baseEntryDZIndex` inside the Dynamic Zone
|
|
101
|
+
*/
|
|
102
|
+
});
|
|
81
103
|
} else {
|
|
82
104
|
// is object
|
|
83
105
|
Object.entries(entry).forEach(([objectKey, value]) => {
|
|
@@ -86,38 +108,34 @@ const parsedLocalazyEntryToCreateEntry = (
|
|
|
86
108
|
// logicaly don't anything, skip...
|
|
87
109
|
} else if (isComponent(attribute)) {
|
|
88
110
|
// is component
|
|
89
|
-
const
|
|
90
|
-
const componentModel = findModel(models,
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
// is no repeatable - object
|
|
107
|
-
const newPrefix = prefix
|
|
108
|
-
? `${prefix}.${objectKey}`
|
|
109
|
-
: `${objectKey}`;
|
|
110
|
-
set(createEntry, `${newPrefix}.__component`, component);
|
|
111
|
-
toCreateEntry(
|
|
112
|
-
value,
|
|
113
|
-
componentModel,
|
|
114
|
-
baseEntry,
|
|
115
|
-
objectKey,
|
|
116
|
-
newPrefix,
|
|
117
|
-
component,
|
|
118
|
-
false
|
|
119
|
-
);
|
|
111
|
+
const innerComponent = attribute.component;
|
|
112
|
+
const componentModel = findModel(models, innerComponent);
|
|
113
|
+
|
|
114
|
+
let newPrefixBase = prefix;
|
|
115
|
+
let newPrefix = newPrefixBase
|
|
116
|
+
? `${newPrefixBase}.${objectKey}`
|
|
117
|
+
: `${objectKey}`;
|
|
118
|
+
if (isInsideDZ) {
|
|
119
|
+
let [dzParamKey, dzEntryId] = newPrefixBase.split(".");
|
|
120
|
+
dzEntryId = parseInt(dzEntryId);
|
|
121
|
+
const baseEntryDZIndex = get(baseEntry, dzParamKey).findIndex((v) => (v.__component === component) && (v.id === dzEntryId));
|
|
122
|
+
newPrefixBase = `${dzParamKey}.${baseEntryDZIndex}`;
|
|
123
|
+
newPrefix = `${newPrefixBase}.${objectKey}`;
|
|
124
|
+
}
|
|
125
|
+
const isRepeatableComponent = isRepeatable(attribute);
|
|
126
|
+
if (!isRepeatableComponent) {
|
|
127
|
+
set(createEntry, `${newPrefix}.__component`, innerComponent);
|
|
120
128
|
}
|
|
129
|
+
toCreateEntry(
|
|
130
|
+
value,
|
|
131
|
+
componentModel,
|
|
132
|
+
objectKey,
|
|
133
|
+
newPrefix,
|
|
134
|
+
innerComponent,
|
|
135
|
+
isRepeatableComponent,
|
|
136
|
+
false,
|
|
137
|
+
isInsideDZ,
|
|
138
|
+
);
|
|
121
139
|
} else if (isDynamicZone(attribute)) {
|
|
122
140
|
// behaves sort of like repeatable component
|
|
123
141
|
const newPrefix = prefix
|
|
@@ -126,7 +144,6 @@ const parsedLocalazyEntryToCreateEntry = (
|
|
|
126
144
|
toCreateEntry(
|
|
127
145
|
value,
|
|
128
146
|
null, // model is evaluated later as it's dynamic (DZ)
|
|
129
|
-
baseEntry,
|
|
130
147
|
objectKey,
|
|
131
148
|
newPrefix,
|
|
132
149
|
"", // component is computed later as it's dynamic (DZ)
|
|
@@ -134,14 +151,22 @@ const parsedLocalazyEntryToCreateEntry = (
|
|
|
134
151
|
true,
|
|
135
152
|
);
|
|
136
153
|
} else {
|
|
137
|
-
|
|
154
|
+
let newPrefixBase = prefix;
|
|
155
|
+
let newPrefix = newPrefixBase ? `${newPrefixBase}.${objectKey}` : `${objectKey}`;
|
|
156
|
+
if (isInsideDZ) {
|
|
157
|
+
let [dzParamKey, dzEntryId] = newPrefixBase.split(".");
|
|
158
|
+
dzEntryId = parseInt(dzEntryId);
|
|
159
|
+
const baseEntryDZIndex = get(baseEntry, dzParamKey).findIndex((v) => (v.__component === component) && (v.id === dzEntryId));
|
|
160
|
+
newPrefixBase = `${dzParamKey}.${baseEntryDZIndex}`;
|
|
161
|
+
newPrefix = `${newPrefixBase}.${objectKey}`;
|
|
162
|
+
}
|
|
138
163
|
set(createEntry, newPrefix, value);
|
|
139
164
|
|
|
140
165
|
if (component) {
|
|
141
|
-
const componentKeyToSet = `${
|
|
166
|
+
const componentKeyToSet = `${newPrefixBase}.__component`;
|
|
142
167
|
set(createEntry, componentKeyToSet, component);
|
|
143
168
|
|
|
144
|
-
if (
|
|
169
|
+
if (isInsideDZ) {
|
|
145
170
|
const isKeyAdded = (typeof dynamicZoneComponentKeys.find((v) => v.key === componentKeyToSet) !== "undefined");
|
|
146
171
|
if (!isKeyAdded)
|
|
147
172
|
dynamicZoneComponentKeys.push({
|
|
@@ -157,7 +182,7 @@ const parsedLocalazyEntryToCreateEntry = (
|
|
|
157
182
|
};
|
|
158
183
|
|
|
159
184
|
const model = findModel(models, uid);
|
|
160
|
-
toCreateEntry(parsedLocalazyEntry, model
|
|
185
|
+
toCreateEntry(parsedLocalazyEntry, model);
|
|
161
186
|
if (locale) {
|
|
162
187
|
createEntry.locale = locale;
|
|
163
188
|
}
|
|
@@ -22,6 +22,14 @@ const parsedLocalazyEntryToUpdateEntry = async (
|
|
|
22
22
|
uid
|
|
23
23
|
);
|
|
24
24
|
|
|
25
|
+
/**
|
|
26
|
+
* TODO: possibly improve for the following case:
|
|
27
|
+
* A `key` is deleted from the base entry, and the same `key` still exist in the localized entry.
|
|
28
|
+
* Even though the `key` is deprecated in Localazy, it concludes that the `key` is still used in the localized entry.
|
|
29
|
+
* Therefore, it leads to an error when updating the entry.
|
|
30
|
+
*
|
|
31
|
+
* The solution for now: Delete the localized entry and re-download to force the creation process.
|
|
32
|
+
*/
|
|
25
33
|
let updateEntry = {};
|
|
26
34
|
merge(updateEntry, currentEntry, createEntry);
|
|
27
35
|
updateEntry = omitDeep(updateEntry, [
|
|
@@ -1,93 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const isDynamicZoneKey = (key, transferSetupModel) => {
|
|
8
|
-
const matches = key.match(/\[\d+\]+/g);
|
|
9
|
-
|
|
10
|
-
if (matches.length < 2) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const dynamicPropertyEntryIdWithSquareBrackets = matches[1];
|
|
15
|
-
const dynamicPropertyNamePart = key
|
|
16
|
-
.split(".")
|
|
17
|
-
.find(
|
|
18
|
-
(s, index) =>
|
|
19
|
-
index > 1 && s.includes(dynamicPropertyEntryIdWithSquareBrackets)
|
|
20
|
-
);
|
|
21
|
-
const dynamicPropertyName = dynamicPropertyNamePart.replace(
|
|
22
|
-
dynamicPropertyEntryIdWithSquareBrackets,
|
|
23
|
-
""
|
|
24
|
-
);
|
|
25
|
-
|
|
26
|
-
return Array.isArray(transferSetupModel[dynamicPropertyName]);
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const getDynamicZoneEntryId = (key, transferSetupModel) => {
|
|
30
|
-
if (!isDynamicZoneKey(key, transferSetupModel)) {
|
|
31
|
-
return undefined;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const matches = key.match(/\[\d+\]+/g);
|
|
35
|
-
// remove square brackets
|
|
36
|
-
const id = matches[1].replace(/[\[\]']+/g, "");
|
|
37
|
-
return id;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const getUniqueDynamicZoneEntryId = (key, transferSetupModel) => {
|
|
41
|
-
if (!isDynamicZoneKey(key, transferSetupModel)) {
|
|
42
|
-
return undefined;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const keySplittedByDot = key.split(".");
|
|
46
|
-
|
|
47
|
-
return keySplittedByDot[2];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const doesPickPathsIncludeTheComponent = (pickPaths, dzParameterKey) => {
|
|
51
|
-
return pickPaths.some((pp) => pp.includes(dzParameterKey));
|
|
3
|
+
const isDynamicZoneKey = (key) => {
|
|
4
|
+
const matches = key.match(/\[\d+;\w+\./g);
|
|
5
|
+
return matches !== null;
|
|
52
6
|
};
|
|
53
7
|
|
|
54
|
-
const pickEntries = (flatten, pickPaths
|
|
55
|
-
// *
|
|
56
|
-
|
|
57
|
-
const dzEntryIdComponentMap = {};
|
|
58
|
-
const flattenComponentProps = Object.fromEntries(
|
|
59
|
-
Object.entries(flatten).filter(([key]) => key.includes("__component"))
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
const pickedDeep = pickDeep(transferSetupModel, ["__component__"]);
|
|
63
|
-
const flattenedPickedDeep = flattenObject(pickedDeep);
|
|
64
|
-
map(flattenedPickedDeep, (v, i) => {
|
|
65
|
-
const newI = i.replace(".__component__", "");
|
|
66
|
-
flattenedPickedDeep[newI] = v;
|
|
67
|
-
delete flattenedPickedDeep[i];
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
Object.keys(flattenComponentProps).map((key) => {
|
|
71
|
-
if (!isDynamicZoneKey(key, transferSetupModel)) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const keySplittedByDot = key.replace(".__component", "").split(".");
|
|
76
|
-
const componentName = keySplittedByDot[keySplittedByDot.length - 1].replace(
|
|
77
|
-
/\[.*\]/g,
|
|
78
|
-
""
|
|
79
|
-
);
|
|
80
|
-
const uniqueEntryId = getUniqueDynamicZoneEntryId(key, transferSetupModel);
|
|
81
|
-
|
|
82
|
-
const keyOfEntry = Object.keys(flattenedPickedDeep)
|
|
83
|
-
.filter((fpdk) => fpdk.replace(/\[.*\]/g, "") == componentName)
|
|
84
|
-
.find((fpdk) => flattenedPickedDeep[fpdk] === flattenComponentProps[key]);
|
|
85
|
-
dzEntryIdComponentMap[uniqueEntryId] = {
|
|
86
|
-
component: flattenComponentProps[key],
|
|
87
|
-
key: keyOfEntry,
|
|
88
|
-
};
|
|
89
|
-
});
|
|
90
|
-
|
|
8
|
+
const pickEntries = (flatten, pickPaths) => {
|
|
9
|
+
// * Dynamic zones properties must! always be in 1st level (not in component; Strapi restrictions)
|
|
91
10
|
const pickedEntries = {};
|
|
92
11
|
const mappedPickPaths = pickPaths.map((pickPath) =>
|
|
93
12
|
pickPath.replace(/\[\d+\]/g, "")
|
|
@@ -98,44 +17,13 @@ const pickEntries = (flatten, pickPaths, transferSetupModel) => {
|
|
|
98
17
|
Object.entries(flatten).filter(([key]) => !key.includes("__component"))
|
|
99
18
|
);
|
|
100
19
|
Object.keys(filteredFlatten).forEach((key) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const uniqueDzEntryId = getUniqueDynamicZoneEntryId(
|
|
106
|
-
key,
|
|
107
|
-
transferSetupModel
|
|
108
|
-
);
|
|
109
|
-
const dzParameterKey = dzEntryIdComponentMap[uniqueDzEntryId].key;
|
|
110
|
-
|
|
111
|
-
if (!doesPickPathsIncludeTheComponent(pickPaths, dzParameterKey)) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
20
|
+
let filteredKey = key;
|
|
21
|
+
filteredKey = filteredKey.replace(/\[\d+\]/g, "");
|
|
22
|
+
if (isDynamicZoneKey(key)) {
|
|
23
|
+
filteredKey = filteredKey.replace(/\[\d+;\w+\./g, `[`);
|
|
114
24
|
}
|
|
115
|
-
|
|
116
|
-
const filteredKey = key.replace(/\[\d+\]/g, "");
|
|
117
25
|
if (mappedPickPaths.includes(filteredKey)) {
|
|
118
|
-
|
|
119
|
-
const dzEntryId = getDynamicZoneEntryId(key, transferSetupModel);
|
|
120
|
-
const uniqueDzEntryId = getUniqueDynamicZoneEntryId(
|
|
121
|
-
key,
|
|
122
|
-
transferSetupModel
|
|
123
|
-
);
|
|
124
|
-
const dzParameterKey = dzEntryIdComponentMap[uniqueDzEntryId].key;
|
|
125
|
-
|
|
126
|
-
const dzParameterName = dzParameterKey.substring(
|
|
127
|
-
0,
|
|
128
|
-
dzParameterKey.indexOf("[")
|
|
129
|
-
);
|
|
130
|
-
const toBeReplaced = `${dzParameterName}[${dzEntryId}]`;
|
|
131
|
-
const dzParameterComponent =
|
|
132
|
-
dzEntryIdComponentMap[uniqueDzEntryId].component;
|
|
133
|
-
const componentAddition = `${dzParameterName}[${dzEntryId};${dzParameterComponent}]`;
|
|
134
|
-
const replacedKey = key.replace(toBeReplaced, componentAddition);
|
|
135
|
-
pickedEntries[replacedKey] = flatten[key];
|
|
136
|
-
} else {
|
|
137
|
-
pickedEntries[key] = flatten[key];
|
|
138
|
-
}
|
|
26
|
+
pickedEntries[key] = flatten[key];
|
|
139
27
|
}
|
|
140
28
|
});
|
|
141
29
|
return pickedEntries;
|
|
@@ -195,10 +195,6 @@ const populateCreateUpdateEntryWithBaseEntry = async (
|
|
|
195
195
|
} else if (isRelation(attribute)) {
|
|
196
196
|
const newPrefix = getNewPrefix(objectKey, prefix);
|
|
197
197
|
const populatedLocalizedEntryVal = get(populatedLocalizedEntry, newPrefix);
|
|
198
|
-
if (doesExistInPopulatedLocalizedEntry(populatedLocalizedEntryVal)) {
|
|
199
|
-
// skip...
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
198
|
|
|
203
199
|
const isArray = Array.isArray(value);
|
|
204
200
|
let arraiedValue = value;
|