@localazy/strapi-plugin 0.1.15 → 0.1.17
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 +19 -22
- 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 +21 -0
- package/server/utils/__tests__/populate-create-update-entry-with-base-entry.test.js +37 -0
- 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/populate-create-update-entry-with-base-entry.js +6 -12
- package/server/utils/transfer-setup-utils.js +2 -1
- 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(
|
|
@@ -28,6 +41,14 @@ describe("parsed-localazy-entry-to-update-entry.js", () => {
|
|
|
28
41
|
const expected = {
|
|
29
42
|
id: 24,
|
|
30
43
|
title: "Pro každý den v roce",
|
|
44
|
+
used_in_restaurants: [
|
|
45
|
+
{
|
|
46
|
+
id: 1,
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
id: 3,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
31
52
|
author_name: "David V.",
|
|
32
53
|
pages: 365,
|
|
33
54
|
recipes: [
|
|
@@ -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,
|
|
@@ -144,6 +159,9 @@ describe("populate-create-update-entry-with-base-entry.js", () => {
|
|
|
144
159
|
cuisine: "Thai",
|
|
145
160
|
capacity: 68,
|
|
146
161
|
our_story: "Za nami jest więcej**! Sprawdź naszą historię na [Localazy] (https://localazy.com).\n\n! [Logo_sq-01.png] (/uploads/Logo_sq_01_08b9bb6be1.png)",
|
|
162
|
+
used_cookbooks: {
|
|
163
|
+
id: 1,
|
|
164
|
+
},
|
|
147
165
|
menu: [
|
|
148
166
|
{
|
|
149
167
|
id: 40,
|
|
@@ -306,6 +324,17 @@ describe("populate-create-update-entry-with-base-entry.js", () => {
|
|
|
306
324
|
cuisine: "Italian",
|
|
307
325
|
capacity: 16,
|
|
308
326
|
our_story: "Długa tradycja, mądrość przekazywana z pokolenia na pokolenie... Od 1822 roku.",
|
|
327
|
+
supported_restaurants: [
|
|
328
|
+
{
|
|
329
|
+
id: 2,
|
|
330
|
+
},
|
|
331
|
+
{
|
|
332
|
+
id: 1,
|
|
333
|
+
},
|
|
334
|
+
],
|
|
335
|
+
used_cookbooks: {
|
|
336
|
+
id: 1,
|
|
337
|
+
},
|
|
309
338
|
menu: [
|
|
310
339
|
],
|
|
311
340
|
featured_image: null,
|
|
@@ -351,6 +380,14 @@ describe("populate-create-update-entry-with-base-entry.js", () => {
|
|
|
351
380
|
const expected = {
|
|
352
381
|
id: 24,
|
|
353
382
|
title: "Pro každý den v roce",
|
|
383
|
+
used_in_restaurants: [
|
|
384
|
+
{
|
|
385
|
+
id: 1,
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
id: 3,
|
|
389
|
+
},
|
|
390
|
+
],
|
|
354
391
|
author_name: "David V.",
|
|
355
392
|
pages: 365,
|
|
356
393
|
recipes: [
|
|
@@ -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, [
|
|
@@ -194,11 +194,6 @@ const populateCreateUpdateEntryWithBaseEntry = async (
|
|
|
194
194
|
// }
|
|
195
195
|
} else if (isRelation(attribute)) {
|
|
196
196
|
const newPrefix = getNewPrefix(objectKey, prefix);
|
|
197
|
-
const populatedLocalizedEntryVal = get(populatedLocalizedEntry, newPrefix);
|
|
198
|
-
if (doesExistInPopulatedLocalizedEntry(populatedLocalizedEntryVal)) {
|
|
199
|
-
// skip...
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
197
|
|
|
203
198
|
const isArray = Array.isArray(value);
|
|
204
199
|
let arraiedValue = value;
|
|
@@ -213,13 +208,12 @@ const populateCreateUpdateEntryWithBaseEntry = async (
|
|
|
213
208
|
populate: ['localizations'],
|
|
214
209
|
});
|
|
215
210
|
|
|
216
|
-
const localizedEntry = entryWithLocalizations.localizations
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
211
|
+
const localizedEntry = entryWithLocalizations.localizations?.find((item) => item.locale === locale);
|
|
212
|
+
const idToAssign = localizedEntry?.id || entityId;
|
|
213
|
+
if (!isArray) {
|
|
214
|
+
set(populatedEntry, newPrefix, { id: idToAssign });
|
|
215
|
+
} else {
|
|
216
|
+
set(populatedEntry, `${newPrefix}.${index}`, { id: idToAssign });
|
|
223
217
|
}
|
|
224
218
|
}
|
|
225
219
|
}
|
|
@@ -55,9 +55,10 @@ const getPickPathsWithComponents = (transferSetupModelProps) => {
|
|
|
55
55
|
Object.keys(flattenedObject).forEach((key) => {
|
|
56
56
|
if (key.includes(".__component__")) {
|
|
57
57
|
const componentKey = key.split(".__component__")[0];
|
|
58
|
+
const propertyName = componentKey.split("[")[0];
|
|
58
59
|
if (!pickComponents[componentKey]) {
|
|
59
60
|
const splitByDot = flattenedObject[key].split(".");
|
|
60
|
-
pickComponents[
|
|
61
|
+
pickComponents[componentKey] = `${propertyName}[${splitByDot[1]}]`;
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
});
|