@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
@@ -30,15 +30,23 @@ var react_context_selector_1 = require("@fluentui/react-context-selector");
30
30
  exports.ChangeRequestEditorContext = (0, react_context_selector_1.createContext)({
31
31
  updateChange: undefined,
32
32
  getLineData: undefined,
33
+ getLinesByChangeId: undefined,
33
34
  rejectChange: undefined,
34
35
  revertChangeUpdateOrReject: undefined,
35
36
  getIsParentLineRejected: undefined,
36
37
  getIsLineRejected: undefined,
37
- getIsLineUpdated: undefined
38
+ getIsLineUpdated: undefined,
39
+ getAllChanges: undefined,
40
+ setErrors: undefined,
41
+ getErrorByLineId: undefined,
42
+ getErrors: undefined
38
43
  });
44
+ var emptyArray = [];
39
45
  var ChangeRequestEditorProvider = function (_a) {
40
46
  var children = _a.children;
41
47
  var _b = (0, react_1.useState)(new Map()), lineDataMap = _b[0], setLineDataMap = _b[1];
48
+ var lineDataMapRef = (0, react_1.useRef)(lineDataMap);
49
+ var _c = (0, react_1.useState)([]), errors = _c[0], setErrors = _c[1];
42
50
  var updateChange = (0, react_1.useCallback)(function (lineIds, data) {
43
51
  setLineDataMap(function (prevMap) {
44
52
  var newMap = new Map(prevMap);
@@ -88,14 +96,44 @@ var ChangeRequestEditorProvider = function (_a) {
88
96
  var _a;
89
97
  return !(0, ramda_1.isNil)((_a = lineDataMap.get(lineId)) === null || _a === void 0 ? void 0 : _a.value);
90
98
  }, [lineDataMap]);
99
+ var getLinesByChangeId = (0, react_1.useCallback)(function (changeId) {
100
+ return Array.from(lineDataMapRef.current).filter(function (_a) {
101
+ var key = _a[0], _value = _a[1];
102
+ return key.split('/')[1] === changeId;
103
+ });
104
+ }, []);
105
+ var getAllChanges = (0, react_1.useCallback)(function () {
106
+ var changes = Array.from(lineDataMapRef.current).map(function (_a) {
107
+ var lineId = _a[0], data = _a[1];
108
+ return ({ lineId: lineId, data: data });
109
+ });
110
+ return changes.length > 0 ? changes : emptyArray;
111
+ }, []);
112
+ (0, react_1.useEffect)(function () {
113
+ lineDataMapRef.current = lineDataMap;
114
+ }, [lineDataMap]);
115
+ var getErrorByLineId = (0, react_1.useCallback)(function (lineId) {
116
+ return errors.find(function (_a) {
117
+ var lineIds = _a.lineIds;
118
+ return lineIds.includes(lineId);
119
+ });
120
+ }, [errors]);
121
+ var getErrors = (0, react_1.useCallback)(function () {
122
+ return errors;
123
+ }, [errors]);
91
124
  var contextValue = {
92
125
  updateChange: updateChange,
93
126
  getLineData: getLineData,
127
+ getLinesByChangeId: getLinesByChangeId,
94
128
  rejectChange: rejectChange,
95
129
  revertChangeUpdateOrReject: revertChangeUpdateOrReject,
96
130
  getIsParentLineRejected: getIsParentLineRejected,
97
131
  getIsLineRejected: getIsLineRejected,
98
- getIsLineUpdated: getIsLineUpdated
132
+ getIsLineUpdated: getIsLineUpdated,
133
+ getAllChanges: getAllChanges,
134
+ setErrors: setErrors,
135
+ getErrorByLineId: getErrorByLineId,
136
+ getErrors: getErrors
99
137
  };
100
138
  return react_1.default.createElement(exports.ChangeRequestEditorContext.Provider, { value: contextValue }, children);
101
139
  };
@@ -1,4 +1,5 @@
1
- import { ChangeRequest, DCRChanges, DCRObjectInfo, DCRObjectsInfo, GroupedObjectsInfo } from '@reltio/mdm-sdk';
1
+ import { AttributeDelete, ChangeRequest, DCRChange, DCRChanges, DCRObjectInfo, DCRObjectsInfo, GroupedObjectsInfo, Metadata } from '@reltio/mdm-sdk';
2
+ import { LineData } from '../types';
2
3
  export declare const getEntitiesObjects: any;
3
4
  export declare const getRelationsObjects: any;
4
5
  export declare const extractObjectsFromChangeRequest: (changes: DCRChanges, objectsInfo: DCRObjectsInfo) => DCRObjectInfo[];
@@ -7,3 +8,9 @@ export declare const createEntityRelationsObjectByRelation: any;
7
8
  export declare const concatEntityRelationsObjects: (acc: Record<string, GroupedObjectsInfo>, object: GroupedObjectsInfo) => Record<string, GroupedObjectsInfo>;
8
9
  export declare const getEntityUriForChangeRequest: (dcrUri: string, entityUri: string) => string;
9
10
  export declare const isCreateEntityOperation: (dcr: ChangeRequest) => boolean;
11
+ export declare const buildDCRSavePlan: (changes: DCRChanges, getLinesByChangeId: (changeId: string) => Array<[string, LineData]>, metadata: Metadata) => {
12
+ rejectedChangeIds: string[];
13
+ updatedChanges: Record<string, DCRChange[]>;
14
+ deleteEntityAttributes: Record<string, AttributeDelete[]>;
15
+ deleteRelationAttributes: Record<string, AttributeDelete[]>;
16
+ };
@@ -10,8 +10,17 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
13
22
  Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.isCreateEntityOperation = exports.getEntityUriForChangeRequest = exports.concatEntityRelationsObjects = exports.createEntityRelationsObjectByRelation = exports.createEntityRelationsObjectByEntity = exports.extractObjectsFromChangeRequest = exports.getRelationsObjects = exports.getEntitiesObjects = void 0;
23
+ exports.buildDCRSavePlan = exports.isCreateEntityOperation = exports.getEntityUriForChangeRequest = exports.concatEntityRelationsObjects = exports.createEntityRelationsObjectByRelation = exports.createEntityRelationsObjectByEntity = exports.extractObjectsFromChangeRequest = exports.getRelationsObjects = exports.getEntitiesObjects = void 0;
15
24
  var mdm_sdk_1 = require("@reltio/mdm-sdk");
16
25
  var ramda_1 = require("ramda");
17
26
  exports.getEntitiesObjects = (0, ramda_1.filter)((0, ramda_1.pipe)((0, ramda_1.prop)('uri'), mdm_sdk_1.isEntityUri));
@@ -54,3 +63,179 @@ var isCreateEntityOperation = function (dcr) {
54
63
  return dcr.type === mdm_sdk_1.DCRTypes.CREATE_ENTITY;
55
64
  };
56
65
  exports.isCreateEntityOperation = isCreateEntityOperation;
66
+ var cleanValueRecursively = function (value) {
67
+ if (typeof value === 'string' || (0, ramda_1.isEmpty)(value)) {
68
+ return value;
69
+ }
70
+ var cleanedProperties = (0, ramda_1.map)(function (propertyValues) {
71
+ return propertyValues
72
+ .map(function (item) {
73
+ var itemValue = item.value;
74
+ var cleanedItemValue = itemValue && typeof itemValue === 'object' ? cleanValueRecursively(itemValue) : itemValue;
75
+ return __assign(__assign({}, item), { value: cleanedItemValue });
76
+ })
77
+ .filter(function (item) {
78
+ var itemValue = item.value;
79
+ return !(0, ramda_1.isEmpty)(itemValue) && !(0, ramda_1.isNil)(itemValue);
80
+ });
81
+ }, value);
82
+ return (0, ramda_1.filter)(function (propertyValues) { return !(0, ramda_1.isEmpty)(propertyValues); }, cleanedProperties);
83
+ };
84
+ var cleanChange = function (change) {
85
+ var _a, _b, _c;
86
+ if (Array.isArray(change.newValue)) {
87
+ return change;
88
+ }
89
+ if ((0, mdm_sdk_1.isRelationTypeUri)(change.objectType)) {
90
+ if (change.type === mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE || change.type === mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE) {
91
+ var cleanedValues = cleanValueRecursively((_a = change.newValue) === null || _a === void 0 ? void 0 : _a.value);
92
+ return (0, ramda_1.assocPath)(['newValue', 'value'], cleanedValues, change);
93
+ }
94
+ var cleanedAttributes = cleanValueRecursively((_b = change.newValue) === null || _b === void 0 ? void 0 : _b.attributes);
95
+ var changeWithCleanedAttributes = (0, ramda_1.assocPath)(['newValue', 'attributes'], cleanedAttributes, change);
96
+ if (change.type === mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP) {
97
+ var cleanByPath = function (valuePath) {
98
+ return (0, ramda_1.when)((0, ramda_1.allPass)([(0, ramda_1.hasPath)(valuePath), (0, ramda_1.pipe)((0, ramda_1.path)(valuePath), ramda_1.isNil)]), (0, ramda_1.dissocPath)(valuePath));
99
+ };
100
+ return (0, ramda_1.pipe)(cleanByPath(['newValue', 'startDate']), cleanByPath(['newValue', 'endDate']))(changeWithCleanedAttributes);
101
+ }
102
+ return changeWithCleanedAttributes;
103
+ }
104
+ if (typeof change.newValue === 'object') {
105
+ var cleanedValue = cleanValueRecursively((_c = change.newValue) === null || _c === void 0 ? void 0 : _c.value);
106
+ return (0, ramda_1.assocPath)(['newValue', 'value'], cleanedValue, change);
107
+ }
108
+ return change;
109
+ };
110
+ var calculateValuePath = function (key, change) {
111
+ var path = key
112
+ .split('/')
113
+ .slice(2)
114
+ .map(function (part) { return (isNaN(Number(part)) ? part : parseInt(part)); });
115
+ switch (change.type) {
116
+ case mdm_sdk_1.DCRTypes.UPDATE_TAGS:
117
+ case mdm_sdk_1.DCRTypes.UPDATE_ROLES:
118
+ return path;
119
+ case mdm_sdk_1.DCRTypes.UPDATE_START_DATE:
120
+ case mdm_sdk_1.DCRTypes.UPDATE_END_DATE:
121
+ return __spreadArray(__spreadArray([], path, true), [0], false);
122
+ case mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP:
123
+ if (path.length === 2) {
124
+ if (path[1] === 'activeness.startDate') {
125
+ return [path[0], 'startDate'];
126
+ }
127
+ if (path[1] === 'activeness.endDate') {
128
+ return [path[0], 'endDate'];
129
+ }
130
+ }
131
+ return __spreadArray(__spreadArray([], path, true), ['value'], false);
132
+ default:
133
+ return __spreadArray(__spreadArray([], path, true), ['value'], false);
134
+ }
135
+ };
136
+ var valuesAreEqual = function (oldValue, newValue) {
137
+ var sortWithLocale = function (array) { return array.slice().sort(function (a, b) { return a.localeCompare(b); }); };
138
+ if (Array.isArray(oldValue) && Array.isArray(newValue)) {
139
+ return oldValue.length === newValue.length && (0, ramda_1.equals)(sortWithLocale(oldValue), sortWithLocale(newValue));
140
+ }
141
+ if (typeof oldValue === 'string' && typeof newValue === 'number') {
142
+ return oldValue === newValue.toString();
143
+ }
144
+ return oldValue === newValue;
145
+ };
146
+ var getOldValueByNewValuePath = function (valuePath, change) {
147
+ if (valuePath.includes('newValue')) {
148
+ return (0, ramda_1.pathOr)(null, valuePath.map(function (item) { return (item === 'newValue' ? 'oldValue' : item); }), change);
149
+ }
150
+ return null;
151
+ };
152
+ var buildDCRSavePlan = function (changes, getLinesByChangeId, metadata) {
153
+ var _a, _b;
154
+ var rejectedChangeIds = [];
155
+ var updatedChanges = {};
156
+ var deleteAttributes = {};
157
+ for (var _i = 0, _c = Object.entries(changes); _i < _c.length; _i++) {
158
+ var _d = _c[_i], objectUri = _d[0], objectChanges = _d[1];
159
+ var rawChanges = new Map();
160
+ var _loop_1 = function (change) {
161
+ var _h = (0, ramda_1.pipe)((0, ramda_1.prop)('id'), getLinesByChangeId, (0, ramda_1.partition)(function (_a) {
162
+ var _b;
163
+ var key = _a[0], lineData = _a[1];
164
+ return key.split('/').length === 3 &&
165
+ (lineData.isRejected ||
166
+ ((0, ramda_1.isEmpty)((_b = lineData.value) === null || _b === void 0 ? void 0 : _b.value) && change.type !== mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE));
167
+ }))(change), rejectedRootLines = _h[0], otherLines = _h[1];
168
+ rejectedChangeIds.push.apply(rejectedChangeIds, rejectedRootLines.map(function (_a) {
169
+ var key = _a[0];
170
+ return key.split('/')[1];
171
+ }));
172
+ var rejectedRootLinesMap = new Map(rejectedRootLines);
173
+ for (var _j = 0, otherLines_1 = otherLines; _j < otherLines_1.length; _j++) {
174
+ var _k = otherLines_1[_j], key = _k[0], lineData = _k[1];
175
+ var rootId = key.split('/').slice(0, 3).join('/');
176
+ var newValue = (_a = lineData.value) === null || _a === void 0 ? void 0 : _a.value;
177
+ if (rootId === key && change.type === mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE && (0, ramda_1.isEmpty)(newValue)) {
178
+ var attributeUri = [objectUri, 'attributes', change.attributePath].join('/');
179
+ var entry = __assign(__assign({}, (0, mdm_sdk_1.createEntryDeleteAttribute)({ uri: attributeUri })[0]), (change.crosswalk && { crosswalk: change.crosswalk }));
180
+ deleteAttributes[objectUri] = (0, ramda_1.uniqBy)((0, ramda_1.prop)('uri'), (0, ramda_1.append)(entry, (0, ramda_1.propOr)([], objectUri, deleteAttributes)));
181
+ rejectedChangeIds.push(change.id);
182
+ }
183
+ else if (!rejectedRootLinesMap.has(rootId)) {
184
+ var valuePath = calculateValuePath(key, change);
185
+ var oldDCRValue = (0, ramda_1.path)(valuePath, change);
186
+ var oldValue = getOldValueByNewValuePath(valuePath, change);
187
+ var initialChange = rawChanges.has(change.id) ? rawChanges.get(change.id) : change;
188
+ var updatedChange = void 0;
189
+ if (lineData.isRejected || (0, ramda_1.isEmpty)(newValue)) {
190
+ updatedChange = (0, ramda_1.assocPath)(valuePath, null, initialChange);
191
+ }
192
+ else if (!valuesAreEqual(oldDCRValue, newValue)) {
193
+ if (oldValue && valuesAreEqual(oldValue, newValue)) {
194
+ rejectedChangeIds.push(change.id);
195
+ }
196
+ else {
197
+ var processedNewValue = typeof oldDCRValue === 'string' && typeof newValue === 'number'
198
+ ? newValue.toString()
199
+ : newValue;
200
+ updatedChange = (0, ramda_1.assocPath)(valuePath, processedNewValue, initialChange);
201
+ }
202
+ }
203
+ if (updatedChange) {
204
+ rawChanges.set(change.id, updatedChange);
205
+ }
206
+ }
207
+ }
208
+ };
209
+ for (var _e = 0, objectChanges_1 = objectChanges; _e < objectChanges_1.length; _e++) {
210
+ var change = objectChanges_1[_e];
211
+ _loop_1(change);
212
+ }
213
+ for (var _f = 0, _g = Array.from(rawChanges.values()); _f < _g.length; _f++) {
214
+ var rawChange = _g[_f];
215
+ var cleanedChange = cleanChange(rawChange);
216
+ var isNestedChange = (0, ramda_1.has)('attributeType', cleanedChange) &&
217
+ (0, mdm_sdk_1.isNested)((0, mdm_sdk_1.findAttributeTypeByUri)(metadata, cleanedChange.attributeType));
218
+ if (isNestedChange && (0, ramda_1.isEmpty)((_b = cleanedChange.newValue) === null || _b === void 0 ? void 0 : _b.value)) {
219
+ rejectedChangeIds.push(cleanedChange.id);
220
+ }
221
+ else {
222
+ updatedChanges[objectUri] = (0, ramda_1.append)(cleanedChange, (0, ramda_1.propOr)([], objectUri, updatedChanges));
223
+ }
224
+ }
225
+ }
226
+ var rejectedBeforeUpdateIds = (0, ramda_1.pipe)(ramda_1.values, ramda_1.flatten, (0, ramda_1.pluck)('id'))(updatedChanges);
227
+ rejectedChangeIds.push.apply(rejectedChangeIds, rejectedBeforeUpdateIds);
228
+ var deleteAttributesGroups = (0, ramda_1.groupBy)(function (_a) {
229
+ var uri = _a[0];
230
+ return ((0, mdm_sdk_1.isRelationUri)(uri) ? 'relation' : 'entity');
231
+ }, (0, ramda_1.toPairs)(deleteAttributes));
232
+ var deleteRelationAttributes = (0, ramda_1.fromPairs)(deleteAttributesGroups.relation || []);
233
+ var deleteEntityAttributes = (0, ramda_1.fromPairs)(deleteAttributesGroups.entity || []);
234
+ return {
235
+ rejectedChangeIds: rejectedChangeIds,
236
+ updatedChanges: updatedChanges,
237
+ deleteEntityAttributes: deleteEntityAttributes,
238
+ deleteRelationAttributes: deleteRelationAttributes
239
+ };
240
+ };
241
+ exports.buildDCRSavePlan = buildDCRSavePlan;
@@ -73,7 +73,7 @@ var prepareStartOrEndDate = function (_a) {
73
73
  ];
74
74
  }
75
75
  };
76
- var prepareRolesOrTags = function (metadata, change) {
76
+ var prepareRolesOrTags = function (change) {
77
77
  var _a = change.newValue, newValue = _a === void 0 ? [] : _a, _b = change.oldValue, oldValue = _b === void 0 ? [] : _b;
78
78
  var preparedNewValue = 'value' in newValue ? newValue.value : newValue;
79
79
  var preparedOldValue = 'value' in oldValue ? oldValue.value : oldValue;
@@ -201,10 +201,10 @@ var mergeAttributesInChange = function (metadata, objectInfo, change, container)
201
201
  container['defaultProfilePicValue'] = [change.newValue];
202
202
  break;
203
203
  case mdm_sdk_1.DCRTypes.UPDATE_TAGS:
204
- container[mdm_sdk_1.EntityAttrTypes.tags.name] = prepareRolesOrTags(metadata, change);
204
+ container[mdm_sdk_1.EntityAttrTypes.tags.name] = prepareRolesOrTags(change);
205
205
  break;
206
206
  case mdm_sdk_1.DCRTypes.UPDATE_ROLES: {
207
- container[mdm_sdk_1.EntityAttrTypes.roles.name] = prepareRolesOrTags(metadata, change);
207
+ container[mdm_sdk_1.EntityAttrTypes.roles.name] = prepareRolesOrTags(change);
208
208
  break;
209
209
  }
210
210
  case mdm_sdk_1.DCRTypes.UPDATE_START_DATE:
@@ -0,0 +1,17 @@
1
+ import { AttributeError, DCRChanges, Entity, Metadata, Relation } from '@reltio/mdm-sdk';
2
+ import { LineData } from '../types';
3
+ type UserChange = {
4
+ lineId: string;
5
+ data: LineData;
6
+ };
7
+ type ValidationError = {
8
+ error: AttributeError;
9
+ lineIds: string[];
10
+ };
11
+ export declare const getValidationErrors: ({ changes, userChanges, entitiesOrRelations, metadata }: {
12
+ changes: DCRChanges;
13
+ userChanges: UserChange[];
14
+ entitiesOrRelations: Record<string, Entity | Relation>;
15
+ metadata: Metadata;
16
+ }) => ValidationError[];
17
+ export {};
@@ -0,0 +1,333 @@
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
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getValidationErrors = void 0;
27
+ var ramda_1 = require("ramda");
28
+ var ui_i18n_1 = __importDefault(require("ui-i18n"));
29
+ var mdm_sdk_1 = require("@reltio/mdm-sdk");
30
+ var ALLOWED_CHANGE_TYPES = [
31
+ mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE,
32
+ mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE,
33
+ mdm_sdk_1.DCRTypes.DELETE_ATTRIBUTE,
34
+ mdm_sdk_1.DCRTypes.IGNORE_ATTRIBUTE
35
+ ];
36
+ var getValidationErrors = function (_a) {
37
+ var changes = _a.changes, userChanges = _a.userChanges, entitiesOrRelations = _a.entitiesOrRelations, metadata = _a.metadata;
38
+ var _b = validateTopLevelAttributes({
39
+ changes: changes,
40
+ userChanges: userChanges,
41
+ entitiesOrRelations: entitiesOrRelations,
42
+ metadata: metadata
43
+ }), topLevelErrors = _b.errors, topRejectedChangeIds = _b.topRejectedChangeIds;
44
+ var complexErrors = validateComplexAttributes({ changes: changes, userChanges: userChanges, metadata: metadata, topRejectedChangeIds: topRejectedChangeIds });
45
+ return __spreadArray(__spreadArray([], topLevelErrors, true), complexErrors, true);
46
+ };
47
+ exports.getValidationErrors = getValidationErrors;
48
+ var validateTopLevelAttributes = function (_a) {
49
+ var changes = _a.changes, userChanges = _a.userChanges, entitiesOrRelations = _a.entitiesOrRelations, metadata = _a.metadata;
50
+ var errors = [];
51
+ var topRejectedChangeIds = [];
52
+ var _loop_1 = function (entityUri) {
53
+ var entityOrRelation = entitiesOrRelations[entityUri];
54
+ var objectChanges = changes[entityUri] || [];
55
+ var requiredAttributeUris = getRequiredAttributeUris(metadata, entityOrRelation.type);
56
+ var changesByAttributePath = {};
57
+ objectChanges.forEach(function (change) {
58
+ var _a;
59
+ var attributeTypeUri = change.refAttributeType || change.attributeType;
60
+ if (!change.type ||
61
+ !ALLOWED_CHANGE_TYPES.includes(change.type) ||
62
+ !requiredAttributeUris.includes(change.attributeType || '')) {
63
+ return;
64
+ }
65
+ var foundUserChanges = getTopLevelUserChangesByChangeId(userChanges, change.id);
66
+ foundUserChanges.forEach(function (userChange) {
67
+ if (userChange.data.isRejected) {
68
+ topRejectedChangeIds.push(change.id);
69
+ }
70
+ });
71
+ var hasUserChanges = foundUserChanges.length > 0;
72
+ var adjustedChange = adjustChangeWithUserChanges(change, foundUserChanges);
73
+ var currentAttributePath = getCurrentAttributePath(change.attributePath);
74
+ if (!changesByAttributePath[currentAttributePath]) {
75
+ var objectValues = (0, mdm_sdk_1.findAttributeValuesByTypeUri)(metadata, entityOrRelation, attributeTypeUri);
76
+ changesByAttributePath[currentAttributePath] = {
77
+ changes: [],
78
+ objectValues: objectValues,
79
+ attributeTypeUri: attributeTypeUri,
80
+ attributeType: (0, mdm_sdk_1.findAttributeTypeByUri)(metadata, attributeTypeUri),
81
+ parentUri: (0, mdm_sdk_1.getParentUri)(change.attributePath),
82
+ lineIds: []
83
+ };
84
+ }
85
+ if (adjustedChange) {
86
+ changesByAttributePath[currentAttributePath].changes.push(adjustedChange);
87
+ }
88
+ if (hasUserChanges) {
89
+ changesByAttributePath[currentAttributePath].hasUserChanges = true;
90
+ }
91
+ (_a = changesByAttributePath[currentAttributePath].lineIds).push.apply(_a, foundUserChanges.map(function (userChange) { return userChange.lineId; }));
92
+ });
93
+ Object.values(changesByAttributePath).forEach(function (_a) {
94
+ var _b;
95
+ var hasUserChanges = _a.hasUserChanges, objectValues = _a.objectValues, attributeChanges = _a.changes, attributeTypeUri = _a.attributeTypeUri, attributeType = _a.attributeType, parentUri = _a.parentUri, lineIds = _a.lineIds;
96
+ if (hasUserChanges && !hasAttributeValue(objectValues, attributeChanges, entityUri)) {
97
+ var valueUri = (_b = objectValues === null || objectValues === void 0 ? void 0 : objectValues[0]) === null || _b === void 0 ? void 0 : _b.uri;
98
+ errors.push(createRequiredError({
99
+ attributeType: attributeType,
100
+ attributeTypeUri: attributeTypeUri,
101
+ parentUri: parentUri,
102
+ lineIds: lineIds,
103
+ metadata: metadata,
104
+ entityUri: entityUri,
105
+ entitiesMap: entitiesOrRelations,
106
+ valueUri: valueUri
107
+ }));
108
+ }
109
+ });
110
+ };
111
+ for (var entityUri in entitiesOrRelations) {
112
+ _loop_1(entityUri);
113
+ }
114
+ return { errors: errors, topRejectedChangeIds: topRejectedChangeIds };
115
+ };
116
+ var validateComplexAttributes = function (_a) {
117
+ var changes = _a.changes, userChanges = _a.userChanges, metadata = _a.metadata, _b = _a.topRejectedChangeIds, topRejectedChangeIds = _b === void 0 ? [] : _b;
118
+ var errors = [];
119
+ var _loop_2 = function (entityUri) {
120
+ var objectChanges = changes[entityUri] || [];
121
+ objectChanges.forEach(function (change) {
122
+ var _a, _b, _c, _d;
123
+ if (topRejectedChangeIds.includes(change.id)) {
124
+ return;
125
+ }
126
+ var hasComplexValue = (typeof ((_a = change.newValue) === null || _a === void 0 ? void 0 : _a.value) === 'object' &&
127
+ !Array.isArray((_b = change.newValue) === null || _b === void 0 ? void 0 : _b.value)) ||
128
+ (typeof ((_c = change.oldValue) === null || _c === void 0 ? void 0 : _c.value) === 'object' &&
129
+ !Array.isArray((_d = change.oldValue) === null || _d === void 0 ? void 0 : _d.value));
130
+ var isCreateType = change.type === mdm_sdk_1.DCRTypes.CREATE_ENTITY || change.type === mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP;
131
+ if (!hasComplexValue && !isCreateType) {
132
+ return;
133
+ }
134
+ var foundUserChanges = getUserChangesByChangeId(userChanges, change.id);
135
+ var complexErrors = validateRequiredComplexAttributes({
136
+ metadata: metadata,
137
+ change: change,
138
+ userChanges: foundUserChanges,
139
+ entityUri: entityUri
140
+ });
141
+ errors.push.apply(errors, complexErrors);
142
+ });
143
+ };
144
+ for (var entityUri in changes) {
145
+ _loop_2(entityUri);
146
+ }
147
+ return errors;
148
+ };
149
+ var getTopLevelUserChangesByChangeId = function (userChanges, changeId) {
150
+ return getUserChangesByChangeId(userChanges, changeId).filter(function (userChange) { return userChange.lineId.split('/').length === 3; });
151
+ };
152
+ var getUserChangesByChangeId = function (userChanges, changeId) {
153
+ return userChanges.filter(function (userChange) { return userChange.lineId.split('/')[1] === changeId; });
154
+ };
155
+ var getIsChangeRejected = function (userChanges, changeType) {
156
+ if (userChanges.length === 0)
157
+ return false;
158
+ var isInsertType = changeType === mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE;
159
+ return userChanges.some(function (userChange) { var _a; return userChange.data.isRejected || (isInsertType && (0, mdm_sdk_1.isEmptyValue)((_a = userChange.data.value) === null || _a === void 0 ? void 0 : _a.value)); });
160
+ };
161
+ var adjustChangeWithUserChanges = function (change, userChanges) {
162
+ var _a;
163
+ if (getIsChangeRejected(userChanges, change.type)) {
164
+ return null;
165
+ }
166
+ if (change.type === mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE && userChanges.length > 0) {
167
+ if ((0, mdm_sdk_1.isEmptyValue)((_a = userChanges[0].data.value) === null || _a === void 0 ? void 0 : _a.value)) {
168
+ return __assign(__assign({}, change), { type: mdm_sdk_1.DCRTypes.DELETE_ATTRIBUTE });
169
+ }
170
+ }
171
+ return change;
172
+ };
173
+ var getCurrentAttributePath = function (attributePath) {
174
+ var parts = attributePath.split('/');
175
+ return parts.slice(0, parts.length % 2 === 0 ? parts.length - 1 : parts.length).join('/');
176
+ };
177
+ var getEntityValueUri = function (entityOrRelationTypeUri, change) {
178
+ if (change.refObjectURI) {
179
+ var relationId = change.refObjectURI.split('/').pop();
180
+ var refAttributeTypeParts = change.refAttributeType.split('/attributes/');
181
+ return "".concat(entityOrRelationTypeUri, "/attributes/").concat(refAttributeTypeParts[1], "/").concat(relationId, "/").concat(change.attributePath);
182
+ }
183
+ return "".concat(entityOrRelationTypeUri, "/attributes/").concat(change.attributePath);
184
+ };
185
+ var hasAttributeValue = function (objectValues, changes, entityUri) {
186
+ var values = (0, ramda_1.clone)(objectValues);
187
+ var _loop_3 = function (change) {
188
+ if (change.type === mdm_sdk_1.DCRTypes.UPDATE_ATTRIBUTE || change.type === mdm_sdk_1.DCRTypes.INSERT_ATTRIBUTE) {
189
+ return { value: true };
190
+ }
191
+ var valueUri = getEntityValueUri(entityUri, change);
192
+ var valueIndex = values.findIndex(function (value) { return value.uri === valueUri; });
193
+ if (change.type === mdm_sdk_1.DCRTypes.DELETE_ATTRIBUTE) {
194
+ if (valueIndex !== -1) {
195
+ values.splice(valueIndex, 1);
196
+ }
197
+ }
198
+ else if (change.type === mdm_sdk_1.DCRTypes.IGNORE_ATTRIBUTE && valueIndex !== -1) {
199
+ values[valueIndex].ignored = change.newPinOrIgnoreValue;
200
+ }
201
+ };
202
+ for (var _i = 0, changes_1 = changes; _i < changes_1.length; _i++) {
203
+ var change = changes_1[_i];
204
+ var state_1 = _loop_3(change);
205
+ if (typeof state_1 === "object")
206
+ return state_1.value;
207
+ }
208
+ return values.filter(mdm_sdk_1.isOv).filter(function (value) { return !(0, mdm_sdk_1.isIgnored)(value); }).length > 0;
209
+ };
210
+ var getEntityTypeUriFromAttributeUri = function (attributeUri) {
211
+ return attributeUri.split('/').slice(0, 3).join('/');
212
+ };
213
+ var getAttributeTypeUriFromLineId = function (attributeTypeUri, lineId) {
214
+ var EXCLUDED_PARTS = new Set(['value', 'newValue', 'oldValue', 'attributes']);
215
+ var lineParts = lineId
216
+ .split('/')
217
+ .slice(2)
218
+ .filter(function (part) {
219
+ if (!isNaN(Number(part)))
220
+ return false;
221
+ return !EXCLUDED_PARTS.has(part);
222
+ });
223
+ return __spreadArray([attributeTypeUri], lineParts, true).join('/attributes/');
224
+ };
225
+ var getEntityTypeUriFromChange = function (change) {
226
+ if (change.type === mdm_sdk_1.DCRTypes.CREATE_ENTITY || change.type === mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP) {
227
+ return change.objectType || '';
228
+ }
229
+ return getEntityTypeUriFromAttributeUri(change.attributeType || change.objectType || '');
230
+ };
231
+ var getRequiredAttributeUris = function (metadata, typeUri) {
232
+ var requiredAttrTypes = (0, mdm_sdk_1.getRequiredAttributeTypesByTypeUri)(metadata, typeUri, true) || [];
233
+ return requiredAttrTypes.map(function (attr) { return attr.uri; });
234
+ };
235
+ var createRequiredError = function (_a) {
236
+ 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;
237
+ var error = (0, mdm_sdk_1.buildError)({
238
+ type: mdm_sdk_1.ErrorType.missed,
239
+ attributeType: attributeType,
240
+ attributeTypeUri: attributeTypeUri,
241
+ parentUri: parentUri,
242
+ message: ui_i18n_1.default.text('Attribute is required'),
243
+ source: mdm_sdk_1.ErrorSource.local,
244
+ alwaysShow: true,
245
+ uri: lineIds[0]
246
+ });
247
+ var path = [];
248
+ if ((entitiesMap === null || entitiesMap === void 0 ? void 0 : entitiesMap[entityUri]) && valueUri) {
249
+ path = (0, mdm_sdk_1.evaluateErrorPath)({
250
+ entityUri: entityUri,
251
+ metadata: metadata,
252
+ entitiesMap: entitiesMap
253
+ }, valueUri);
254
+ }
255
+ return {
256
+ error: __assign(__assign({}, error), { path: path }),
257
+ lineIds: lineIds
258
+ };
259
+ };
260
+ var validateRequiredComplexAttributes = function (_a) {
261
+ var _b;
262
+ var metadata = _a.metadata, change = _a.change, userChanges = _a.userChanges, entityUri = _a.entityUri;
263
+ if (userChanges.length === 0 || change.type === mdm_sdk_1.DCRTypes.DELETE_ATTRIBUTE) {
264
+ return [];
265
+ }
266
+ var valueHolder = change.type === mdm_sdk_1.DCRTypes.CREATE_ENTITY || change.type === mdm_sdk_1.DCRTypes.CREATE_RELATIONSHIP ? 'attributes' : 'value';
267
+ var rootAttributeTypeUri = change.refAttributeType || change.attributeType || change.objectType;
268
+ var attributeType = (0, mdm_sdk_1.findAttributeTypeByUri)(metadata, rootAttributeTypeUri);
269
+ var isReferenceType = (0, mdm_sdk_1.isReference)(attributeType);
270
+ var entityTypeUri = isReferenceType ? attributeType.relationshipTypeURI : getEntityTypeUriFromChange(change);
271
+ var requiredAttributeUris = getRequiredAttributeUris(metadata, entityTypeUri);
272
+ var calculateLineIdFromPath = function (path) {
273
+ if (path === void 0) { path = ''; }
274
+ var entityId = entityUri.split('/').pop() || '';
275
+ return "".concat(entityId, "/").concat(change.id, "/newValue").concat(path ? "/".concat(path) : '');
276
+ };
277
+ var checkIsChangeRejected = function (path) {
278
+ var _a, _b, _c;
279
+ var searchLineId = calculateLineIdFromPath(path);
280
+ var lineUserChanges = userChanges.find(function (userChange) { return userChange.lineId === searchLineId; });
281
+ return (((_a = lineUserChanges === null || lineUserChanges === void 0 ? void 0 : lineUserChanges.data) === null || _a === void 0 ? void 0 : _a.isRejected) || (lineUserChanges && (0, mdm_sdk_1.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)));
282
+ };
283
+ var collectErrors = function (attributes) {
284
+ var errors = [];
285
+ var visitValue = function (value, path) {
286
+ var isRejected = checkIsChangeRejected(path.slice(0, -1).join('/'));
287
+ if (typeof value === 'string') {
288
+ return !isRejected;
289
+ }
290
+ if (isRejected) {
291
+ return false;
292
+ }
293
+ var anyFieldHasValue = false;
294
+ Object.entries(value).forEach(function (_a) {
295
+ var fieldName = _a[0], subAttributes = _a[1];
296
+ var anyChildHasValue = false;
297
+ var attributePath = __spreadArray(__spreadArray([], path, true), [fieldName], false);
298
+ var rejectedLineIds = [];
299
+ subAttributes.forEach(function (subAttribute, index) {
300
+ var childPath = __spreadArray(__spreadArray([], attributePath, true), [index, 'value'], false);
301
+ var childHasValue = visitValue(subAttribute.value, childPath);
302
+ if (!childHasValue) {
303
+ rejectedLineIds.push(calculateLineIdFromPath(childPath.slice(0, -1).join('/')));
304
+ }
305
+ anyChildHasValue = anyChildHasValue || childHasValue;
306
+ });
307
+ anyFieldHasValue = anyFieldHasValue || anyChildHasValue;
308
+ if (!anyChildHasValue) {
309
+ var attributeTypeUri = getAttributeTypeUriFromLineId(isReferenceType ? entityTypeUri : rootAttributeTypeUri, rejectedLineIds[0]);
310
+ var isRequired = requiredAttributeUris.includes(attributeTypeUri);
311
+ if (isRequired) {
312
+ errors.push(createRequiredError({
313
+ attributeType: (0, mdm_sdk_1.findAttributeTypeByUri)(metadata, attributeTypeUri),
314
+ attributeTypeUri: attributeTypeUri,
315
+ lineIds: rejectedLineIds
316
+ }));
317
+ }
318
+ }
319
+ });
320
+ return anyFieldHasValue;
321
+ };
322
+ var hasValue = visitValue(attributes, [valueHolder]);
323
+ if (!hasValue && attributeType.required) {
324
+ errors.push(createRequiredError({
325
+ attributeType: attributeType,
326
+ attributeTypeUri: attributeType.uri,
327
+ lineIds: [calculateLineIdFromPath()]
328
+ }));
329
+ }
330
+ return errors;
331
+ };
332
+ return collectErrors((_b = change.newValue) === null || _b === void 0 ? void 0 : _b[valueHolder]);
333
+ };
@@ -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>;