@localazy/strapi-plugin 0.1.11-rc.0 → 0.1.11-rc.2

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.
Files changed (31) hide show
  1. package/admin/src/modules/plugin-settings/components/ContentTransferSetup/index.js +5 -0
  2. package/admin/src/modules/plugin-settings/components/Tree/index.js +21 -6
  3. package/admin/src/modules/plugin-settings/functions/build-content-transfer-setup-schema.js +1 -1
  4. package/admin/src/modules/plugin-settings/functions/has-model-changed.js +1 -1
  5. package/admin/src/modules/plugin-settings/locale/en.js +1 -1
  6. package/admin/src/modules/plugin-settings/utils/get-filtered-models-schemas.js +1 -7
  7. package/admin/src/modules/plugin-settings/utils/get-models-tree.js +19 -3
  8. package/package.json +4 -4
  9. package/server/controllers/localazy-transfer-controller.js +29 -8
  10. package/server/functions/should-set-downloaded-property.js +48 -3
  11. package/server/services/strapi-i18n-service.js +1 -1
  12. package/server/services/strapi-localazy-i18n-service.js +1 -1
  13. package/server/tests/fixtures/parsed-localazy-entry-to-create-entry-lesson-dz.js +392 -0
  14. package/server/tests/fixtures/parsed-localazy-entry-to-create-entry-sample-json-dz.js +4675 -0
  15. package/server/tests/fixtures/populate-create-update-entry-with-base-entry-lesson-dz.js +309 -0
  16. package/server/tests/fixtures/populate-create-update-entry-with-base-entry-sample-json-dz.js +884 -0
  17. package/server/tests/fixtures/strapi-plugin-all-models.js +844 -37
  18. package/server/utils/__tests__/parsed-localazy-entry-to-create-entry.test.js +211 -62
  19. package/server/utils/__tests__/pick-entries.test.js +936 -56
  20. package/server/utils/__tests__/populate-create-update-entry-with-base-entry.test.js +287 -0
  21. package/server/utils/build-populate.js +5 -0
  22. package/server/utils/model-utils.js +5 -0
  23. package/server/utils/omit-deep.js +7 -0
  24. package/server/utils/parsed-localazy-entry-to-create-entry.js +58 -4
  25. package/server/utils/parsed-localazy-entry-to-update-entry.js +6 -1
  26. package/server/utils/pick-deep.js +22 -0
  27. package/server/utils/pick-entries.js +90 -5
  28. package/server/utils/populate-create-update-entry-with-base-entry.js +51 -3
  29. package/server/tests/fixtures/collection-flattened.js +0 -76
  30. package/server/tests/fixtures/restaurant-flattened.js +0 -46
  31. package/server/tests/fixtures/restaurants-pick-paths.js +0 -15
@@ -8,6 +8,7 @@ const {
8
8
  getAttribute,
9
9
  isComponent,
10
10
  isRepeatable,
11
+ isDynamicZone,
11
12
  isRelation,
12
13
  findModel
13
14
  } = require("./model-utils");
@@ -49,7 +50,8 @@ const populateCreateUpdateEntryWithBaseEntry = async (
49
50
  objectKey = "",
50
51
  prefix = "",
51
52
  component = "",
52
- isRepeatableComponent = false
53
+ isRepeatableComponent = false,
54
+ isDZ = false,
53
55
  ) => {
54
56
  if (Array.isArray(partialBaseEntry)) {
55
57
  // is array
@@ -77,7 +79,19 @@ const populateCreateUpdateEntryWithBaseEntry = async (
77
79
  );
78
80
  }
79
81
  }
80
- } else if (isRepeatableComponent) {
82
+ } else if (!component && isRepeatableComponent && isDZ) {
83
+ Object.entries(partialBaseEntry).forEach(async ([partialBaseEntryItemIndex, partialBaseEntryItem]) => {
84
+ const component = partialBaseEntryItem.__component;
85
+ const model = findModel(models, component);
86
+ const newPrefix = `${prefix}.${partialBaseEntryItemIndex}`;
87
+ await populateEntry(
88
+ partialBaseEntryItem,
89
+ model,
90
+ partialBaseEntryItemIndex,
91
+ newPrefix,
92
+ );
93
+ });
94
+ } else if (component && isRepeatableComponent) {
81
95
  Object.entries(partialBaseEntry).forEach(async ([partialBaseEntryItemIndex, partialBaseEntryItem]) => {
82
96
  const newPrefix = `${prefix}.${partialBaseEntryItemIndex}`;
83
97
  await populateEntry(
@@ -97,7 +111,10 @@ const populateCreateUpdateEntryWithBaseEntry = async (
97
111
 
98
112
  for (const [objectKey, value] of Object.entries(partialBaseEntry)) {
99
113
  const attribute = getAttribute(model, objectKey);
100
- if (typeof attribute === 'undefined') {
114
+ if (typeof attribute === 'undefined' && objectKey === '__component') {
115
+ const newPrefix = getNewPrefix(objectKey, prefix);
116
+ set(populatedEntry, newPrefix, value);
117
+ } else if (typeof attribute === 'undefined') {
101
118
  // skip...
102
119
  continue;
103
120
  } else if (isComponent(attribute)) {
@@ -144,6 +161,37 @@ const populateCreateUpdateEntryWithBaseEntry = async (
144
161
  component,
145
162
  isRepeatable(attribute),
146
163
  );
164
+ } else if (isDynamicZone(attribute)) {
165
+ // is dynamic zone
166
+ const newPrefix = getNewPrefix(objectKey, prefix);
167
+ const inCreateUpdateEntry = get(createUpdateEntry, newPrefix);
168
+ const isMissingInCreateUpdateEntry = !!((typeof inCreateUpdateEntry === 'undefined') || (inCreateUpdateEntry && !inCreateUpdateEntry.length));
169
+
170
+ if (isMissingInCreateUpdateEntry) {
171
+ const populatedLocalizedEntryVal = get(populatedLocalizedEntry, newPrefix);
172
+ let valueToSet = value;
173
+ if (doesExistInPopulatedLocalizedEntry(populatedLocalizedEntryVal)) {
174
+ valueToSet = populatedLocalizedEntryVal;
175
+ }
176
+ valueToSet = value.map((item) => {
177
+ delete item.id;
178
+ return {
179
+ __component: component,
180
+ ...item,
181
+ };
182
+ });
183
+ set(populatedEntry, newPrefix, valueToSet);
184
+ }
185
+ await populateEntry(
186
+ value,
187
+ "", // model is evaluated later as it's dynamic (DZ)
188
+ objectKey,
189
+ newPrefix,
190
+ "", // component is computed later as it's dynamic (DZ)
191
+ true,
192
+ true,
193
+ );
194
+ // }
147
195
  } else if (isRelation(attribute)) {
148
196
  const newPrefix = getNewPrefix(objectKey, prefix);
149
197
  const populatedLocalizedEntryVal = get(populatedLocalizedEntry, newPrefix);
@@ -1,76 +0,0 @@
1
- module.exports = {
2
- "plugin::localazy.token[1].access_token": "some access token",
3
- "plugin::localazy.token[1].createdAt": "2022-04-07T14:50:44.905Z",
4
- "plugin::localazy.token[1].updatedAt": "2022-04-07T14:50:44.905Z",
5
- "api::book.book[1].Title": "My First Child Book",
6
- "api::book.book[1].Author": "David V.",
7
- "api::book.book[1].Pages": 48,
8
- "api::book.book[1].createdAt": "2022-03-24T13:26:59.757Z",
9
- "api::book.book[1].updatedAt": "2022-04-07T19:12:48.481Z",
10
- "api::book.book[1].publishedAt": "2022-03-24T13:32:20.570Z",
11
- "api::book.book[1].locale": "en",
12
- "api::book.book[1].additional_info[2].rich_description":
13
- "# H1\n## H2\n#### H4\n\n**One** _two_ <u>three</u>... and maybe even more fairytales...",
14
- "api::book.book[1].additional_info[2].history": "There's no...",
15
- "api::book.book[1].additional_info[2].excerpt": "Short excerpt",
16
- "api::book.book[1].additional_info[2].test_variants[3].name":
17
- "this is a final version",
18
- "api::restaurant.restaurant[1].title": "Restaurant 1",
19
- "api::restaurant.restaurant[1].description": "Restaurant 1 description",
20
- "api::restaurant.restaurant[1].createdAt": "2022-03-10T14:45:51.764Z",
21
- "api::restaurant.restaurant[1].updatedAt": "2022-04-07T18:34:34.132Z",
22
- "api::restaurant.restaurant[1].publishedAt": "2022-03-23T11:57:05.812Z",
23
- "api::restaurant.restaurant[1].locale": "en",
24
- "api::restaurant.restaurant[1].descs[1].rich_description":
25
- "restaurant 1 rich_desc",
26
- "api::restaurant.restaurant[2].title": "Restaurant 2",
27
- "api::restaurant.restaurant[2].description": "Restaurant 2 description",
28
- "api::restaurant.restaurant[2].createdAt": "2022-03-14T10:35:27.187Z",
29
- "api::restaurant.restaurant[2].updatedAt": "2022-04-07T18:34:34.154Z",
30
- "api::restaurant.restaurant[2].publishedAt": "2022-03-24T13:32:31.066Z",
31
- "api::restaurant.restaurant[2].locale": "en",
32
- "api::restaurant.restaurant[3].title": "Full Restaurant",
33
- "api::restaurant.restaurant[3].description": "With some great description",
34
- "api::restaurant.restaurant[3].createdAt": "2022-03-24T13:17:22.161Z",
35
- "api::restaurant.restaurant[3].updatedAt": "2022-04-07T18:34:34.168Z",
36
- "api::restaurant.restaurant[3].publishedAt": "2022-03-24T13:37:31.870Z",
37
- "api::restaurant.restaurant[3].locale": "en",
38
- "api::restaurant.restaurant[3].street": "Testowa",
39
- "api::restaurant.restaurant[3].city": "Testow",
40
- "api::restaurant.restaurant[3].country": "Test Rep.",
41
- "api::restaurant.restaurant[3].recipes[3].name": "Tomato Soup",
42
- "api::restaurant.restaurant[3].recipes[3].ingredients[2].name": "Tomato",
43
- "api::restaurant.restaurant[3].recipes[3].ingredients[2].pcs": 4,
44
- "api::restaurant.restaurant[3].recipes[3].ingredients[2].required": false,
45
- "api::restaurant.restaurant[3].recipes[3].ingredients[3].name": "Soup",
46
- "api::restaurant.restaurant[3].recipes[3].ingredients[3].pcs": 1,
47
- "api::restaurant.restaurant[3].recipes[3].ingredients[3].required": true,
48
- "api::restaurant.restaurant[3].recipes[3].variants[4].name":
49
- "Red, yellow, green",
50
- "api::restaurant.restaurant[3].recipes[2].name": "Beef Broth",
51
- "api::restaurant.restaurant[3].recipes[2].ingredients[4].name": "Beef",
52
- "api::restaurant.restaurant[3].recipes[2].ingredients[4].pcs": 1,
53
- "api::restaurant.restaurant[3].recipes[2].ingredients[4].required": true,
54
- "api::restaurant.restaurant[3].recipes[2].ingredients[5].name": "Water",
55
- "api::restaurant.restaurant[3].recipes[2].ingredients[5].pcs": 2,
56
- "api::restaurant.restaurant[3].recipes[2].ingredients[5].required": true,
57
- "api::restaurant.restaurant[3].recipes[4].name": "Goulash",
58
- "api::restaurant.restaurant[3].recipes[4].ingredients[6].name": "Beef meat",
59
- "api::restaurant.restaurant[3].recipes[4].ingredients[6].pcs": 1,
60
- "api::restaurant.restaurant[3].recipes[4].ingredients[6].required": true,
61
- "api::restaurant.restaurant[3].recipes[4].ingredients[7].name": "Pepper",
62
- "api::restaurant.restaurant[3].recipes[4].ingredients[7].pcs": 4,
63
- "api::restaurant.restaurant[3].recipes[4].ingredients[8].name":
64
- "Pepper spices",
65
- "api::restaurant.restaurant[3].recipes[4].ingredients[8].pcs": 1,
66
- "api::restaurant.restaurant[3].recipes[4].ingredients[8].required": true,
67
- "api::restaurant.restaurant[3].recipes[4].ingredients[9].name": "Water",
68
- "api::restaurant.restaurant[3].recipes[4].ingredients[9].pcs": 1,
69
- "api::restaurant.restaurant[3].descs[3].rich_description":
70
- "Another restaurant desc",
71
- "api::restaurant.restaurant[3].descs[3].history":
72
- "Est. 2022, based in NY, NY",
73
- "api::restaurant.restaurant[3].descs[3].excerpt": "Est. 2022",
74
- "api::restaurant.restaurant[3].descs[3].test_variants[5].name":
75
- "no such thing...",
76
- };
@@ -1,46 +0,0 @@
1
- module.exports = {
2
- "api::restaurant.restaurant[3].title": "Full Restaurant",
3
- "api::restaurant.restaurant[3].description": "With some great description",
4
- "api::restaurant.restaurant[3].createdAt": "2022-03-24T13:17:22.161Z",
5
- "api::restaurant.restaurant[3].updatedAt": "2022-04-07T18:34:34.168Z",
6
- "api::restaurant.restaurant[3].publishedAt": "2022-03-24T13:37:31.870Z",
7
- "api::restaurant.restaurant[3].locale": "en",
8
- "api::restaurant.restaurant[3].street": "Testowa",
9
- "api::restaurant.restaurant[3].city": "Testow",
10
- "api::restaurant.restaurant[3].country": "Test Rep.",
11
- "api::restaurant.restaurant[3].recipes[2].name": "Beef Broth",
12
- "api::restaurant.restaurant[3].recipes[2].ingredients[4].name": "Beef",
13
- "api::restaurant.restaurant[3].recipes[2].ingredients[4].pcs": 1,
14
- "api::restaurant.restaurant[3].recipes[2].ingredients[4].required": true,
15
- "api::restaurant.restaurant[3].recipes[2].ingredients[5].name": "Water",
16
- "api::restaurant.restaurant[3].recipes[2].ingredients[5].pcs": 2,
17
- "api::restaurant.restaurant[3].recipes[2].ingredients[5].required": true,
18
- "api::restaurant.restaurant[3].recipes[3].name": "Tomato Soup",
19
- "api::restaurant.restaurant[3].recipes[3].ingredients[2].name": "Tomato",
20
- "api::restaurant.restaurant[3].recipes[3].ingredients[2].pcs": 4,
21
- "api::restaurant.restaurant[3].recipes[3].ingredients[2].required": false,
22
- "api::restaurant.restaurant[3].recipes[3].ingredients[3].name": "Soup",
23
- "api::restaurant.restaurant[3].recipes[3].ingredients[3].pcs": 1,
24
- "api::restaurant.restaurant[3].recipes[3].ingredients[3].required": true,
25
- "api::restaurant.restaurant[3].recipes[3].variants[4].name":
26
- "Red, yellow, green",
27
- "api::restaurant.restaurant[3].recipes[4].name": "Goulash",
28
- "api::restaurant.restaurant[3].recipes[4].ingredients[6].name": "Beef meat",
29
- "api::restaurant.restaurant[3].recipes[4].ingredients[6].pcs": 1,
30
- "api::restaurant.restaurant[3].recipes[4].ingredients[6].required": true,
31
- "api::restaurant.restaurant[3].recipes[4].ingredients[7].name": "Pepper",
32
- "api::restaurant.restaurant[3].recipes[4].ingredients[7].pcs": 4,
33
- "api::restaurant.restaurant[3].recipes[4].ingredients[8].name":
34
- "Pepper spices",
35
- "api::restaurant.restaurant[3].recipes[4].ingredients[8].pcs": 1,
36
- "api::restaurant.restaurant[3].recipes[4].ingredients[8].required": true,
37
- "api::restaurant.restaurant[3].recipes[4].ingredients[9].name": "Water",
38
- "api::restaurant.restaurant[3].recipes[4].ingredients[9].pcs": 1,
39
- "api::restaurant.restaurant[3].descs[3].rich_description":
40
- "Another restaurant desc",
41
- "api::restaurant.restaurant[3].descs[3].history":
42
- "Est. 2022, based in NY, NY",
43
- "api::restaurant.restaurant[3].descs[3].excerpt": "Est. 2022",
44
- "api::restaurant.restaurant[3].descs[3].test_variants[5].name":
45
- "no such thing...",
46
- };
@@ -1,15 +0,0 @@
1
- module.exports = (uidPrefix = "") => [
2
- `${uidPrefix}.title`,
3
- `${uidPrefix}.description`,
4
- `${uidPrefix}.recipes.name`,
5
- `${uidPrefix}.recipes.ingredients.name`,
6
- `${uidPrefix}.recipes.variants.name`,
7
- `${uidPrefix}.descs.rich_description`,
8
- `${uidPrefix}.descs.history`,
9
- `${uidPrefix}.descs.excerpt`,
10
- `${uidPrefix}.descs.test_variants.name`,
11
- `${uidPrefix}.street`,
12
- `${uidPrefix}.city`,
13
- `${uidPrefix}.country`,
14
- `${uidPrefix}.id`,
15
- ];