@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.
- package/admin/src/modules/plugin-settings/components/ContentTransferSetup/index.js +5 -0
- package/admin/src/modules/plugin-settings/components/Tree/index.js +21 -6
- package/admin/src/modules/plugin-settings/functions/build-content-transfer-setup-schema.js +1 -1
- package/admin/src/modules/plugin-settings/functions/has-model-changed.js +1 -1
- package/admin/src/modules/plugin-settings/locale/en.js +1 -1
- package/admin/src/modules/plugin-settings/utils/get-filtered-models-schemas.js +1 -7
- package/admin/src/modules/plugin-settings/utils/get-models-tree.js +19 -3
- package/package.json +4 -4
- package/server/controllers/localazy-transfer-controller.js +29 -8
- package/server/functions/should-set-downloaded-property.js +48 -3
- package/server/services/strapi-i18n-service.js +1 -1
- package/server/services/strapi-localazy-i18n-service.js +1 -1
- package/server/tests/fixtures/parsed-localazy-entry-to-create-entry-lesson-dz.js +392 -0
- package/server/tests/fixtures/parsed-localazy-entry-to-create-entry-sample-json-dz.js +4675 -0
- package/server/tests/fixtures/populate-create-update-entry-with-base-entry-lesson-dz.js +309 -0
- package/server/tests/fixtures/populate-create-update-entry-with-base-entry-sample-json-dz.js +884 -0
- package/server/tests/fixtures/strapi-plugin-all-models.js +844 -37
- package/server/utils/__tests__/parsed-localazy-entry-to-create-entry.test.js +211 -62
- package/server/utils/__tests__/pick-entries.test.js +936 -56
- package/server/utils/__tests__/populate-create-update-entry-with-base-entry.test.js +287 -0
- package/server/utils/build-populate.js +5 -0
- package/server/utils/model-utils.js +5 -0
- package/server/utils/omit-deep.js +7 -0
- package/server/utils/parsed-localazy-entry-to-create-entry.js +58 -4
- package/server/utils/parsed-localazy-entry-to-update-entry.js +6 -1
- package/server/utils/pick-deep.js +22 -0
- package/server/utils/pick-entries.js +90 -5
- package/server/utils/populate-create-update-entry-with-base-entry.js +51 -3
- package/server/tests/fixtures/collection-flattened.js +0 -76
- package/server/tests/fixtures/restaurant-flattened.js +0 -46
- package/server/tests/fixtures/restaurants-pick-paths.js +0 -15
|
@@ -8,6 +8,8 @@ const simpleMenuEmptyModel = require("../../tests/fixtures/populate-create-updat
|
|
|
8
8
|
const sampleJSONModel = require("../../tests/fixtures/populate-create-update-entry-with-base-entry-sample-json");
|
|
9
9
|
const cookbookModel = require("../../tests/fixtures/populate-create-update-entry-with-base-entry-cookbook");
|
|
10
10
|
const cookbookEmptyRecipesModel = require("../../tests/fixtures/populate-create-update-entry-with-base-entry-cookbook-empty-recipes");
|
|
11
|
+
const sampleJSONWithDZsModel = require("../../tests/fixtures/populate-create-update-entry-with-base-entry-sample-json-dz");
|
|
12
|
+
const lessonWithDZsModel = require("../../tests/fixtures/populate-create-update-entry-with-base-entry-lesson-dz");
|
|
11
13
|
|
|
12
14
|
const populateCreateUpdateEntryWithBaseEntry = require("../populate-create-update-entry-with-base-entry");
|
|
13
15
|
|
|
@@ -849,4 +851,289 @@ describe("populate-create-update-entry-with-base-entry.js", () => {
|
|
|
849
851
|
|
|
850
852
|
expect(populatedEntry).toEqual(expected);
|
|
851
853
|
});
|
|
854
|
+
|
|
855
|
+
it("should populate a 'sample-json' including DZs correctly", async () => {
|
|
856
|
+
const populatedEntry = await populateCreateUpdateEntryWithBaseEntry(
|
|
857
|
+
allModels,
|
|
858
|
+
sampleJSONWithDZsModel.updateEntry,
|
|
859
|
+
sampleJSONWithDZsModel.baseEntry,
|
|
860
|
+
sampleJSONWithDZsModel.fullyPopulatedLocalizedEntry,
|
|
861
|
+
sampleJSONWithDZsModel.uid,
|
|
862
|
+
sampleJSONWithDZsModel.locale,
|
|
863
|
+
);
|
|
864
|
+
|
|
865
|
+
const expected = {
|
|
866
|
+
id: 24,
|
|
867
|
+
purpose: "Bar",
|
|
868
|
+
data: {
|
|
869
|
+
bar: "baz",
|
|
870
|
+
},
|
|
871
|
+
dynamic_property: [
|
|
872
|
+
{
|
|
873
|
+
id: 170,
|
|
874
|
+
image_title: "Nějaký název obrázku",
|
|
875
|
+
image_description: "Nějaký popis obrázku",
|
|
876
|
+
image: {
|
|
877
|
+
id: 11,
|
|
878
|
+
name: "heather-ford-G4LFhuLXhLE-unsplash.jpg",
|
|
879
|
+
alternativeText: "heather-ford-G4LFhuLXhLE-unsplash.jpg",
|
|
880
|
+
caption: "heather-ford-G4LFhuLXhLE-unsplash.jpg",
|
|
881
|
+
width: 6127,
|
|
882
|
+
height: 3844,
|
|
883
|
+
formats: {
|
|
884
|
+
thumbnail: {
|
|
885
|
+
name: "thumbnail_heather-ford-G4LFhuLXhLE-unsplash.jpg",
|
|
886
|
+
hash: "thumbnail_heather_ford_G4_L_Fhu_L_Xh_LE_unsplash_7a2c2cac8f",
|
|
887
|
+
ext: ".jpg",
|
|
888
|
+
mime: "image/jpeg",
|
|
889
|
+
path: null,
|
|
890
|
+
width: 245,
|
|
891
|
+
height: 154,
|
|
892
|
+
size: 9.54,
|
|
893
|
+
url: "/uploads/thumbnail_heather_ford_G4_L_Fhu_L_Xh_LE_unsplash_7a2c2cac8f.jpg",
|
|
894
|
+
},
|
|
895
|
+
large: {
|
|
896
|
+
name: "large_heather-ford-G4LFhuLXhLE-unsplash.jpg",
|
|
897
|
+
hash: "large_heather_ford_G4_L_Fhu_L_Xh_LE_unsplash_7a2c2cac8f",
|
|
898
|
+
ext: ".jpg",
|
|
899
|
+
mime: "image/jpeg",
|
|
900
|
+
path: null,
|
|
901
|
+
width: 1000,
|
|
902
|
+
height: 628,
|
|
903
|
+
size: 117.56,
|
|
904
|
+
url: "/uploads/large_heather_ford_G4_L_Fhu_L_Xh_LE_unsplash_7a2c2cac8f.jpg",
|
|
905
|
+
},
|
|
906
|
+
medium: {
|
|
907
|
+
name: "medium_heather-ford-G4LFhuLXhLE-unsplash.jpg",
|
|
908
|
+
hash: "medium_heather_ford_G4_L_Fhu_L_Xh_LE_unsplash_7a2c2cac8f",
|
|
909
|
+
ext: ".jpg",
|
|
910
|
+
mime: "image/jpeg",
|
|
911
|
+
path: null,
|
|
912
|
+
width: 750,
|
|
913
|
+
height: 471,
|
|
914
|
+
size: 66.32,
|
|
915
|
+
url: "/uploads/medium_heather_ford_G4_L_Fhu_L_Xh_LE_unsplash_7a2c2cac8f.jpg",
|
|
916
|
+
},
|
|
917
|
+
small: {
|
|
918
|
+
name: "small_heather-ford-G4LFhuLXhLE-unsplash.jpg",
|
|
919
|
+
hash: "small_heather_ford_G4_L_Fhu_L_Xh_LE_unsplash_7a2c2cac8f",
|
|
920
|
+
ext: ".jpg",
|
|
921
|
+
mime: "image/jpeg",
|
|
922
|
+
path: null,
|
|
923
|
+
width: 500,
|
|
924
|
+
height: 314,
|
|
925
|
+
size: 31.42,
|
|
926
|
+
url: "/uploads/small_heather_ford_G4_L_Fhu_L_Xh_LE_unsplash_7a2c2cac8f.jpg",
|
|
927
|
+
},
|
|
928
|
+
},
|
|
929
|
+
hash: "heather_ford_G4_L_Fhu_L_Xh_LE_unsplash_7a2c2cac8f",
|
|
930
|
+
ext: ".jpg",
|
|
931
|
+
mime: "image/jpeg",
|
|
932
|
+
size: 6971.47,
|
|
933
|
+
url: "/uploads/heather_ford_G4_L_Fhu_L_Xh_LE_unsplash_7a2c2cac8f.jpg",
|
|
934
|
+
previewUrl: null,
|
|
935
|
+
provider: "local",
|
|
936
|
+
provider_metadata: null,
|
|
937
|
+
},
|
|
938
|
+
__component: "food.gallery-item",
|
|
939
|
+
},
|
|
940
|
+
{
|
|
941
|
+
id: 191,
|
|
942
|
+
name: "Přísada I",
|
|
943
|
+
amount: null,
|
|
944
|
+
unit: null,
|
|
945
|
+
is_required: true,
|
|
946
|
+
__component: "food.recipe-ingredient",
|
|
947
|
+
},
|
|
948
|
+
{
|
|
949
|
+
id: 36,
|
|
950
|
+
name: "První položka CB",
|
|
951
|
+
recipe: null,
|
|
952
|
+
estimated_cook_time: "00:03:00.000",
|
|
953
|
+
difficulty: "beginner",
|
|
954
|
+
author_name: "Já",
|
|
955
|
+
gallery: [
|
|
956
|
+
{
|
|
957
|
+
id: 171,
|
|
958
|
+
image_title: "Obrázek G Jedna",
|
|
959
|
+
image_description: "Obrázek G Popis Jedna",
|
|
960
|
+
},
|
|
961
|
+
{
|
|
962
|
+
id: 172,
|
|
963
|
+
image_title: "Img G Two",
|
|
964
|
+
image_description: "Img G Desc Two",
|
|
965
|
+
},
|
|
966
|
+
],
|
|
967
|
+
ingredients: [
|
|
968
|
+
{
|
|
969
|
+
id: 193,
|
|
970
|
+
name: "První Ingr DZ",
|
|
971
|
+
amount: null,
|
|
972
|
+
unit: null,
|
|
973
|
+
is_required: true,
|
|
974
|
+
},
|
|
975
|
+
],
|
|
976
|
+
__component: "food.cookbook-item",
|
|
977
|
+
},
|
|
978
|
+
{
|
|
979
|
+
id: 192,
|
|
980
|
+
name: "Druhá přísada",
|
|
981
|
+
amount: null,
|
|
982
|
+
unit: null,
|
|
983
|
+
is_required: true,
|
|
984
|
+
__component: "food.recipe-ingredient",
|
|
985
|
+
},
|
|
986
|
+
],
|
|
987
|
+
repeatable_component_property: [
|
|
988
|
+
{
|
|
989
|
+
id: 61,
|
|
990
|
+
name: "Položka 1",
|
|
991
|
+
price: 1,
|
|
992
|
+
currency: "CZK",
|
|
993
|
+
description: "Nějaký popis",
|
|
994
|
+
is_available: null,
|
|
995
|
+
food_gallery: null,
|
|
996
|
+
},
|
|
997
|
+
{
|
|
998
|
+
id: 62,
|
|
999
|
+
name: "Položka 2",
|
|
1000
|
+
price: 2,
|
|
1001
|
+
currency: "CZK",
|
|
1002
|
+
description: "Nějaký další popis",
|
|
1003
|
+
is_available: null,
|
|
1004
|
+
food_gallery: [
|
|
1005
|
+
{
|
|
1006
|
+
id: 6,
|
|
1007
|
+
name: "rodrigo-dos-reis-h3AkzboxK4Q-unsplash.jpg",
|
|
1008
|
+
alternativeText: "rodrigo-dos-reis-h3AkzboxK4Q-unsplash.jpg",
|
|
1009
|
+
caption: "rodrigo-dos-reis-h3AkzboxK4Q-unsplash.jpg",
|
|
1010
|
+
width: 2268,
|
|
1011
|
+
height: 4032,
|
|
1012
|
+
formats: {
|
|
1013
|
+
thumbnail: {
|
|
1014
|
+
name: "thumbnail_rodrigo-dos-reis-h3AkzboxK4Q-unsplash.jpg",
|
|
1015
|
+
hash: "thumbnail_rodrigo_dos_reis_h3_Akzbox_K4_Q_unsplash_d17e795cea",
|
|
1016
|
+
ext: ".jpg",
|
|
1017
|
+
mime: "image/jpeg",
|
|
1018
|
+
path: null,
|
|
1019
|
+
width: 88,
|
|
1020
|
+
height: 156,
|
|
1021
|
+
size: 5.35,
|
|
1022
|
+
url: "/uploads/thumbnail_rodrigo_dos_reis_h3_Akzbox_K4_Q_unsplash_d17e795cea.jpg",
|
|
1023
|
+
},
|
|
1024
|
+
large: {
|
|
1025
|
+
name: "large_rodrigo-dos-reis-h3AkzboxK4Q-unsplash.jpg",
|
|
1026
|
+
hash: "large_rodrigo_dos_reis_h3_Akzbox_K4_Q_unsplash_d17e795cea",
|
|
1027
|
+
ext: ".jpg",
|
|
1028
|
+
mime: "image/jpeg",
|
|
1029
|
+
path: null,
|
|
1030
|
+
width: 563,
|
|
1031
|
+
height: 1000,
|
|
1032
|
+
size: 108.15,
|
|
1033
|
+
url: "/uploads/large_rodrigo_dos_reis_h3_Akzbox_K4_Q_unsplash_d17e795cea.jpg",
|
|
1034
|
+
},
|
|
1035
|
+
medium: {
|
|
1036
|
+
name: "medium_rodrigo-dos-reis-h3AkzboxK4Q-unsplash.jpg",
|
|
1037
|
+
hash: "medium_rodrigo_dos_reis_h3_Akzbox_K4_Q_unsplash_d17e795cea",
|
|
1038
|
+
ext: ".jpg",
|
|
1039
|
+
mime: "image/jpeg",
|
|
1040
|
+
path: null,
|
|
1041
|
+
width: 422,
|
|
1042
|
+
height: 750,
|
|
1043
|
+
size: 65.52,
|
|
1044
|
+
url: "/uploads/medium_rodrigo_dos_reis_h3_Akzbox_K4_Q_unsplash_d17e795cea.jpg",
|
|
1045
|
+
},
|
|
1046
|
+
small: {
|
|
1047
|
+
name: "small_rodrigo-dos-reis-h3AkzboxK4Q-unsplash.jpg",
|
|
1048
|
+
hash: "small_rodrigo_dos_reis_h3_Akzbox_K4_Q_unsplash_d17e795cea",
|
|
1049
|
+
ext: ".jpg",
|
|
1050
|
+
mime: "image/jpeg",
|
|
1051
|
+
path: null,
|
|
1052
|
+
width: 281,
|
|
1053
|
+
height: 500,
|
|
1054
|
+
size: 34.23,
|
|
1055
|
+
url: "/uploads/small_rodrigo_dos_reis_h3_Akzbox_K4_Q_unsplash_d17e795cea.jpg",
|
|
1056
|
+
},
|
|
1057
|
+
},
|
|
1058
|
+
hash: "rodrigo_dos_reis_h3_Akzbox_K4_Q_unsplash_d17e795cea",
|
|
1059
|
+
ext: ".jpg",
|
|
1060
|
+
mime: "image/jpeg",
|
|
1061
|
+
size: 1081.59,
|
|
1062
|
+
url: "/uploads/rodrigo_dos_reis_h3_Akzbox_K4_Q_unsplash_d17e795cea.jpg",
|
|
1063
|
+
previewUrl: null,
|
|
1064
|
+
provider: "local",
|
|
1065
|
+
provider_metadata: null,
|
|
1066
|
+
},
|
|
1067
|
+
],
|
|
1068
|
+
},
|
|
1069
|
+
],
|
|
1070
|
+
};
|
|
1071
|
+
|
|
1072
|
+
expect(populatedEntry).toEqual(expected);
|
|
1073
|
+
});
|
|
1074
|
+
|
|
1075
|
+
it("should populate a 'lesson' including DZs correctly", async () => {
|
|
1076
|
+
const populatedEntry = await populateCreateUpdateEntryWithBaseEntry(
|
|
1077
|
+
allModels,
|
|
1078
|
+
lessonWithDZsModel.updateEntry,
|
|
1079
|
+
lessonWithDZsModel.baseEntry,
|
|
1080
|
+
lessonWithDZsModel.fullyPopulatedLocalizedEntry,
|
|
1081
|
+
lessonWithDZsModel.uid,
|
|
1082
|
+
lessonWithDZsModel.locale,
|
|
1083
|
+
);
|
|
1084
|
+
|
|
1085
|
+
const expected = {
|
|
1086
|
+
id: 4,
|
|
1087
|
+
title: "Test: Sčítání",
|
|
1088
|
+
start_time: "2022-10-01T13:00:00.000Z",
|
|
1089
|
+
duration: "02:00:00.000",
|
|
1090
|
+
description: "Otestujte si své dovednosti, které jsme se naučili v předchozí lekci.",
|
|
1091
|
+
lesson_type: [
|
|
1092
|
+
{
|
|
1093
|
+
id: 2,
|
|
1094
|
+
title: "Vyberte správnou odpověď",
|
|
1095
|
+
questions: [
|
|
1096
|
+
{
|
|
1097
|
+
id: 4,
|
|
1098
|
+
question: "1 + 1 = ",
|
|
1099
|
+
is_active: true,
|
|
1100
|
+
question_number: 1,
|
|
1101
|
+
},
|
|
1102
|
+
{
|
|
1103
|
+
id: 5,
|
|
1104
|
+
question: "5 + 15 = ",
|
|
1105
|
+
is_active: false,
|
|
1106
|
+
question_number: 2,
|
|
1107
|
+
},
|
|
1108
|
+
{
|
|
1109
|
+
id: 6,
|
|
1110
|
+
question: "Kolik pohárů je na fotce?",
|
|
1111
|
+
is_active: false,
|
|
1112
|
+
question_number: 3,
|
|
1113
|
+
},
|
|
1114
|
+
],
|
|
1115
|
+
answers: [
|
|
1116
|
+
{
|
|
1117
|
+
id: 4,
|
|
1118
|
+
question_number: 1,
|
|
1119
|
+
correct_answer: "2",
|
|
1120
|
+
},
|
|
1121
|
+
{
|
|
1122
|
+
id: 5,
|
|
1123
|
+
question_number: 2,
|
|
1124
|
+
correct_answer: "20",
|
|
1125
|
+
},
|
|
1126
|
+
{
|
|
1127
|
+
id: 6,
|
|
1128
|
+
question_number: 3,
|
|
1129
|
+
correct_answer: "15",
|
|
1130
|
+
},
|
|
1131
|
+
],
|
|
1132
|
+
__component: "lesson.quiz",
|
|
1133
|
+
},
|
|
1134
|
+
],
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
expect(populatedEntry).toEqual(expected);
|
|
1138
|
+
});
|
|
852
1139
|
});
|
|
@@ -30,6 +30,11 @@ const buildPopulate = (models, modelUid) => {
|
|
|
30
30
|
: `${attributeName}`;
|
|
31
31
|
const innerModelUid = attribute.component;
|
|
32
32
|
buildPopulateStep(models, innerModelUid, newPrefix);
|
|
33
|
+
} else if (attribute.type === "dynamiczone") {
|
|
34
|
+
const key = prefix
|
|
35
|
+
? `${prefix}.${attributeName}.populate`
|
|
36
|
+
: `${attributeName}.populate`;
|
|
37
|
+
keys.push(key);
|
|
33
38
|
}
|
|
34
39
|
}
|
|
35
40
|
|
|
@@ -15,6 +15,10 @@ const isComponent = (attributeObj) => {
|
|
|
15
15
|
return attributeObj.type === "component";
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
+
const isDynamicZone = (attributeObj) => {
|
|
19
|
+
return attributeObj.type === "dynamiczone";
|
|
20
|
+
}
|
|
21
|
+
|
|
18
22
|
const isRepeatable = (attributeObj) => {
|
|
19
23
|
return isComponent(attributeObj) && !!attributeObj.repeatable;
|
|
20
24
|
};
|
|
@@ -32,6 +36,7 @@ const findModel = (models, uid) => {
|
|
|
32
36
|
module.exports = {
|
|
33
37
|
getAttribute,
|
|
34
38
|
isComponent,
|
|
39
|
+
isDynamicZone,
|
|
35
40
|
isRepeatable,
|
|
36
41
|
isRelation,
|
|
37
42
|
findModel,
|
|
@@ -11,6 +11,13 @@ function omitDeep(collection, excludeKeys) {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
if (Array.isArray(collection)) {
|
|
15
|
+
const clonedData = [];
|
|
16
|
+
for (const collectionItem of collection) {
|
|
17
|
+
clonedData.push(cloneDeepWith(collectionItem, omitFn));
|
|
18
|
+
}
|
|
19
|
+
return clonedData;
|
|
20
|
+
}
|
|
14
21
|
return cloneDeepWith(collection, omitFn);
|
|
15
22
|
}
|
|
16
23
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const set = require("lodash/set");
|
|
4
4
|
const get = require("lodash/get");
|
|
5
5
|
const resetArrayKeysDeep = require("./reset-array-keys-deep");
|
|
6
|
-
const { getAttribute, isComponent, isRepeatable, findModel } = require("./model-utils");
|
|
6
|
+
const { getAttribute, isComponent, isDynamicZone, isRepeatable, findModel } = require("./model-utils");
|
|
7
7
|
|
|
8
8
|
const parsedLocalazyEntryToCreateEntry = (
|
|
9
9
|
models,
|
|
@@ -14,6 +14,7 @@ const parsedLocalazyEntryToCreateEntry = (
|
|
|
14
14
|
) => {
|
|
15
15
|
const createEntry = {};
|
|
16
16
|
const repeatableComponentsKeystoFilter = [];
|
|
17
|
+
const dynamicZoneComponentKeys = [];
|
|
17
18
|
|
|
18
19
|
const toCreateEntry = (
|
|
19
20
|
entry,
|
|
@@ -23,7 +24,8 @@ const parsedLocalazyEntryToCreateEntry = (
|
|
|
23
24
|
key = "",
|
|
24
25
|
prefix = "",
|
|
25
26
|
component = "",
|
|
26
|
-
isRepeatableComponent = false
|
|
27
|
+
isRepeatableComponent = false,
|
|
28
|
+
isDZ = false,
|
|
27
29
|
) => {
|
|
28
30
|
if (Array.isArray(entry)) {
|
|
29
31
|
// is array
|
|
@@ -47,6 +49,33 @@ const parsedLocalazyEntryToCreateEntry = (
|
|
|
47
49
|
if (component && !isRepeatableComponent) {
|
|
48
50
|
toCreateEntry(value, model, baseEntry, `${prefix}`, `${prefix}`);
|
|
49
51
|
}
|
|
52
|
+
|
|
53
|
+
if (!component && isRepeatableComponent) {
|
|
54
|
+
// used for indices filtering in dynamic zones
|
|
55
|
+
if (!repeatableComponentsKeystoFilter.includes(prefix)) {
|
|
56
|
+
repeatableComponentsKeystoFilter.push(prefix);
|
|
57
|
+
}
|
|
58
|
+
const baseEntryRepeatableItemId = parseInt(baseEntryItemId);
|
|
59
|
+
const baseEntryRepeateableGroup = get(baseEntry, prefix);
|
|
60
|
+
if (baseEntryRepeateableGroup !== undefined) {
|
|
61
|
+
const localizedEntryRepeatableItemPosition = baseEntryRepeateableGroup.findIndex((repeatableItem) => !!repeatableItem && repeatableItem.id === baseEntryRepeatableItemId);
|
|
62
|
+
if (localizedEntryRepeatableItemPosition > -1) {
|
|
63
|
+
const dzEntry = get(baseEntry, prefix).find((v) => v.id === baseEntryRepeatableItemId);
|
|
64
|
+
const dzEntryComponent = dzEntry.__component;
|
|
65
|
+
const dzEntryComponentModel = findModel(models, dzEntryComponent);
|
|
66
|
+
toCreateEntry(
|
|
67
|
+
value,
|
|
68
|
+
dzEntryComponentModel,
|
|
69
|
+
baseEntry,
|
|
70
|
+
localizedEntryRepeatableItemPosition,
|
|
71
|
+
`${prefix}.${localizedEntryRepeatableItemPosition}`,
|
|
72
|
+
dzEntryComponent,
|
|
73
|
+
true,
|
|
74
|
+
true,
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
50
79
|
}
|
|
51
80
|
});
|
|
52
81
|
} else {
|
|
@@ -89,12 +118,37 @@ const parsedLocalazyEntryToCreateEntry = (
|
|
|
89
118
|
false
|
|
90
119
|
);
|
|
91
120
|
}
|
|
121
|
+
} else if (isDynamicZone(attribute)) {
|
|
122
|
+
// behaves sort of like repeatable component
|
|
123
|
+
const newPrefix = prefix
|
|
124
|
+
? `${prefix}.${objectKey}`
|
|
125
|
+
: `${objectKey}`;
|
|
126
|
+
toCreateEntry(
|
|
127
|
+
value,
|
|
128
|
+
null, // model is evaluated later as it's dynamic (DZ)
|
|
129
|
+
baseEntry,
|
|
130
|
+
objectKey,
|
|
131
|
+
newPrefix,
|
|
132
|
+
"", // component is computed later as it's dynamic (DZ)
|
|
133
|
+
true,
|
|
134
|
+
true,
|
|
135
|
+
);
|
|
92
136
|
} else {
|
|
93
137
|
const newPrefix = prefix ? `${prefix}.${objectKey}` : `${objectKey}`;
|
|
94
138
|
set(createEntry, newPrefix, value);
|
|
95
139
|
|
|
96
140
|
if (component) {
|
|
97
|
-
|
|
141
|
+
const componentKeyToSet = `${prefix}.__component`;
|
|
142
|
+
set(createEntry, componentKeyToSet, component);
|
|
143
|
+
|
|
144
|
+
if (isDZ) {
|
|
145
|
+
const isKeyAdded = (typeof dynamicZoneComponentKeys.find((v) => v.key === componentKeyToSet) !== "undefined");
|
|
146
|
+
if (!isKeyAdded)
|
|
147
|
+
dynamicZoneComponentKeys.push({
|
|
148
|
+
key: componentKeyToSet,
|
|
149
|
+
component,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
98
152
|
}
|
|
99
153
|
// is not component
|
|
100
154
|
}
|
|
@@ -109,7 +163,7 @@ const parsedLocalazyEntryToCreateEntry = (
|
|
|
109
163
|
}
|
|
110
164
|
|
|
111
165
|
resetArrayKeysDeep(createEntry, repeatableComponentsKeystoFilter);
|
|
112
|
-
return createEntry;
|
|
166
|
+
return { createEntry, dynamicZoneComponentKeys };
|
|
113
167
|
};
|
|
114
168
|
|
|
115
169
|
module.exports = parsedLocalazyEntryToCreateEntry;
|
|
@@ -4,6 +4,7 @@ const merge = require("lodash/merge");
|
|
|
4
4
|
const parsedLocalazyEntryToCreateEntry = require("./parsed-localazy-entry-to-create-entry");
|
|
5
5
|
const omitDeep = require("./omit-deep");
|
|
6
6
|
const populateCreateUpdateEntryWithBaseEntry = require("./populate-create-update-entry-with-base-entry");
|
|
7
|
+
const { set } = require("lodash");
|
|
7
8
|
|
|
8
9
|
const parsedLocalazyEntryToUpdateEntry = async (
|
|
9
10
|
allModels,
|
|
@@ -14,7 +15,7 @@ const parsedLocalazyEntryToUpdateEntry = async (
|
|
|
14
15
|
uid,
|
|
15
16
|
locale
|
|
16
17
|
) => {
|
|
17
|
-
const createEntry = parsedLocalazyEntryToCreateEntry(
|
|
18
|
+
const { createEntry, dynamicZoneComponentKeys } = parsedLocalazyEntryToCreateEntry(
|
|
18
19
|
allModels,
|
|
19
20
|
localazyEntry,
|
|
20
21
|
baseEntry,
|
|
@@ -33,6 +34,10 @@ const parsedLocalazyEntryToUpdateEntry = async (
|
|
|
33
34
|
"updatedBy",
|
|
34
35
|
"publishedAt",
|
|
35
36
|
]);
|
|
37
|
+
// set dynamic zone compoonent keys again
|
|
38
|
+
dynamicZoneComponentKeys.forEach((v) => {
|
|
39
|
+
set(updateEntry, v.key, v.component);
|
|
40
|
+
});
|
|
36
41
|
|
|
37
42
|
const filteredBaseEntry = omitDeep(baseEntry, [
|
|
38
43
|
// "__component", // do not omit the __component
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const isObject = require("lodash/isObject");
|
|
3
|
+
const set = require("lodash/set");
|
|
4
|
+
const includes = require("lodash/includes");
|
|
5
|
+
|
|
6
|
+
const deepLodashPick = (obj, keys, newObj = {}, path = []) => {
|
|
7
|
+
for (let k in obj) {
|
|
8
|
+
const value = obj[k];
|
|
9
|
+
|
|
10
|
+
if (isObject(value)) {
|
|
11
|
+
path.push(k);
|
|
12
|
+
deepLodashPick(value, keys, newObj, path);
|
|
13
|
+
path.pop();
|
|
14
|
+
} else if (includes(keys, k)) {
|
|
15
|
+
set(newObj, [...path, k], value);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return newObj;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = deepLodashPick;
|
|
@@ -1,12 +1,97 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const map = require("lodash/map");
|
|
4
|
+
const pickDeep = require("./pick-deep");
|
|
5
|
+
const flattenObject = require("./flatten-object");
|
|
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.split(".").find((s, index) => index > 1 && s.includes(dynamicPropertyEntryIdWithSquareBrackets));
|
|
16
|
+
const dynamicPropertyName = dynamicPropertyNamePart.replace(dynamicPropertyEntryIdWithSquareBrackets, "");
|
|
17
|
+
|
|
18
|
+
return Array.isArray(transferSetupModel[dynamicPropertyName]);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const getDynamicZoneEntryId = (key, transferSetupModel) => {
|
|
22
|
+
if (!isDynamicZoneKey(key, transferSetupModel)) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const matches = key.match(/\[\d+\]+/g);
|
|
27
|
+
// remove square brackets
|
|
28
|
+
const id = matches[1].replace(/[\[\]']+/g, '');
|
|
29
|
+
return id;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const doesPickPathsIncludeTheComponent = (pickPaths, dzParameterKey) => {
|
|
33
|
+
return pickPaths.some((pp) => pp.includes(dzParameterKey));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const pickEntries = (flatten, pickPaths, transferSetupModel) => {
|
|
37
|
+
// * dynamic zones properties must! always be in 1st level (not in component; Strapi restrictions)
|
|
38
|
+
|
|
39
|
+
const dzEntryIdComponentMap = {};
|
|
40
|
+
const flattenComponentProps = Object.fromEntries(Object.entries(flatten).filter(([key]) => key.includes('__component')));
|
|
41
|
+
|
|
42
|
+
const pickedDeep = pickDeep(transferSetupModel, ["__component__"]);
|
|
43
|
+
const flattenedPickedDeep = flattenObject(pickedDeep);
|
|
44
|
+
map(flattenedPickedDeep, (v, i) => {
|
|
45
|
+
const newI = i.replace(".__component__", "");
|
|
46
|
+
flattenedPickedDeep[newI] = v;
|
|
47
|
+
delete flattenedPickedDeep[i];
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
Object.keys(flattenComponentProps).map((key) => {
|
|
51
|
+
if (!isDynamicZoneKey(key, transferSetupModel)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const entryId = getDynamicZoneEntryId(key, transferSetupModel);
|
|
56
|
+
dzEntryIdComponentMap[entryId] = {
|
|
57
|
+
component: flattenComponentProps[key],
|
|
58
|
+
key: Object.keys(flattenedPickedDeep).find((fpdk) => flattenedPickedDeep[fpdk] === flattenComponentProps[key]),
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
|
|
4
62
|
const pickedEntries = {};
|
|
5
|
-
|
|
63
|
+
const mappedPickPaths = pickPaths.map((pickPath) => pickPath.replace(/\[\d+\]/g, ""));
|
|
64
|
+
|
|
65
|
+
// filter out "__component"
|
|
66
|
+
const filteredFlatten = Object.fromEntries(Object.entries(flatten).filter(([key]) => !key.includes('__component')));
|
|
67
|
+
Object.keys(filteredFlatten).forEach((key) => {
|
|
68
|
+
// decide whether it is a dynamic zone
|
|
69
|
+
// handle dynamic zones, in case of similarly-named fields across more components
|
|
70
|
+
const isDynamicZone = isDynamicZoneKey(key, transferSetupModel);
|
|
71
|
+
if (isDynamicZone) {
|
|
72
|
+
const dzEntryId = getDynamicZoneEntryId(key, transferSetupModel);
|
|
73
|
+
const dzParameterKey = dzEntryIdComponentMap[dzEntryId].key;
|
|
74
|
+
|
|
75
|
+
if (!doesPickPathsIncludeTheComponent(pickPaths, dzParameterKey)) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
6
80
|
const filteredKey = key.replace(/\[\d+\]/g, "");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
81
|
+
if (mappedPickPaths.includes(filteredKey)) {
|
|
82
|
+
if (isDynamicZone) {
|
|
83
|
+
const dzEntryId = getDynamicZoneEntryId(key, transferSetupModel);
|
|
84
|
+
const dzParameterKey = dzEntryIdComponentMap[dzEntryId].key;
|
|
85
|
+
|
|
86
|
+
const dzParameterName = dzParameterKey.substring(0, dzParameterKey.indexOf('['));
|
|
87
|
+
const toBeReplaced = `${dzParameterName}[${dzEntryId}]`;
|
|
88
|
+
const dzParameterComponent = dzEntryIdComponentMap[dzEntryId].component;
|
|
89
|
+
const componentAddition = `${dzParameterName}[${dzEntryId};${dzParameterComponent}]`;
|
|
90
|
+
const replacedKey = key.replace(toBeReplaced, componentAddition);
|
|
91
|
+
pickedEntries[replacedKey] = flatten[key];
|
|
92
|
+
} else {
|
|
93
|
+
pickedEntries[key] = flatten[key];
|
|
94
|
+
}
|
|
10
95
|
}
|
|
11
96
|
});
|
|
12
97
|
return pickedEntries;
|