@localazy/strapi-plugin 0.1.13-rc.2 → 0.1.13-rc.4
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.
|
@@ -200,14 +200,16 @@ function GlobalSettings() {
|
|
|
200
200
|
<Option value="updated">{t("plugin_settings.editing_data_entry")}</Option>
|
|
201
201
|
</Select>
|
|
202
202
|
{/* Deprecate source keys on deletion */}
|
|
203
|
-
<
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
203
|
+
<div style={{ display: "none" }}>
|
|
204
|
+
<br /><br />
|
|
205
|
+
<ToggleInput
|
|
206
|
+
label={t("plugin_settings.deprecate_source_keys_on_delete")}
|
|
207
|
+
hint={t("plugin_settings.deprecate_source_keys_on_delete_info")}
|
|
208
|
+
offLabel={t("plugin_settings.off")}
|
|
209
|
+
onLabel={t("plugin_settings.on")}
|
|
210
|
+
checked={typeof formModel?.upload?.allowDeprecate === "boolean" ? formModel.upload.allowDeprecate : false}
|
|
211
|
+
onChange={e => patchFormModel("upload.allowDeprecate", e.target.checked)} />
|
|
212
|
+
</div>
|
|
211
213
|
<br /><br />
|
|
212
214
|
<Divider />
|
|
213
215
|
{/* Download Settings */}
|
package/package.json
CHANGED
package/server/bootstrap.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const deepPopulateHook = require('./lifecycles/deep-populate-hook');
|
|
4
4
|
const uploadEventEntryToLocalazyHook = require('./lifecycles/upload-event-entry-to-localazy-hook');
|
|
5
|
-
const deprecateEventEntryInLocalazyHook = require('./lifecycles/deprecate-event-entry-in-localazy-hook');
|
|
6
5
|
const RequestInitiatorHelper = require('./utils/request-initiator-helper');
|
|
7
6
|
|
|
8
7
|
module.exports = ({ strapi }) => {
|
|
@@ -35,24 +34,6 @@ module.exports = ({ strapi }) => {
|
|
|
35
34
|
break;
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
|
-
case 'beforeDeleteMany':
|
|
39
|
-
case 'beforeDelete': {
|
|
40
|
-
try {
|
|
41
|
-
if (requestInitiatorHelper.isInitiatedByLocalazyWebhook() || requestInitiatorHelper.isInitiatedByLocalazyPluginUI()) {
|
|
42
|
-
break;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// have to await here
|
|
46
|
-
const result = await deprecateEventEntryInLocalazyHook(event);
|
|
47
|
-
if (typeof result !== 'undefined') {
|
|
48
|
-
strapi.log.info(`${action} hook result: ${JSON.stringify(result)}`);
|
|
49
|
-
}
|
|
50
|
-
} catch (e) {
|
|
51
|
-
strapi.log.error(e);
|
|
52
|
-
} finally {
|
|
53
|
-
break;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
37
|
default:
|
|
57
38
|
break;
|
|
58
39
|
}
|
|
@@ -12,8 +12,16 @@ const isDynamicZoneKey = (key, transferSetupModel) => {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
const dynamicPropertyEntryIdWithSquareBrackets = matches[1];
|
|
15
|
-
const dynamicPropertyNamePart = key
|
|
16
|
-
|
|
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
|
+
);
|
|
17
25
|
|
|
18
26
|
return Array.isArray(transferSetupModel[dynamicPropertyName]);
|
|
19
27
|
};
|
|
@@ -25,19 +33,31 @@ const getDynamicZoneEntryId = (key, transferSetupModel) => {
|
|
|
25
33
|
|
|
26
34
|
const matches = key.match(/\[\d+\]+/g);
|
|
27
35
|
// remove square brackets
|
|
28
|
-
const id = matches[1].replace(/[\[\]']+/g,
|
|
36
|
+
const id = matches[1].replace(/[\[\]']+/g, "");
|
|
29
37
|
return id;
|
|
30
|
-
}
|
|
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
|
+
};
|
|
31
49
|
|
|
32
50
|
const doesPickPathsIncludeTheComponent = (pickPaths, dzParameterKey) => {
|
|
33
51
|
return pickPaths.some((pp) => pp.includes(dzParameterKey));
|
|
34
|
-
}
|
|
52
|
+
};
|
|
35
53
|
|
|
36
54
|
const pickEntries = (flatten, pickPaths, transferSetupModel) => {
|
|
37
55
|
// * dynamic zones properties must! always be in 1st level (not in component; Strapi restrictions)
|
|
38
56
|
|
|
39
57
|
const dzEntryIdComponentMap = {};
|
|
40
|
-
const flattenComponentProps = Object.fromEntries(
|
|
58
|
+
const flattenComponentProps = Object.fromEntries(
|
|
59
|
+
Object.entries(flatten).filter(([key]) => key.includes("__component"))
|
|
60
|
+
);
|
|
41
61
|
|
|
42
62
|
const pickedDeep = pickDeep(transferSetupModel, ["__component__"]);
|
|
43
63
|
const flattenedPickedDeep = flattenObject(pickedDeep);
|
|
@@ -52,25 +72,41 @@ const pickEntries = (flatten, pickPaths, transferSetupModel) => {
|
|
|
52
72
|
return;
|
|
53
73
|
}
|
|
54
74
|
|
|
55
|
-
const
|
|
56
|
-
|
|
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] = {
|
|
57
86
|
component: flattenComponentProps[key],
|
|
58
|
-
key:
|
|
87
|
+
key: keyOfEntry,
|
|
59
88
|
};
|
|
60
89
|
});
|
|
61
90
|
|
|
62
91
|
const pickedEntries = {};
|
|
63
|
-
const mappedPickPaths = pickPaths.map((pickPath) =>
|
|
92
|
+
const mappedPickPaths = pickPaths.map((pickPath) =>
|
|
93
|
+
pickPath.replace(/\[\d+\]/g, "")
|
|
94
|
+
);
|
|
64
95
|
|
|
65
96
|
// filter out "__component"
|
|
66
|
-
const filteredFlatten = Object.fromEntries(
|
|
97
|
+
const filteredFlatten = Object.fromEntries(
|
|
98
|
+
Object.entries(flatten).filter(([key]) => !key.includes("__component"))
|
|
99
|
+
);
|
|
67
100
|
Object.keys(filteredFlatten).forEach((key) => {
|
|
68
101
|
// decide whether it is a dynamic zone
|
|
69
102
|
// handle dynamic zones, in case of similarly-named fields across more components
|
|
70
103
|
const isDynamicZone = isDynamicZoneKey(key, transferSetupModel);
|
|
71
104
|
if (isDynamicZone) {
|
|
72
|
-
const
|
|
73
|
-
|
|
105
|
+
const uniqueDzEntryId = getUniqueDynamicZoneEntryId(
|
|
106
|
+
key,
|
|
107
|
+
transferSetupModel
|
|
108
|
+
);
|
|
109
|
+
const dzParameterKey = dzEntryIdComponentMap[uniqueDzEntryId].key;
|
|
74
110
|
|
|
75
111
|
if (!doesPickPathsIncludeTheComponent(pickPaths, dzParameterKey)) {
|
|
76
112
|
return;
|
|
@@ -81,11 +117,19 @@ const pickEntries = (flatten, pickPaths, transferSetupModel) => {
|
|
|
81
117
|
if (mappedPickPaths.includes(filteredKey)) {
|
|
82
118
|
if (isDynamicZone) {
|
|
83
119
|
const dzEntryId = getDynamicZoneEntryId(key, transferSetupModel);
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
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
|
+
);
|
|
87
130
|
const toBeReplaced = `${dzParameterName}[${dzEntryId}]`;
|
|
88
|
-
const dzParameterComponent =
|
|
131
|
+
const dzParameterComponent =
|
|
132
|
+
dzEntryIdComponentMap[uniqueDzEntryId].component;
|
|
89
133
|
const componentAddition = `${dzParameterName}[${dzEntryId};${dzParameterComponent}]`;
|
|
90
134
|
const replacedKey = key.replace(toBeReplaced, componentAddition);
|
|
91
135
|
pickedEntries[replacedKey] = flatten[key];
|