@reltio/components 1.4.2244 → 1.4.2245

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.
@@ -43,6 +43,7 @@ var ScrollToAddedAttributeContext_1 = require("../../../contexts/ScrollToAddedAt
43
43
  var ChangeItemRow_module_css_1 = __importDefault(require("./ChangeItemRow.module.css"));
44
44
  var ChangeItemRow = function (_a) {
45
45
  var _b;
46
+ var _c;
46
47
  var change = _a.change, entityInfo = _a.entityInfo;
47
48
  var lineIds = change.lineIds || (0, merge_1.extractLineIds)(change === null || change === void 0 ? void 0 : change.newValue);
48
49
  var isParentLineRejected = (0, react_context_selector_1.useContextSelector)(ChangeRequestEditorContext_1.ChangeRequestEditorContext, function (context) {
@@ -54,6 +55,7 @@ var ChangeItemRow = function (_a) {
54
55
  var isUpdated = (0, react_context_selector_1.useContextSelector)(ChangeRequestEditorContext_1.ChangeRequestEditorContext, function (context) {
55
56
  return context.getIsLineUpdated(lineIds === null || lineIds === void 0 ? void 0 : lineIds[0]);
56
57
  });
58
+ var lineData = (0, react_context_selector_1.useContextSelector)(ChangeRequestEditorContext_1.ChangeRequestEditorContext, function (context) { return context.getLineData(lineIds === null || lineIds === void 0 ? void 0 : lineIds[0]); });
57
59
  var errorByLineId = (0, react_context_selector_1.useContextSelector)(ChangeRequestEditorContext_1.ChangeRequestEditorContext, function (context) {
58
60
  return context.getErrorByLineId(lineIds === null || lineIds === void 0 ? void 0 : lineIds[0]);
59
61
  });
@@ -64,12 +66,12 @@ var ChangeItemRow = function (_a) {
64
66
  var isHighlighted = (0, ScrollToElementContext_1.isHighlightedErrorType)(scrollToElementContext === null || scrollToElementContext === void 0 ? void 0 : scrollToElementContext.type) &&
65
67
  highlightedError &&
66
68
  errorLineIds.includes(highlightedError.uri);
67
- var _c = (0, useScrollToAttributeError_1.useScrollToAttributeError)({
69
+ var _d = (0, useScrollToAttributeError_1.useScrollToAttributeError)({
68
70
  highlightedError: isHighlighted ? scrollToElementContext : null,
69
71
  className: ChangeItemRow_module_css_1.default.changeItemRowWithError
70
- }), ref = _c.ref, errorClassName = _c.errorClassName;
72
+ }), ref = _d.ref, errorClassName = _d.errorClassName;
71
73
  var addedId = (0, addedAttributes_1.getAddedId)(change);
72
- var _d = (0, react_1.useContext)(ScrollToAddedAttributeContext_1.ScrollToAddedAttributeContext), highlightedIds = _d.highlightedIds, scrollToFirst = _d.scrollToFirst;
74
+ var _e = (0, react_1.useContext)(ScrollToAddedAttributeContext_1.ScrollToAddedAttributeContext), highlightedIds = _e.highlightedIds, scrollToFirst = _e.scrollToFirst;
73
75
  var isHighlightedAdded = !!addedId && highlightedIds.has(addedId);
74
76
  var scrollRef = (0, react_1.useRef)(null);
75
77
  (0, react_1.useEffect)(function () {
@@ -84,10 +86,11 @@ var ChangeItemRow = function (_a) {
84
86
  var isEditedOperation = change.operation === mdm_sdk_1.DCROperationTypes.EDITED;
85
87
  var editable = (0, helpers_1.isEditableChange)(change, entityInfo);
86
88
  var isAdded = (0, addedAttributes_1.isAddedAttribute)(change);
87
- var hasValue = !!(0, mdm_sdk_1.getAttributeValue)(change.newValue);
88
- var isAddedWithValue = isAdded && (isUpdated || hasValue);
89
+ var currentValue = (_c = lineData === null || lineData === void 0 ? void 0 : lineData.value) !== null && _c !== void 0 ? _c : change.newValue;
90
+ var hasValue = !!(0, mdm_sdk_1.getAttributeValue)(currentValue);
91
+ var isAddedWithValue = isAdded && hasValue;
89
92
  return (react_1.default.createElement("div", { ref: combinedRef, className: (0, classnames_1.default)(ChangeItemRow_module_css_1.default.changeItemRow, errorClassName, (_b = {},
90
- _b[ChangeItemRow_module_css_1.default.changedRow] = isUpdated,
93
+ _b[ChangeItemRow_module_css_1.default.changedRow] = isUpdated && !isAdded,
91
94
  _b[ChangeItemRow_module_css_1.default.addedWithValueRow] = isAddedWithValue,
92
95
  _b[ChangeItemRow_module_css_1.default.rejectedRow] = isLineRejected || isParentLineRejected,
93
96
  _b[ChangeItemRow_module_css_1.default.highlightedRow] = isHighlightedAdded,
@@ -88,11 +88,12 @@ exports.createEntityRelationsObjectByRelation = (0, ramda_1.curry)(function (obj
88
88
  return entity ? { entity: __assign(__assign({}, entity), { uri: relation.startObjectUri }), relations: relations } : { relations: relations };
89
89
  });
90
90
  var concatEntityRelationsObjects = function (acc, object) {
91
+ var _a, _b;
91
92
  var entity = object.entity, relations = object.relations;
92
93
  var entityUri = entity.uri;
93
94
  var mergedRelations = (0, ramda_1.pipe)((0, ramda_1.pathOr)([], [entityUri, 'relations']), (0, ramda_1.concat)(relations), ramda_1.uniq)(acc);
94
95
  acc[entityUri] = {
95
- entity: entity,
96
+ entity: (_b = (_a = acc[entityUri]) === null || _a === void 0 ? void 0 : _a.entity) !== null && _b !== void 0 ? _b : entity,
96
97
  relations: mergedRelations
97
98
  };
98
99
  return acc;
@@ -260,6 +261,14 @@ var buildDCRSavePlan = function (changes, getLinesByChangeId, metadata) {
260
261
  ? newValue.toString()
261
262
  : newValue;
262
263
  updatedChange = (0, ramda_1.assocPath)(valuePath, processedNewValue, initialChange);
264
+ var lineValue = lineData.value;
265
+ if (lineValue && typeof lineValue === 'object' && 'lookupCode' in lineValue) {
266
+ var parentPath = valuePath.slice(0, -1);
267
+ updatedChange = (0, ramda_1.assocPath)(__spreadArray(__spreadArray([], parentPath, true), ['lookupCode'], false), lineValue.lookupCode, updatedChange);
268
+ if ('lookupRawValue' in lineValue) {
269
+ updatedChange = (0, ramda_1.assocPath)(__spreadArray(__spreadArray([], parentPath, true), ['lookupRawValue'], false), lineValue.lookupRawValue, updatedChange);
270
+ }
271
+ }
263
272
  }
264
273
  }
265
274
  if (updatedChange) {
@@ -128,6 +128,55 @@ describe('dcr helpers tests', function () {
128
128
  'entities/10f6Jabc': objects[3]
129
129
  });
130
130
  });
131
+ it('concatEntityRelationsObjects preserves existing entity when duplicate uri appears', function () {
132
+ var originalEntity = {
133
+ uri: 'entities/10f6JMNk',
134
+ isExist: true,
135
+ label: 'Test Label',
136
+ secondaryLabel: '',
137
+ type: 'configuration/entityTypes/Type'
138
+ };
139
+ var fetchedEntity = {
140
+ uri: 'entities/10f6JMNk',
141
+ type: 'configuration/entityTypes/Type',
142
+ label: 'Test Label',
143
+ secondaryLabel: '',
144
+ roles: ['configuration/roles/Admin']
145
+ };
146
+ var objects = [
147
+ {
148
+ entity: originalEntity,
149
+ relations: [
150
+ {
151
+ uri: 'relations/rel1',
152
+ type: 'configuration/relationTypes/HasAddress',
153
+ startObjectUri: 'entities/10f6JMNk',
154
+ startObjectLabel: 'label 1',
155
+ endObjectUri: 'entities/abc',
156
+ endObjectLabel: 'label 2',
157
+ isExist: true
158
+ }
159
+ ]
160
+ },
161
+ {
162
+ entity: fetchedEntity,
163
+ relations: [
164
+ {
165
+ uri: 'relations/rel2',
166
+ type: 'configuration/relationTypes/HasAddress',
167
+ startObjectUri: 'entities/10f6JMNk',
168
+ startObjectLabel: 'label 1',
169
+ endObjectUri: 'entities/def',
170
+ endObjectLabel: 'label 3',
171
+ isExist: true
172
+ }
173
+ ]
174
+ }
175
+ ];
176
+ var result = objects.reduce(function (acc, object) { return (0, dcr_1.concatEntityRelationsObjects)(acc, object); }, {});
177
+ expect(result['entities/10f6JMNk'].entity).toBe(originalEntity);
178
+ expect(result['entities/10f6JMNk'].relations).toEqual([objects[1].relations[0], objects[0].relations[0]]);
179
+ });
131
180
  it('getEntityUriForChangeRequest behaviour', function () {
132
181
  expect((0, dcr_1.getEntityUriForChangeRequest)('dcrUri', 'entityUri')).toBe('dcrUri/changes/entityUri');
133
182
  });
@@ -14,6 +14,7 @@ import { ScrollToAddedAttributeContext } from '../../../contexts/ScrollToAddedAt
14
14
  import styles from './ChangeItemRow.module.css';
15
15
  export var ChangeItemRow = function (_a) {
16
16
  var _b;
17
+ var _c;
17
18
  var change = _a.change, entityInfo = _a.entityInfo;
18
19
  var lineIds = change.lineIds || extractLineIds(change === null || change === void 0 ? void 0 : change.newValue);
19
20
  var isParentLineRejected = useContextSelector(ChangeRequestEditorContext, function (context) {
@@ -25,6 +26,7 @@ export var ChangeItemRow = function (_a) {
25
26
  var isUpdated = useContextSelector(ChangeRequestEditorContext, function (context) {
26
27
  return context.getIsLineUpdated(lineIds === null || lineIds === void 0 ? void 0 : lineIds[0]);
27
28
  });
29
+ var lineData = useContextSelector(ChangeRequestEditorContext, function (context) { return context.getLineData(lineIds === null || lineIds === void 0 ? void 0 : lineIds[0]); });
28
30
  var errorByLineId = useContextSelector(ChangeRequestEditorContext, function (context) {
29
31
  return context.getErrorByLineId(lineIds === null || lineIds === void 0 ? void 0 : lineIds[0]);
30
32
  });
@@ -35,12 +37,12 @@ export var ChangeItemRow = function (_a) {
35
37
  var isHighlighted = isHighlightedErrorType(scrollToElementContext === null || scrollToElementContext === void 0 ? void 0 : scrollToElementContext.type) &&
36
38
  highlightedError &&
37
39
  errorLineIds.includes(highlightedError.uri);
38
- var _c = useScrollToAttributeError({
40
+ var _d = useScrollToAttributeError({
39
41
  highlightedError: isHighlighted ? scrollToElementContext : null,
40
42
  className: styles.changeItemRowWithError
41
- }), ref = _c.ref, errorClassName = _c.errorClassName;
43
+ }), ref = _d.ref, errorClassName = _d.errorClassName;
42
44
  var addedId = getAddedId(change);
43
- var _d = useContext(ScrollToAddedAttributeContext), highlightedIds = _d.highlightedIds, scrollToFirst = _d.scrollToFirst;
45
+ var _e = useContext(ScrollToAddedAttributeContext), highlightedIds = _e.highlightedIds, scrollToFirst = _e.scrollToFirst;
44
46
  var isHighlightedAdded = !!addedId && highlightedIds.has(addedId);
45
47
  var scrollRef = useRef(null);
46
48
  useEffect(function () {
@@ -55,10 +57,11 @@ export var ChangeItemRow = function (_a) {
55
57
  var isEditedOperation = change.operation === DCROperationTypes.EDITED;
56
58
  var editable = isEditableChange(change, entityInfo);
57
59
  var isAdded = isAddedAttribute(change);
58
- var hasValue = !!getAttributeValue(change.newValue);
59
- var isAddedWithValue = isAdded && (isUpdated || hasValue);
60
+ var currentValue = (_c = lineData === null || lineData === void 0 ? void 0 : lineData.value) !== null && _c !== void 0 ? _c : change.newValue;
61
+ var hasValue = !!getAttributeValue(currentValue);
62
+ var isAddedWithValue = isAdded && hasValue;
60
63
  return (React.createElement("div", { ref: combinedRef, className: classnames(styles.changeItemRow, errorClassName, (_b = {},
61
- _b[styles.changedRow] = isUpdated,
64
+ _b[styles.changedRow] = isUpdated && !isAdded,
62
65
  _b[styles.addedWithValueRow] = isAddedWithValue,
63
66
  _b[styles.rejectedRow] = isLineRejected || isParentLineRejected,
64
67
  _b[styles.highlightedRow] = isHighlightedAdded,
@@ -84,11 +84,12 @@ export var createEntityRelationsObjectByRelation = curry(function (objectsInfo,
84
84
  return entity ? { entity: __assign(__assign({}, entity), { uri: relation.startObjectUri }), relations: relations } : { relations: relations };
85
85
  });
86
86
  export var concatEntityRelationsObjects = function (acc, object) {
87
+ var _a, _b;
87
88
  var entity = object.entity, relations = object.relations;
88
89
  var entityUri = entity.uri;
89
90
  var mergedRelations = pipe(pathOr([], [entityUri, 'relations']), concat(relations), uniq)(acc);
90
91
  acc[entityUri] = {
91
- entity: entity,
92
+ entity: (_b = (_a = acc[entityUri]) === null || _a === void 0 ? void 0 : _a.entity) !== null && _b !== void 0 ? _b : entity,
92
93
  relations: mergedRelations
93
94
  };
94
95
  return acc;
@@ -253,6 +254,14 @@ export var buildDCRSavePlan = function (changes, getLinesByChangeId, metadata) {
253
254
  ? newValue.toString()
254
255
  : newValue;
255
256
  updatedChange = assocPath(valuePath, processedNewValue, initialChange);
257
+ var lineValue = lineData.value;
258
+ if (lineValue && typeof lineValue === 'object' && 'lookupCode' in lineValue) {
259
+ var parentPath = valuePath.slice(0, -1);
260
+ updatedChange = assocPath(__spreadArray(__spreadArray([], parentPath, true), ['lookupCode'], false), lineValue.lookupCode, updatedChange);
261
+ if ('lookupRawValue' in lineValue) {
262
+ updatedChange = assocPath(__spreadArray(__spreadArray([], parentPath, true), ['lookupRawValue'], false), lineValue.lookupRawValue, updatedChange);
263
+ }
264
+ }
256
265
  }
257
266
  }
258
267
  if (updatedChange) {
@@ -126,6 +126,55 @@ describe('dcr helpers tests', function () {
126
126
  'entities/10f6Jabc': objects[3]
127
127
  });
128
128
  });
129
+ it('concatEntityRelationsObjects preserves existing entity when duplicate uri appears', function () {
130
+ var originalEntity = {
131
+ uri: 'entities/10f6JMNk',
132
+ isExist: true,
133
+ label: 'Test Label',
134
+ secondaryLabel: '',
135
+ type: 'configuration/entityTypes/Type'
136
+ };
137
+ var fetchedEntity = {
138
+ uri: 'entities/10f6JMNk',
139
+ type: 'configuration/entityTypes/Type',
140
+ label: 'Test Label',
141
+ secondaryLabel: '',
142
+ roles: ['configuration/roles/Admin']
143
+ };
144
+ var objects = [
145
+ {
146
+ entity: originalEntity,
147
+ relations: [
148
+ {
149
+ uri: 'relations/rel1',
150
+ type: 'configuration/relationTypes/HasAddress',
151
+ startObjectUri: 'entities/10f6JMNk',
152
+ startObjectLabel: 'label 1',
153
+ endObjectUri: 'entities/abc',
154
+ endObjectLabel: 'label 2',
155
+ isExist: true
156
+ }
157
+ ]
158
+ },
159
+ {
160
+ entity: fetchedEntity,
161
+ relations: [
162
+ {
163
+ uri: 'relations/rel2',
164
+ type: 'configuration/relationTypes/HasAddress',
165
+ startObjectUri: 'entities/10f6JMNk',
166
+ startObjectLabel: 'label 1',
167
+ endObjectUri: 'entities/def',
168
+ endObjectLabel: 'label 3',
169
+ isExist: true
170
+ }
171
+ ]
172
+ }
173
+ ];
174
+ var result = objects.reduce(function (acc, object) { return concatEntityRelationsObjects(acc, object); }, {});
175
+ expect(result['entities/10f6JMNk'].entity).toBe(originalEntity);
176
+ expect(result['entities/10f6JMNk'].relations).toEqual([objects[1].relations[0], objects[0].relations[0]]);
177
+ });
129
178
  it('getEntityUriForChangeRequest behaviour', function () {
130
179
  expect(getEntityUriForChangeRequest('dcrUri', 'entityUri')).toBe('dcrUri/changes/entityUri');
131
180
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reltio/components",
3
- "version": "1.4.2244",
3
+ "version": "1.4.2245",
4
4
  "license": "SEE LICENSE IN LICENSE FILE",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./index.js",