@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.
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
@@ -0,0 +1,368 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { assocPath } from 'ramda';
13
+ import { renderHook } from '@testing-library/react-hooks';
14
+ import { Mode } from '@reltio/mdm-sdk';
15
+ import { useMdmAction, useMdmEntity, useMdmMetadata, useMdmModifiedEntity, useMdmMode } from '../../contexts/MdmModuleContext/hooks';
16
+ import { useHiddenAttributes } from './useHiddenAttributes';
17
+ 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() })); });
18
+ describe('useHiddenAttributes', function () {
19
+ var metadata = {
20
+ entityTypes: [
21
+ {
22
+ uri: 'configuration/entityTypes/HCP',
23
+ attributes: [
24
+ {
25
+ name: 'Category1',
26
+ type: 'String',
27
+ uri: 'configuration/entityTypes/HCP/attributes/Category1'
28
+ },
29
+ {
30
+ name: 'Category2',
31
+ type: 'String',
32
+ uri: 'configuration/entityTypes/HCP/attributes/Category2'
33
+ },
34
+ {
35
+ name: 'Category3',
36
+ type: 'String',
37
+ uri: 'configuration/entityTypes/HCP/attributes/Category3'
38
+ },
39
+ {
40
+ name: 'Category4',
41
+ type: 'String',
42
+ uri: 'configuration/entityTypes/HCP/attributes/Category4'
43
+ },
44
+ {
45
+ name: 'Nested1',
46
+ label: 'Nested1',
47
+ type: 'Nested',
48
+ uri: 'configuration/entityTypes/HCP/attributes/Nested1',
49
+ attributes: [
50
+ {
51
+ name: 'NestedCategory1',
52
+ type: 'String',
53
+ uri: 'configuration/entityTypes/HCP/attributes/Nested1/attributes/NestedCategory1'
54
+ },
55
+ {
56
+ name: 'NestedCategory2',
57
+ type: 'String',
58
+ uri: 'configuration/entityTypes/HCP/attributes/Nested1/attributes/NestedCategory2'
59
+ }
60
+ ]
61
+ }
62
+ ],
63
+ ruleBasedAttributes: [
64
+ {
65
+ uri: 'configuration/entityTypes/HCP/ruleBasedAttributes/DynamicRule1',
66
+ label: 'Dynamic Rule 1',
67
+ description: 'Dynamic Attributes Rule 1',
68
+ name: 'DynamicRule1',
69
+ type: 'Dynamic',
70
+ controlFunction: {
71
+ expression: "listEquals(attributes.Category1.value, 'category1_value1') and listEquals(attributes.Category2.value, 'category2_value1', 'category2_value2')",
72
+ showAttributeURI: [
73
+ 'configuration/entityTypes/HCP/attributes/Category3',
74
+ 'configuration/entityTypes/HCP/attributes/Category4'
75
+ ]
76
+ }
77
+ },
78
+ {
79
+ uri: 'configuration/entityTypes/HCP/ruleBasedAttributes/DynamicRule2',
80
+ label: 'Dynamic Rule 2',
81
+ description: 'Dynamic Attributes Rule 2',
82
+ name: 'DynamicRule2',
83
+ type: 'Dynamic',
84
+ controlFunction: {
85
+ expression: "listEquals(attributes.Category1.value, 'category1_value1')",
86
+ showAttributeURI: ['configuration/entityTypes/HCP/attributes/Category2']
87
+ }
88
+ },
89
+ {
90
+ uri: 'configuration/entityTypes/HCP/ruleBasedAttributes/DynamicRule3',
91
+ label: 'Dynamic Rule 3',
92
+ description: 'Dynamic Attributes Rule 3',
93
+ name: 'DynamicRule3',
94
+ type: 'Dynamic',
95
+ controlFunction: {
96
+ expression: "listEquals(attributes.Category1.value, 'category1_value2')",
97
+ showAttributeURI: ['configuration/entityTypes/HCP/attributes/Category4']
98
+ }
99
+ }
100
+ ]
101
+ }
102
+ ]
103
+ };
104
+ var updateHiddenAttributes = jest.fn();
105
+ var setUp = function () { return renderHook(useHiddenAttributes); };
106
+ beforeEach(function () {
107
+ useMdmMetadata.mockReturnValue(metadata);
108
+ useMdmEntity.mockReturnValue(null);
109
+ useMdmModifiedEntity.mockReturnValue(null);
110
+ useMdmMode.mockReturnValue(Mode.Viewing);
111
+ useMdmAction.mockReturnValue(updateHiddenAttributes);
112
+ });
113
+ afterEach(function () {
114
+ jest.clearAllMocks();
115
+ });
116
+ it('should hide attributes if there is no satisfied dynamic rules', function () {
117
+ var entity = {
118
+ type: 'configuration/entityTypes/HCP',
119
+ uri: 'entities/uri_e',
120
+ attributes: {
121
+ Category1: [
122
+ {
123
+ uri: 'entities/uri_e/attributes/uri1',
124
+ value: 'category1_value1_diff'
125
+ }
126
+ ],
127
+ Category2: [
128
+ {
129
+ uri: 'entities/uri_e/attributes/uri2',
130
+ value: 'category2_value1_diff'
131
+ }
132
+ ],
133
+ Category3: [
134
+ {
135
+ uri: 'entities/uri_e/attributes/uri3',
136
+ value: 'category3_value1'
137
+ }
138
+ ],
139
+ Category4: [
140
+ {
141
+ uri: 'entities/uri_e/attributes/uri4',
142
+ value: 'category4_value1'
143
+ }
144
+ ]
145
+ }
146
+ };
147
+ useMdmEntity.mockReturnValue(entity);
148
+ setUp();
149
+ expect(updateHiddenAttributes).toHaveBeenCalledWith(entity.uri, [
150
+ 'configuration/entityTypes/HCP/attributes/Category3',
151
+ 'configuration/entityTypes/HCP/attributes/Category4',
152
+ 'configuration/entityTypes/HCP/attributes/Category2'
153
+ ]);
154
+ });
155
+ it('should not hide attributes if there is a satisfied dynamic rule', function () {
156
+ var entity = {
157
+ type: 'configuration/entityTypes/HCP',
158
+ uri: 'entities/uri_e',
159
+ attributes: {
160
+ Category1: [
161
+ {
162
+ uri: 'entities/uri_e/attributes/uri1',
163
+ value: 'category1_value1'
164
+ }
165
+ ],
166
+ Category2: [
167
+ {
168
+ uri: 'entities/uri_e/attributes/uri2',
169
+ value: 'category2_value1'
170
+ }
171
+ ],
172
+ Category3: [
173
+ {
174
+ uri: 'entities/uri_e/attributes/uri3',
175
+ value: 'category3_value1'
176
+ }
177
+ ],
178
+ Category4: [
179
+ {
180
+ uri: 'entities/uri_e/attributes/uri4',
181
+ value: 'category4_value1'
182
+ }
183
+ ]
184
+ }
185
+ };
186
+ useMdmEntity.mockReturnValue(entity);
187
+ setUp();
188
+ expect(updateHiddenAttributes).toHaveBeenCalledWith(entity.uri, []);
189
+ });
190
+ it('should not hide attributes if at least one rule allows to show the attribute from showAttributeURI', function () {
191
+ var entity = {
192
+ type: 'configuration/entityTypes/HCP',
193
+ uri: 'entities/uri_e',
194
+ attributes: {
195
+ Category1: [
196
+ {
197
+ uri: 'entities/uri_e/attributes/uri1',
198
+ value: 'category1_value2'
199
+ }
200
+ ],
201
+ Category4: [
202
+ {
203
+ uri: 'entities/uri_e/attributes/uri4',
204
+ value: 'category4_value1'
205
+ }
206
+ ]
207
+ }
208
+ };
209
+ var newMetadata = {
210
+ entityTypes: [
211
+ __assign(__assign({}, metadata.entityTypes[0]), { ruleBasedAttributes: [
212
+ metadata.entityTypes[0].ruleBasedAttributes[0],
213
+ metadata.entityTypes[0].ruleBasedAttributes[2]
214
+ ] })
215
+ ]
216
+ };
217
+ useMdmMetadata.mockReturnValue(newMetadata);
218
+ useMdmEntity.mockReturnValue(entity);
219
+ setUp();
220
+ expect(updateHiddenAttributes).toHaveBeenCalledWith(entity.uri, [
221
+ 'configuration/entityTypes/HCP/attributes/Category3'
222
+ ]);
223
+ });
224
+ it('should hide nested attributes if there are no rules allow to show the attribute from showAttributeURI', function () {
225
+ var entity = {
226
+ type: 'configuration/entityTypes/HCP',
227
+ uri: 'entities/uri_e',
228
+ attributes: {
229
+ Nested1: [
230
+ {
231
+ uri: 'entities/uri_e/attributes/nesteduri1',
232
+ value: {
233
+ NestedCategory1: [
234
+ {
235
+ ov: true,
236
+ uri: 'entities/uri_e/attributes/nesteduri1/attributes/nestedcaturi1',
237
+ value: 'nested_category1_value_diff'
238
+ }
239
+ ],
240
+ NestedCategory2: [
241
+ {
242
+ ov: true,
243
+ uri: 'entities/uri_e/attributes/nesteduri1/attributes/nestedcaturi2',
244
+ value: 'nested_category2_value1'
245
+ }
246
+ ]
247
+ }
248
+ }
249
+ ]
250
+ }
251
+ };
252
+ var nestedRuleBasedAttribute = {
253
+ uri: 'configuration/entityTypes/HCP/ruleBasedAttributes/DynamicRuleNested',
254
+ label: 'Dynamic Rule nested',
255
+ description: 'Dynamic Attributes Rule nested',
256
+ name: 'DynamicRuleNested',
257
+ type: 'Dynamic',
258
+ controlFunction: {
259
+ expression: "listEquals(attributes.Nested1.value.NestedCategory1, 'nested_category1_value1')",
260
+ showAttributeURI: ['configuration/entityTypes/HCP/attributes/Nested1/attributes/NestedCategory2']
261
+ }
262
+ };
263
+ var newMetadata = {
264
+ entityTypes: [
265
+ __assign(__assign({}, metadata.entityTypes[0]), { ruleBasedAttributes: [nestedRuleBasedAttribute] })
266
+ ]
267
+ };
268
+ useMdmMetadata.mockReturnValue(newMetadata);
269
+ useMdmEntity.mockReturnValue(entity);
270
+ setUp();
271
+ expect(updateHiddenAttributes).toHaveBeenCalledWith(entity.uri, [
272
+ 'configuration/entityTypes/HCP/attributes/Nested1/attributes/NestedCategory2'
273
+ ]);
274
+ });
275
+ it('should correctly show/hide attributes in edit mode while changing the entity', function () {
276
+ var entity = {
277
+ type: 'configuration/entityTypes/HCP',
278
+ uri: 'entities/uri_e',
279
+ attributes: {
280
+ Category1: [
281
+ {
282
+ uri: 'entities/uri_e/attributes/uri1',
283
+ value: 'category1_value1_diff'
284
+ }
285
+ ],
286
+ Category2: [
287
+ {
288
+ uri: 'entities/uri_e/attributes/uri2',
289
+ value: 'category2_value1_diff'
290
+ }
291
+ ],
292
+ Category3: [
293
+ {
294
+ uri: 'entities/uri_e/attributes/uri3',
295
+ value: 'category3_value1'
296
+ }
297
+ ],
298
+ Category4: [
299
+ {
300
+ uri: 'entities/uri_e/attributes/uri4',
301
+ value: 'category4_value1'
302
+ }
303
+ ]
304
+ }
305
+ };
306
+ useMdmMode.mockReturnValue(Mode.Editing);
307
+ useMdmEntity.mockReturnValue(entity);
308
+ useMdmModifiedEntity.mockReturnValue(entity);
309
+ var rerender = setUp().rerender;
310
+ expect(updateHiddenAttributes).toHaveBeenCalledWith(entity.uri, [
311
+ 'configuration/entityTypes/HCP/attributes/Category3',
312
+ 'configuration/entityTypes/HCP/attributes/Category4',
313
+ 'configuration/entityTypes/HCP/attributes/Category2'
314
+ ]);
315
+ // change the entity to satisfy the rules
316
+ var changedEntity1 = assocPath(['attributes', 'Category1'], [
317
+ {
318
+ uri: 'entities/uri_e/attributes/uri1',
319
+ value: 'category1_value1'
320
+ }
321
+ ], entity);
322
+ updateHiddenAttributes.mockClear();
323
+ useMdmModifiedEntity.mockReturnValue(changedEntity1);
324
+ rerender();
325
+ expect(updateHiddenAttributes).toHaveBeenCalledWith(entity.uri, [
326
+ 'configuration/entityTypes/HCP/attributes/Category3',
327
+ 'configuration/entityTypes/HCP/attributes/Category4'
328
+ ]);
329
+ var changedEntity2 = assocPath(['attributes', 'Category2'], [
330
+ {
331
+ uri: 'entities/uri_e/attributes/uri2',
332
+ value: 'category2_value1'
333
+ }
334
+ ], changedEntity1);
335
+ updateHiddenAttributes.mockClear();
336
+ useMdmModifiedEntity.mockReturnValue(changedEntity2);
337
+ rerender();
338
+ expect(updateHiddenAttributes).toHaveBeenCalledWith(entity.uri, []);
339
+ // change the entity to not satisfy the rules
340
+ var changedEntity3 = assocPath(['attributes', 'Category2'], [
341
+ {
342
+ uri: 'entities/uri_e/attributes/uri2',
343
+ value: 'category2_value1_diff'
344
+ }
345
+ ], changedEntity2);
346
+ updateHiddenAttributes.mockClear();
347
+ useMdmModifiedEntity.mockReturnValue(changedEntity3);
348
+ rerender();
349
+ expect(updateHiddenAttributes).toHaveBeenCalledWith(entity.uri, [
350
+ 'configuration/entityTypes/HCP/attributes/Category3',
351
+ 'configuration/entityTypes/HCP/attributes/Category4'
352
+ ]);
353
+ var changedEntity4 = assocPath(['attributes', 'Category1'], [
354
+ {
355
+ uri: 'entities/uri_e/attributes/uri1',
356
+ value: 'category1_value1_diff'
357
+ }
358
+ ], changedEntity3);
359
+ updateHiddenAttributes.mockClear();
360
+ useMdmModifiedEntity.mockReturnValue(changedEntity4);
361
+ rerender();
362
+ expect(updateHiddenAttributes).toHaveBeenCalledWith(entity.uri, [
363
+ 'configuration/entityTypes/HCP/attributes/Category3',
364
+ 'configuration/entityTypes/HCP/attributes/Category4',
365
+ 'configuration/entityTypes/HCP/attributes/Category2'
366
+ ]);
367
+ });
368
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.1850",
3
+ "version": "1.4.1851",
4
4
  "license": "SEE LICENSE IN LICENSE FILE",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -8,7 +8,7 @@
8
8
  "@fluentui/react-context-selector": "^9.1.26",
9
9
  "@react-google-maps/api": "2.7.0",
10
10
  "@react-sigma/core": "3.4.0",
11
- "@reltio/mdm-sdk": "^1.4.1798",
11
+ "@reltio/mdm-sdk": "^1.4.1799",
12
12
  "classnames": "^2.2.5",
13
13
  "d3-cloud": "^1.2.5",
14
14
  "d3-geo": "^2.0.1",