@reltio/components 1.4.1850 → 1.4.1852

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.
Files changed (41) hide show
  1. package/cjs/EditModeAttributesList/EditModeAttributesList.js +6 -3
  2. package/cjs/EditModeAttributesView/EditModeAttributesView.test.js +218 -24
  3. package/cjs/ReadOnlyAttributesList/ReadOnlyAttributesList.js +4 -1
  4. package/cjs/ReadOnlyAttributesView/ReadOnlyAttributesView.js +1 -9
  5. package/cjs/ReadOnlyAttributesView/ReadOnlyAttributesView.test.js +113 -104
  6. package/cjs/contexts/MdmModuleContext/context.d.ts +6 -0
  7. package/cjs/contexts/MdmModuleContext/hooks.d.ts +4 -1
  8. package/cjs/contexts/MdmModuleContext/hooks.js +5 -1
  9. package/cjs/contexts/MdmModuleContext/index.d.ts +1 -1
  10. package/cjs/contexts/MdmModuleContext/index.js +2 -1
  11. package/cjs/hooks/index.d.ts +1 -0
  12. package/cjs/hooks/index.js +3 -1
  13. package/cjs/hooks/useHiddenAttributes/helpers.d.ts +7 -0
  14. package/cjs/hooks/useHiddenAttributes/helpers.js +22 -0
  15. package/cjs/hooks/useHiddenAttributes/useChangedAttributes.d.ts +2 -0
  16. package/cjs/hooks/useHiddenAttributes/useChangedAttributes.js +37 -0
  17. package/cjs/hooks/useHiddenAttributes/useHiddenAttributes.d.ts +1 -0
  18. package/cjs/hooks/useHiddenAttributes/useHiddenAttributes.js +61 -0
  19. package/cjs/hooks/useHiddenAttributes/useHiddenAttributes.test.d.ts +1 -0
  20. package/cjs/hooks/useHiddenAttributes/useHiddenAttributes.test.js +370 -0
  21. package/esm/EditModeAttributesList/EditModeAttributesList.js +6 -3
  22. package/esm/EditModeAttributesView/EditModeAttributesView.test.js +219 -25
  23. package/esm/ReadOnlyAttributesList/ReadOnlyAttributesList.js +4 -1
  24. package/esm/ReadOnlyAttributesView/ReadOnlyAttributesView.js +2 -10
  25. package/esm/ReadOnlyAttributesView/ReadOnlyAttributesView.test.js +114 -105
  26. package/esm/contexts/MdmModuleContext/context.d.ts +6 -0
  27. package/esm/contexts/MdmModuleContext/hooks.d.ts +4 -1
  28. package/esm/contexts/MdmModuleContext/hooks.js +3 -0
  29. package/esm/contexts/MdmModuleContext/index.d.ts +1 -1
  30. package/esm/contexts/MdmModuleContext/index.js +1 -1
  31. package/esm/hooks/index.d.ts +1 -0
  32. package/esm/hooks/index.js +1 -0
  33. package/esm/hooks/useHiddenAttributes/helpers.d.ts +7 -0
  34. package/esm/hooks/useHiddenAttributes/helpers.js +17 -0
  35. package/esm/hooks/useHiddenAttributes/useChangedAttributes.d.ts +2 -0
  36. package/esm/hooks/useHiddenAttributes/useChangedAttributes.js +33 -0
  37. package/esm/hooks/useHiddenAttributes/useHiddenAttributes.d.ts +1 -0
  38. package/esm/hooks/useHiddenAttributes/useHiddenAttributes.js +57 -0
  39. package/esm/hooks/useHiddenAttributes/useHiddenAttributes.test.d.ts +1 -0
  40. package/esm/hooks/useHiddenAttributes/useHiddenAttributes.test.js +368 -0
  41. package/package.json +2 -2
@@ -53,8 +53,11 @@ var HasDeletionsContext_1 = require("../contexts/HasDeletionsContext");
53
53
  var withContext_1 = require("../HOCs/withContext");
54
54
  var ConfigPermissionsContext_1 = require("../contexts/ConfigPermissionsContext");
55
55
  var ScrollToElementContext_1 = require("../contexts/ScrollToElementContext");
56
+ var contexts_1 = require("../contexts");
56
57
  var EditModeAttributesList = function (_a) {
57
58
  var parentAttributeType = _a.parentAttributeType, attrTypes = _a.attrTypes, entity = _a.entity, parentUri = _a.parentUri, showEmptyEditors = _a.showEmptyEditors, mode = _a.mode, crosswalks = _a.crosswalks, drawLines = _a.drawLines, children = _a.children, className = _a.className, _b = _a.alwaysVisibleTypeUris, alwaysVisibleTypeUris = _b === void 0 ? constants_1.ALWAYS_VISIBLE_TYPE_URIS : _b, onAddAttributes = _a.onAddAttributes, onChangeAttribute = _a.onChangeAttribute, onDeleteAttribute = _a.onDeleteAttribute, additionalControlsRenderer = _a.additionalControlsRenderer, showNonOv = _a.showNonOv, highlightAttribute = _a.highlightAttribute;
59
+ var hiddenAttributes = (0, contexts_1.useMdmHiddenAttributes)();
60
+ var filteredAttrTypes = (0, react_1.useMemo)(function () { return attrTypes.filter(function (attrType) { return !hiddenAttributes.includes(attrType.uri); }); }, [attrTypes, hiddenAttributes]);
58
61
  var _c = entity.attributes, attributes = _c === void 0 ? {} : _c;
59
62
  var _d = (0, react_1.useState)({}), hasDeletionsMap = _d[0], setHasDeletionsMap = _d[1];
60
63
  var setHasDeletions = (0, react_1.useCallback)(function (attrTypeUri, value) {
@@ -68,12 +71,12 @@ var EditModeAttributesList = function (_a) {
68
71
  }, [parentUri]);
69
72
  var canCreate = (0, react_1.useContext)(ConfigPermissionsContext_1.ConfigPermissionsContext).canCreate;
70
73
  var canCreateParentAttrType = (0, react_1.useMemo)(function () { return canCreate && parentAttributeType && (0, mdm_sdk_1.checkCanCreateAttribute)({ attributeType: parentAttributeType, mode: mode }); }, [parentAttributeType, mode, canCreate]);
71
- var creatableAttrTypes = (0, react_1.useMemo)(function () { return (canCreate ? (0, mdm_sdk_1.getCreatableAttributeTypes)(mode, attrTypes) : []); }, [attrTypes, mode, canCreate]);
74
+ var creatableAttrTypes = (0, react_1.useMemo)(function () { return (canCreate ? (0, mdm_sdk_1.getCreatableAttributeTypes)(mode, filteredAttrTypes) : []); }, [filteredAttrTypes, mode, canCreate]);
72
75
  var moreAttrTypes = (0, helpers_1.getMoreAttrTypes)(creatableAttrTypes, entity, showEmptyEditors, hasDeletionsMap);
73
76
  var pinnedAttributes = (0, react_1.useContext)(PinnedAttributesContext_1.PinnedAttributesContext);
74
77
  var pagersData = (0, react_1.useMemo)(function () {
75
- return (0, mdm_sdk_1.getAttributesListForEditMode)(attrTypes, mode, entity, showEmptyEditors, showNonOv, pinnedAttributes, canCreate);
76
- }, [attrTypes, mode, entity, showEmptyEditors, showNonOv, pinnedAttributes, canCreate]);
78
+ return (0, mdm_sdk_1.getAttributesListForEditMode)(filteredAttrTypes, mode, entity, showEmptyEditors, showNonOv, pinnedAttributes, canCreate);
79
+ }, [filteredAttrTypes, mode, entity, showEmptyEditors, showNonOv, pinnedAttributes, canCreate]);
77
80
  var _e = (0, react_1.useMemo)(function () { return (0, attributesView_1.splitPagersData)(alwaysVisibleTypeUris, pagersData); }, [pagersData, alwaysVisibleTypeUris]), alwaysVisiblePagersData = _e[0], regularPagersData = _e[1];
78
81
  var onAddMoreAttributes = (0, react_1.useCallback)(function (attributeTypes) {
79
82
  onAddAttributes(attributeTypes.map(function (attributeType) { return ({
@@ -10,16 +10,54 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
13
49
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
51
  };
16
52
  Object.defineProperty(exports, "__esModule", { value: true });
17
53
  var react_1 = __importDefault(require("react"));
18
54
  var enzyme_1 = require("enzyme");
55
+ var react_2 = require("@testing-library/react");
56
+ var user_event_1 = __importDefault(require("@testing-library/user-event"));
19
57
  var PinnedAttributesContext_1 = require("../contexts/PinnedAttributesContext");
20
58
  var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
21
59
  var EditModeAttributesView_1 = require("./EditModeAttributesView");
22
- jest.mock('../contexts/MdmModuleContext', function () { return (__assign(__assign({}, jest.requireActual('../contexts/MdmModuleContext')), { useMdmAction: jest.fn(), useMdmMetadata: jest.fn(), useMdmUserRoles: jest.fn(), useMdmModifiedEntity: jest.fn() })); });
60
+ jest.mock('../contexts/MdmModuleContext', function () { return (__assign(__assign({}, jest.requireActual('../contexts/MdmModuleContext')), { useMdmAction: jest.fn(), useMdmMetadata: jest.fn(), useMdmUserRoles: jest.fn(), useMdmModifiedEntity: jest.fn(), useMdmDependentLookupEditorState: jest.fn(), useMdmHiddenAttributes: jest.fn() })); });
23
61
  var metadata = {
24
62
  entityTypes: []
25
63
  };
@@ -35,29 +73,185 @@ var pinnedAttributes = [
35
73
  var entity = { uri: 'entities/123' };
36
74
  var setUp = function (props) { return (0, enzyme_1.shallow)(react_1.default.createElement(EditModeAttributesView_1.EditModeAttributesView, __assign({ entity: entity }, props))); };
37
75
  describe('EditModeAttributesView', function () {
38
- beforeEach(function () {
39
- MdmModuleContext_1.useMdmMetadata.mockReturnValue(metadata);
40
- MdmModuleContext_1.useMdmUserRoles.mockReturnValue([]);
41
- MdmModuleContext_1.useMdmModifiedEntity.mockReturnValue(null);
42
- MdmModuleContext_1.useMdmAction.mockReturnValue(jest.fn());
43
- });
44
- afterEach(function () {
45
- jest.clearAllMocks();
46
- });
47
- it('should render PinnedAttributesContext.Provider with passing pinnedAttributes for this user', function () {
48
- MdmModuleContext_1.useMdmUserRoles.mockReturnValue(['ROLE_ADMIN']);
49
- var component = setUp({ pinnedAttributes: pinnedAttributes });
50
- expect(component.find(PinnedAttributesContext_1.PinnedAttributesContext.Provider)).toHaveLength(1);
51
- expect(component.find(PinnedAttributesContext_1.PinnedAttributesContext.Provider).prop('value')).toEqual(pinnedAttributes[0].attributes);
52
- });
53
- it('should render PinnedAttributesContext.Provider with passing pinnedAttributes as empty array for user without roles', function () {
54
- var component = setUp({ pinnedAttributes: pinnedAttributes });
55
- expect(component.find(PinnedAttributesContext_1.PinnedAttributesContext.Provider)).toHaveLength(1);
56
- expect(component.find(PinnedAttributesContext_1.PinnedAttributesContext.Provider).prop('value')).toEqual([]);
76
+ describe('PinnedAttributesContext', function () {
77
+ beforeEach(function () {
78
+ MdmModuleContext_1.useMdmMetadata.mockReturnValue(metadata);
79
+ MdmModuleContext_1.useMdmUserRoles.mockReturnValue([]);
80
+ MdmModuleContext_1.useMdmModifiedEntity.mockReturnValue(null);
81
+ MdmModuleContext_1.useMdmAction.mockReturnValue(jest.fn());
82
+ });
83
+ afterEach(function () {
84
+ jest.clearAllMocks();
85
+ });
86
+ it('should render PinnedAttributesContext.Provider with passing pinnedAttributes for this user', function () {
87
+ MdmModuleContext_1.useMdmUserRoles.mockReturnValue(['ROLE_ADMIN']);
88
+ var component = setUp({ pinnedAttributes: pinnedAttributes });
89
+ expect(component.find(PinnedAttributesContext_1.PinnedAttributesContext.Provider)).toHaveLength(1);
90
+ expect(component.find(PinnedAttributesContext_1.PinnedAttributesContext.Provider).prop('value')).toEqual(pinnedAttributes[0].attributes);
91
+ });
92
+ it('should render PinnedAttributesContext.Provider with passing pinnedAttributes as empty array for user without roles', function () {
93
+ var component = setUp({ pinnedAttributes: pinnedAttributes });
94
+ expect(component.find(PinnedAttributesContext_1.PinnedAttributesContext.Provider)).toHaveLength(1);
95
+ expect(component.find(PinnedAttributesContext_1.PinnedAttributesContext.Provider).prop('value')).toEqual([]);
96
+ });
97
+ it('should render PinnedAttributesContext.Provider with passing pinnedAttributes as empty array if no pinnedAttributes', function () {
98
+ var component = setUp({});
99
+ expect(component.find(PinnedAttributesContext_1.PinnedAttributesContext.Provider)).toHaveLength(1);
100
+ expect(component.find(PinnedAttributesContext_1.PinnedAttributesContext.Provider).prop('value')).toEqual([]);
101
+ });
57
102
  });
58
- it('should render PinnedAttributesContext.Provider with passing pinnedAttributes as empty array if no pinnedAttributes', function () {
59
- var component = setUp({});
60
- expect(component.find(PinnedAttributesContext_1.PinnedAttributesContext.Provider)).toHaveLength(1);
61
- expect(component.find(PinnedAttributesContext_1.PinnedAttributesContext.Provider).prop('value')).toEqual([]);
103
+ describe('rule based attributes', function () {
104
+ var metadata = {
105
+ entityTypes: [
106
+ {
107
+ uri: 'configuration/entityTypes/HCP',
108
+ attributes: [
109
+ {
110
+ name: 'Category1',
111
+ type: 'String',
112
+ uri: 'configuration/entityTypes/HCP/attributes/Category1'
113
+ },
114
+ {
115
+ name: 'Category2',
116
+ type: 'String',
117
+ uri: 'configuration/entityTypes/HCP/attributes/Category2'
118
+ },
119
+ {
120
+ name: 'Category3',
121
+ type: 'String',
122
+ uri: 'configuration/entityTypes/HCP/attributes/Category3'
123
+ },
124
+ {
125
+ name: 'Category4',
126
+ type: 'String',
127
+ uri: 'configuration/entityTypes/HCP/attributes/Category4'
128
+ },
129
+ {
130
+ name: 'Nested1',
131
+ label: 'Nested1',
132
+ type: 'Nested',
133
+ uri: 'configuration/entityTypes/HCP/attributes/Nested1',
134
+ attributes: [
135
+ {
136
+ name: 'NestedCategory1',
137
+ type: 'String',
138
+ uri: 'configuration/entityTypes/HCP/attributes/Nested1/attributes/NestedCategory1'
139
+ },
140
+ {
141
+ name: 'NestedCategory2',
142
+ type: 'String',
143
+ uri: 'configuration/entityTypes/HCP/attributes/Nested1/attributes/NestedCategory2'
144
+ }
145
+ ]
146
+ }
147
+ ]
148
+ }
149
+ ]
150
+ };
151
+ var setUp = function (props) {
152
+ var user = user_event_1.default.setup();
153
+ return __assign({ user: user }, (0, react_2.render)(react_1.default.createElement(EditModeAttributesView_1.EditModeAttributesView, __assign({}, props))));
154
+ };
155
+ beforeAll(function () {
156
+ MdmModuleContext_1.useMdmUserRoles.mockReturnValue([]);
157
+ MdmModuleContext_1.useMdmAction.mockReturnValue(jest.fn());
158
+ MdmModuleContext_1.useMdmMetadata.mockReturnValue(metadata);
159
+ MdmModuleContext_1.useMdmHiddenAttributes.mockReturnValue([]);
160
+ });
161
+ it('should hide attributes if there are no rules allow to show the attribute', function () {
162
+ var entity = {
163
+ type: 'configuration/entityTypes/HCP',
164
+ uri: 'entities/uri_e'
165
+ };
166
+ MdmModuleContext_1.useMdmModifiedEntity.mockReturnValue({
167
+ type: 'configuration/entityTypes/HCP',
168
+ uri: 'entities/uri_e',
169
+ attributes: {
170
+ Category1: [
171
+ {
172
+ uri: 'entities/uri_e/attributes/uri1',
173
+ value: 'category1_value1'
174
+ }
175
+ ],
176
+ Category2: [
177
+ {
178
+ uri: 'entities/uri_e/attributes/uri2',
179
+ value: 'category2_value1'
180
+ }
181
+ ],
182
+ Category3: [
183
+ {
184
+ uri: 'entities/uri_e/attributes/uri3',
185
+ value: 'category3_value1'
186
+ }
187
+ ],
188
+ Category4: [
189
+ {
190
+ uri: 'entities/uri_e/attributes/uri4',
191
+ value: 'category4_value1'
192
+ }
193
+ ]
194
+ }
195
+ });
196
+ MdmModuleContext_1.useMdmHiddenAttributes.mockReturnValue([
197
+ 'configuration/entityTypes/HCP/attributes/Category2',
198
+ 'configuration/entityTypes/HCP/attributes/Category3',
199
+ 'configuration/entityTypes/HCP/attributes/Category4'
200
+ ]);
201
+ setUp({ entity: entity });
202
+ expect(react_2.screen.getByText('category1_value1')).toBeInTheDocument();
203
+ expect(react_2.screen.queryByText('category2_value1')).not.toBeInTheDocument();
204
+ expect(react_2.screen.queryByText('category3_value1')).not.toBeInTheDocument();
205
+ expect(react_2.screen.queryByText('category4_value1')).not.toBeInTheDocument();
206
+ });
207
+ it('should hide nested attributes if there are no rules allow to show the attribute', function () { return __awaiter(void 0, void 0, void 0, function () {
208
+ var entity, user;
209
+ return __generator(this, function (_a) {
210
+ switch (_a.label) {
211
+ case 0:
212
+ entity = {
213
+ type: 'configuration/entityTypes/HCP',
214
+ uri: 'entities/uri_e'
215
+ };
216
+ MdmModuleContext_1.useMdmModifiedEntity.mockReturnValue({
217
+ type: 'configuration/entityTypes/HCP',
218
+ uri: 'entities/uri_e',
219
+ attributes: {
220
+ Nested1: [
221
+ {
222
+ uri: 'entities/uri_e/attributes/nesteduri1',
223
+ value: {
224
+ NestedCategory1: [
225
+ {
226
+ ov: true,
227
+ uri: 'entities/uri_e/attributes/nesteduri1/attributes/nestedcaturi1',
228
+ value: 'nested_category1_value1'
229
+ }
230
+ ],
231
+ NestedCategory2: [
232
+ {
233
+ ov: true,
234
+ uri: 'entities/uri_e/attributes/nesteduri1/attributes/nestedcaturi2',
235
+ value: 'nested_category2_value1'
236
+ }
237
+ ]
238
+ }
239
+ }
240
+ ]
241
+ }
242
+ });
243
+ MdmModuleContext_1.useMdmHiddenAttributes.mockReturnValue([
244
+ 'configuration/entityTypes/HCP/attributes/Nested1/attributes/NestedCategory2'
245
+ ]);
246
+ user = setUp({ entity: entity }).user;
247
+ return [4 /*yield*/, user.click(react_2.screen.getByTestId('arrow-expand-button'))];
248
+ case 1:
249
+ _a.sent();
250
+ expect(react_2.screen.getByText('nested_category1_value1')).toBeInTheDocument();
251
+ expect(react_2.screen.queryByText('nested_category2_value1')).not.toBeInTheDocument();
252
+ return [2 /*return*/];
253
+ }
254
+ });
255
+ }); });
62
256
  });
63
257
  });
@@ -43,10 +43,13 @@ var ShowMore_1 = require("../ShowMore");
43
43
  var ShowLess_1 = require("../ShowLess");
44
44
  var constants_1 = require("../constants");
45
45
  var attributesView_1 = require("../helpers/attributesView");
46
+ var contexts_1 = require("../contexts");
46
47
  var ReadOnlyAttributesList = function (_a) {
47
48
  var attrTypes = _a.attrTypes, entity = _a.entity, parentUri = _a.parentUri, drawLines = _a.drawLines, children = _a.children, className = _a.className, max = _a.max, _b = _a.alwaysVisibleTypeUris, alwaysVisibleTypeUris = _b === void 0 ? constants_1.ALWAYS_VISIBLE_TYPE_URIS : _b, showNonOv = _a.showNonOv;
49
+ var hiddenAttributes = (0, contexts_1.useMdmHiddenAttributes)();
50
+ var filteredAttrTypes = (0, react_1.useMemo)(function () { return attrTypes.filter(function (attrType) { return !hiddenAttributes.includes(attrType.uri); }); }, [attrTypes, hiddenAttributes]);
48
51
  var _c = (0, react_1.useState)(max || Infinity), visibleValuesCount = _c[0], setVisibleValuesCount = _c[1];
49
- var pagersData = (0, react_1.useMemo)(function () { return (0, mdm_sdk_1.getAttributesListForReadMode)(attrTypes, entity, showNonOv); }, [attrTypes, entity, showNonOv]);
52
+ var pagersData = (0, react_1.useMemo)(function () { return (0, mdm_sdk_1.getAttributesListForReadMode)(filteredAttrTypes, entity, showNonOv); }, [filteredAttrTypes, entity, showNonOv]);
50
53
  var _d = (0, react_1.useMemo)(function () { return (0, attributesView_1.splitPagersData)(alwaysVisibleTypeUris, pagersData); }, [pagersData, alwaysVisibleTypeUris]), alwaysVisiblePagersData = _d[0], regularPagersData = _d[1];
51
54
  var visibleAttributePagersData = regularPagersData.slice(0, visibleValuesCount);
52
55
  var showMore = max && visibleAttributePagersData.length < regularPagersData.length;
@@ -28,7 +28,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.ReadOnlyAttributesView = void 0;
30
30
  var react_1 = __importStar(require("react"));
31
- var ramda_1 = require("ramda");
32
31
  var mdm_sdk_1 = require("@reltio/mdm-sdk");
33
32
  var classnames_1 = __importDefault(require("classnames"));
34
33
  var ui_i18n_1 = __importDefault(require("ui-i18n"));
@@ -48,14 +47,7 @@ var ReadOnlyAttributesView = function (_a) {
48
47
  var styles = (0, styles_1.useStyles)();
49
48
  var metadata = (0, MdmModuleContext_1.useMdmMetadata)();
50
49
  var pivotingAttributes = (0, MdmModuleContext_1.useMdmPivotingAttributes)();
51
- var filteredAttrTypes = (0, react_1.useMemo)(function () {
52
- var dynamicRules = (0, mdm_sdk_1.getRuleBasedAttributes)(metadata, entity.type);
53
- var hiddenAttributes = (0, mdm_sdk_1.getHiddenDynamicAttributes)(dynamicRules, entity);
54
- return (0, ramda_1.pipe)(attributesView_1.getFilteredAttrTypes, (0, ramda_1.reject)(function (_a) {
55
- var uri = _a.uri;
56
- return hiddenAttributes.includes(uri);
57
- }))(metadata, entity.type, includeUris, excludeUris, hiddenAttributes);
58
- }, [excludeUris, includeUris, metadata, entity]);
50
+ var filteredAttrTypes = (0, react_1.useMemo)(function () { return (0, attributesView_1.getFilteredAttrTypes)(metadata, entity.type, includeUris, excludeUris); }, [excludeUris, includeUris, metadata, entity]);
59
51
  var attributesCount = attributesCountProp || DEFAULT_ATTRIBUTES_COUNT;
60
52
  var attributesList = (0, mdm_sdk_1.getAttributesListForReadMode)(filteredAttrTypes, entity);
61
53
  var isShowAttributeList = attributesList.filter(function (_a) {
@@ -10,6 +10,42 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
13
49
  var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
50
  if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
51
  if (ar || !(i in from)) {
@@ -26,6 +62,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
62
  var react_1 = __importDefault(require("react"));
27
63
  var enzyme_1 = require("enzyme");
28
64
  var react_2 = require("@testing-library/react");
65
+ var user_event_1 = __importDefault(require("@testing-library/user-event"));
29
66
  var mdm_sdk_1 = require("@reltio/mdm-sdk");
30
67
  var Typography_1 = __importDefault(require("@mui/material/Typography"));
31
68
  var ReadOnlyAttributesView_1 = require("./ReadOnlyAttributesView");
@@ -34,7 +71,7 @@ var ReadOnlyAttributesList_1 = require("../ReadOnlyAttributesList");
34
71
  var FacetViewHeader_1 = require("../FacetViewHeader");
35
72
  var PivotingAttributeContext_1 = require("../contexts/PivotingAttributeContext");
36
73
  var MdmModuleContext_1 = require("../contexts/MdmModuleContext");
37
- jest.mock('../contexts/MdmModuleContext', function () { return (__assign(__assign({}, jest.requireActual('../contexts/MdmModuleContext')), { useMdmMetadata: jest.fn(), useMdmPivotingAttributes: jest.fn() })); });
74
+ jest.mock('../contexts/MdmModuleContext', function () { return (__assign(__assign({}, jest.requireActual('../contexts/MdmModuleContext')), { useMdmMetadata: jest.fn(), useMdmPivotingAttributes: jest.fn(), useMdmHiddenAttributes: jest.fn() })); });
38
75
  describe('ReadOnlyAttributesView tests', function () {
39
76
  var metadata = {
40
77
  entityTypes: [
@@ -208,8 +245,8 @@ describe('ReadOnlyAttributesView tests', function () {
208
245
  var provider = component.find(PivotingAttributeContext_1.PivotingAttributeContext.Provider);
209
246
  expect(provider.prop('value')).toEqual(pivotingAttributes);
210
247
  });
211
- describe('dynamic rules', function () {
212
- var metadataWithDynamicRules = {
248
+ describe('rule based attributes', function () {
249
+ var metadata = {
213
250
  entityTypes: [
214
251
  {
215
252
  uri: 'configuration/entityTypes/HCP',
@@ -233,93 +270,38 @@ describe('ReadOnlyAttributesView tests', function () {
233
270
  name: 'Category4',
234
271
  type: 'String',
235
272
  uri: 'configuration/entityTypes/HCP/attributes/Category4'
236
- }
237
- ],
238
- ruleBasedAttributes: [
239
- {
240
- uri: 'configuration/entityTypes/HCP/ruleBasedAttributes/DynamicRule1',
241
- label: 'Dynamic Rule 1',
242
- description: 'Dynamic Attributes Rule 1',
243
- name: 'DynamicRule1',
244
- type: 'Dynamic',
245
- controlFunction: {
246
- expression: "listEquals(attributes.Category1.value, 'category1_value1') and listEquals(attributes.Category2.value, 'category2_value1', 'category2_value2')",
247
- showAttributeURI: [
248
- 'configuration/entityTypes/HCP/attributes/Category3',
249
- 'configuration/entityTypes/HCP/attributes/Category4'
250
- ]
251
- }
252
- },
253
- {
254
- uri: 'configuration/entityTypes/HCP/ruleBasedAttributes/DynamicRule2',
255
- label: 'Dynamic Rule 2',
256
- description: 'Dynamic Attributes Rule 2',
257
- name: 'DynamicRule2',
258
- type: 'Dynamic',
259
- controlFunction: {
260
- expression: "listEquals(attributes.Category1.value, 'category1_value1')",
261
- showAttributeURI: ['configuration/entityTypes/HCP/attributes/Category2']
262
- }
263
273
  },
264
274
  {
265
- uri: 'configuration/entityTypes/HCP/ruleBasedAttributes/DynamicRule3',
266
- label: 'Dynamic Rule 3',
267
- description: 'Dynamic Attributes Rule 3',
268
- name: 'DynamicRule3',
269
- type: 'Dynamic',
270
- controlFunction: {
271
- expression: "listEquals(attributes.Category1.value, 'category1_value2')",
272
- showAttributeURI: ['configuration/entityTypes/HCP/attributes/Category4']
273
- }
275
+ name: 'Nested1',
276
+ label: 'Nested1',
277
+ type: 'Nested',
278
+ uri: 'configuration/entityTypes/HCP/attributes/Nested1',
279
+ attributes: [
280
+ {
281
+ name: 'NestedCategory1',
282
+ type: 'String',
283
+ uri: 'configuration/entityTypes/HCP/attributes/Nested1/attributes/NestedCategory1'
284
+ },
285
+ {
286
+ name: 'NestedCategory2',
287
+ type: 'String',
288
+ uri: 'configuration/entityTypes/HCP/attributes/Nested1/attributes/NestedCategory2'
289
+ }
290
+ ]
274
291
  }
275
292
  ]
276
293
  }
277
294
  ]
278
295
  };
279
296
  var setUp = function (props) {
280
- return (0, react_2.render)(react_1.default.createElement(ReadOnlyAttributesView_1.ReadOnlyAttributesView, __assign({}, props)));
297
+ var user = user_event_1.default.setup();
298
+ return __assign(__assign({}, (0, react_2.render)(react_1.default.createElement(ReadOnlyAttributesView_1.ReadOnlyAttributesView, __assign({}, props)))), { user: user });
281
299
  };
282
300
  beforeAll(function () {
283
- MdmModuleContext_1.useMdmMetadata.mockReturnValue(metadataWithDynamicRules);
284
- });
285
- it('should hide attributes which does not fit dynamic rules', function () {
286
- var entity = {
287
- type: 'configuration/entityTypes/HCP',
288
- uri: 'entities/uri_e',
289
- attributes: {
290
- Category1: [
291
- {
292
- uri: 'entities/uri_e/attributes/uri1',
293
- value: 'category1_value1_diff'
294
- }
295
- ],
296
- Category2: [
297
- {
298
- uri: 'entities/uri_e/attributes/uri2',
299
- value: 'category2_value1_diff'
300
- }
301
- ],
302
- Category3: [
303
- {
304
- uri: 'entities/uri_e/attributes/uri3',
305
- value: 'category3_value1'
306
- }
307
- ],
308
- Category4: [
309
- {
310
- uri: 'entities/uri_e/attributes/uri4',
311
- value: 'category4_value1'
312
- }
313
- ]
314
- }
315
- };
316
- setUp({ entity: entity });
317
- expect(react_2.screen.getByText('category1_value1_diff')).toBeInTheDocument();
318
- expect(react_2.screen.queryByText('category2_value1_diff')).not.toBeInTheDocument();
319
- expect(react_2.screen.queryByText('category3_value1')).not.toBeInTheDocument();
320
- expect(react_2.screen.queryByText('category4_value1')).not.toBeInTheDocument();
301
+ MdmModuleContext_1.useMdmMetadata.mockReturnValue(metadata);
302
+ MdmModuleContext_1.useMdmHiddenAttributes.mockReturnValue([]);
321
303
  });
322
- it('should show attributes which fits dynamic rules', function () {
304
+ it('should hide attributes', function () {
323
305
  var entity = {
324
306
  type: 'configuration/entityTypes/HCP',
325
307
  uri: 'entities/uri_e',
@@ -350,34 +332,61 @@ describe('ReadOnlyAttributesView tests', function () {
350
332
  ]
351
333
  }
352
334
  };
335
+ MdmModuleContext_1.useMdmHiddenAttributes.mockReturnValue([
336
+ 'configuration/entityTypes/HCP/attributes/Category2',
337
+ 'configuration/entityTypes/HCP/attributes/Category3',
338
+ 'configuration/entityTypes/HCP/attributes/Category4'
339
+ ]);
353
340
  setUp({ entity: entity });
354
341
  expect(react_2.screen.getByText('category1_value1')).toBeInTheDocument();
355
- expect(react_2.screen.getByText('category2_value1')).toBeInTheDocument();
356
- expect(react_2.screen.getByText('category3_value1')).toBeInTheDocument();
357
- expect(react_2.screen.getByText('category4_value1')).toBeInTheDocument();
342
+ expect(react_2.screen.queryByText('category2_value1')).not.toBeInTheDocument();
343
+ expect(react_2.screen.queryByText('category3_value1')).not.toBeInTheDocument();
344
+ expect(react_2.screen.queryByText('category4_value1')).not.toBeInTheDocument();
358
345
  });
359
- it('should show attributes if at least one rule allows to show the attribute from showAttributeURI', function () {
360
- var entity = {
361
- type: 'configuration/entityTypes/HCP',
362
- uri: 'entities/uri_e',
363
- attributes: {
364
- Category1: [
365
- {
366
- uri: 'entities/uri_e/attributes/uri1',
367
- value: 'category1_value2'
368
- }
369
- ],
370
- Category4: [
371
- {
372
- uri: 'entities/uri_e/attributes/uri4',
373
- value: 'category4_value1'
374
- }
375
- ]
346
+ it('should hide nested attributes', function () { return __awaiter(void 0, void 0, void 0, function () {
347
+ var entity, user;
348
+ return __generator(this, function (_a) {
349
+ switch (_a.label) {
350
+ case 0:
351
+ entity = {
352
+ type: 'configuration/entityTypes/HCP',
353
+ uri: 'entities/uri_e',
354
+ attributes: {
355
+ Nested1: [
356
+ {
357
+ uri: 'entities/uri_e/attributes/nesteduri1',
358
+ value: {
359
+ NestedCategory1: [
360
+ {
361
+ ov: true,
362
+ uri: 'entities/uri_e/attributes/nesteduri1/attributes/nestedcaturi1',
363
+ value: 'nested_category1_value'
364
+ }
365
+ ],
366
+ NestedCategory2: [
367
+ {
368
+ ov: true,
369
+ uri: 'entities/uri_e/attributes/nesteduri1/attributes/nestedcaturi2',
370
+ value: 'nested_category2_value1'
371
+ }
372
+ ]
373
+ }
374
+ }
375
+ ]
376
+ }
377
+ };
378
+ MdmModuleContext_1.useMdmHiddenAttributes.mockReturnValue([
379
+ 'configuration/entityTypes/HCP/attributes/Nested1/attributes/NestedCategory2'
380
+ ]);
381
+ user = setUp({ entity: entity }).user;
382
+ return [4 /*yield*/, user.click(react_2.screen.getByTestId('arrow-expand-button'))];
383
+ case 1:
384
+ _a.sent();
385
+ expect(react_2.screen.getByText('nested_category1_value')).toBeInTheDocument();
386
+ expect(react_2.screen.queryByText('nested_category2_value1')).not.toBeInTheDocument();
387
+ return [2 /*return*/];
376
388
  }
377
- };
378
- setUp({ entity: entity });
379
- expect(react_2.screen.getByText('category1_value2')).toBeInTheDocument();
380
- expect(react_2.screen.getByText('category4_value1')).toBeInTheDocument();
381
- });
389
+ });
390
+ }); });
382
391
  });
383
392
  });