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