@reltio/components 1.4.2207 → 1.4.2208

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/features/workflow/ChangeRequestEditor/ChangeRequestEditor.js +1 -2
  2. package/cjs/features/workflow/ChangeRequestEditor/components/ChangeItemEditor/ChangeItemEditor.js +2 -1
  3. package/cjs/features/workflow/ChangeRequestEditor/components/ChangeItemRow/ChangeItemRow.js +4 -4
  4. package/cjs/features/workflow/ChangeRequestEditor/components/DCRValueEditor/DCRValueEditor.d.ts +1 -1
  5. package/cjs/features/workflow/ChangeRequestEditor/components/DCRValueEditorFactory/DCRValueEditorFactory.d.ts +1 -1
  6. package/cjs/features/workflow/ChangeRequestEditor/hooks/useChangeRequestEditor.d.ts +2 -1
  7. package/cjs/features/workflow/ChangeRequestEditor/hooks/useChangeRequestEditor.js +14 -8
  8. package/cjs/features/workflow/ReviewDCRDialog/ReviewDCRDialog.js +10 -7
  9. package/cjs/features/workflow/TaskActionButtons/TaskActionButtons.js +6 -4
  10. package/cjs/features/workflow/WorkflowTaskCard/components/DataChangeRequestTaskCard/DataChangeRequestTaskCard.js +8 -3
  11. package/cjs/features/workflow/WorkflowTaskCard/components/GenericWorkflowTaskCard/GenericWorkflowTaskCard.js +6 -4
  12. package/cjs/features/workflow/{ChangeRequestEditor/context → contexts/ChangeRequestEditorContext}/index.d.ts +1 -0
  13. package/cjs/features/workflow/{ChangeRequestEditor/context → contexts/ChangeRequestEditorContext}/index.js +12 -0
  14. package/cjs/features/workflow/helpers/dcr.d.ts +8 -1
  15. package/cjs/features/workflow/helpers/dcr.js +186 -1
  16. package/cjs/features/workflow/hooks/useApplyDcrChanges.d.ts +3 -0
  17. package/cjs/features/workflow/hooks/useApplyDcrChanges.js +145 -0
  18. package/cjs/features/workflow/hooks/useWorkflowActions.d.ts +7 -2
  19. package/cjs/features/workflow/hooks/useWorkflowActions.js +31 -8
  20. package/cjs/features/workflow/types.d.ts +4 -0
  21. package/features/workflow/ChangeRequestEditor/ChangeRequestEditor.js +1 -2
  22. package/features/workflow/ChangeRequestEditor/components/ChangeItemEditor/ChangeItemEditor.js +2 -1
  23. package/features/workflow/ChangeRequestEditor/components/ChangeItemRow/ChangeItemRow.js +1 -1
  24. package/features/workflow/ChangeRequestEditor/components/DCRValueEditor/DCRValueEditor.d.ts +1 -1
  25. package/features/workflow/ChangeRequestEditor/components/DCRValueEditorFactory/DCRValueEditorFactory.d.ts +1 -1
  26. package/features/workflow/ChangeRequestEditor/hooks/useChangeRequestEditor.d.ts +2 -1
  27. package/features/workflow/ChangeRequestEditor/hooks/useChangeRequestEditor.js +8 -2
  28. package/features/workflow/ReviewDCRDialog/ReviewDCRDialog.js +10 -7
  29. package/features/workflow/TaskActionButtons/TaskActionButtons.js +6 -4
  30. package/features/workflow/WorkflowTaskCard/components/DataChangeRequestTaskCard/DataChangeRequestTaskCard.js +9 -4
  31. package/features/workflow/WorkflowTaskCard/components/GenericWorkflowTaskCard/GenericWorkflowTaskCard.js +6 -4
  32. package/features/workflow/{ChangeRequestEditor/context → contexts/ChangeRequestEditorContext}/index.d.ts +1 -0
  33. package/features/workflow/{ChangeRequestEditor/context → contexts/ChangeRequestEditorContext}/index.js +13 -1
  34. package/features/workflow/helpers/dcr.d.ts +8 -1
  35. package/features/workflow/helpers/dcr.js +186 -2
  36. package/features/workflow/hooks/useApplyDcrChanges.d.ts +3 -0
  37. package/features/workflow/hooks/useApplyDcrChanges.js +141 -0
  38. package/features/workflow/hooks/useWorkflowActions.d.ts +7 -2
  39. package/features/workflow/hooks/useWorkflowActions.js +31 -8
  40. package/features/workflow/types.d.ts +4 -0
  41. package/package.json +2 -2
@@ -9,8 +9,17 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { DCRTypes, isEntityUri, isRelationUri } from '@reltio/mdm-sdk';
13
- import { allPass, concat, curry, equals, filter, keys, map, pathOr, pipe, prop, uniq } from 'ramda';
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 { createEntryDeleteAttribute, DCRTypes, findAttributeTypeByUri, isEntityUri, isNested, isRelationTypeUri, isRelationUri } from '@reltio/mdm-sdk';
22
+ import { allPass, append, assocPath, concat, curry, dissocPath, equals, filter, flatten, fromPairs, groupBy, has, hasPath, isEmpty, isNil, keys, map, partition, path, pathOr, pipe, pluck, prop, propOr, toPairs, values, uniq, uniqBy, when } from 'ramda';
14
23
  export var getEntitiesObjects = filter(pipe(prop('uri'), isEntityUri));
15
24
  export var getRelationsObjects = filter(pipe(prop('uri'), isRelationUri));
16
25
  var getRelations = function (objectsWithChanges, entityUri) {
@@ -47,3 +56,178 @@ export var getEntityUriForChangeRequest = function (dcrUri, entityUri) {
47
56
  export var isCreateEntityOperation = function (dcr) {
48
57
  return dcr.type === DCRTypes.CREATE_ENTITY;
49
58
  };
59
+ var cleanValueRecursively = function (value) {
60
+ if (typeof value === 'string' || isEmpty(value)) {
61
+ return value;
62
+ }
63
+ var cleanedProperties = map(function (propertyValues) {
64
+ return propertyValues
65
+ .map(function (item) {
66
+ var itemValue = item.value;
67
+ var cleanedItemValue = itemValue && typeof itemValue === 'object' ? cleanValueRecursively(itemValue) : itemValue;
68
+ return __assign(__assign({}, item), { value: cleanedItemValue });
69
+ })
70
+ .filter(function (item) {
71
+ var itemValue = item.value;
72
+ return !isEmpty(itemValue) && !isNil(itemValue);
73
+ });
74
+ }, value);
75
+ return filter(function (propertyValues) { return !isEmpty(propertyValues); }, cleanedProperties);
76
+ };
77
+ var cleanChange = function (change) {
78
+ var _a, _b, _c;
79
+ if (Array.isArray(change.newValue)) {
80
+ return change;
81
+ }
82
+ if (isRelationTypeUri(change.objectType)) {
83
+ if (change.type === DCRTypes.INSERT_ATTRIBUTE || change.type === DCRTypes.UPDATE_ATTRIBUTE) {
84
+ var cleanedValues = cleanValueRecursively((_a = change.newValue) === null || _a === void 0 ? void 0 : _a.value);
85
+ return assocPath(['newValue', 'value'], cleanedValues, change);
86
+ }
87
+ var cleanedAttributes = cleanValueRecursively((_b = change.newValue) === null || _b === void 0 ? void 0 : _b.attributes);
88
+ var changeWithCleanedAttributes = assocPath(['newValue', 'attributes'], cleanedAttributes, change);
89
+ if (change.type === DCRTypes.CREATE_RELATIONSHIP) {
90
+ var cleanByPath = function (valuePath) {
91
+ return when(allPass([hasPath(valuePath), pipe(path(valuePath), isNil)]), dissocPath(valuePath));
92
+ };
93
+ return pipe(cleanByPath(['newValue', 'startDate']), cleanByPath(['newValue', 'endDate']))(changeWithCleanedAttributes);
94
+ }
95
+ return changeWithCleanedAttributes;
96
+ }
97
+ if (typeof change.newValue === 'object') {
98
+ var cleanedValue = cleanValueRecursively((_c = change.newValue) === null || _c === void 0 ? void 0 : _c.value);
99
+ return assocPath(['newValue', 'value'], cleanedValue, change);
100
+ }
101
+ return change;
102
+ };
103
+ var calculateValuePath = function (key, change) {
104
+ var path = key
105
+ .split('/')
106
+ .slice(2)
107
+ .map(function (part) { return (isNaN(Number(part)) ? part : parseInt(part)); });
108
+ switch (change.type) {
109
+ case DCRTypes.UPDATE_TAGS:
110
+ case DCRTypes.UPDATE_ROLES:
111
+ return path;
112
+ case DCRTypes.UPDATE_START_DATE:
113
+ case DCRTypes.UPDATE_END_DATE:
114
+ return __spreadArray(__spreadArray([], path, true), [0], false);
115
+ case DCRTypes.CREATE_RELATIONSHIP:
116
+ if (path.length === 2) {
117
+ if (path[1] === 'activeness.startDate') {
118
+ return [path[0], 'startDate'];
119
+ }
120
+ if (path[1] === 'activeness.endDate') {
121
+ return [path[0], 'endDate'];
122
+ }
123
+ }
124
+ return __spreadArray(__spreadArray([], path, true), ['value'], false);
125
+ default:
126
+ return __spreadArray(__spreadArray([], path, true), ['value'], false);
127
+ }
128
+ };
129
+ var valuesAreEqual = function (oldValue, newValue) {
130
+ var sortWithLocale = function (array) { return array.slice().sort(function (a, b) { return a.localeCompare(b); }); };
131
+ if (Array.isArray(oldValue) && Array.isArray(newValue)) {
132
+ return oldValue.length === newValue.length && equals(sortWithLocale(oldValue), sortWithLocale(newValue));
133
+ }
134
+ if (typeof oldValue === 'string' && typeof newValue === 'number') {
135
+ return oldValue === newValue.toString();
136
+ }
137
+ return oldValue === newValue;
138
+ };
139
+ var getOldValueByNewValuePath = function (valuePath, change) {
140
+ if (valuePath.includes('newValue')) {
141
+ return pathOr(null, valuePath.map(function (item) { return (item === 'newValue' ? 'oldValue' : item); }), change);
142
+ }
143
+ return null;
144
+ };
145
+ export var buildDCRSavePlan = function (changes, getLinesByChangeId, metadata) {
146
+ var _a, _b;
147
+ var rejectedChangeIds = [];
148
+ var updatedChanges = {};
149
+ var deleteAttributes = {};
150
+ for (var _i = 0, _c = Object.entries(changes); _i < _c.length; _i++) {
151
+ var _d = _c[_i], objectUri = _d[0], objectChanges = _d[1];
152
+ var rawChanges = new Map();
153
+ var _loop_1 = function (change) {
154
+ var _h = pipe(prop('id'), getLinesByChangeId, partition(function (_a) {
155
+ var _b;
156
+ var key = _a[0], lineData = _a[1];
157
+ return key.split('/').length === 3 &&
158
+ (lineData.isRejected ||
159
+ (isEmpty((_b = lineData.value) === null || _b === void 0 ? void 0 : _b.value) && change.type !== DCRTypes.UPDATE_ATTRIBUTE));
160
+ }))(change), rejectedRootLines = _h[0], otherLines = _h[1];
161
+ rejectedChangeIds.push.apply(rejectedChangeIds, rejectedRootLines.map(function (_a) {
162
+ var key = _a[0];
163
+ return key.split('/')[1];
164
+ }));
165
+ var rejectedRootLinesMap = new Map(rejectedRootLines);
166
+ for (var _j = 0, otherLines_1 = otherLines; _j < otherLines_1.length; _j++) {
167
+ var _k = otherLines_1[_j], key = _k[0], lineData = _k[1];
168
+ var rootId = key.split('/').slice(0, 3).join('/');
169
+ var newValue = (_a = lineData.value) === null || _a === void 0 ? void 0 : _a.value;
170
+ if (rootId === key && change.type === DCRTypes.UPDATE_ATTRIBUTE && isEmpty(newValue)) {
171
+ var attributeUri = [objectUri, 'attributes', change.attributePath].join('/');
172
+ var entry = __assign(__assign({}, createEntryDeleteAttribute({ uri: attributeUri })[0]), (change.crosswalk && { crosswalk: change.crosswalk }));
173
+ deleteAttributes[objectUri] = uniqBy(prop('uri'), append(entry, propOr([], objectUri, deleteAttributes)));
174
+ rejectedChangeIds.push(change.id);
175
+ }
176
+ else if (!rejectedRootLinesMap.has(rootId)) {
177
+ var valuePath = calculateValuePath(key, change);
178
+ var oldDCRValue = path(valuePath, change);
179
+ var oldValue = getOldValueByNewValuePath(valuePath, change);
180
+ var initialChange = rawChanges.has(change.id) ? rawChanges.get(change.id) : change;
181
+ var updatedChange = void 0;
182
+ if (lineData.isRejected || isEmpty(newValue)) {
183
+ updatedChange = assocPath(valuePath, null, initialChange);
184
+ }
185
+ else if (!valuesAreEqual(oldDCRValue, newValue)) {
186
+ if (oldValue && valuesAreEqual(oldValue, newValue)) {
187
+ rejectedChangeIds.push(change.id);
188
+ }
189
+ else {
190
+ var processedNewValue = typeof oldDCRValue === 'string' && typeof newValue === 'number'
191
+ ? newValue.toString()
192
+ : newValue;
193
+ updatedChange = assocPath(valuePath, processedNewValue, initialChange);
194
+ }
195
+ }
196
+ if (updatedChange) {
197
+ rawChanges.set(change.id, updatedChange);
198
+ }
199
+ }
200
+ }
201
+ };
202
+ for (var _e = 0, objectChanges_1 = objectChanges; _e < objectChanges_1.length; _e++) {
203
+ var change = objectChanges_1[_e];
204
+ _loop_1(change);
205
+ }
206
+ for (var _f = 0, _g = Array.from(rawChanges.values()); _f < _g.length; _f++) {
207
+ var rawChange = _g[_f];
208
+ var cleanedChange = cleanChange(rawChange);
209
+ var isNestedChange = has('attributeType', cleanedChange) &&
210
+ isNested(findAttributeTypeByUri(metadata, cleanedChange.attributeType));
211
+ if (isNestedChange && isEmpty((_b = cleanedChange.newValue) === null || _b === void 0 ? void 0 : _b.value)) {
212
+ rejectedChangeIds.push(cleanedChange.id);
213
+ }
214
+ else {
215
+ updatedChanges[objectUri] = append(cleanedChange, propOr([], objectUri, updatedChanges));
216
+ }
217
+ }
218
+ }
219
+ var rejectedBeforeUpdateIds = pipe(values, flatten, pluck('id'))(updatedChanges);
220
+ rejectedChangeIds.push.apply(rejectedChangeIds, rejectedBeforeUpdateIds);
221
+ var deleteAttributesGroups = groupBy(function (_a) {
222
+ var uri = _a[0];
223
+ return (isRelationUri(uri) ? 'relation' : 'entity');
224
+ }, toPairs(deleteAttributes));
225
+ var deleteRelationAttributes = fromPairs(deleteAttributesGroups.relation || []);
226
+ var deleteEntityAttributes = fromPairs(deleteAttributesGroups.entity || []);
227
+ return {
228
+ rejectedChangeIds: rejectedChangeIds,
229
+ updatedChanges: updatedChanges,
230
+ deleteEntityAttributes: deleteEntityAttributes,
231
+ deleteRelationAttributes: deleteRelationAttributes
232
+ };
233
+ };
@@ -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,141 @@
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
+ var withChangeRequestId = function (dcrUri) { return function (url) {
45
+ return url + (url.includes('?') ? '&' : '?') + "changeRequestId=".concat(encodeURIComponent(dcrUri.split('/')[1]));
46
+ }; };
47
+ export var useApplyDcrChanges = function (dcr) {
48
+ var getLinesByChangeId = useContextSelector(ChangeRequestEditorContext, function (context) { return context.getLinesByChangeId; });
49
+ var metadata = useMdmMetadata();
50
+ var applyDcrChanges = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
51
+ var _a, rejectedChangeIds, updatedChanges, deleteEntityAttributes, deleteRelationAttributes, deleteChangeResults, deleteEntityAttributesResults, deleteRelationAttributesResults, deleteChangeFailures, error_1, deleteEntityAttributesFailures, deleteRelationAttributesFailures;
52
+ return __generator(this, function (_b) {
53
+ switch (_b.label) {
54
+ case 0:
55
+ if (!(dcr === null || dcr === void 0 ? void 0 : dcr.changes)) return [3 /*break*/, 11];
56
+ _a = buildDCRSavePlan(dcr.changes, getLinesByChangeId, metadata), rejectedChangeIds = _a.rejectedChangeIds, updatedChanges = _a.updatedChanges, deleteEntityAttributes = _a.deleteEntityAttributes, deleteRelationAttributes = _a.deleteRelationAttributes;
57
+ deleteChangeResults = [];
58
+ deleteEntityAttributesResults = [];
59
+ deleteRelationAttributesResults = [];
60
+ if (!(rejectedChangeIds.length > 0)) return [3 /*break*/, 2];
61
+ return [4 /*yield*/, promiseAllSettled(rejectedChangeIds.map(function (changeId) {
62
+ return deleteChangeRequestItem({ dcrUri: dcr.uri, changeItemId: changeId });
63
+ }))];
64
+ case 1:
65
+ deleteChangeResults = _b.sent();
66
+ _b.label = 2;
67
+ case 2:
68
+ deleteChangeFailures = deleteChangeResults.filter(function (result) { return result.status === 'rejected'; });
69
+ if (deleteChangeFailures.length) {
70
+ return [2 /*return*/, {
71
+ proceed: false,
72
+ error: new Error("Failed to delete DCR change(s): ".concat(deleteChangeFailures.map(function (result) { return result.reason; }).join(', ')))
73
+ }];
74
+ }
75
+ if (!!isEmpty(updatedChanges)) return [3 /*break*/, 6];
76
+ _b.label = 3;
77
+ case 3:
78
+ _b.trys.push([3, 5, , 6]);
79
+ return [4 /*yield*/, updateChangeRequest({ dcrUri: dcr.uri, payload: updatedChanges })];
80
+ case 4:
81
+ _b.sent();
82
+ return [3 /*break*/, 6];
83
+ case 5:
84
+ error_1 = _b.sent();
85
+ return [2 /*return*/, {
86
+ proceed: false,
87
+ error: error_1
88
+ }];
89
+ case 6:
90
+ if (!!isEmpty(deleteEntityAttributes)) return [3 /*break*/, 8];
91
+ return [4 /*yield*/, promiseAllSettled(Object.entries(deleteEntityAttributes).map(function (_a) {
92
+ var entityUri = _a[0], diff = _a[1];
93
+ return entityCumulativeUpdate({
94
+ uri: entityUri,
95
+ diff: diff,
96
+ uriPreprocessor: withChangeRequestId(dcr.uri)
97
+ });
98
+ }))];
99
+ case 7:
100
+ deleteEntityAttributesResults = _b.sent();
101
+ _b.label = 8;
102
+ case 8:
103
+ deleteEntityAttributesFailures = deleteEntityAttributesResults.filter(function (result) { return result.status === 'rejected'; });
104
+ if (deleteEntityAttributesFailures.length) {
105
+ return [2 /*return*/, {
106
+ proceed: false,
107
+ error: new Error("Failed to delete entity attributes: ".concat(deleteEntityAttributesFailures.map(function (result) { return result.reason; }).join(', ')))
108
+ }];
109
+ }
110
+ if (!!isEmpty(deleteRelationAttributes)) return [3 /*break*/, 10];
111
+ return [4 /*yield*/, promiseAllSettled(Object.entries(deleteRelationAttributes).map(function (_a) {
112
+ var relationUri = _a[0], diff = _a[1];
113
+ return updateRelationWithDiff({
114
+ uri: relationUri,
115
+ diff: diff,
116
+ uriPreprocessor: withChangeRequestId(dcr.uri)
117
+ });
118
+ }))];
119
+ case 9:
120
+ deleteRelationAttributesResults = _b.sent();
121
+ _b.label = 10;
122
+ case 10:
123
+ deleteRelationAttributesFailures = deleteRelationAttributesResults.filter(function (result) { return result.status === 'rejected'; });
124
+ if (deleteRelationAttributesFailures.length) {
125
+ return [2 /*return*/, {
126
+ proceed: false,
127
+ error: new Error("Failed to delete relation attributes: ".concat(deleteRelationAttributesFailures.map(function (result) { return result.reason; }).join(', ')))
128
+ }];
129
+ }
130
+ return [2 /*return*/, {
131
+ proceed: true
132
+ }];
133
+ case 11: return [2 /*return*/, {
134
+ proceed: false,
135
+ error: new Error('No changes to apply')
136
+ }];
137
+ }
138
+ });
139
+ }); }, [dcr, getLinesByChangeId, metadata]);
140
+ return applyDcrChanges;
141
+ };
@@ -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
  };
@@ -41,23 +41,25 @@ import { isOpenTask } from '../helpers/common';
41
41
  import { WorkflowTasksContext } from '../../../contexts/WorkflowTasksContext';
42
42
  import { useMdmTenant, useMdmUsername, useMdmWorkflowEnvironmentUrl, useMdmWorkflowPath } from '../../../contexts/MdmModuleContext';
43
43
  import { useCommentDialog } from '../../../contexts/CommentDialogContext';
44
- export var useWorkflowActions = function (task, onActionSuccess) {
45
- var _a = task !== null && task !== void 0 ? task : {}, possibleActions = _a.possibleActions, assignee = _a.assignee, taskId = _a.taskId, isOpen = _a.isOpen;
44
+ import { showDefaultErrorMessage } from '../../../helpers/errors';
45
+ export var useWorkflowActions = function (_a) {
46
+ var task = _a.task, onActionSuccess = _a.onActionSuccess, beforeAction = _a.beforeAction;
47
+ var _b = task !== null && task !== void 0 ? task : {}, possibleActions = _b.possibleActions, assignee = _b.assignee, taskId = _b.taskId, isOpen = _b.isOpen;
46
48
  var workflowTasks = useContext(WorkflowTasksContext);
47
49
  var workflowPath = useMdmWorkflowPath();
48
50
  var environment = useMdmWorkflowEnvironmentUrl();
49
51
  var tenant = useMdmTenant();
50
52
  var username = useMdmUsername();
51
53
  var showCommentDialog = useCommentDialog();
52
- var _b = useState(false), actionRequestIsInProgress = _b[0], setActionRequestIsInProgress = _b[1];
54
+ var _c = useState(false), actionRequestIsInProgress = _c[0], setActionRequestIsInProgress = _c[1];
53
55
  var handleActionSuccess = onActionSuccess !== null && onActionSuccess !== void 0 ? onActionSuccess : workflowTasks === null || workflowTasks === void 0 ? void 0 : workflowTasks.onActionSuccess;
54
56
  var performTaskAction = useCallback(function (action, commentRequired) {
55
57
  return function (comment) { return __awaiter(void 0, void 0, void 0, function () {
56
- var processInstanceComment;
58
+ var processInstanceComment, outcome, error_1;
57
59
  return __generator(this, function (_a) {
58
60
  switch (_a.label) {
59
61
  case 0:
60
- if (!(workflowPath && taskId)) return [3 /*break*/, 3];
62
+ if (!(workflowPath && taskId)) return [3 /*break*/, 7];
61
63
  setActionRequestIsInProgress(true);
62
64
  processInstanceComment = typeof comment === 'string' && comment.length ? comment : null;
63
65
  if (!(commentRequired && !processInstanceComment)) return [3 /*break*/, 2];
@@ -70,6 +72,27 @@ export var useWorkflowActions = function (task, onActionSuccess) {
70
72
  }
71
73
  _a.label = 2;
72
74
  case 2:
75
+ if (!beforeAction) return [3 /*break*/, 6];
76
+ _a.label = 3;
77
+ case 3:
78
+ _a.trys.push([3, 5, , 6]);
79
+ return [4 /*yield*/, beforeAction()];
80
+ case 4:
81
+ outcome = _a.sent();
82
+ if (!outcome.proceed) {
83
+ if (outcome.error) {
84
+ showDefaultErrorMessage(outcome.error);
85
+ }
86
+ setActionRequestIsInProgress(false);
87
+ return [2 /*return*/];
88
+ }
89
+ return [3 /*break*/, 6];
90
+ case 5:
91
+ error_1 = _a.sent();
92
+ showDefaultErrorMessage(error_1);
93
+ setActionRequestIsInProgress(false);
94
+ return [2 /*return*/];
95
+ case 6:
73
96
  runTaskAction({
74
97
  taskId: taskId,
75
98
  workflowPath: workflowPath,
@@ -85,12 +108,12 @@ export var useWorkflowActions = function (task, onActionSuccess) {
85
108
  .finally(function () {
86
109
  setActionRequestIsInProgress(false);
87
110
  });
88
- _a.label = 3;
89
- case 3: return [2 /*return*/];
111
+ _a.label = 7;
112
+ case 7: return [2 /*return*/];
90
113
  }
91
114
  });
92
115
  }); };
93
- }, [workflowPath, taskId, environment, tenant, handleActionSuccess, showCommentDialog]);
116
+ }, [workflowPath, taskId, environment, tenant, handleActionSuccess, showCommentDialog, beforeAction]);
94
117
  var actions = useMemo(function () {
95
118
  return username === assignee && isOpenTask(isOpen)
96
119
  ? (possibleActions || []).map(function (_a) {
@@ -19,3 +19,7 @@ export type Diff = {
19
19
  export type Title = {
20
20
  label: string;
21
21
  };
22
+ export type BeforeActionOutcome = {
23
+ proceed: boolean;
24
+ error?: unknown;
25
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.2207",
3
+ "version": "1.4.2208",
4
4
  "license": "SEE LICENSE IN LICENSE FILE",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./index.js",
@@ -11,7 +11,7 @@
11
11
  "@fluentui/react-context-selector": "^9.1.26",
12
12
  "@googlemaps/markerclusterer": "^2.5.3",
13
13
  "@react-sigma/core": "3.4.0",
14
- "@reltio/mdm-sdk": "^1.4.2009",
14
+ "@reltio/mdm-sdk": "^1.4.2010",
15
15
  "@vis.gl/react-google-maps": "^1.3.0",
16
16
  "d3-cloud": "^1.2.5",
17
17
  "d3-geo": "^2.0.1",