@reltio/components 1.4.2117 → 1.4.2118
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/EditModeAttributesFactory/EditModeAttributesFactory.test.js +6 -2
- package/EntitySelector/EntitySelector.js +5 -5
- package/EntitySelector/EntitySelector.test.js +18 -0
- package/cjs/EditModeAttributesFactory/EditModeAttributesFactory.test.js +6 -2
- package/cjs/EntitySelector/EntitySelector.js +4 -4
- package/cjs/EntitySelector/EntitySelector.test.js +18 -0
- package/package.json +1 -1
|
@@ -52,7 +52,10 @@ import { MdmModuleProvider } from '../contexts/MdmModuleContext';
|
|
|
52
52
|
import { EditModeAttributesFactory } from './EditModeAttributesFactory';
|
|
53
53
|
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { typeAheadSearch: jest.fn() })); });
|
|
54
54
|
var dependentLookups = { editors: {}, structure: {}, initedTypeUris: [] };
|
|
55
|
-
var metadata = {
|
|
55
|
+
var metadata = {
|
|
56
|
+
entityTypes: [{ uri: 'configuration/entityTypes/HCP' }, { uri: 'configuration/entityTypes/Location' }],
|
|
57
|
+
relationTypes: []
|
|
58
|
+
};
|
|
56
59
|
var defaultMdmValues = { dependentLookups: dependentLookups, metadata: metadata };
|
|
57
60
|
var setUp = function (_a) {
|
|
58
61
|
var props = _a.props, _b = _a.mdmValues, mdmValues = _b === void 0 ? defaultMdmValues : _b;
|
|
@@ -116,7 +119,8 @@ describe('Edit mode attributes factory attributes', function () {
|
|
|
116
119
|
attributeType = {
|
|
117
120
|
type: 'Reference',
|
|
118
121
|
uri: 'configuration/entityTypes/HCP/attributes/Reference',
|
|
119
|
-
referencedAttributeURIs: []
|
|
122
|
+
referencedAttributeURIs: ['configuration/entityTypes/Location'],
|
|
123
|
+
referencedEntityTypeURI: 'configuration/entityTypes/Location'
|
|
120
124
|
};
|
|
121
125
|
props = {
|
|
122
126
|
attributeValue: {
|
|
@@ -20,7 +20,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
}
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
|
-
import React, { useState, useMemo } from 'react';
|
|
23
|
+
import React, { useState, useMemo, useCallback } from 'react';
|
|
24
24
|
import i18n from 'ui-i18n';
|
|
25
25
|
import { isEmpty, prop } from 'ramda';
|
|
26
26
|
import { typeAheadSearch, getEntityType, isTempUri, isAvailableEntityType } from '@reltio/mdm-sdk';
|
|
@@ -39,7 +39,7 @@ export var EntitySelector = function (_a) {
|
|
|
39
39
|
var styles = useStyles();
|
|
40
40
|
var _g = useState(''), inputValue = _g[0], setInputValue = _g[1];
|
|
41
41
|
var entityTypes = useMemo(function () { return entityTypesUris.map(function (type) { return getEntityType(metadata, type); }).filter(isAvailableEntityType); }, [entityTypesUris, metadata]);
|
|
42
|
-
var options = __assign(__assign({}, globalSearchRequestOptions), { max: max, sendMasked: isMasked });
|
|
42
|
+
var options = useMemo(function () { return (__assign(__assign({}, globalSearchRequestOptions), { max: max, sendMasked: isMasked })); }, [globalSearchRequestOptions, isMasked, max]);
|
|
43
43
|
var handleCreate = onCreate
|
|
44
44
|
? function (value, entityTypeUri) {
|
|
45
45
|
onCreate(entityTypeUri || entityTypes[0].uri, value);
|
|
@@ -59,9 +59,9 @@ export var EntitySelector = function (_a) {
|
|
|
59
59
|
handleChange({});
|
|
60
60
|
};
|
|
61
61
|
var groupMode = useMemo(function () { return entityTypes.length !== 1; }, [entityTypes]);
|
|
62
|
-
var getOptions = function (value) {
|
|
63
|
-
return typeAheadSearch(entityTypes, value, options).then(buildEntityOptions(entityTypes, onCreate));
|
|
64
|
-
};
|
|
62
|
+
var getOptions = useCallback(function (value) {
|
|
63
|
+
return (isEmpty(entityTypes) ? Promise.resolve([]) : typeAheadSearch(entityTypes, value, options)).then(buildEntityOptions(entityTypes, onCreate));
|
|
64
|
+
}, [entityTypes, onCreate, options]);
|
|
65
65
|
var currentEntityType = (isEmpty(entity) ? entityTypes[0] : getEntityType(metadata, entity.entityType)) || {};
|
|
66
66
|
var createLabel = onCreate && i18n.text("Create ".concat(inputValue ? "\"".concat(inputValue, "\" as ") : '', "new ").concat(currentEntityType.label));
|
|
67
67
|
var label = i18n.text("Select ".concat(entityTypes.length === 1 ? "".concat(entityTypes[0].label, " ") : '', "profile"));
|
|
@@ -253,6 +253,24 @@ describe('Entity selector tests', function () {
|
|
|
253
253
|
}
|
|
254
254
|
});
|
|
255
255
|
}); });
|
|
256
|
+
it('should not send typeAheadSearch request if have not available entity type', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
257
|
+
var props, user;
|
|
258
|
+
return __generator(this, function (_a) {
|
|
259
|
+
switch (_a.label) {
|
|
260
|
+
case 0:
|
|
261
|
+
props = __assign(__assign({}, defaultProps), { max: 10, entityTypesUris: ['configuration/entityTypes/HCP'], metadata: {
|
|
262
|
+
entityTypes: [{ uri: 'configuration/entityTypes/HCP', label: 'HCP', attributes: [], access: [] }]
|
|
263
|
+
} });
|
|
264
|
+
user = setUp({ props: props }).user;
|
|
265
|
+
return [4 /*yield*/, user.click(screen.getByRole('combobox'))];
|
|
266
|
+
case 1:
|
|
267
|
+
_a.sent();
|
|
268
|
+
expect(typeAheadSearch).not.toHaveBeenCalled();
|
|
269
|
+
screen.getByText('No results found');
|
|
270
|
+
return [2 /*return*/];
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
}); });
|
|
256
274
|
it('should render correctly in case of temp entity', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
257
275
|
var entityUri, entityType, mdmValues, props, user, entityCreator;
|
|
258
276
|
var _a;
|
|
@@ -57,7 +57,10 @@ var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
|
|
|
57
57
|
var EditModeAttributesFactory_1 = require("./EditModeAttributesFactory");
|
|
58
58
|
jest.mock('@reltio/mdm-sdk', function () { return (__assign(__assign({}, jest.requireActual('@reltio/mdm-sdk')), { typeAheadSearch: jest.fn() })); });
|
|
59
59
|
var dependentLookups = { editors: {}, structure: {}, initedTypeUris: [] };
|
|
60
|
-
var metadata = {
|
|
60
|
+
var metadata = {
|
|
61
|
+
entityTypes: [{ uri: 'configuration/entityTypes/HCP' }, { uri: 'configuration/entityTypes/Location' }],
|
|
62
|
+
relationTypes: []
|
|
63
|
+
};
|
|
61
64
|
var defaultMdmValues = { dependentLookups: dependentLookups, metadata: metadata };
|
|
62
65
|
var setUp = function (_a) {
|
|
63
66
|
var props = _a.props, _b = _a.mdmValues, mdmValues = _b === void 0 ? defaultMdmValues : _b;
|
|
@@ -121,7 +124,8 @@ describe('Edit mode attributes factory attributes', function () {
|
|
|
121
124
|
attributeType = {
|
|
122
125
|
type: 'Reference',
|
|
123
126
|
uri: 'configuration/entityTypes/HCP/attributes/Reference',
|
|
124
|
-
referencedAttributeURIs: []
|
|
127
|
+
referencedAttributeURIs: ['configuration/entityTypes/Location'],
|
|
128
|
+
referencedEntityTypeURI: 'configuration/entityTypes/Location'
|
|
125
129
|
};
|
|
126
130
|
props = {
|
|
127
131
|
attributeValue: {
|
|
@@ -68,7 +68,7 @@ var EntitySelector = function (_a) {
|
|
|
68
68
|
var styles = (0, styles_1.useStyles)();
|
|
69
69
|
var _g = (0, react_1.useState)(''), inputValue = _g[0], setInputValue = _g[1];
|
|
70
70
|
var entityTypes = (0, react_1.useMemo)(function () { return entityTypesUris.map(function (type) { return (0, mdm_sdk_1.getEntityType)(metadata, type); }).filter(mdm_sdk_1.isAvailableEntityType); }, [entityTypesUris, metadata]);
|
|
71
|
-
var options = __assign(__assign({}, globalSearchRequestOptions), { max: max, sendMasked: isMasked });
|
|
71
|
+
var options = (0, react_1.useMemo)(function () { return (__assign(__assign({}, globalSearchRequestOptions), { max: max, sendMasked: isMasked })); }, [globalSearchRequestOptions, isMasked, max]);
|
|
72
72
|
var handleCreate = onCreate
|
|
73
73
|
? function (value, entityTypeUri) {
|
|
74
74
|
onCreate(entityTypeUri || entityTypes[0].uri, value);
|
|
@@ -88,9 +88,9 @@ var EntitySelector = function (_a) {
|
|
|
88
88
|
handleChange({});
|
|
89
89
|
};
|
|
90
90
|
var groupMode = (0, react_1.useMemo)(function () { return entityTypes.length !== 1; }, [entityTypes]);
|
|
91
|
-
var getOptions = function (value) {
|
|
92
|
-
return (0, mdm_sdk_1.typeAheadSearch)(entityTypes, value, options).then((0, helpers_1.buildEntityOptions)(entityTypes, onCreate));
|
|
93
|
-
};
|
|
91
|
+
var getOptions = (0, react_1.useCallback)(function (value) {
|
|
92
|
+
return ((0, ramda_1.isEmpty)(entityTypes) ? Promise.resolve([]) : (0, mdm_sdk_1.typeAheadSearch)(entityTypes, value, options)).then((0, helpers_1.buildEntityOptions)(entityTypes, onCreate));
|
|
93
|
+
}, [entityTypes, onCreate, options]);
|
|
94
94
|
var currentEntityType = ((0, ramda_1.isEmpty)(entity) ? entityTypes[0] : (0, mdm_sdk_1.getEntityType)(metadata, entity.entityType)) || {};
|
|
95
95
|
var createLabel = onCreate && ui_i18n_1.default.text("Create ".concat(inputValue ? "\"".concat(inputValue, "\" as ") : '', "new ").concat(currentEntityType.label));
|
|
96
96
|
var label = ui_i18n_1.default.text("Select ".concat(entityTypes.length === 1 ? "".concat(entityTypes[0].label, " ") : '', "profile"));
|
|
@@ -258,6 +258,24 @@ describe('Entity selector tests', function () {
|
|
|
258
258
|
}
|
|
259
259
|
});
|
|
260
260
|
}); });
|
|
261
|
+
it('should not send typeAheadSearch request if have not available entity type', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
262
|
+
var props, user;
|
|
263
|
+
return __generator(this, function (_a) {
|
|
264
|
+
switch (_a.label) {
|
|
265
|
+
case 0:
|
|
266
|
+
props = __assign(__assign({}, defaultProps), { max: 10, entityTypesUris: ['configuration/entityTypes/HCP'], metadata: {
|
|
267
|
+
entityTypes: [{ uri: 'configuration/entityTypes/HCP', label: 'HCP', attributes: [], access: [] }]
|
|
268
|
+
} });
|
|
269
|
+
user = setUp({ props: props }).user;
|
|
270
|
+
return [4 /*yield*/, user.click(react_2.screen.getByRole('combobox'))];
|
|
271
|
+
case 1:
|
|
272
|
+
_a.sent();
|
|
273
|
+
expect(mdm_sdk_1.typeAheadSearch).not.toHaveBeenCalled();
|
|
274
|
+
react_2.screen.getByText('No results found');
|
|
275
|
+
return [2 /*return*/];
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}); });
|
|
261
279
|
it('should render correctly in case of temp entity', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
262
280
|
var entityUri, entityType, mdmValues, props, user, entityCreator;
|
|
263
281
|
var _a;
|