orc-shared 1.2.0-dev.10 → 1.2.0-dev.11
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/dist/selectors/metadata.js +13 -3
- package/dist/selectors/scope.js +2 -1
- package/dist/utils/setTranslation.js +27 -1
- package/dist/utils/setTranslationWithFallback.js +30 -1
- package/package.json +1 -1
- package/src/selectors/metadata.js +18 -7
- package/src/selectors/metadata.test.js +221 -283
- package/src/selectors/scope.js +1 -1
- package/src/utils/setTranslation.js +16 -1
- package/src/utils/setTranslation.test.js +24 -0
- package/src/utils/setTranslationWithFallback.js +18 -1
- package/src/utils/setTranslationWithFallback.test.js +108 -0
|
@@ -93,9 +93,9 @@ var namedLookupSelector = (0, _utils.memoize)(function (moduleName, lookupName)
|
|
|
93
93
|
});
|
|
94
94
|
exports.namedLookupSelector = namedLookupSelector;
|
|
95
95
|
var namedLookupValuesSelector = (0, _utils.memoize)(function (moduleName, lookupName) {
|
|
96
|
-
return (0, _reselect.createSelector)(namedLookupSelector(moduleName, lookupName), _locale.currentLocaleOrDefault, function (
|
|
97
|
-
return (
|
|
98
|
-
return (0,
|
|
96
|
+
return (0, _reselect.createSelector)(namedLookupSelector(moduleName, lookupName), _locale.currentLocaleOrDefault, function (lookup, locale) {
|
|
97
|
+
return (lookup.get("values") || _immutable.default.Map()).map(function (lookupValue) {
|
|
98
|
+
return (0, _setTranslationWithFallback.setTranslationWithFallbackField)(locale, lookupValue, "name", "displayName");
|
|
99
99
|
});
|
|
100
100
|
});
|
|
101
101
|
});
|
|
@@ -230,6 +230,8 @@ var filterIsBuiltInAttributes = function filterIsBuiltInAttributes(isBuiltIn) {
|
|
|
230
230
|
return function (attributes) {
|
|
231
231
|
return attributes.filter(function (a) {
|
|
232
232
|
return a.get("isBuiltIn") === isBuiltIn;
|
|
233
|
+
}).sortBy(function (x) {
|
|
234
|
+
return x.get("displayOrder");
|
|
233
235
|
});
|
|
234
236
|
};
|
|
235
237
|
};
|
|
@@ -278,8 +280,12 @@ var groupedCustomAttributesDefinitionSelector = (0, _utils.memoize)(function (mo
|
|
|
278
280
|
displayOrder: profileAttributeGroup == null ? void 0 : profileAttributeGroup.get("displayOrder")
|
|
279
281
|
}).set("baseAttributes", group.filter(function (i) {
|
|
280
282
|
return i.get("dataType") !== _constants.attributeDataType.entityReference;
|
|
283
|
+
}).sortBy(function (x) {
|
|
284
|
+
return x.get("displayOrder");
|
|
281
285
|
})).set("profileAttributes", group.filter(function (i) {
|
|
282
286
|
return i.get("dataType") === _constants.attributeDataType.entityReference;
|
|
287
|
+
}).sortBy(function (x) {
|
|
288
|
+
return x.get("displayOrder");
|
|
283
289
|
}));
|
|
284
290
|
}).sortBy(function (x) {
|
|
285
291
|
return x.get("displayOrder");
|
|
@@ -291,9 +297,13 @@ var customAttributesDefinitionSelector = (0, _utils.memoize)(function (moduleNam
|
|
|
291
297
|
return (0, _reselect.createSelector)(mappedDefinitionEntity(moduleName, profileEntityName), customAttributesSelector(moduleName, profileEntityName), function (definition, attributes) {
|
|
292
298
|
var profileAttributes = attributes == null ? void 0 : attributes.filter(function (a) {
|
|
293
299
|
return a.get("dataType") === _constants.attributeDataType.entityReference;
|
|
300
|
+
}).sortBy(function (x) {
|
|
301
|
+
return x.get("displayOrder");
|
|
294
302
|
});
|
|
295
303
|
var baseAttributes = attributes == null ? void 0 : attributes.filter(function (a) {
|
|
296
304
|
return a.get("dataType") !== _constants.attributeDataType.entityReference;
|
|
305
|
+
}).sortBy(function (x) {
|
|
306
|
+
return x.get("displayOrder");
|
|
297
307
|
});
|
|
298
308
|
return definition.set("baseAttributes", baseAttributes).set("profileAttributes", profileAttributes);
|
|
299
309
|
});
|
package/dist/selectors/scope.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.__esModule = true;
|
|
4
|
-
exports.scopeGetter = exports.scopeDefaultCultureSelector = exports.localizedScopesSelectorByIds = exports.localizedScopeSelector = exports.isCurrentScopeAuthorizedSelector = exports.getScopesSelector = exports.currentScopeSelector = void 0;
|
|
4
|
+
exports.scopeGetter = exports.scopeDefaultCultureSelector = exports.localizedScopesSelectorByIds = exports.localizedScopesSelector = exports.localizedScopeSelector = exports.isCurrentScopeAuthorizedSelector = exports.getScopesSelector = exports.currentScopeSelector = void 0;
|
|
5
5
|
|
|
6
6
|
var _reselect = require("reselect");
|
|
7
7
|
|
|
@@ -52,6 +52,7 @@ var localizedScopesSelector = (0, _reselect.createSelector)(scopeData, _locale.c
|
|
|
52
52
|
});
|
|
53
53
|
});
|
|
54
54
|
});
|
|
55
|
+
exports.localizedScopesSelector = localizedScopesSelector;
|
|
55
56
|
var currentScopeSelector = (0, _reselect.createSelector)(_navigation.getCurrentScope, localizedScopesSelector, function (id, scopes) {
|
|
56
57
|
return scopes.get(id) || _immutable.default.Map();
|
|
57
58
|
});
|
|
@@ -15,6 +15,12 @@ var _flatten = require("./flatten");
|
|
|
15
15
|
enterModule && enterModule(module);
|
|
16
16
|
})();
|
|
17
17
|
|
|
18
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
19
|
+
|
|
20
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
21
|
+
|
|
22
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
23
|
+
|
|
18
24
|
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
|
|
19
25
|
return a;
|
|
20
26
|
};
|
|
@@ -30,7 +36,27 @@ var setTranslation = function setTranslation(locale, obj) {
|
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
if (!obj || !obj.getIn((0, _flatten.flatten)([field]))) return obj;
|
|
33
|
-
var
|
|
39
|
+
var localeValue = obj.getIn((0, _flatten.flatten)([field, locale]));
|
|
40
|
+
|
|
41
|
+
if (!localeValue && locale.includes("-")) {
|
|
42
|
+
var fieldValue = obj.getIn((0, _flatten.flatten)([field]));
|
|
43
|
+
var fieldKeys = fieldValue.keys();
|
|
44
|
+
var language = locale.substring(0, locale.indexOf("-"));
|
|
45
|
+
|
|
46
|
+
for (var _iterator = _createForOfIteratorHelperLoose(fieldKeys), _step; !(_step = _iterator()).done;) {
|
|
47
|
+
var key = _step.value;
|
|
48
|
+
|
|
49
|
+
if (key !== locale && key.startsWith(language)) {
|
|
50
|
+
localeValue = obj.getIn((0, _flatten.flatten)([field, key]));
|
|
51
|
+
|
|
52
|
+
if (localeValue) {
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var value = localeValue || obj.getIn((0, _flatten.flatten)([field])).filter(function (i) {
|
|
34
60
|
return i;
|
|
35
61
|
}).first() || "";
|
|
36
62
|
return obj.setIn((0, _flatten.flatten)([field]), value);
|
|
@@ -15,6 +15,12 @@ var _flatten = require("./flatten");
|
|
|
15
15
|
enterModule && enterModule(module);
|
|
16
16
|
})();
|
|
17
17
|
|
|
18
|
+
function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
19
|
+
|
|
20
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
21
|
+
|
|
22
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
23
|
+
|
|
18
24
|
var __signature__ = typeof reactHotLoaderGlobal !== 'undefined' ? reactHotLoaderGlobal.default.signature : function (a) {
|
|
19
25
|
return a;
|
|
20
26
|
};
|
|
@@ -30,7 +36,30 @@ var setTranslationWithFallbackValue = function setTranslationWithFallbackValue(l
|
|
|
30
36
|
field[_key - 3] = arguments[_key];
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
var
|
|
39
|
+
var localeValue = obj.getIn((0, _flatten.flatten)([field, locale]));
|
|
40
|
+
|
|
41
|
+
if (!localeValue && locale.includes("-")) {
|
|
42
|
+
var fieldValue = obj.getIn((0, _flatten.flatten)([field]));
|
|
43
|
+
|
|
44
|
+
if (fieldValue) {
|
|
45
|
+
var fieldKeys = fieldValue.keys();
|
|
46
|
+
var language = locale.substring(0, locale.indexOf("-"));
|
|
47
|
+
|
|
48
|
+
for (var _iterator = _createForOfIteratorHelperLoose(fieldKeys), _step; !(_step = _iterator()).done;) {
|
|
49
|
+
var key = _step.value;
|
|
50
|
+
|
|
51
|
+
if (key !== locale && key.startsWith(language)) {
|
|
52
|
+
localeValue = obj.getIn((0, _flatten.flatten)([field, key]));
|
|
53
|
+
|
|
54
|
+
if (localeValue) {
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
var value = localeValue || fallbackValue || "";
|
|
34
63
|
return obj.setIn((0, _flatten.flatten)([field]), value);
|
|
35
64
|
};
|
|
36
65
|
|
package/package.json
CHANGED
|
@@ -46,8 +46,10 @@ export const namedLookupSelector = memoize((moduleName, lookupName) =>
|
|
|
46
46
|
);
|
|
47
47
|
|
|
48
48
|
export const namedLookupValuesSelector = memoize((moduleName, lookupName) =>
|
|
49
|
-
createSelector(namedLookupSelector(moduleName, lookupName), currentLocaleOrDefault, (
|
|
50
|
-
(
|
|
49
|
+
createSelector(namedLookupSelector(moduleName, lookupName), currentLocaleOrDefault, (lookup, locale) =>
|
|
50
|
+
(lookup.get("values") || Immutable.Map()).map(lookupValue =>
|
|
51
|
+
setTranslationWithFallbackField(locale, lookupValue, "name", "displayName"),
|
|
52
|
+
),
|
|
51
53
|
),
|
|
52
54
|
);
|
|
53
55
|
|
|
@@ -157,7 +159,8 @@ const definitionEntityAttributes = memoize((moduleName, entityName) =>
|
|
|
157
159
|
),
|
|
158
160
|
);
|
|
159
161
|
|
|
160
|
-
const filterIsBuiltInAttributes = isBuiltIn => attributes =>
|
|
162
|
+
const filterIsBuiltInAttributes = isBuiltIn => attributes =>
|
|
163
|
+
attributes.filter(a => a.get("isBuiltIn") === isBuiltIn).sortBy(x => x.get("displayOrder"));
|
|
161
164
|
|
|
162
165
|
export const definitionEntityCustomAttributesSelector = memoize((moduleName, entityName) =>
|
|
163
166
|
createSelector(definitionEntityAttributes(moduleName, entityName), filterIsBuiltInAttributes(false)),
|
|
@@ -204,11 +207,15 @@ export const groupedCustomAttributesDefinitionSelector = memoize((moduleName, en
|
|
|
204
207
|
})
|
|
205
208
|
.set(
|
|
206
209
|
"baseAttributes",
|
|
207
|
-
group
|
|
210
|
+
group
|
|
211
|
+
.filter(i => i.get("dataType") !== attributeDataType.entityReference)
|
|
212
|
+
.sortBy(x => x.get("displayOrder")),
|
|
208
213
|
)
|
|
209
214
|
.set(
|
|
210
215
|
"profileAttributes",
|
|
211
|
-
group
|
|
216
|
+
group
|
|
217
|
+
.filter(i => i.get("dataType") === attributeDataType.entityReference)
|
|
218
|
+
.sortBy(x => x.get("displayOrder")),
|
|
212
219
|
);
|
|
213
220
|
})
|
|
214
221
|
.sortBy(x => x.get("displayOrder")),
|
|
@@ -220,8 +227,12 @@ export const customAttributesDefinitionSelector = memoize((moduleName, profileEn
|
|
|
220
227
|
mappedDefinitionEntity(moduleName, profileEntityName),
|
|
221
228
|
customAttributesSelector(moduleName, profileEntityName),
|
|
222
229
|
(definition, attributes) => {
|
|
223
|
-
const profileAttributes = attributes
|
|
224
|
-
|
|
230
|
+
const profileAttributes = attributes
|
|
231
|
+
?.filter(a => a.get("dataType") === attributeDataType.entityReference)
|
|
232
|
+
.sortBy(x => x.get("displayOrder"));
|
|
233
|
+
const baseAttributes = attributes
|
|
234
|
+
?.filter(a => a.get("dataType") !== attributeDataType.entityReference)
|
|
235
|
+
.sortBy(x => x.get("displayOrder"));
|
|
225
236
|
return definition.set("baseAttributes", baseAttributes).set("profileAttributes", profileAttributes);
|
|
226
237
|
},
|
|
227
238
|
),
|
|
@@ -848,6 +848,143 @@ describe("definitions", () => {
|
|
|
848
848
|
description: "InnaCustom2",
|
|
849
849
|
};
|
|
850
850
|
|
|
851
|
+
let baseBuitInAttribute1 = {
|
|
852
|
+
maximum: 256,
|
|
853
|
+
dataType: "Text",
|
|
854
|
+
isRequired: false,
|
|
855
|
+
name: "Username",
|
|
856
|
+
displayOrder: 1,
|
|
857
|
+
isSearchable: true,
|
|
858
|
+
displayName: {
|
|
859
|
+
"en-CA": "User name",
|
|
860
|
+
"en-US": "User name",
|
|
861
|
+
"fr-CA": "User name",
|
|
862
|
+
},
|
|
863
|
+
minimum: 1,
|
|
864
|
+
multilingual: false,
|
|
865
|
+
isBuiltIn: true,
|
|
866
|
+
groupId: "Default",
|
|
867
|
+
allowMultipleValues: false,
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
let baseBuitInAttribute2 = {
|
|
871
|
+
maximum: 256,
|
|
872
|
+
dataType: "Text",
|
|
873
|
+
isRequired: false,
|
|
874
|
+
name: "Email",
|
|
875
|
+
displayOrder: 2,
|
|
876
|
+
isSearchable: true,
|
|
877
|
+
displayName: {
|
|
878
|
+
"en-CA": "Email",
|
|
879
|
+
"en-US": "Email",
|
|
880
|
+
"fr-CA": "Email",
|
|
881
|
+
},
|
|
882
|
+
minimum: 0,
|
|
883
|
+
multilingual: false,
|
|
884
|
+
isBuiltIn: true,
|
|
885
|
+
groupId: "Default",
|
|
886
|
+
allowMultipleValues: false,
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
let baseBuitInAttribute3 = {
|
|
890
|
+
maximum: 64,
|
|
891
|
+
dataType: "Text",
|
|
892
|
+
isRequired: false,
|
|
893
|
+
name: "LastName",
|
|
894
|
+
displayOrder: 3,
|
|
895
|
+
isSearchable: true,
|
|
896
|
+
displayName: {
|
|
897
|
+
"en-CA": "Last name",
|
|
898
|
+
"en-US": "Last name",
|
|
899
|
+
"fr-CA": "Last name",
|
|
900
|
+
"it-IT": "Cognome",
|
|
901
|
+
},
|
|
902
|
+
minimum: 0,
|
|
903
|
+
multilingual: false,
|
|
904
|
+
isBuiltIn: true,
|
|
905
|
+
groupId: "Default",
|
|
906
|
+
allowMultipleValues: false,
|
|
907
|
+
};
|
|
908
|
+
|
|
909
|
+
let baseBuitInAttribute4 = {
|
|
910
|
+
maximum: 64,
|
|
911
|
+
dataType: "Text",
|
|
912
|
+
isRequired: false,
|
|
913
|
+
name: "FirstName",
|
|
914
|
+
displayOrder: 4,
|
|
915
|
+
isSearchable: true,
|
|
916
|
+
displayName: {
|
|
917
|
+
"ar-JO": "",
|
|
918
|
+
"en-CA": "First Name",
|
|
919
|
+
"en-US": "First Name",
|
|
920
|
+
"es-ES": "",
|
|
921
|
+
"fr-CA": "First Name",
|
|
922
|
+
"it-IT": "Nome",
|
|
923
|
+
},
|
|
924
|
+
minimum: 0,
|
|
925
|
+
multilingual: false,
|
|
926
|
+
isBuiltIn: true,
|
|
927
|
+
groupId: "Default",
|
|
928
|
+
allowMultipleValues: false,
|
|
929
|
+
};
|
|
930
|
+
|
|
931
|
+
let baseCustomAttribute1 = {
|
|
932
|
+
maximum: 64,
|
|
933
|
+
dataType: "Text",
|
|
934
|
+
isRequired: false,
|
|
935
|
+
name: "BaseAttribute1",
|
|
936
|
+
displayOrder: 1,
|
|
937
|
+
isSearchable: true,
|
|
938
|
+
displayName: {
|
|
939
|
+
"en-CA": "Base Attribute1",
|
|
940
|
+
"en-US": "Base Attribute1",
|
|
941
|
+
"fr-CA": "Base Attribute1",
|
|
942
|
+
},
|
|
943
|
+
minimum: 0,
|
|
944
|
+
multilingual: false,
|
|
945
|
+
isBuiltIn: false,
|
|
946
|
+
groupId: "Default",
|
|
947
|
+
allowMultipleValues: false,
|
|
948
|
+
};
|
|
949
|
+
|
|
950
|
+
let baseCustomAttribute2 = {
|
|
951
|
+
maximum: 64,
|
|
952
|
+
dataType: "Text",
|
|
953
|
+
isRequired: false,
|
|
954
|
+
name: "BaseAttribute2",
|
|
955
|
+
displayOrder: 2,
|
|
956
|
+
isSearchable: true,
|
|
957
|
+
displayName: {
|
|
958
|
+
"en-CA": "Base Attribute 2",
|
|
959
|
+
"en-US": "Base Attribute 2",
|
|
960
|
+
"fr-CA": "Base Attribute 2",
|
|
961
|
+
},
|
|
962
|
+
minimum: 0,
|
|
963
|
+
multilingual: false,
|
|
964
|
+
isBuiltIn: false,
|
|
965
|
+
groupId: "Default",
|
|
966
|
+
allowMultipleValues: false,
|
|
967
|
+
};
|
|
968
|
+
|
|
969
|
+
let baseCustomAttribute3 = {
|
|
970
|
+
maximum: 64,
|
|
971
|
+
dataType: "Text",
|
|
972
|
+
isRequired: false,
|
|
973
|
+
name: "BaseAttribute3",
|
|
974
|
+
displayOrder: 3,
|
|
975
|
+
isSearchable: true,
|
|
976
|
+
displayName: {
|
|
977
|
+
"en-CA": "Base Attribute 3",
|
|
978
|
+
"en-US": "Base Attribute 3",
|
|
979
|
+
"fr-CA": "Base Attribute 3",
|
|
980
|
+
},
|
|
981
|
+
minimum: 0,
|
|
982
|
+
multilingual: false,
|
|
983
|
+
isBuiltIn: false,
|
|
984
|
+
groupId: "Default",
|
|
985
|
+
allowMultipleValues: false,
|
|
986
|
+
};
|
|
987
|
+
|
|
851
988
|
beforeEach(() => {
|
|
852
989
|
state = Immutable.fromJS({
|
|
853
990
|
locale: {
|
|
@@ -978,90 +1115,15 @@ describe("definitions", () => {
|
|
|
978
1115
|
entityTypeName: "CUSTOMER",
|
|
979
1116
|
isBuiltIn: true,
|
|
980
1117
|
attributes: [
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
dataType: "Text",
|
|
984
|
-
isRequired: false,
|
|
985
|
-
name: "Username",
|
|
986
|
-
displayOrder: 0,
|
|
987
|
-
isSearchable: true,
|
|
988
|
-
displayName: {
|
|
989
|
-
"ar-JO": "",
|
|
990
|
-
"en-CA": "User name",
|
|
991
|
-
"en-US": "User name",
|
|
992
|
-
"es-ES": "",
|
|
993
|
-
"fr-CA": "User name",
|
|
994
|
-
"it-IT": "Nome utente",
|
|
995
|
-
},
|
|
996
|
-
minimum: 1,
|
|
997
|
-
multilingual: false,
|
|
998
|
-
isBuiltIn: true,
|
|
999
|
-
groupId: "Default",
|
|
1000
|
-
allowMultipleValues: false,
|
|
1001
|
-
},
|
|
1002
|
-
{
|
|
1003
|
-
maximum: 256,
|
|
1004
|
-
dataType: "Text",
|
|
1005
|
-
isRequired: false,
|
|
1006
|
-
name: "Email",
|
|
1007
|
-
displayOrder: 0,
|
|
1008
|
-
isSearchable: true,
|
|
1009
|
-
displayName: {
|
|
1010
|
-
"ar-JO": "",
|
|
1011
|
-
"en-CA": "Email",
|
|
1012
|
-
"en-US": "Email",
|
|
1013
|
-
"es-ES": "",
|
|
1014
|
-
"fr-CA": "Email",
|
|
1015
|
-
"it-IT": "Email",
|
|
1016
|
-
},
|
|
1017
|
-
minimum: 0,
|
|
1018
|
-
multilingual: false,
|
|
1019
|
-
isBuiltIn: true,
|
|
1020
|
-
groupId: "Default",
|
|
1021
|
-
allowMultipleValues: false,
|
|
1022
|
-
},
|
|
1118
|
+
baseBuitInAttribute1,
|
|
1119
|
+
baseBuitInAttribute2,
|
|
1023
1120
|
customProfileAttribute1,
|
|
1024
1121
|
customProfileAttribute2,
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
displayOrder: 0,
|
|
1031
|
-
isSearchable: true,
|
|
1032
|
-
displayName: {
|
|
1033
|
-
"en-CA": "Last name",
|
|
1034
|
-
"en-US": "Last name",
|
|
1035
|
-
"fr-CA": "Last name",
|
|
1036
|
-
"it-IT": "Cognome",
|
|
1037
|
-
},
|
|
1038
|
-
minimum: 0,
|
|
1039
|
-
multilingual: false,
|
|
1040
|
-
isBuiltIn: true,
|
|
1041
|
-
groupId: "Default",
|
|
1042
|
-
allowMultipleValues: false,
|
|
1043
|
-
},
|
|
1044
|
-
{
|
|
1045
|
-
maximum: 64,
|
|
1046
|
-
dataType: "Text",
|
|
1047
|
-
isRequired: false,
|
|
1048
|
-
name: "FirstName",
|
|
1049
|
-
displayOrder: 0,
|
|
1050
|
-
isSearchable: true,
|
|
1051
|
-
displayName: {
|
|
1052
|
-
"ar-JO": "",
|
|
1053
|
-
"en-CA": "First Name",
|
|
1054
|
-
"en-US": "First Name",
|
|
1055
|
-
"es-ES": "",
|
|
1056
|
-
"fr-CA": "First Name",
|
|
1057
|
-
"it-IT": "Nome",
|
|
1058
|
-
},
|
|
1059
|
-
minimum: 0,
|
|
1060
|
-
multilingual: false,
|
|
1061
|
-
isBuiltIn: true,
|
|
1062
|
-
groupId: "Default",
|
|
1063
|
-
allowMultipleValues: false,
|
|
1064
|
-
},
|
|
1122
|
+
baseBuitInAttribute4,
|
|
1123
|
+
baseBuitInAttribute3,
|
|
1124
|
+
baseCustomAttribute1,
|
|
1125
|
+
baseCustomAttribute3,
|
|
1126
|
+
baseCustomAttribute2,
|
|
1065
1127
|
],
|
|
1066
1128
|
isSharedEntity: true,
|
|
1067
1129
|
},
|
|
@@ -1359,7 +1421,7 @@ describe("definitions", () => {
|
|
|
1359
1421
|
{},
|
|
1360
1422
|
));
|
|
1361
1423
|
|
|
1362
|
-
it("will return correct custom profile attributes definition", () => {
|
|
1424
|
+
it("will return correct custom profile attributes definition in correct order", () => {
|
|
1363
1425
|
const expectedGroup1 = customProfileAttribute1.groupId;
|
|
1364
1426
|
const expectedGroup2 = customProfileAttribute2.groupId;
|
|
1365
1427
|
const expectedItem1 = {
|
|
@@ -1371,11 +1433,26 @@ describe("definitions", () => {
|
|
|
1371
1433
|
...{ displayName: customProfileAttribute2.displayName["en-US"] },
|
|
1372
1434
|
};
|
|
1373
1435
|
|
|
1436
|
+
const expectedBaseCustomWithOrder1 = {
|
|
1437
|
+
...baseCustomAttribute1,
|
|
1438
|
+
...{ displayName: baseCustomAttribute1.displayName["en-US"] },
|
|
1439
|
+
};
|
|
1440
|
+
|
|
1441
|
+
const expectedBaseCustomWithOrder2 = {
|
|
1442
|
+
...baseCustomAttribute2,
|
|
1443
|
+
...{ displayName: baseCustomAttribute2.displayName["en-US"] },
|
|
1444
|
+
};
|
|
1445
|
+
|
|
1446
|
+
const expectedBaseCustomWithOrder3 = {
|
|
1447
|
+
...baseCustomAttribute3,
|
|
1448
|
+
...{ displayName: baseCustomAttribute3.displayName["en-US"] },
|
|
1449
|
+
};
|
|
1450
|
+
|
|
1374
1451
|
const expected = Immutable.fromJS({
|
|
1375
1452
|
[expectedGroup1]: {
|
|
1376
1453
|
id: expectedGroup1,
|
|
1377
1454
|
name: "Default en-US",
|
|
1378
|
-
baseAttributes: [],
|
|
1455
|
+
baseAttributes: [expectedBaseCustomWithOrder1, expectedBaseCustomWithOrder2, expectedBaseCustomWithOrder3],
|
|
1379
1456
|
profileAttributes: [expectedItem1],
|
|
1380
1457
|
},
|
|
1381
1458
|
[expectedGroup2]: {
|
|
@@ -1397,90 +1474,12 @@ describe("definitions", () => {
|
|
|
1397
1474
|
);
|
|
1398
1475
|
});
|
|
1399
1476
|
|
|
1400
|
-
it("will return correct full base customer definition attributes", () => {
|
|
1477
|
+
it("will return correct full base (built in) customer definition attributes", () => {
|
|
1401
1478
|
const expected = Immutable.fromJS([
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
name: "Username",
|
|
1407
|
-
displayOrder: 0,
|
|
1408
|
-
isSearchable: true,
|
|
1409
|
-
displayName: {
|
|
1410
|
-
"ar-JO": "",
|
|
1411
|
-
"en-CA": "User name",
|
|
1412
|
-
"en-US": "User name",
|
|
1413
|
-
"es-ES": "",
|
|
1414
|
-
"fr-CA": "User name",
|
|
1415
|
-
"it-IT": "Nome utente",
|
|
1416
|
-
},
|
|
1417
|
-
minimum: 1,
|
|
1418
|
-
multilingual: false,
|
|
1419
|
-
isBuiltIn: true,
|
|
1420
|
-
groupId: "Default",
|
|
1421
|
-
allowMultipleValues: false,
|
|
1422
|
-
},
|
|
1423
|
-
{
|
|
1424
|
-
maximum: 256,
|
|
1425
|
-
dataType: "Text",
|
|
1426
|
-
isRequired: false,
|
|
1427
|
-
name: "Email",
|
|
1428
|
-
displayOrder: 0,
|
|
1429
|
-
isSearchable: true,
|
|
1430
|
-
displayName: {
|
|
1431
|
-
"ar-JO": "",
|
|
1432
|
-
"en-CA": "Email",
|
|
1433
|
-
"en-US": "Email",
|
|
1434
|
-
"es-ES": "",
|
|
1435
|
-
"fr-CA": "Email",
|
|
1436
|
-
"it-IT": "Email",
|
|
1437
|
-
},
|
|
1438
|
-
minimum: 0,
|
|
1439
|
-
multilingual: false,
|
|
1440
|
-
isBuiltIn: true,
|
|
1441
|
-
groupId: "Default",
|
|
1442
|
-
allowMultipleValues: false,
|
|
1443
|
-
},
|
|
1444
|
-
{
|
|
1445
|
-
maximum: 64,
|
|
1446
|
-
dataType: "Text",
|
|
1447
|
-
isRequired: false,
|
|
1448
|
-
name: "LastName",
|
|
1449
|
-
displayOrder: 0,
|
|
1450
|
-
isSearchable: true,
|
|
1451
|
-
displayName: {
|
|
1452
|
-
"en-CA": "Last name",
|
|
1453
|
-
"en-US": "Last name",
|
|
1454
|
-
"fr-CA": "Last name",
|
|
1455
|
-
"it-IT": "Cognome",
|
|
1456
|
-
},
|
|
1457
|
-
minimum: 0,
|
|
1458
|
-
multilingual: false,
|
|
1459
|
-
isBuiltIn: true,
|
|
1460
|
-
groupId: "Default",
|
|
1461
|
-
allowMultipleValues: false,
|
|
1462
|
-
},
|
|
1463
|
-
{
|
|
1464
|
-
maximum: 64,
|
|
1465
|
-
dataType: "Text",
|
|
1466
|
-
isRequired: false,
|
|
1467
|
-
name: "FirstName",
|
|
1468
|
-
displayOrder: 0,
|
|
1469
|
-
isSearchable: true,
|
|
1470
|
-
displayName: {
|
|
1471
|
-
"ar-JO": "",
|
|
1472
|
-
"en-CA": "First Name",
|
|
1473
|
-
"en-US": "First Name",
|
|
1474
|
-
"es-ES": "",
|
|
1475
|
-
"fr-CA": "First Name",
|
|
1476
|
-
"it-IT": "Nome",
|
|
1477
|
-
},
|
|
1478
|
-
minimum: 0,
|
|
1479
|
-
multilingual: false,
|
|
1480
|
-
isBuiltIn: true,
|
|
1481
|
-
groupId: "Default",
|
|
1482
|
-
allowMultipleValues: false,
|
|
1483
|
-
},
|
|
1479
|
+
baseBuitInAttribute1,
|
|
1480
|
+
baseBuitInAttribute2,
|
|
1481
|
+
baseBuitInAttribute3,
|
|
1482
|
+
baseBuitInAttribute4,
|
|
1484
1483
|
]);
|
|
1485
1484
|
expect(
|
|
1486
1485
|
definitionEntityBaseAttributesSelector,
|
|
@@ -1495,34 +1494,11 @@ describe("definitions", () => {
|
|
|
1495
1494
|
|
|
1496
1495
|
it("will return correct full custom customer definition attributes", () => {
|
|
1497
1496
|
const expected = Immutable.fromJS([
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
isSearchable: false,
|
|
1504
|
-
displayName: { "en-CA": "attribute en-CA", "en-US": "attribute en-US", "fr-CA": "" },
|
|
1505
|
-
referenceTypeName: "CustomProfile1",
|
|
1506
|
-
multilingual: false,
|
|
1507
|
-
isBuiltIn: false,
|
|
1508
|
-
groupId: "Default",
|
|
1509
|
-
allowMultipleValues: true,
|
|
1510
|
-
description: "InnaCustomer",
|
|
1511
|
-
},
|
|
1512
|
-
{
|
|
1513
|
-
dataType: "EntityReference",
|
|
1514
|
-
isRequired: false,
|
|
1515
|
-
name: "InnaCustom2",
|
|
1516
|
-
displayOrder: 0,
|
|
1517
|
-
isSearchable: false,
|
|
1518
|
-
displayName: { "en-CA": "attribute en-CA", "en-US": "attribute en-UA", "fr-CA": "" },
|
|
1519
|
-
referenceTypeName: "CustomProfile2",
|
|
1520
|
-
multilingual: false,
|
|
1521
|
-
isBuiltIn: false,
|
|
1522
|
-
groupId: "CustomGroup",
|
|
1523
|
-
allowMultipleValues: true,
|
|
1524
|
-
description: "InnaCustom2",
|
|
1525
|
-
},
|
|
1497
|
+
customProfileAttribute1,
|
|
1498
|
+
customProfileAttribute2,
|
|
1499
|
+
baseCustomAttribute1,
|
|
1500
|
+
baseCustomAttribute2,
|
|
1501
|
+
baseCustomAttribute3,
|
|
1526
1502
|
]);
|
|
1527
1503
|
expect(
|
|
1528
1504
|
definitionEntityCustomAttributesSelector,
|
|
@@ -1535,64 +1511,30 @@ describe("definitions", () => {
|
|
|
1535
1511
|
);
|
|
1536
1512
|
});
|
|
1537
1513
|
|
|
1538
|
-
it("will return correct customer attributes", () => {
|
|
1514
|
+
it("will return correct customer base (build in) attributes in correct order", () => {
|
|
1515
|
+
const locale = "en-US";
|
|
1516
|
+
const expectedBaseBuitInAttribute1 = {
|
|
1517
|
+
...baseBuitInAttribute1,
|
|
1518
|
+
...{ displayName: baseBuitInAttribute1.displayName[locale] },
|
|
1519
|
+
};
|
|
1520
|
+
const expectedBaseBuitInAttribute2 = {
|
|
1521
|
+
...baseBuitInAttribute2,
|
|
1522
|
+
...{ displayName: baseBuitInAttribute2.displayName[locale] },
|
|
1523
|
+
};
|
|
1524
|
+
const expectedBaseBuitInAttribute3 = {
|
|
1525
|
+
...baseBuitInAttribute3,
|
|
1526
|
+
...{ displayName: baseBuitInAttribute3.displayName[locale] },
|
|
1527
|
+
};
|
|
1528
|
+
const expectedBaseBuitInAttribute4 = {
|
|
1529
|
+
...baseBuitInAttribute4,
|
|
1530
|
+
...{ displayName: baseBuitInAttribute4.displayName[locale] },
|
|
1531
|
+
};
|
|
1532
|
+
|
|
1539
1533
|
const expected = Immutable.fromJS([
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
name: "Username",
|
|
1545
|
-
displayOrder: 0,
|
|
1546
|
-
isSearchable: true,
|
|
1547
|
-
displayName: "User name",
|
|
1548
|
-
minimum: 1,
|
|
1549
|
-
multilingual: false,
|
|
1550
|
-
isBuiltIn: true,
|
|
1551
|
-
groupId: "Default",
|
|
1552
|
-
allowMultipleValues: false,
|
|
1553
|
-
},
|
|
1554
|
-
{
|
|
1555
|
-
maximum: 256,
|
|
1556
|
-
dataType: "Text",
|
|
1557
|
-
isRequired: false,
|
|
1558
|
-
name: "Email",
|
|
1559
|
-
displayOrder: 0,
|
|
1560
|
-
isSearchable: true,
|
|
1561
|
-
displayName: "Email",
|
|
1562
|
-
minimum: 0,
|
|
1563
|
-
multilingual: false,
|
|
1564
|
-
isBuiltIn: true,
|
|
1565
|
-
groupId: "Default",
|
|
1566
|
-
allowMultipleValues: false,
|
|
1567
|
-
},
|
|
1568
|
-
{
|
|
1569
|
-
maximum: 64,
|
|
1570
|
-
dataType: "Text",
|
|
1571
|
-
isRequired: false,
|
|
1572
|
-
name: "LastName",
|
|
1573
|
-
displayOrder: 0,
|
|
1574
|
-
isSearchable: true,
|
|
1575
|
-
displayName: "Last name",
|
|
1576
|
-
minimum: 0,
|
|
1577
|
-
multilingual: false,
|
|
1578
|
-
isBuiltIn: true,
|
|
1579
|
-
groupId: "Default",
|
|
1580
|
-
allowMultipleValues: false,
|
|
1581
|
-
},
|
|
1582
|
-
{
|
|
1583
|
-
maximum: 64,
|
|
1584
|
-
dataType: "Text",
|
|
1585
|
-
isRequired: false,
|
|
1586
|
-
name: "FirstName",
|
|
1587
|
-
displayOrder: 0,
|
|
1588
|
-
isSearchable: true,
|
|
1589
|
-
displayName: "First Name",
|
|
1590
|
-
minimum: 0,
|
|
1591
|
-
multilingual: false,
|
|
1592
|
-
isBuiltIn: true,
|
|
1593
|
-
groupId: "Default",
|
|
1594
|
-
allowMultipleValues: false,
|
|
1595
|
-
},
|
|
1534
|
+
expectedBaseBuitInAttribute1,
|
|
1535
|
+
expectedBaseBuitInAttribute2,
|
|
1536
|
+
expectedBaseBuitInAttribute3,
|
|
1537
|
+
expectedBaseBuitInAttribute4,
|
|
1596
1538
|
]);
|
|
1597
1539
|
expect(
|
|
1598
1540
|
baseAttributesSelector,
|
|
@@ -1606,41 +1548,37 @@ describe("definitions", () => {
|
|
|
1606
1548
|
});
|
|
1607
1549
|
|
|
1608
1550
|
it("will return correct customer attributes definition", () => {
|
|
1551
|
+
const locale = "en-US";
|
|
1552
|
+
const expectedProfileAttribute1 = {
|
|
1553
|
+
...customProfileAttribute1,
|
|
1554
|
+
...{ displayName: customProfileAttribute1.displayName[locale] },
|
|
1555
|
+
};
|
|
1556
|
+
const expectedProfileAttribute2 = {
|
|
1557
|
+
...customProfileAttribute2,
|
|
1558
|
+
...{ displayName: customProfileAttribute2.displayName[locale] },
|
|
1559
|
+
};
|
|
1560
|
+
|
|
1561
|
+
const expectedBase1 = {
|
|
1562
|
+
...baseCustomAttribute1,
|
|
1563
|
+
...{ displayName: baseCustomAttribute1.displayName[locale] },
|
|
1564
|
+
};
|
|
1565
|
+
|
|
1566
|
+
const expectedBase2 = {
|
|
1567
|
+
...baseCustomAttribute2,
|
|
1568
|
+
...{ displayName: baseCustomAttribute2.displayName[locale] },
|
|
1569
|
+
};
|
|
1570
|
+
|
|
1571
|
+
const expectedBase3 = {
|
|
1572
|
+
...baseCustomAttribute3,
|
|
1573
|
+
...{ displayName: baseCustomAttribute3.displayName[locale] },
|
|
1574
|
+
};
|
|
1575
|
+
|
|
1609
1576
|
const expected = Immutable.fromJS({
|
|
1610
1577
|
displayName: "Customer",
|
|
1611
1578
|
entityTypeName: "CUSTOMER",
|
|
1612
1579
|
isBuiltIn: true,
|
|
1613
|
-
baseAttributes: [],
|
|
1614
|
-
profileAttributes: [
|
|
1615
|
-
{
|
|
1616
|
-
dataType: "EntityReference",
|
|
1617
|
-
isRequired: false,
|
|
1618
|
-
name: "InnaCustom1",
|
|
1619
|
-
displayOrder: 0,
|
|
1620
|
-
isSearchable: false,
|
|
1621
|
-
displayName: "attribute en-US",
|
|
1622
|
-
referenceTypeName: "CustomProfile1",
|
|
1623
|
-
multilingual: false,
|
|
1624
|
-
isBuiltIn: false,
|
|
1625
|
-
groupId: "Default",
|
|
1626
|
-
allowMultipleValues: true,
|
|
1627
|
-
description: "InnaCustomer",
|
|
1628
|
-
},
|
|
1629
|
-
{
|
|
1630
|
-
dataType: "EntityReference",
|
|
1631
|
-
isRequired: false,
|
|
1632
|
-
name: "InnaCustom2",
|
|
1633
|
-
displayOrder: 0,
|
|
1634
|
-
isSearchable: false,
|
|
1635
|
-
displayName: "attribute en-UA",
|
|
1636
|
-
referenceTypeName: "CustomProfile2",
|
|
1637
|
-
multilingual: false,
|
|
1638
|
-
isBuiltIn: false,
|
|
1639
|
-
groupId: "CustomGroup",
|
|
1640
|
-
allowMultipleValues: true,
|
|
1641
|
-
description: "InnaCustom2",
|
|
1642
|
-
},
|
|
1643
|
-
],
|
|
1580
|
+
baseAttributes: [expectedBase1, expectedBase2, expectedBase3],
|
|
1581
|
+
profileAttributes: [expectedProfileAttribute1, expectedProfileAttribute2],
|
|
1644
1582
|
isSharedEntity: true,
|
|
1645
1583
|
});
|
|
1646
1584
|
expect(
|
package/src/selectors/scope.js
CHANGED
|
@@ -15,7 +15,7 @@ const scopeData = state => state.get("scopes");
|
|
|
15
15
|
|
|
16
16
|
export const getScopesSelector = createSelector(scopeData, scopes => scopes);
|
|
17
17
|
|
|
18
|
-
const localizedScopesSelector = createSelector(scopeData, currentLocaleOrDefault, (scopes, locale) =>
|
|
18
|
+
export const localizedScopesSelector = createSelector(scopeData, currentLocaleOrDefault, (scopes, locale) =>
|
|
19
19
|
scopes.map(scope =>
|
|
20
20
|
scope.withMutations(s => {
|
|
21
21
|
setTranslationWithFallbackField(locale, s, "id", "name");
|
|
@@ -3,8 +3,23 @@ import { flatten } from "./flatten";
|
|
|
3
3
|
/* Replaces a locale string structure with the string for the given locale. */
|
|
4
4
|
const setTranslation = (locale, obj, ...field) => {
|
|
5
5
|
if (!obj || !obj.getIn(flatten([field]))) return obj;
|
|
6
|
+
let localeValue = obj.getIn(flatten([field, locale]));
|
|
7
|
+
if (!localeValue && locale.includes("-")) {
|
|
8
|
+
let fieldValue = obj.getIn(flatten([field]));
|
|
9
|
+
let fieldKeys = fieldValue.keys();
|
|
10
|
+
let language = locale.substring(0, locale.indexOf("-"));
|
|
11
|
+
|
|
12
|
+
for (let key of fieldKeys) {
|
|
13
|
+
if (key !== locale && key.startsWith(language)) {
|
|
14
|
+
localeValue = obj.getIn(flatten([field, key]));
|
|
15
|
+
if (localeValue) {
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
6
21
|
const value =
|
|
7
|
-
|
|
22
|
+
localeValue ||
|
|
8
23
|
obj
|
|
9
24
|
.getIn(flatten([field]))
|
|
10
25
|
.filter(i => i)
|
|
@@ -96,4 +96,28 @@ describe("setTranslation", () => {
|
|
|
96
96
|
hat: { name: "it-name" },
|
|
97
97
|
}),
|
|
98
98
|
));
|
|
99
|
+
|
|
100
|
+
it("returns first not empty match by language if language-culture not found", () =>
|
|
101
|
+
expect(
|
|
102
|
+
setTranslation,
|
|
103
|
+
"when called with",
|
|
104
|
+
[
|
|
105
|
+
"en-US",
|
|
106
|
+
Immutable.fromJS({
|
|
107
|
+
hat: {
|
|
108
|
+
name: {
|
|
109
|
+
"en-CA": "",
|
|
110
|
+
"fr-CA": "fr CA name",
|
|
111
|
+
"en-GB": "en GB name",
|
|
112
|
+
"it-IT": "it-name",
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
}),
|
|
116
|
+
["hat", "name"],
|
|
117
|
+
],
|
|
118
|
+
"to equal",
|
|
119
|
+
Immutable.fromJS({
|
|
120
|
+
hat: { name: "en GB name" },
|
|
121
|
+
}),
|
|
122
|
+
));
|
|
99
123
|
});
|
|
@@ -2,7 +2,24 @@ import { flatten } from "./flatten";
|
|
|
2
2
|
|
|
3
3
|
export const setTranslationWithFallbackValue = (locale, obj, fallbackValue, ...field) => {
|
|
4
4
|
if (!obj) return obj;
|
|
5
|
-
|
|
5
|
+
let localeValue = obj.getIn(flatten([field, locale]));
|
|
6
|
+
if (!localeValue && locale.includes("-")) {
|
|
7
|
+
let fieldValue = obj.getIn(flatten([field]));
|
|
8
|
+
if (fieldValue) {
|
|
9
|
+
let fieldKeys = fieldValue.keys();
|
|
10
|
+
let language = locale.substring(0, locale.indexOf("-"));
|
|
11
|
+
|
|
12
|
+
for (let key of fieldKeys) {
|
|
13
|
+
if (key !== locale && key.startsWith(language)) {
|
|
14
|
+
localeValue = obj.getIn(flatten([field, key]));
|
|
15
|
+
if (localeValue) {
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const value = localeValue || fallbackValue || "";
|
|
6
23
|
return obj.setIn(flatten([field]), value);
|
|
7
24
|
};
|
|
8
25
|
|
|
@@ -147,4 +147,112 @@ describe("setTranslationWithFallbackValue", () => {
|
|
|
147
147
|
"to equal",
|
|
148
148
|
null,
|
|
149
149
|
));
|
|
150
|
+
|
|
151
|
+
it("returns value matched by language-culture when exist", () =>
|
|
152
|
+
expect(
|
|
153
|
+
setTranslationWithFallbackValue,
|
|
154
|
+
"when called with",
|
|
155
|
+
[
|
|
156
|
+
"en-US",
|
|
157
|
+
Immutable.fromJS({
|
|
158
|
+
hat: { name: { "en-US": "en-US Name", "en-GB": "en-GB Name" } },
|
|
159
|
+
}),
|
|
160
|
+
"fallbakValue",
|
|
161
|
+
["hat", "name"],
|
|
162
|
+
],
|
|
163
|
+
"to equal",
|
|
164
|
+
Immutable.fromJS({
|
|
165
|
+
hat: { name: "en-US Name" },
|
|
166
|
+
}),
|
|
167
|
+
));
|
|
168
|
+
|
|
169
|
+
it("returns value matched by language when match by language-culture does not exist", () =>
|
|
170
|
+
expect(
|
|
171
|
+
setTranslationWithFallbackValue,
|
|
172
|
+
"when called with",
|
|
173
|
+
[
|
|
174
|
+
"en-US",
|
|
175
|
+
Immutable.fromJS({
|
|
176
|
+
hat: { name: { "en-GB": "en-GB Name" } },
|
|
177
|
+
}),
|
|
178
|
+
"fallbakValue",
|
|
179
|
+
["hat", "name"],
|
|
180
|
+
],
|
|
181
|
+
"to equal",
|
|
182
|
+
Immutable.fromJS({
|
|
183
|
+
hat: { name: "en-GB Name" },
|
|
184
|
+
}),
|
|
185
|
+
));
|
|
186
|
+
|
|
187
|
+
it("returns first not empty value matched by language when match by language-culture does not exist", () =>
|
|
188
|
+
expect(
|
|
189
|
+
setTranslationWithFallbackValue,
|
|
190
|
+
"when called with",
|
|
191
|
+
[
|
|
192
|
+
"en-US",
|
|
193
|
+
Immutable.fromJS({
|
|
194
|
+
hat: { name: { "en-GB": "", "en-CA": "en-CA Name" } },
|
|
195
|
+
}),
|
|
196
|
+
"fallbakValue",
|
|
197
|
+
["hat", "name"],
|
|
198
|
+
],
|
|
199
|
+
"to equal",
|
|
200
|
+
Immutable.fromJS({
|
|
201
|
+
hat: { name: "en-CA Name" },
|
|
202
|
+
}),
|
|
203
|
+
));
|
|
204
|
+
|
|
205
|
+
it("returns value fallback value when match by language-culture and language does not exist", () =>
|
|
206
|
+
expect(
|
|
207
|
+
setTranslationWithFallbackValue,
|
|
208
|
+
"when called with",
|
|
209
|
+
[
|
|
210
|
+
"en-GB",
|
|
211
|
+
Immutable.fromJS({
|
|
212
|
+
hat: { name: { "fr-CA": "fr-CA Name" } },
|
|
213
|
+
}),
|
|
214
|
+
"fallbakValue",
|
|
215
|
+
["hat", "name"],
|
|
216
|
+
],
|
|
217
|
+
"to equal",
|
|
218
|
+
Immutable.fromJS({
|
|
219
|
+
hat: { name: "fallbakValue" },
|
|
220
|
+
}),
|
|
221
|
+
));
|
|
222
|
+
|
|
223
|
+
it("returns fallbak Value when field value is empty ", () =>
|
|
224
|
+
expect(
|
|
225
|
+
setTranslationWithFallbackValue,
|
|
226
|
+
"when called with",
|
|
227
|
+
[
|
|
228
|
+
"en-GB",
|
|
229
|
+
Immutable.fromJS({
|
|
230
|
+
hat: { name: {} },
|
|
231
|
+
}),
|
|
232
|
+
"fallbakValue",
|
|
233
|
+
["hat", "name"],
|
|
234
|
+
],
|
|
235
|
+
"to equal",
|
|
236
|
+
Immutable.fromJS({
|
|
237
|
+
hat: { name: "fallbakValue" },
|
|
238
|
+
}),
|
|
239
|
+
));
|
|
240
|
+
|
|
241
|
+
it("returns fallbakValue when field is undefined ", () =>
|
|
242
|
+
expect(
|
|
243
|
+
setTranslationWithFallbackValue,
|
|
244
|
+
"when called with",
|
|
245
|
+
[
|
|
246
|
+
"en-GB",
|
|
247
|
+
Immutable.fromJS({
|
|
248
|
+
hat: { name: {} },
|
|
249
|
+
}),
|
|
250
|
+
"fallbakValue",
|
|
251
|
+
["hat", "name2"],
|
|
252
|
+
],
|
|
253
|
+
"to equal",
|
|
254
|
+
Immutable.fromJS({
|
|
255
|
+
hat: { name: {}, name2: "fallbakValue" },
|
|
256
|
+
}),
|
|
257
|
+
));
|
|
150
258
|
});
|