@localazy/strapi-plugin 0.1.13-rc.4 → 0.1.13-rc.5
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/functions/build-content-transfer-setup-schema.js +11 -51
- package/admin/src/modules/plugin-settings/functions/get-content-transfer-setup-keys-sets.js +85 -0
- package/admin/src/modules/plugin-settings/functions/has-model-changed.js +13 -43
- package/package.json +1 -1
|
@@ -1,66 +1,26 @@
|
|
|
1
1
|
import set from "lodash-es/set";
|
|
2
2
|
import get from "lodash-es/get";
|
|
3
|
-
import uniq from "lodash-es/uniq";
|
|
4
|
-
import deepKeys from "@david-vaclavek/deep-keys";
|
|
5
|
-
import sortByModelName from "../../@common/utils/sort-by-model-name";
|
|
6
|
-
import arrayOfModelsToObject from "../utils/array-of-models-to-object";
|
|
7
3
|
import findModelValueByKey from "../utils/find-model-value-by-key";
|
|
4
|
+
import getContentTransferSetupKeysSets from "./get-content-transfer-setup-keys-sets";
|
|
8
5
|
|
|
9
6
|
export default (
|
|
10
7
|
localizableTree = [],
|
|
11
8
|
storedSetupSchema = [],
|
|
12
9
|
allModelsTree = []
|
|
13
10
|
) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const unsortedStoredSetupSchemaKeys = deepKeys(storedSetupSchema);
|
|
23
|
-
const unsortedAllModelsSchemaKeys = deepKeys(allModelsTree);
|
|
24
|
-
|
|
25
|
-
// components order may have changed; this would prevent properties from mixing up
|
|
26
|
-
const regex = /\.\d+\.__component__/;
|
|
27
|
-
let currentModelsSchemaComponentKeys = unsortedCurrentModelsSchemaKeys.filter((key) => key.match(regex)).map((key) => key.replace(regex, ''));
|
|
28
|
-
let storedSetupSchemaComponentKeys = unsortedStoredSetupSchemaKeys.filter((key) => key.match(regex)).map((key) => key.replace(regex, ''));
|
|
29
|
-
let allModelsSchemaComponentKeys = unsortedAllModelsSchemaKeys.filter((key) => key.match(regex)).map((key) => key.replace(regex, ''));
|
|
30
|
-
currentModelsSchemaComponentKeys = uniq(currentModelsSchemaComponentKeys);
|
|
31
|
-
storedSetupSchemaComponentKeys = uniq(storedSetupSchemaComponentKeys);
|
|
32
|
-
allModelsSchemaComponentKeys = uniq(allModelsSchemaComponentKeys);
|
|
33
|
-
|
|
34
|
-
currentModelsSchemaComponentKeys.forEach((key) => {
|
|
35
|
-
get(localizableTree, key).sort((a, b) => a.__component__ > b.__component__ ? 1 : -1);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
storedSetupSchemaComponentKeys.forEach((key) => {
|
|
39
|
-
get(storedSetupSchema, key).sort((a, b) => a.__component__ > b.__component__ ? 1 : -1);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
allModelsSchemaComponentKeys.forEach((key) => {
|
|
43
|
-
get(allModelsTree, key).sort((a, b) => a.__component__ > b.__component__ ? 1 : -1);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
const currentModelsSchemaKeys = deepKeys(localizableTree);
|
|
47
|
-
const storedSetupSchemaKeys = deepKeys(storedSetupSchema);
|
|
48
|
-
|
|
49
|
-
const removedKeys = storedSetupSchemaKeys.filter(
|
|
50
|
-
(x) => !currentModelsSchemaKeys.includes(x)
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const newKeys = currentModelsSchemaKeys.filter(
|
|
54
|
-
(key) => !storedSetupSchemaKeys.includes(key)
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const filteredStoredSetupSchemaKeys = storedSetupSchemaKeys.filter(
|
|
58
|
-
(key) => !removedKeys.includes(key)
|
|
11
|
+
const {
|
|
12
|
+
oLocalizableTree,
|
|
13
|
+
oStoredSetupSchema,
|
|
14
|
+
newKeys,
|
|
15
|
+
filteredStoredSetupSchemaKeys
|
|
16
|
+
} = getContentTransferSetupKeysSets(
|
|
17
|
+
localizableTree,
|
|
18
|
+
storedSetupSchema,
|
|
59
19
|
);
|
|
60
20
|
|
|
61
21
|
const destinationObject = {};
|
|
62
22
|
filteredStoredSetupSchemaKeys.forEach((key) => {
|
|
63
|
-
const localizableTreeValueToSet = get(
|
|
23
|
+
const localizableTreeValueToSet = get(oStoredSetupSchema, key);
|
|
64
24
|
const allModelsTreeValueToSet = findModelValueByKey(allModelsTree, key);
|
|
65
25
|
|
|
66
26
|
if (allModelsTreeValueToSet === null) {
|
|
@@ -74,7 +34,7 @@ export default (
|
|
|
74
34
|
}
|
|
75
35
|
});
|
|
76
36
|
newKeys.forEach((key) => {
|
|
77
|
-
set(destinationObject, key, get(
|
|
37
|
+
set(destinationObject, key, get(oLocalizableTree, key));
|
|
78
38
|
});
|
|
79
39
|
|
|
80
40
|
const destinationArray = [];
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import get from "lodash-es/get";
|
|
2
|
+
import uniq from "lodash-es/uniq";
|
|
3
|
+
import deepKeys from "@david-vaclavek/deep-keys";
|
|
4
|
+
import sortByModelName from "../../@common/utils/sort-by-model-name";
|
|
5
|
+
import arrayOfModelsToObject from "../utils/array-of-models-to-object";
|
|
6
|
+
|
|
7
|
+
export default (
|
|
8
|
+
localizableTree = [],
|
|
9
|
+
storedSetupSchema = [],
|
|
10
|
+
) => {
|
|
11
|
+
localizableTree = arrayOfModelsToObject(
|
|
12
|
+
localizableTree.sort(sortByModelName)
|
|
13
|
+
);
|
|
14
|
+
storedSetupSchema = arrayOfModelsToObject(
|
|
15
|
+
storedSetupSchema.sort(sortByModelName)
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
const currentModelsSchemaKeys = deepKeys(localizableTree);
|
|
19
|
+
const storedSetupSchemaKeys = deepKeys(storedSetupSchema);
|
|
20
|
+
|
|
21
|
+
// components order may have changed; this would prevent properties from mixing up
|
|
22
|
+
const regex = /\.\d+\.__component__/;
|
|
23
|
+
let currentModelsSchemaComponentKeys = currentModelsSchemaKeys.filter((key) => key.match(regex)).map((key) => key.replace(regex, ''));
|
|
24
|
+
let storedSetupSchemaComponentKeys = storedSetupSchemaKeys.filter((key) => key.match(regex)).map((key) => key.replace(regex, ''));
|
|
25
|
+
currentModelsSchemaComponentKeys = uniq(currentModelsSchemaComponentKeys);
|
|
26
|
+
storedSetupSchemaComponentKeys = uniq(storedSetupSchemaComponentKeys);
|
|
27
|
+
|
|
28
|
+
const currentModelsSchemaComponentKeysComponentProp = currentModelsSchemaKeys.filter((key) => key.includes('__component__') && currentModelsSchemaComponentKeys.some((k) => key.includes(k)));
|
|
29
|
+
const storedSetupSchemaComponentKeysComponentProp = storedSetupSchemaKeys.filter((key) => key.includes('__component__') && storedSetupSchemaComponentKeys.some((k) => key.includes(k)));
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Is in the "stored setup schema" but not in the "current model"
|
|
33
|
+
*/
|
|
34
|
+
let removedKeys = [];
|
|
35
|
+
removedKeys.push(...storedSetupSchemaComponentKeysComponentProp.map((key) => {
|
|
36
|
+
const storedComponentName = get(storedSetupSchema, key);
|
|
37
|
+
const currentComponentName = get(localizableTree, key);
|
|
38
|
+
|
|
39
|
+
// this must return an array of keys
|
|
40
|
+
if (storedComponentName !== currentComponentName) {
|
|
41
|
+
const part = key.split('.').slice(0, -1).join('.');
|
|
42
|
+
|
|
43
|
+
return storedSetupSchemaKeys.filter((k) => k.includes(part));
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return [];
|
|
47
|
+
}).reduce((acc, val) => acc.concat(val), []));
|
|
48
|
+
removedKeys.push(...storedSetupSchemaKeys.filter((key) => !currentModelsSchemaKeys.includes(key)));
|
|
49
|
+
removedKeys = uniq(removedKeys);
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Is in the "current model" but not in the "stored setup schema"
|
|
53
|
+
*/
|
|
54
|
+
let newKeys = [];
|
|
55
|
+
newKeys.push(...currentModelsSchemaComponentKeysComponentProp.map((key) => {
|
|
56
|
+
const storedComponentName = get(storedSetupSchema, key);
|
|
57
|
+
const currentComponentName = get(localizableTree, key);
|
|
58
|
+
|
|
59
|
+
// this must return an array of keys
|
|
60
|
+
if (storedComponentName !== currentComponentName) {
|
|
61
|
+
const part = key.split('.').slice(0, -1).join('.');
|
|
62
|
+
|
|
63
|
+
return currentModelsSchemaKeys.filter((k) => k.includes(part));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return [];
|
|
67
|
+
}).reduce((acc, val) => acc.concat(val), []));
|
|
68
|
+
newKeys.push(...currentModelsSchemaKeys.filter((key) => !storedSetupSchemaKeys.includes(key)));
|
|
69
|
+
newKeys = uniq(newKeys);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Filter out the removed keys
|
|
73
|
+
*/
|
|
74
|
+
const filteredStoredSetupSchemaKeys = storedSetupSchemaKeys.filter(
|
|
75
|
+
(key) => !removedKeys.includes(key)
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
oLocalizableTree: localizableTree,
|
|
80
|
+
oStoredSetupSchema: storedSetupSchema,
|
|
81
|
+
removedKeys,
|
|
82
|
+
newKeys,
|
|
83
|
+
filteredStoredSetupSchemaKeys,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import deepKeys from "@david-vaclavek/deep-keys";
|
|
2
1
|
import get from "lodash-es/get";
|
|
3
|
-
import uniq from "lodash-es/uniq";
|
|
4
2
|
import PluginSettingsService from "../services/plugin-settings-service";
|
|
5
3
|
import StrapiModelService from "../services/strapi-model-service";
|
|
6
4
|
import getModelsTree from "../utils/get-models-tree";
|
|
7
|
-
import sortByModelName from "../../@common/utils/sort-by-model-name";
|
|
8
|
-
import arrayOfModelsToObject from "../utils/array-of-models-to-object";
|
|
9
5
|
import findModelValueByKey from "../utils/find-model-value-by-key";
|
|
6
|
+
import getContentTransferSetupKeysSets from "./get-content-transfer-setup-keys-sets";
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* Pass parameters optionally so we don't have to fetch them again
|
|
@@ -37,53 +34,26 @@ export default async (
|
|
|
37
34
|
allModelsTree = getModelsTree(models, models);
|
|
38
35
|
}
|
|
39
36
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const unsortedStoredSetupSchemaKeys = deepKeys(storedSetupSchema);
|
|
49
|
-
|
|
50
|
-
// components order may have changed; this would prevent properties from mixing up
|
|
51
|
-
const regex = /\.\d+\.__component__/;
|
|
52
|
-
let currentModelsSchemaComponentKeys = currentModelsSchemaKeys.filter((key) => key.match(regex)).map((key) => key.replace(regex, ''));
|
|
53
|
-
let storedSetupSchemaComponentKeys = unsortedStoredSetupSchemaKeys.filter((key) => key.match(regex)).map((key) => key.replace(regex, ''));
|
|
54
|
-
currentModelsSchemaComponentKeys = uniq(currentModelsSchemaComponentKeys);
|
|
55
|
-
storedSetupSchemaComponentKeys = uniq(storedSetupSchemaComponentKeys);
|
|
56
|
-
|
|
57
|
-
currentModelsSchemaComponentKeys.forEach((key) => {
|
|
58
|
-
get(localizableTree, key).sort((a, b) => a.__component__ > b.__component__ ? 1 : -1);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
storedSetupSchemaComponentKeys.forEach((key) => {
|
|
62
|
-
get(storedSetupSchema, key).sort((a, b) => a.__component__ > b.__component__ ? 1 : -1);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
const modelsTreeKeys = deepKeys(localizableTree);
|
|
66
|
-
const storedSetupSchemaKeys = deepKeys(storedSetupSchema);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const removedKeys = storedSetupSchemaKeys.filter(
|
|
70
|
-
(x) => !modelsTreeKeys.includes(x)
|
|
71
|
-
);
|
|
72
|
-
const newKeys = modelsTreeKeys.filter(
|
|
73
|
-
(key) => !storedSetupSchemaKeys.includes(key)
|
|
37
|
+
const {
|
|
38
|
+
oStoredSetupSchema,
|
|
39
|
+
removedKeys,
|
|
40
|
+
newKeys,
|
|
41
|
+
filteredStoredSetupSchemaKeys
|
|
42
|
+
} = getContentTransferSetupKeysSets(
|
|
43
|
+
localizableTree,
|
|
44
|
+
storedSetupSchema,
|
|
74
45
|
);
|
|
75
46
|
|
|
76
47
|
if (newKeys.length || removedKeys.length) {
|
|
77
48
|
return true;
|
|
78
49
|
}
|
|
79
50
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
51
|
+
/**
|
|
52
|
+
* Check if the values are different (type might have changed; boolean to null or vice versa)
|
|
53
|
+
*/
|
|
84
54
|
// eslint-disable-next-line no-restricted-syntax
|
|
85
55
|
for (const key of filteredStoredSetupSchemaKeys) {
|
|
86
|
-
const localizableTreeValueToSet = get(
|
|
56
|
+
const localizableTreeValueToSet = get(oStoredSetupSchema, key);
|
|
87
57
|
const allModelsTreeValueToSet = findModelValueByKey(allModelsTree, key);
|
|
88
58
|
|
|
89
59
|
if (
|