@reltio/components 1.4.1849 → 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 (81) 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/SaveSegmentDialog/SaveSegmentDialog.d.ts +8 -0
  7. package/cjs/SaveSegmentDialog/SaveSegmentDialog.js +129 -0
  8. package/cjs/SaveSegmentDialog/SaveSegmentDialog.test.d.ts +1 -0
  9. package/cjs/SaveSegmentDialog/SaveSegmentDialog.test.js +214 -0
  10. package/cjs/SaveSegmentDialog/index.d.ts +1 -0
  11. package/cjs/SaveSegmentDialog/index.js +5 -0
  12. package/cjs/SaveSegmentDialog/styles.d.ts +1 -0
  13. package/cjs/SaveSegmentDialog/styles.js +15 -0
  14. package/cjs/contexts/MdmModuleContext/context.d.ts +6 -0
  15. package/cjs/contexts/MdmModuleContext/hooks.d.ts +4 -1
  16. package/cjs/contexts/MdmModuleContext/hooks.js +5 -1
  17. package/cjs/contexts/MdmModuleContext/index.d.ts +1 -1
  18. package/cjs/contexts/MdmModuleContext/index.js +2 -1
  19. package/cjs/hooks/index.d.ts +1 -0
  20. package/cjs/hooks/index.js +3 -1
  21. package/cjs/hooks/useHiddenAttributes/helpers.d.ts +7 -0
  22. package/cjs/hooks/useHiddenAttributes/helpers.js +22 -0
  23. package/cjs/hooks/useHiddenAttributes/useChangedAttributes.d.ts +2 -0
  24. package/cjs/hooks/useHiddenAttributes/useChangedAttributes.js +37 -0
  25. package/cjs/hooks/useHiddenAttributes/useHiddenAttributes.d.ts +1 -0
  26. package/cjs/hooks/useHiddenAttributes/useHiddenAttributes.js +61 -0
  27. package/cjs/hooks/useHiddenAttributes/useHiddenAttributes.test.d.ts +1 -0
  28. package/cjs/hooks/useHiddenAttributes/useHiddenAttributes.test.js +370 -0
  29. package/cjs/hooks/useSavedSearchesRequest/index.d.ts +1 -0
  30. package/cjs/hooks/useSavedSearchesRequest/index.js +5 -0
  31. package/cjs/hooks/useSavedSearchesRequest/requests.d.ts +6 -0
  32. package/cjs/hooks/useSavedSearchesRequest/requests.js +72 -0
  33. package/cjs/hooks/useSavedSearchesRequest/useSavedSearchesRequest.d.ts +76 -0
  34. package/cjs/hooks/useSavedSearchesRequest/useSavedSearchesRequest.js +255 -0
  35. package/cjs/hooks/useSavedSearchesRequest/useSavedSearchesRequest.test.d.ts +1 -0
  36. package/cjs/hooks/useSavedSearchesRequest/useSavedSearchesRequest.test.js +743 -0
  37. package/cjs/index.d.ts +1 -0
  38. package/cjs/index.js +3 -1
  39. package/esm/EditModeAttributesList/EditModeAttributesList.js +6 -3
  40. package/esm/EditModeAttributesView/EditModeAttributesView.test.js +219 -25
  41. package/esm/ReadOnlyAttributesList/ReadOnlyAttributesList.js +4 -1
  42. package/esm/ReadOnlyAttributesView/ReadOnlyAttributesView.js +2 -10
  43. package/esm/ReadOnlyAttributesView/ReadOnlyAttributesView.test.js +114 -105
  44. package/esm/SaveSegmentDialog/SaveSegmentDialog.d.ts +8 -0
  45. package/esm/SaveSegmentDialog/SaveSegmentDialog.js +99 -0
  46. package/esm/SaveSegmentDialog/SaveSegmentDialog.test.d.ts +1 -0
  47. package/esm/SaveSegmentDialog/SaveSegmentDialog.test.js +209 -0
  48. package/esm/SaveSegmentDialog/index.d.ts +1 -0
  49. package/esm/SaveSegmentDialog/index.js +1 -0
  50. package/esm/SaveSegmentDialog/styles.d.ts +1 -0
  51. package/esm/SaveSegmentDialog/styles.js +12 -0
  52. package/esm/contexts/MdmModuleContext/context.d.ts +6 -0
  53. package/esm/contexts/MdmModuleContext/hooks.d.ts +4 -1
  54. package/esm/contexts/MdmModuleContext/hooks.js +3 -0
  55. package/esm/contexts/MdmModuleContext/index.d.ts +1 -1
  56. package/esm/contexts/MdmModuleContext/index.js +1 -1
  57. package/esm/hooks/index.d.ts +1 -0
  58. package/esm/hooks/index.js +1 -0
  59. package/esm/hooks/useHiddenAttributes/helpers.d.ts +7 -0
  60. package/esm/hooks/useHiddenAttributes/helpers.js +17 -0
  61. package/esm/hooks/useHiddenAttributes/useChangedAttributes.d.ts +2 -0
  62. package/esm/hooks/useHiddenAttributes/useChangedAttributes.js +33 -0
  63. package/esm/hooks/useHiddenAttributes/useHiddenAttributes.d.ts +1 -0
  64. package/esm/hooks/useHiddenAttributes/useHiddenAttributes.js +57 -0
  65. package/esm/hooks/useHiddenAttributes/useHiddenAttributes.test.d.ts +1 -0
  66. package/esm/hooks/useHiddenAttributes/useHiddenAttributes.test.js +368 -0
  67. package/esm/hooks/useSavedSearchesRequest/index.d.ts +1 -0
  68. package/esm/hooks/useSavedSearchesRequest/index.js +1 -0
  69. package/esm/hooks/useSavedSearchesRequest/requests.d.ts +6 -0
  70. package/esm/hooks/useSavedSearchesRequest/requests.js +68 -0
  71. package/esm/hooks/useSavedSearchesRequest/useSavedSearchesRequest.d.ts +76 -0
  72. package/esm/hooks/useSavedSearchesRequest/useSavedSearchesRequest.js +251 -0
  73. package/esm/hooks/useSavedSearchesRequest/useSavedSearchesRequest.test.d.ts +1 -0
  74. package/esm/hooks/useSavedSearchesRequest/useSavedSearchesRequest.test.js +738 -0
  75. package/esm/index.d.ts +1 -0
  76. package/esm/index.js +1 -0
  77. package/package.json +2 -2
  78. package/cjs/hooks/useSavedSearchesRequest.d.ts +0 -23
  79. package/cjs/hooks/useSavedSearchesRequest.js +0 -224
  80. package/esm/hooks/useSavedSearchesRequest.d.ts +0 -23
  81. package/esm/hooks/useSavedSearchesRequest.js +0 -220
@@ -0,0 +1,61 @@
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
+ exports.useHiddenAttributes = void 0;
15
+ var react_1 = require("react");
16
+ var ramda_1 = require("ramda");
17
+ var mdm_sdk_1 = require("@reltio/mdm-sdk");
18
+ var useChangedAttributes_1 = require("./useChangedAttributes");
19
+ var helpers_1 = require("./helpers");
20
+ var hooks_1 = require("../../contexts/MdmModuleContext/hooks");
21
+ var useHiddenAttributes = function () {
22
+ var metadata = (0, hooks_1.useMdmMetadata)();
23
+ var mdmEntity = (0, hooks_1.useMdmEntity)();
24
+ var mode = (0, hooks_1.useMdmMode)();
25
+ var modifiedEntity = (0, hooks_1.useMdmModifiedEntity)(mdmEntity === null || mdmEntity === void 0 ? void 0 : mdmEntity.uri) || {};
26
+ var entity = mode === mdm_sdk_1.Mode.Viewing ? mdmEntity : modifiedEntity;
27
+ var entityUri = entity === null || entity === void 0 ? void 0 : entity.uri;
28
+ var updateHiddenAttributes = (0, hooks_1.useMdmAction)('updateHiddenAttributes');
29
+ var resetHiddenAttributes = (0, hooks_1.useMdmAction)('resetHiddenAttributes');
30
+ var hiddenAttributes = (0, hooks_1.useMdmHiddenAttributes)(entity === null || entity === void 0 ? void 0 : entity.uri);
31
+ var ruleBasedAttributes = (0, react_1.useMemo)(function () { return (0, mdm_sdk_1.getRuleBasedAttributes)(metadata, entity === null || entity === void 0 ? void 0 : entity.type); }, [metadata, entity === null || entity === void 0 ? void 0 : entity.type]);
32
+ var parsedRuleBasedAttributes = (0, react_1.useMemo)(function () {
33
+ return ruleBasedAttributes.map(function (rule) {
34
+ var _a;
35
+ return (__assign(__assign({}, (0, mdm_sdk_1.parseRuleBasedAttribute)(rule)), { showAttributeURIs: ((_a = rule === null || rule === void 0 ? void 0 : rule.controlFunction) === null || _a === void 0 ? void 0 : _a.showAttributeURI) || [] }));
36
+ });
37
+ }, [ruleBasedAttributes]);
38
+ var controlAttributes = (0, react_1.useMemo)(function () { return (0, ramda_1.pipe)((0, ramda_1.pluck)('controlAttributes'), ramda_1.flatten, ramda_1.uniq)(parsedRuleBasedAttributes); }, [parsedRuleBasedAttributes]);
39
+ var changedAttributes = (0, useChangedAttributes_1.useChangedAttributes)(entity === null || entity === void 0 ? void 0 : entity.attributes, controlAttributes);
40
+ var showAttributeURIs = (0, react_1.useMemo)(function () {
41
+ return changedAttributes.length ? (0, helpers_1.findShowAttributeURIs)(changedAttributes, parsedRuleBasedAttributes) : [];
42
+ }, [parsedRuleBasedAttributes, changedAttributes]);
43
+ var rulesToCheck = (0, react_1.useMemo)(function () {
44
+ return showAttributeURIs.length ? (0, helpers_1.findRulesToCheck)(showAttributeURIs, parsedRuleBasedAttributes) : [];
45
+ }, [parsedRuleBasedAttributes, showAttributeURIs]);
46
+ var addedHiddenAttributes = (0, react_1.useMemo)(function () {
47
+ return rulesToCheck.length
48
+ ? rulesToCheck.reduce(function (hiddenAttributes, _a) {
49
+ var checkFn = _a.checkFn, showAttributeURIs = _a.showAttributeURIs;
50
+ return checkFn(entity) ? (0, ramda_1.without)(showAttributeURIs, hiddenAttributes) : hiddenAttributes;
51
+ }, showAttributeURIs)
52
+ : [];
53
+ }, [rulesToCheck, entity, showAttributeURIs]);
54
+ (0, react_1.useEffect)(function () {
55
+ if (entityUri && (addedHiddenAttributes.length || showAttributeURIs.length)) {
56
+ updateHiddenAttributes(entityUri, (0, ramda_1.without)(showAttributeURIs, hiddenAttributes).concat(addedHiddenAttributes));
57
+ }
58
+ }, [addedHiddenAttributes, showAttributeURIs, entityUri]);
59
+ (0, react_1.useEffect)(function () { return function () { return resetHiddenAttributes(entityUri); }; }, [entityUri]);
60
+ };
61
+ exports.useHiddenAttributes = useHiddenAttributes;
@@ -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
+ });
@@ -0,0 +1 @@
1
+ export { useSavedSearchesRequest } from './useSavedSearchesRequest';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSavedSearchesRequest = void 0;
4
+ var useSavedSearchesRequest_1 = require("./useSavedSearchesRequest");
5
+ Object.defineProperty(exports, "useSavedSearchesRequest", { enumerable: true, get: function () { return useSavedSearchesRequest_1.useSavedSearchesRequest; } });
@@ -0,0 +1,6 @@
1
+ import { SavedSearchData } from '@reltio/mdm-sdk';
2
+ export declare const getTotalsForSavedSearches: (savedSearches: SavedSearchData[], queryEstimatorEnabled: boolean, signal: AbortSignal) => Promise<{
3
+ [k: string]: {
4
+ readonly count: number;
5
+ };
6
+ }>;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getTotalsForSavedSearches = void 0;
40
+ var mdm_sdk_1 = require("@reltio/mdm-sdk");
41
+ var getTotalsForSavedSearches = function (savedSearches, queryEstimatorEnabled, signal) { return __awaiter(void 0, void 0, void 0, function () {
42
+ var totalRequests, totalResults, entries;
43
+ return __generator(this, function (_a) {
44
+ switch (_a.label) {
45
+ case 0:
46
+ totalRequests = savedSearches.map(function (search) {
47
+ return (0, mdm_sdk_1.getTotalsForQuery)((0, mdm_sdk_1.replacePlaceholdersInQuery)(search.query), queryEstimatorEnabled, signal);
48
+ });
49
+ return [4 /*yield*/, (0, mdm_sdk_1.promiseAllSettled)(totalRequests)];
50
+ case 1:
51
+ totalResults = _a.sent();
52
+ entries = totalResults
53
+ .map(function (_a, index) {
54
+ var status = _a.status, value = _a.value, reason = _a.reason;
55
+ switch (status) {
56
+ case 'fulfilled': {
57
+ var uri = savedSearches[index].uri;
58
+ return [uri, { count: value.total }];
59
+ }
60
+ case 'rejected': {
61
+ console.warn(reason);
62
+ return null;
63
+ }
64
+ }
65
+ return null;
66
+ })
67
+ .filter(Boolean);
68
+ return [2 /*return*/, Object.fromEntries(entries)];
69
+ }
70
+ });
71
+ }); };
72
+ exports.getTotalsForSavedSearches = getTotalsForSavedSearches;
@@ -0,0 +1,76 @@
1
+ /// <reference types="react" />
2
+ import { SavedSearchData, SavedSearchesOptions } from '@reltio/mdm-sdk';
3
+ import { RequestStates } from '../../types';
4
+ type RequestsStates = {
5
+ loading: RequestStates;
6
+ creating: RequestStates;
7
+ updating: RequestStates;
8
+ deleting: RequestStates;
9
+ };
10
+ type Props = {
11
+ options?: SavedSearchesOptions;
12
+ defaultRowsPerPage: number;
13
+ queryEstimatorEnabled?: boolean;
14
+ };
15
+ export declare const useSavedSearchesRequest: ({ options, defaultRowsPerPage, queryEstimatorEnabled }: Props) => {
16
+ states: RequestsStates;
17
+ data: {
18
+ uri: string;
19
+ name: string;
20
+ description?: string;
21
+ query: string;
22
+ isFavorite: boolean;
23
+ uiState: Record<string, any>;
24
+ createDate: number;
25
+ updateDate: number;
26
+ isPublic: boolean;
27
+ count: number;
28
+ owner: string;
29
+ type: import("@reltio/mdm-sdk").SavedSearchType;
30
+ isLoadingTotal?: boolean;
31
+ }[];
32
+ total: number;
33
+ page: number;
34
+ rowsPerPage: number;
35
+ updatePage: import("react").Dispatch<import("react").SetStateAction<number>>;
36
+ updateRowsPerPage: import("react").Dispatch<import("react").SetStateAction<number>>;
37
+ reload: () => Promise<void>;
38
+ loadTotalForSearchByUri: (uri: string) => Promise<void>;
39
+ createSearch: (savedSearch: Partial<SavedSearchData> & {
40
+ name: string;
41
+ query: string;
42
+ uiState: Record<string, any>;
43
+ }) => Promise<{
44
+ readonly success: true;
45
+ readonly result: SavedSearchData;
46
+ error?: undefined;
47
+ } | {
48
+ readonly success: false;
49
+ readonly error: any;
50
+ readonly result?: undefined;
51
+ }>;
52
+ updateSearch: (savedSearch: SavedSearchData) => Promise<{
53
+ success: boolean;
54
+ result: SavedSearchData;
55
+ error?: undefined;
56
+ } | {
57
+ success: boolean;
58
+ error: any;
59
+ readonly result?: undefined;
60
+ }>;
61
+ deleteSearch: (uri: string) => Promise<{
62
+ success: boolean;
63
+ result: {
64
+ success: true;
65
+ } | {
66
+ success: false;
67
+ error: unknown;
68
+ };
69
+ error?: undefined;
70
+ } | {
71
+ success: boolean;
72
+ error: any;
73
+ readonly result?: undefined;
74
+ }>;
75
+ };
76
+ export {};