@reltio/components 1.4.2207 → 1.4.2209

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 (77) hide show
  1. package/AttributesErrorsPanel/components/Error/Error.js +2 -2
  2. package/cjs/AttributesErrorsPanel/components/Error/Error.js +2 -2
  3. package/cjs/contexts/MdmModuleContext/context.d.ts +2 -0
  4. package/cjs/contexts/MdmModuleContext/hooks.d.ts +1 -0
  5. package/cjs/contexts/MdmModuleContext/hooks.js +3 -1
  6. package/cjs/contexts/MdmModuleContext/index.d.ts +1 -1
  7. package/cjs/contexts/MdmModuleContext/index.js +2 -1
  8. package/cjs/features/workflow/ChangeRequestEditor/ChangeRequestEditor.js +1 -2
  9. package/cjs/features/workflow/ChangeRequestEditor/components/ChangeItemEditor/ChangeItemEditor.js +2 -1
  10. package/cjs/features/workflow/ChangeRequestEditor/components/ChangeItemLabel/ChangeItemLabel.js +8 -3
  11. package/cjs/features/workflow/ChangeRequestEditor/components/ChangeItemRow/ChangeItemRow.js +49 -8
  12. package/cjs/features/workflow/ChangeRequestEditor/components/ChangeItemRow/ChangeItemRow.module.css.js +2 -2
  13. package/cjs/features/workflow/ChangeRequestEditor/components/DCRValueEditor/DCRValueEditor.d.ts +1 -1
  14. package/cjs/features/workflow/ChangeRequestEditor/components/DCRValueEditorFactory/DCRValueEditorFactory.d.ts +1 -1
  15. package/cjs/features/workflow/ChangeRequestEditor/hooks/useChangeRequestEditor.d.ts +2 -1
  16. package/cjs/features/workflow/ChangeRequestEditor/hooks/useChangeRequestEditor.js +14 -8
  17. package/cjs/features/workflow/ReviewDCRDialog/DCRErrorsPanel/DCRErrorsPanel.d.ts +2 -0
  18. package/cjs/features/workflow/ReviewDCRDialog/DCRErrorsPanel/DCRErrorsPanel.js +44 -0
  19. package/cjs/features/workflow/ReviewDCRDialog/DCRErrorsPanel/DCRErrorsPanel.module.css.js +9 -0
  20. package/cjs/features/workflow/ReviewDCRDialog/ReviewDCRDialog.js +12 -7
  21. package/cjs/features/workflow/TaskActionButtons/TaskActionButtons.js +6 -4
  22. package/cjs/features/workflow/WorkflowTaskCard/components/DataChangeRequestTaskCard/DataChangeRequestTaskCard.js +10 -3
  23. package/cjs/features/workflow/WorkflowTaskCard/components/GenericWorkflowTaskCard/GenericWorkflowTaskCard.js +6 -4
  24. package/cjs/features/workflow/{ChangeRequestEditor/context → contexts/ChangeRequestEditorContext}/index.d.ts +20 -10
  25. package/cjs/features/workflow/{ChangeRequestEditor/context → contexts/ChangeRequestEditorContext}/index.js +40 -2
  26. package/cjs/features/workflow/helpers/dcr.d.ts +8 -1
  27. package/cjs/features/workflow/helpers/dcr.js +186 -1
  28. package/cjs/features/workflow/helpers/merge.js +3 -3
  29. package/cjs/features/workflow/helpers/validation.d.ts +17 -0
  30. package/cjs/features/workflow/helpers/validation.js +333 -0
  31. package/cjs/features/workflow/hooks/useApplyDcrChanges.d.ts +3 -0
  32. package/cjs/features/workflow/hooks/useApplyDcrChanges.js +155 -0
  33. package/cjs/features/workflow/hooks/useDCRValidation.d.ts +5 -0
  34. package/cjs/features/workflow/hooks/useDCRValidation.js +153 -0
  35. package/cjs/features/workflow/hooks/useWorkflowActions.d.ts +7 -2
  36. package/cjs/features/workflow/hooks/useWorkflowActions.js +31 -8
  37. package/cjs/features/workflow/types.d.ts +12 -1
  38. package/cjs/hooks/useScrollToAttributeError/useScrollToAttributeError.d.ts +2 -1
  39. package/cjs/hooks/useScrollToAttributeError/useScrollToAttributeError.js +2 -2
  40. package/contexts/MdmModuleContext/context.d.ts +2 -0
  41. package/contexts/MdmModuleContext/hooks.d.ts +1 -0
  42. package/contexts/MdmModuleContext/hooks.js +1 -0
  43. package/contexts/MdmModuleContext/index.d.ts +1 -1
  44. package/contexts/MdmModuleContext/index.js +1 -1
  45. package/features/workflow/ChangeRequestEditor/ChangeRequestEditor.js +1 -2
  46. package/features/workflow/ChangeRequestEditor/components/ChangeItemEditor/ChangeItemEditor.js +2 -1
  47. package/features/workflow/ChangeRequestEditor/components/ChangeItemLabel/ChangeItemLabel.js +8 -3
  48. package/features/workflow/ChangeRequestEditor/components/ChangeItemRow/ChangeItemRow.js +23 -5
  49. package/features/workflow/ChangeRequestEditor/components/ChangeItemRow/ChangeItemRow.module.css.js +2 -2
  50. package/features/workflow/ChangeRequestEditor/components/DCRValueEditor/DCRValueEditor.d.ts +1 -1
  51. package/features/workflow/ChangeRequestEditor/components/DCRValueEditorFactory/DCRValueEditorFactory.d.ts +1 -1
  52. package/features/workflow/ChangeRequestEditor/hooks/useChangeRequestEditor.d.ts +2 -1
  53. package/features/workflow/ChangeRequestEditor/hooks/useChangeRequestEditor.js +8 -2
  54. package/features/workflow/ReviewDCRDialog/DCRErrorsPanel/DCRErrorsPanel.d.ts +2 -0
  55. package/features/workflow/ReviewDCRDialog/DCRErrorsPanel/DCRErrorsPanel.js +14 -0
  56. package/features/workflow/ReviewDCRDialog/DCRErrorsPanel/DCRErrorsPanel.module.css.js +9 -0
  57. package/features/workflow/ReviewDCRDialog/ReviewDCRDialog.js +12 -7
  58. package/features/workflow/TaskActionButtons/TaskActionButtons.js +6 -4
  59. package/features/workflow/WorkflowTaskCard/components/DataChangeRequestTaskCard/DataChangeRequestTaskCard.js +11 -4
  60. package/features/workflow/WorkflowTaskCard/components/GenericWorkflowTaskCard/GenericWorkflowTaskCard.js +6 -4
  61. package/features/workflow/{ChangeRequestEditor/context → contexts/ChangeRequestEditorContext}/index.d.ts +20 -10
  62. package/features/workflow/{ChangeRequestEditor/context → contexts/ChangeRequestEditorContext}/index.js +41 -3
  63. package/features/workflow/helpers/dcr.d.ts +8 -1
  64. package/features/workflow/helpers/dcr.js +186 -2
  65. package/features/workflow/helpers/merge.js +3 -3
  66. package/features/workflow/helpers/validation.d.ts +17 -0
  67. package/features/workflow/helpers/validation.js +326 -0
  68. package/features/workflow/hooks/useApplyDcrChanges.d.ts +3 -0
  69. package/features/workflow/hooks/useApplyDcrChanges.js +151 -0
  70. package/features/workflow/hooks/useDCRValidation.d.ts +5 -0
  71. package/features/workflow/hooks/useDCRValidation.js +149 -0
  72. package/features/workflow/hooks/useWorkflowActions.d.ts +7 -2
  73. package/features/workflow/hooks/useWorkflowActions.js +31 -8
  74. package/features/workflow/types.d.ts +12 -1
  75. package/hooks/useScrollToAttributeError/useScrollToAttributeError.d.ts +2 -1
  76. package/hooks/useScrollToAttributeError/useScrollToAttributeError.js +2 -2
  77. package/package.json +2 -2
@@ -0,0 +1,326 @@
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
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
21
+ import { clone } from 'ramda';
22
+ import i18n from 'ui-i18n';
23
+ import { findAttributeTypeByUri, DCRTypes, getRequiredAttributeTypesByTypeUri, buildError, ErrorType, getParentUri, findAttributeValuesByTypeUri, isEmptyValue, isOv, isIgnored, ErrorSource, evaluateErrorPath, isReference } from '@reltio/mdm-sdk';
24
+ var ALLOWED_CHANGE_TYPES = [
25
+ DCRTypes.UPDATE_ATTRIBUTE,
26
+ DCRTypes.INSERT_ATTRIBUTE,
27
+ DCRTypes.DELETE_ATTRIBUTE,
28
+ DCRTypes.IGNORE_ATTRIBUTE
29
+ ];
30
+ export var getValidationErrors = function (_a) {
31
+ var changes = _a.changes, userChanges = _a.userChanges, entitiesOrRelations = _a.entitiesOrRelations, metadata = _a.metadata;
32
+ var _b = validateTopLevelAttributes({
33
+ changes: changes,
34
+ userChanges: userChanges,
35
+ entitiesOrRelations: entitiesOrRelations,
36
+ metadata: metadata
37
+ }), topLevelErrors = _b.errors, topRejectedChangeIds = _b.topRejectedChangeIds;
38
+ var complexErrors = validateComplexAttributes({ changes: changes, userChanges: userChanges, metadata: metadata, topRejectedChangeIds: topRejectedChangeIds });
39
+ return __spreadArray(__spreadArray([], topLevelErrors, true), complexErrors, true);
40
+ };
41
+ var validateTopLevelAttributes = function (_a) {
42
+ var changes = _a.changes, userChanges = _a.userChanges, entitiesOrRelations = _a.entitiesOrRelations, metadata = _a.metadata;
43
+ var errors = [];
44
+ var topRejectedChangeIds = [];
45
+ var _loop_1 = function (entityUri) {
46
+ var entityOrRelation = entitiesOrRelations[entityUri];
47
+ var objectChanges = changes[entityUri] || [];
48
+ var requiredAttributeUris = getRequiredAttributeUris(metadata, entityOrRelation.type);
49
+ var changesByAttributePath = {};
50
+ objectChanges.forEach(function (change) {
51
+ var _a;
52
+ var attributeTypeUri = change.refAttributeType || change.attributeType;
53
+ if (!change.type ||
54
+ !ALLOWED_CHANGE_TYPES.includes(change.type) ||
55
+ !requiredAttributeUris.includes(change.attributeType || '')) {
56
+ return;
57
+ }
58
+ var foundUserChanges = getTopLevelUserChangesByChangeId(userChanges, change.id);
59
+ foundUserChanges.forEach(function (userChange) {
60
+ if (userChange.data.isRejected) {
61
+ topRejectedChangeIds.push(change.id);
62
+ }
63
+ });
64
+ var hasUserChanges = foundUserChanges.length > 0;
65
+ var adjustedChange = adjustChangeWithUserChanges(change, foundUserChanges);
66
+ var currentAttributePath = getCurrentAttributePath(change.attributePath);
67
+ if (!changesByAttributePath[currentAttributePath]) {
68
+ var objectValues = findAttributeValuesByTypeUri(metadata, entityOrRelation, attributeTypeUri);
69
+ changesByAttributePath[currentAttributePath] = {
70
+ changes: [],
71
+ objectValues: objectValues,
72
+ attributeTypeUri: attributeTypeUri,
73
+ attributeType: findAttributeTypeByUri(metadata, attributeTypeUri),
74
+ parentUri: getParentUri(change.attributePath),
75
+ lineIds: []
76
+ };
77
+ }
78
+ if (adjustedChange) {
79
+ changesByAttributePath[currentAttributePath].changes.push(adjustedChange);
80
+ }
81
+ if (hasUserChanges) {
82
+ changesByAttributePath[currentAttributePath].hasUserChanges = true;
83
+ }
84
+ (_a = changesByAttributePath[currentAttributePath].lineIds).push.apply(_a, foundUserChanges.map(function (userChange) { return userChange.lineId; }));
85
+ });
86
+ Object.values(changesByAttributePath).forEach(function (_a) {
87
+ var _b;
88
+ var hasUserChanges = _a.hasUserChanges, objectValues = _a.objectValues, attributeChanges = _a.changes, attributeTypeUri = _a.attributeTypeUri, attributeType = _a.attributeType, parentUri = _a.parentUri, lineIds = _a.lineIds;
89
+ if (hasUserChanges && !hasAttributeValue(objectValues, attributeChanges, entityUri)) {
90
+ var valueUri = (_b = objectValues === null || objectValues === void 0 ? void 0 : objectValues[0]) === null || _b === void 0 ? void 0 : _b.uri;
91
+ errors.push(createRequiredError({
92
+ attributeType: attributeType,
93
+ attributeTypeUri: attributeTypeUri,
94
+ parentUri: parentUri,
95
+ lineIds: lineIds,
96
+ metadata: metadata,
97
+ entityUri: entityUri,
98
+ entitiesMap: entitiesOrRelations,
99
+ valueUri: valueUri
100
+ }));
101
+ }
102
+ });
103
+ };
104
+ for (var entityUri in entitiesOrRelations) {
105
+ _loop_1(entityUri);
106
+ }
107
+ return { errors: errors, topRejectedChangeIds: topRejectedChangeIds };
108
+ };
109
+ var validateComplexAttributes = function (_a) {
110
+ var changes = _a.changes, userChanges = _a.userChanges, metadata = _a.metadata, _b = _a.topRejectedChangeIds, topRejectedChangeIds = _b === void 0 ? [] : _b;
111
+ var errors = [];
112
+ var _loop_2 = function (entityUri) {
113
+ var objectChanges = changes[entityUri] || [];
114
+ objectChanges.forEach(function (change) {
115
+ var _a, _b, _c, _d;
116
+ if (topRejectedChangeIds.includes(change.id)) {
117
+ return;
118
+ }
119
+ var hasComplexValue = (typeof ((_a = change.newValue) === null || _a === void 0 ? void 0 : _a.value) === 'object' &&
120
+ !Array.isArray((_b = change.newValue) === null || _b === void 0 ? void 0 : _b.value)) ||
121
+ (typeof ((_c = change.oldValue) === null || _c === void 0 ? void 0 : _c.value) === 'object' &&
122
+ !Array.isArray((_d = change.oldValue) === null || _d === void 0 ? void 0 : _d.value));
123
+ var isCreateType = change.type === DCRTypes.CREATE_ENTITY || change.type === DCRTypes.CREATE_RELATIONSHIP;
124
+ if (!hasComplexValue && !isCreateType) {
125
+ return;
126
+ }
127
+ var foundUserChanges = getUserChangesByChangeId(userChanges, change.id);
128
+ var complexErrors = validateRequiredComplexAttributes({
129
+ metadata: metadata,
130
+ change: change,
131
+ userChanges: foundUserChanges,
132
+ entityUri: entityUri
133
+ });
134
+ errors.push.apply(errors, complexErrors);
135
+ });
136
+ };
137
+ for (var entityUri in changes) {
138
+ _loop_2(entityUri);
139
+ }
140
+ return errors;
141
+ };
142
+ var getTopLevelUserChangesByChangeId = function (userChanges, changeId) {
143
+ return getUserChangesByChangeId(userChanges, changeId).filter(function (userChange) { return userChange.lineId.split('/').length === 3; });
144
+ };
145
+ var getUserChangesByChangeId = function (userChanges, changeId) {
146
+ return userChanges.filter(function (userChange) { return userChange.lineId.split('/')[1] === changeId; });
147
+ };
148
+ var getIsChangeRejected = function (userChanges, changeType) {
149
+ if (userChanges.length === 0)
150
+ return false;
151
+ var isInsertType = changeType === DCRTypes.INSERT_ATTRIBUTE;
152
+ return userChanges.some(function (userChange) { var _a; return userChange.data.isRejected || (isInsertType && isEmptyValue((_a = userChange.data.value) === null || _a === void 0 ? void 0 : _a.value)); });
153
+ };
154
+ var adjustChangeWithUserChanges = function (change, userChanges) {
155
+ var _a;
156
+ if (getIsChangeRejected(userChanges, change.type)) {
157
+ return null;
158
+ }
159
+ if (change.type === DCRTypes.UPDATE_ATTRIBUTE && userChanges.length > 0) {
160
+ if (isEmptyValue((_a = userChanges[0].data.value) === null || _a === void 0 ? void 0 : _a.value)) {
161
+ return __assign(__assign({}, change), { type: DCRTypes.DELETE_ATTRIBUTE });
162
+ }
163
+ }
164
+ return change;
165
+ };
166
+ var getCurrentAttributePath = function (attributePath) {
167
+ var parts = attributePath.split('/');
168
+ return parts.slice(0, parts.length % 2 === 0 ? parts.length - 1 : parts.length).join('/');
169
+ };
170
+ var getEntityValueUri = function (entityOrRelationTypeUri, change) {
171
+ if (change.refObjectURI) {
172
+ var relationId = change.refObjectURI.split('/').pop();
173
+ var refAttributeTypeParts = change.refAttributeType.split('/attributes/');
174
+ return "".concat(entityOrRelationTypeUri, "/attributes/").concat(refAttributeTypeParts[1], "/").concat(relationId, "/").concat(change.attributePath);
175
+ }
176
+ return "".concat(entityOrRelationTypeUri, "/attributes/").concat(change.attributePath);
177
+ };
178
+ var hasAttributeValue = function (objectValues, changes, entityUri) {
179
+ var values = clone(objectValues);
180
+ var _loop_3 = function (change) {
181
+ if (change.type === DCRTypes.UPDATE_ATTRIBUTE || change.type === DCRTypes.INSERT_ATTRIBUTE) {
182
+ return { value: true };
183
+ }
184
+ var valueUri = getEntityValueUri(entityUri, change);
185
+ var valueIndex = values.findIndex(function (value) { return value.uri === valueUri; });
186
+ if (change.type === DCRTypes.DELETE_ATTRIBUTE) {
187
+ if (valueIndex !== -1) {
188
+ values.splice(valueIndex, 1);
189
+ }
190
+ }
191
+ else if (change.type === DCRTypes.IGNORE_ATTRIBUTE && valueIndex !== -1) {
192
+ values[valueIndex].ignored = change.newPinOrIgnoreValue;
193
+ }
194
+ };
195
+ for (var _i = 0, changes_1 = changes; _i < changes_1.length; _i++) {
196
+ var change = changes_1[_i];
197
+ var state_1 = _loop_3(change);
198
+ if (typeof state_1 === "object")
199
+ return state_1.value;
200
+ }
201
+ return values.filter(isOv).filter(function (value) { return !isIgnored(value); }).length > 0;
202
+ };
203
+ var getEntityTypeUriFromAttributeUri = function (attributeUri) {
204
+ return attributeUri.split('/').slice(0, 3).join('/');
205
+ };
206
+ var getAttributeTypeUriFromLineId = function (attributeTypeUri, lineId) {
207
+ var EXCLUDED_PARTS = new Set(['value', 'newValue', 'oldValue', 'attributes']);
208
+ var lineParts = lineId
209
+ .split('/')
210
+ .slice(2)
211
+ .filter(function (part) {
212
+ if (!isNaN(Number(part)))
213
+ return false;
214
+ return !EXCLUDED_PARTS.has(part);
215
+ });
216
+ return __spreadArray([attributeTypeUri], lineParts, true).join('/attributes/');
217
+ };
218
+ var getEntityTypeUriFromChange = function (change) {
219
+ if (change.type === DCRTypes.CREATE_ENTITY || change.type === DCRTypes.CREATE_RELATIONSHIP) {
220
+ return change.objectType || '';
221
+ }
222
+ return getEntityTypeUriFromAttributeUri(change.attributeType || change.objectType || '');
223
+ };
224
+ var getRequiredAttributeUris = function (metadata, typeUri) {
225
+ var requiredAttrTypes = getRequiredAttributeTypesByTypeUri(metadata, typeUri, true) || [];
226
+ return requiredAttrTypes.map(function (attr) { return attr.uri; });
227
+ };
228
+ var createRequiredError = function (_a) {
229
+ var attributeType = _a.attributeType, attributeTypeUri = _a.attributeTypeUri, parentUri = _a.parentUri, lineIds = _a.lineIds, metadata = _a.metadata, entityUri = _a.entityUri, entitiesMap = _a.entitiesMap, valueUri = _a.valueUri;
230
+ var error = buildError({
231
+ type: ErrorType.missed,
232
+ attributeType: attributeType,
233
+ attributeTypeUri: attributeTypeUri,
234
+ parentUri: parentUri,
235
+ message: i18n.text('Attribute is required'),
236
+ source: ErrorSource.local,
237
+ alwaysShow: true,
238
+ uri: lineIds[0]
239
+ });
240
+ var path = [];
241
+ if ((entitiesMap === null || entitiesMap === void 0 ? void 0 : entitiesMap[entityUri]) && valueUri) {
242
+ path = evaluateErrorPath({
243
+ entityUri: entityUri,
244
+ metadata: metadata,
245
+ entitiesMap: entitiesMap
246
+ }, valueUri);
247
+ }
248
+ return {
249
+ error: __assign(__assign({}, error), { path: path }),
250
+ lineIds: lineIds
251
+ };
252
+ };
253
+ var validateRequiredComplexAttributes = function (_a) {
254
+ var _b;
255
+ var metadata = _a.metadata, change = _a.change, userChanges = _a.userChanges, entityUri = _a.entityUri;
256
+ if (userChanges.length === 0 || change.type === DCRTypes.DELETE_ATTRIBUTE) {
257
+ return [];
258
+ }
259
+ var valueHolder = change.type === DCRTypes.CREATE_ENTITY || change.type === DCRTypes.CREATE_RELATIONSHIP ? 'attributes' : 'value';
260
+ var rootAttributeTypeUri = change.refAttributeType || change.attributeType || change.objectType;
261
+ var attributeType = findAttributeTypeByUri(metadata, rootAttributeTypeUri);
262
+ var isReferenceType = isReference(attributeType);
263
+ var entityTypeUri = isReferenceType ? attributeType.relationshipTypeURI : getEntityTypeUriFromChange(change);
264
+ var requiredAttributeUris = getRequiredAttributeUris(metadata, entityTypeUri);
265
+ var calculateLineIdFromPath = function (path) {
266
+ if (path === void 0) { path = ''; }
267
+ var entityId = entityUri.split('/').pop() || '';
268
+ return "".concat(entityId, "/").concat(change.id, "/newValue").concat(path ? "/".concat(path) : '');
269
+ };
270
+ var checkIsChangeRejected = function (path) {
271
+ var _a, _b, _c;
272
+ var searchLineId = calculateLineIdFromPath(path);
273
+ var lineUserChanges = userChanges.find(function (userChange) { return userChange.lineId === searchLineId; });
274
+ return (((_a = lineUserChanges === null || lineUserChanges === void 0 ? void 0 : lineUserChanges.data) === null || _a === void 0 ? void 0 : _a.isRejected) || (lineUserChanges && isEmptyValue((_c = (_b = lineUserChanges === null || lineUserChanges === void 0 ? void 0 : lineUserChanges.data) === null || _b === void 0 ? void 0 : _b.value) === null || _c === void 0 ? void 0 : _c.value)));
275
+ };
276
+ var collectErrors = function (attributes) {
277
+ var errors = [];
278
+ var visitValue = function (value, path) {
279
+ var isRejected = checkIsChangeRejected(path.slice(0, -1).join('/'));
280
+ if (typeof value === 'string') {
281
+ return !isRejected;
282
+ }
283
+ if (isRejected) {
284
+ return false;
285
+ }
286
+ var anyFieldHasValue = false;
287
+ Object.entries(value).forEach(function (_a) {
288
+ var fieldName = _a[0], subAttributes = _a[1];
289
+ var anyChildHasValue = false;
290
+ var attributePath = __spreadArray(__spreadArray([], path, true), [fieldName], false);
291
+ var rejectedLineIds = [];
292
+ subAttributes.forEach(function (subAttribute, index) {
293
+ var childPath = __spreadArray(__spreadArray([], attributePath, true), [index, 'value'], false);
294
+ var childHasValue = visitValue(subAttribute.value, childPath);
295
+ if (!childHasValue) {
296
+ rejectedLineIds.push(calculateLineIdFromPath(childPath.slice(0, -1).join('/')));
297
+ }
298
+ anyChildHasValue = anyChildHasValue || childHasValue;
299
+ });
300
+ anyFieldHasValue = anyFieldHasValue || anyChildHasValue;
301
+ if (!anyChildHasValue) {
302
+ var attributeTypeUri = getAttributeTypeUriFromLineId(isReferenceType ? entityTypeUri : rootAttributeTypeUri, rejectedLineIds[0]);
303
+ var isRequired = requiredAttributeUris.includes(attributeTypeUri);
304
+ if (isRequired) {
305
+ errors.push(createRequiredError({
306
+ attributeType: findAttributeTypeByUri(metadata, attributeTypeUri),
307
+ attributeTypeUri: attributeTypeUri,
308
+ lineIds: rejectedLineIds
309
+ }));
310
+ }
311
+ }
312
+ });
313
+ return anyFieldHasValue;
314
+ };
315
+ var hasValue = visitValue(attributes, [valueHolder]);
316
+ if (!hasValue && attributeType.required) {
317
+ errors.push(createRequiredError({
318
+ attributeType: attributeType,
319
+ attributeTypeUri: attributeType.uri,
320
+ lineIds: [calculateLineIdFromPath()]
321
+ }));
322
+ }
323
+ return errors;
324
+ };
325
+ return collectErrors((_b = change.newValue) === null || _b === void 0 ? void 0 : _b[valueHolder]);
326
+ };
@@ -0,0 +1,3 @@
1
+ import { ChangeRequest } from '@reltio/mdm-sdk';
2
+ import { BeforeActionOutcome } from '../types';
3
+ export declare const useApplyDcrChanges: (dcr: ChangeRequest) => () => Promise<BeforeActionOutcome>;
@@ -0,0 +1,151 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __generator = (this && this.__generator) || function (thisArg, body) {
11
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13
+ function verb(n) { return function (v) { return step([n, v]); }; }
14
+ function step(op) {
15
+ if (f) throw new TypeError("Generator is already executing.");
16
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
17
+ 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;
18
+ if (y = 0, t) op = [op[0] & 2, t.value];
19
+ switch (op[0]) {
20
+ case 0: case 1: t = op; break;
21
+ case 4: _.label++; return { value: op[1], done: false };
22
+ case 5: _.label++; y = op[1]; op = [0]; continue;
23
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
24
+ default:
25
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29
+ if (t[2]) _.ops.pop();
30
+ _.trys.pop(); continue;
31
+ }
32
+ op = body.call(thisArg, _);
33
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35
+ }
36
+ };
37
+ import { useCallback } from 'react';
38
+ import { useContextSelector } from '@fluentui/react-context-selector';
39
+ import { deleteChangeRequestItem, updateChangeRequest, promiseAllSettled, entityCumulativeUpdate, updateRelationWithDiff } from '@reltio/mdm-sdk';
40
+ import { isEmpty } from 'ramda';
41
+ import { useMdmMetadata } from '../../../contexts/MdmModuleContext';
42
+ import { ChangeRequestEditorContext } from '../contexts/ChangeRequestEditorContext';
43
+ import { buildDCRSavePlan } from '../helpers/dcr';
44
+ import { useDCRValidation } from './useDCRValidation';
45
+ var withChangeRequestId = function (dcrUri) { return function (url) {
46
+ return url + (url.includes('?') ? '&' : '?') + "changeRequestId=".concat(encodeURIComponent(dcrUri.split('/')[1]));
47
+ }; };
48
+ export var useApplyDcrChanges = function (dcr) {
49
+ var getLinesByChangeId = useContextSelector(ChangeRequestEditorContext, function (context) { return context.getLinesByChangeId; });
50
+ var metadata = useMdmMetadata();
51
+ var getErrors = useDCRValidation(dcr);
52
+ var applyDcrChanges = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
53
+ var errors, _a, rejectedChangeIds, updatedChanges, deleteEntityAttributes, deleteRelationAttributes, deleteChangeResults, deleteEntityAttributesResults, deleteRelationAttributesResults, deleteChangeFailures, error_1, deleteEntityAttributesFailures, deleteRelationAttributesFailures;
54
+ return __generator(this, function (_b) {
55
+ switch (_b.label) {
56
+ case 0:
57
+ if (!(dcr === null || dcr === void 0 ? void 0 : dcr.changes)) return [3 /*break*/, 12];
58
+ return [4 /*yield*/, getErrors()];
59
+ case 1:
60
+ errors = _b.sent();
61
+ if (errors.length > 0) {
62
+ return [2 /*return*/, {
63
+ proceed: false
64
+ }];
65
+ }
66
+ _a = buildDCRSavePlan(dcr.changes, getLinesByChangeId, metadata), rejectedChangeIds = _a.rejectedChangeIds, updatedChanges = _a.updatedChanges, deleteEntityAttributes = _a.deleteEntityAttributes, deleteRelationAttributes = _a.deleteRelationAttributes;
67
+ deleteChangeResults = [];
68
+ deleteEntityAttributesResults = [];
69
+ deleteRelationAttributesResults = [];
70
+ if (!(rejectedChangeIds.length > 0)) return [3 /*break*/, 3];
71
+ return [4 /*yield*/, promiseAllSettled(rejectedChangeIds.map(function (changeId) {
72
+ return deleteChangeRequestItem({ dcrUri: dcr.uri, changeItemId: changeId });
73
+ }))];
74
+ case 2:
75
+ deleteChangeResults = _b.sent();
76
+ _b.label = 3;
77
+ case 3:
78
+ deleteChangeFailures = deleteChangeResults.filter(function (result) { return result.status === 'rejected'; });
79
+ if (deleteChangeFailures.length) {
80
+ return [2 /*return*/, {
81
+ proceed: false,
82
+ error: new Error("Failed to delete DCR change(s): ".concat(deleteChangeFailures.map(function (result) { return result.reason; }).join(', ')))
83
+ }];
84
+ }
85
+ if (!!isEmpty(updatedChanges)) return [3 /*break*/, 7];
86
+ _b.label = 4;
87
+ case 4:
88
+ _b.trys.push([4, 6, , 7]);
89
+ return [4 /*yield*/, updateChangeRequest({ dcrUri: dcr.uri, payload: updatedChanges })];
90
+ case 5:
91
+ _b.sent();
92
+ return [3 /*break*/, 7];
93
+ case 6:
94
+ error_1 = _b.sent();
95
+ return [2 /*return*/, {
96
+ proceed: false,
97
+ error: error_1
98
+ }];
99
+ case 7:
100
+ if (!!isEmpty(deleteEntityAttributes)) return [3 /*break*/, 9];
101
+ return [4 /*yield*/, promiseAllSettled(Object.entries(deleteEntityAttributes).map(function (_a) {
102
+ var entityUri = _a[0], diff = _a[1];
103
+ return entityCumulativeUpdate({
104
+ uri: entityUri,
105
+ diff: diff,
106
+ uriPreprocessor: withChangeRequestId(dcr.uri)
107
+ });
108
+ }))];
109
+ case 8:
110
+ deleteEntityAttributesResults = _b.sent();
111
+ _b.label = 9;
112
+ case 9:
113
+ deleteEntityAttributesFailures = deleteEntityAttributesResults.filter(function (result) { return result.status === 'rejected'; });
114
+ if (deleteEntityAttributesFailures.length) {
115
+ return [2 /*return*/, {
116
+ proceed: false,
117
+ error: new Error("Failed to delete entity attributes: ".concat(deleteEntityAttributesFailures.map(function (result) { return result.reason; }).join(', ')))
118
+ }];
119
+ }
120
+ if (!!isEmpty(deleteRelationAttributes)) return [3 /*break*/, 11];
121
+ return [4 /*yield*/, promiseAllSettled(Object.entries(deleteRelationAttributes).map(function (_a) {
122
+ var relationUri = _a[0], diff = _a[1];
123
+ return updateRelationWithDiff({
124
+ uri: relationUri,
125
+ diff: diff,
126
+ uriPreprocessor: withChangeRequestId(dcr.uri)
127
+ });
128
+ }))];
129
+ case 10:
130
+ deleteRelationAttributesResults = _b.sent();
131
+ _b.label = 11;
132
+ case 11:
133
+ deleteRelationAttributesFailures = deleteRelationAttributesResults.filter(function (result) { return result.status === 'rejected'; });
134
+ if (deleteRelationAttributesFailures.length) {
135
+ return [2 /*return*/, {
136
+ proceed: false,
137
+ error: new Error("Failed to delete relation attributes: ".concat(deleteRelationAttributesFailures.map(function (result) { return result.reason; }).join(', ')))
138
+ }];
139
+ }
140
+ return [2 /*return*/, {
141
+ proceed: true
142
+ }];
143
+ case 12: return [2 /*return*/, {
144
+ proceed: false,
145
+ error: new Error('No changes to apply')
146
+ }];
147
+ }
148
+ });
149
+ }); }, [dcr, getLinesByChangeId, metadata, getErrors]);
150
+ return applyDcrChanges;
151
+ };
@@ -0,0 +1,5 @@
1
+ import { ChangeRequest } from '@reltio/mdm-sdk';
2
+ export declare const useDCRValidation: (dcr: ChangeRequest) => () => Promise<{
3
+ error: import("@reltio/mdm-sdk").AttributeError;
4
+ lineIds: string[];
5
+ }[]>;
@@ -0,0 +1,149 @@
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
+ 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 = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
23
+ return g.next = verb(0), g["throw"] = verb(1), g["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
+ };
48
+ import { useMemo, useEffect, useCallback, useRef } from 'react';
49
+ import { useContextSelector } from '@fluentui/react-context-selector';
50
+ import { DCRTypes, isRelationUri, getRelation, findConnectionRelationObjectByRelationUri } from '@reltio/mdm-sdk';
51
+ import { useMdmMetadata, useMdmEntity, useMdmDcrReviewValidation } from '../../../contexts/MdmModuleContext';
52
+ import { useSafePromise } from '../../../hooks/useSafePromise';
53
+ import { MdmModuleValuesContext } from '../../../contexts/MdmModuleContext/context';
54
+ import { ChangeRequestEditorContext } from '../contexts/ChangeRequestEditorContext';
55
+ import { getValidationErrors } from '../helpers/validation';
56
+ export var useDCRValidation = function (dcr) {
57
+ var metadata = useMdmMetadata();
58
+ var currentEntity = useMdmEntity();
59
+ var dcrReviewValidation = useMdmDcrReviewValidation();
60
+ var relationsState = useContextSelector(MdmModuleValuesContext, function (context) { return context.relations; });
61
+ var getAllChanges = useContextSelector(ChangeRequestEditorContext, function (context) { return context.getAllChanges; });
62
+ var setErrors = useContextSelector(ChangeRequestEditorContext, function (context) { return context.setErrors; });
63
+ var relationsRef = useRef(null);
64
+ var safePromise = useSafePromise();
65
+ var findRelationInStore = useCallback(function (uri) {
66
+ if (!relationsState)
67
+ return null;
68
+ for (var viewId in relationsState) {
69
+ var viewState = relationsState[viewId];
70
+ if (viewState === null || viewState === void 0 ? void 0 : viewState.connections) {
71
+ return findConnectionRelationObjectByRelationUri(viewState.connections, uri);
72
+ }
73
+ }
74
+ return null;
75
+ }, [relationsState]);
76
+ var urisFromDcr = useMemo(function () {
77
+ var result = [];
78
+ if (!(dcr === null || dcr === void 0 ? void 0 : dcr.changes))
79
+ return result;
80
+ for (var key in dcr.changes) {
81
+ var changes = dcr.changes[key] || [];
82
+ var hasCreate = changes.some(function (c) { return (c === null || c === void 0 ? void 0 : c.type) === DCRTypes.CREATE_ENTITY || (c === null || c === void 0 ? void 0 : c.type) === DCRTypes.CREATE_RELATIONSHIP; });
83
+ if (!hasCreate) {
84
+ result.push(key);
85
+ }
86
+ }
87
+ return result;
88
+ }, [dcr]);
89
+ var localObjects = useMemo(function () {
90
+ var currentEntityObject = {};
91
+ currentEntityObject[currentEntity === null || currentEntity === void 0 ? void 0 : currentEntity.uri] = currentEntity;
92
+ return urisFromDcr.reduce(function (acc, uri) {
93
+ if (isRelationUri(uri)) {
94
+ var localRelation = findRelationInStore(uri);
95
+ if (localRelation) {
96
+ acc[uri] = localRelation;
97
+ }
98
+ }
99
+ return acc;
100
+ }, currentEntityObject);
101
+ }, [urisFromDcr, findRelationInStore, currentEntity]);
102
+ useEffect(function () {
103
+ if (!dcrReviewValidation || !urisFromDcr.length || (relationsRef === null || relationsRef === void 0 ? void 0 : relationsRef.current))
104
+ return;
105
+ var relationsPromises = [];
106
+ urisFromDcr.forEach(function (uri) {
107
+ if (isRelationUri(uri) && !localObjects[uri]) {
108
+ relationsPromises.push(getRelation(uri));
109
+ }
110
+ });
111
+ relationsRef.current = safePromise(Promise.all(relationsPromises));
112
+ }, [dcrReviewValidation, urisFromDcr, findRelationInStore, safePromise, localObjects]);
113
+ var getErrors = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
114
+ var relations, _a, loadedRelationsObject, objectsByUri, userChanges, errors;
115
+ return __generator(this, function (_b) {
116
+ switch (_b.label) {
117
+ case 0:
118
+ if (!dcrReviewValidation) {
119
+ return [2 /*return*/, []];
120
+ }
121
+ if (!relationsRef.current) return [3 /*break*/, 2];
122
+ return [4 /*yield*/, relationsRef.current];
123
+ case 1:
124
+ _a = _b.sent();
125
+ return [3 /*break*/, 3];
126
+ case 2:
127
+ _a = [];
128
+ _b.label = 3;
129
+ case 3:
130
+ relations = _a;
131
+ loadedRelationsObject = relations.reduce(function (acc, relation) {
132
+ acc[relation.uri] = relation;
133
+ return acc;
134
+ }, {});
135
+ objectsByUri = __assign(__assign({}, localObjects), loadedRelationsObject);
136
+ userChanges = getAllChanges();
137
+ errors = getValidationErrors({
138
+ changes: dcr === null || dcr === void 0 ? void 0 : dcr.changes,
139
+ userChanges: userChanges,
140
+ entitiesOrRelations: objectsByUri,
141
+ metadata: metadata
142
+ });
143
+ setErrors(errors);
144
+ return [2 /*return*/, errors];
145
+ }
146
+ });
147
+ }); }, [dcrReviewValidation, dcr === null || dcr === void 0 ? void 0 : dcr.changes, getAllChanges, localObjects, metadata, setErrors]);
148
+ return getErrors;
149
+ };
@@ -1,7 +1,12 @@
1
1
  import { WorkflowTaskData } from '@reltio/mdm-sdk';
2
- import { TaskAction } from '../types';
2
+ import { BeforeActionOutcome, TaskAction } from '../types';
3
3
  type Task = Partial<Pick<WorkflowTaskData, 'taskId' | 'possibleActions' | 'assignee' | 'isOpen'>>;
4
- export declare const useWorkflowActions: (task: Task, onActionSuccess?: (action: string) => void) => {
4
+ type Props = {
5
+ task: Task;
6
+ onActionSuccess?: (action: string) => void;
7
+ beforeAction?: () => Promise<BeforeActionOutcome>;
8
+ };
9
+ export declare const useWorkflowActions: ({ task, onActionSuccess, beforeAction }: Props) => {
5
10
  actions: TaskAction[];
6
11
  actionRequestIsInProgress: boolean;
7
12
  };