@reltio/components 1.4.2023 → 1.4.2025
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.
- package/EditModeAttributesPager/components/AttributeRenderer/IntegrationAttributeRenderer.test.js +10 -0
- package/SimpleAttributeEditor/SimpleAttributeEditor.js +12 -5
- package/cjs/EditModeAttributesPager/components/AttributeRenderer/IntegrationAttributeRenderer.test.js +10 -0
- package/cjs/SimpleAttributeEditor/SimpleAttributeEditor.js +12 -5
- package/cjs/contexts/MaskedAttributesContext/context.js +98 -14
- package/contexts/MaskedAttributesContext/context.js +100 -16
- package/package.json +1 -1
package/EditModeAttributesPager/components/AttributeRenderer/IntegrationAttributeRenderer.test.js
CHANGED
|
@@ -212,4 +212,14 @@ describe('Attribute renderer tests', function () {
|
|
|
212
212
|
expect(within(attributeValues[1]).getByText('Yes')).toBeInTheDocument();
|
|
213
213
|
expect(within(attributeValues[1]).queryByText('No')).not.toBeInTheDocument();
|
|
214
214
|
});
|
|
215
|
+
it('should not allow to add more values in edit mode if cardinality max value is one', function () {
|
|
216
|
+
var props = __assign(__assign({}, defaultProps), { attributeType: __assign(__assign({}, attributeType), { cardinality: { maxValue: 1, minValue: 0 } }) });
|
|
217
|
+
setUp({ props: props });
|
|
218
|
+
expect(screen.queryByTestId('reltio-add-one-more-simple-attribute-button')).not.toBeInTheDocument();
|
|
219
|
+
});
|
|
220
|
+
it('should allow to add more values in edit mode if cardinality max value is more than one', function () {
|
|
221
|
+
var props = __assign(__assign({}, defaultProps), { attributeType: __assign(__assign({}, attributeType), { cardinality: { maxValue: 2, minValue: 1 } }) });
|
|
222
|
+
setUp({ props: props });
|
|
223
|
+
expect(screen.getByTestId('reltio-add-one-more-simple-attribute-button')).toBeInTheDocument();
|
|
224
|
+
});
|
|
215
225
|
});
|
|
@@ -50,21 +50,22 @@ var AsyncMountPlaceholder = function () {
|
|
|
50
50
|
};
|
|
51
51
|
var SimpleAttributeEditor = function (_a) {
|
|
52
52
|
var _b, _c;
|
|
53
|
-
var
|
|
53
|
+
var _d;
|
|
54
|
+
var className = _a.className, attributeValue = _a.attributeValue, attributeType = _a.attributeType, isReltioCrosswalk = _a.isReltioCrosswalk, ownError = _a.ownError, mode = _a.mode, onAddOneMore = _a.onAddOneMore, onDeleteAttribute = _a.onDeleteAttribute, onChangeAttribute = _a.onChangeAttribute, onDeactivateError = _a.onDeactivateError, additionalControlsRenderer = _a.additionalControlsRenderer, state = _a.state, highlightedError = _a.highlightedError, _e = _a.isEmptyEditor, isEmptyEditor = _e === void 0 ? false : _e, otherProps = __rest(_a, ["className", "attributeValue", "attributeType", "isReltioCrosswalk", "ownError", "mode", "onAddOneMore", "onDeleteAttribute", "onChangeAttribute", "onDeactivateError", "additionalControlsRenderer", "state", "highlightedError", "isEmptyEditor"]);
|
|
54
55
|
var styles = useStyles();
|
|
55
56
|
var deleted = state === 'deleted';
|
|
56
57
|
var edited = state === 'edited';
|
|
57
58
|
var isEditableMode = checkIsEditableMode(mode);
|
|
58
|
-
var
|
|
59
|
+
var _f = useAttributeValuePermissions({
|
|
59
60
|
attributeValue: attributeValue,
|
|
60
61
|
attributeType: attributeType,
|
|
61
62
|
mode: mode,
|
|
62
63
|
isReltioCrosswalk: isReltioCrosswalk
|
|
63
|
-
}), canCreate =
|
|
64
|
+
}), canCreate = _f.canCreate, canEdit = _f.canEdit, canDelete = _f.canDelete;
|
|
64
65
|
var showToEdit = canEdit && isEditableMode && !attributeValue.masked;
|
|
65
66
|
var errorMessage = getErrorMessage(ownError);
|
|
66
67
|
var dependentLookupEditorContext = useMdmDependentLookupEditorContext(attributeValue, attributeType);
|
|
67
|
-
var
|
|
68
|
+
var _g = useScrollToAttributeError({ highlightedError: highlightedError, isSimple: true }), ref = _g.ref, errorClassName = _g.errorClassName;
|
|
68
69
|
useEffect(function () {
|
|
69
70
|
// when editor is empty but has default lookup code, onChangeAttribute will be called by useLookupsResolver
|
|
70
71
|
if (isEmptyEditor && isDependentLookupAttrType(attributeType) && !has('lookupCode', attributeValue)) {
|
|
@@ -90,7 +91,13 @@ var SimpleAttributeEditor = function (_a) {
|
|
|
90
91
|
deactivateError();
|
|
91
92
|
}
|
|
92
93
|
};
|
|
93
|
-
var
|
|
94
|
+
var maxCardinalityIsOne = ((_d = attributeType === null || attributeType === void 0 ? void 0 : attributeType.cardinality) === null || _d === void 0 ? void 0 : _d.maxValue) === 1;
|
|
95
|
+
var showAddButton = !!onAddOneMore &&
|
|
96
|
+
canCreate &&
|
|
97
|
+
!attributeType.singleValue &&
|
|
98
|
+
!attributeValue.masked &&
|
|
99
|
+
mode !== Mode.Viewing &&
|
|
100
|
+
!maxCardinalityIsOne;
|
|
94
101
|
var showDeleteButton = !deleted && !!onDeleteAttribute && canDelete && !attributeValue.masked && mode !== Mode.Viewing;
|
|
95
102
|
var hasError = !!errorMessage;
|
|
96
103
|
var deletedProps = deleted ? { disabled: true, isCrossedOut: true } : {};
|
|
@@ -217,4 +217,14 @@ describe('Attribute renderer tests', function () {
|
|
|
217
217
|
expect((0, react_2.within)(attributeValues[1]).getByText('Yes')).toBeInTheDocument();
|
|
218
218
|
expect((0, react_2.within)(attributeValues[1]).queryByText('No')).not.toBeInTheDocument();
|
|
219
219
|
});
|
|
220
|
+
it('should not allow to add more values in edit mode if cardinality max value is one', function () {
|
|
221
|
+
var props = __assign(__assign({}, defaultProps), { attributeType: __assign(__assign({}, attributeType), { cardinality: { maxValue: 1, minValue: 0 } }) });
|
|
222
|
+
setUp({ props: props });
|
|
223
|
+
expect(react_2.screen.queryByTestId('reltio-add-one-more-simple-attribute-button')).not.toBeInTheDocument();
|
|
224
|
+
});
|
|
225
|
+
it('should allow to add more values in edit mode if cardinality max value is more than one', function () {
|
|
226
|
+
var props = __assign(__assign({}, defaultProps), { attributeType: __assign(__assign({}, attributeType), { cardinality: { maxValue: 2, minValue: 1 } }) });
|
|
227
|
+
setUp({ props: props });
|
|
228
|
+
expect(react_2.screen.getByTestId('reltio-add-one-more-simple-attribute-button')).toBeInTheDocument();
|
|
229
|
+
});
|
|
220
230
|
});
|
|
@@ -78,21 +78,22 @@ var AsyncMountPlaceholder = function () {
|
|
|
78
78
|
};
|
|
79
79
|
var SimpleAttributeEditor = function (_a) {
|
|
80
80
|
var _b, _c;
|
|
81
|
-
var
|
|
81
|
+
var _d;
|
|
82
|
+
var className = _a.className, attributeValue = _a.attributeValue, attributeType = _a.attributeType, isReltioCrosswalk = _a.isReltioCrosswalk, ownError = _a.ownError, mode = _a.mode, onAddOneMore = _a.onAddOneMore, onDeleteAttribute = _a.onDeleteAttribute, onChangeAttribute = _a.onChangeAttribute, onDeactivateError = _a.onDeactivateError, additionalControlsRenderer = _a.additionalControlsRenderer, state = _a.state, highlightedError = _a.highlightedError, _e = _a.isEmptyEditor, isEmptyEditor = _e === void 0 ? false : _e, otherProps = __rest(_a, ["className", "attributeValue", "attributeType", "isReltioCrosswalk", "ownError", "mode", "onAddOneMore", "onDeleteAttribute", "onChangeAttribute", "onDeactivateError", "additionalControlsRenderer", "state", "highlightedError", "isEmptyEditor"]);
|
|
82
83
|
var styles = (0, styles_1.useStyles)();
|
|
83
84
|
var deleted = state === 'deleted';
|
|
84
85
|
var edited = state === 'edited';
|
|
85
86
|
var isEditableMode = (0, mdm_sdk_1.isEditableMode)(mode);
|
|
86
|
-
var
|
|
87
|
+
var _f = (0, useAttributeValuePermissions_1.useAttributeValuePermissions)({
|
|
87
88
|
attributeValue: attributeValue,
|
|
88
89
|
attributeType: attributeType,
|
|
89
90
|
mode: mode,
|
|
90
91
|
isReltioCrosswalk: isReltioCrosswalk
|
|
91
|
-
}), canCreate =
|
|
92
|
+
}), canCreate = _f.canCreate, canEdit = _f.canEdit, canDelete = _f.canDelete;
|
|
92
93
|
var showToEdit = canEdit && isEditableMode && !attributeValue.masked;
|
|
93
94
|
var errorMessage = (0, mdm_sdk_1.getErrorMessage)(ownError);
|
|
94
95
|
var dependentLookupEditorContext = (0, MdmModuleContext_1.useMdmDependentLookupEditorContext)(attributeValue, attributeType);
|
|
95
|
-
var
|
|
96
|
+
var _g = (0, useScrollToAttributeError_1.useScrollToAttributeError)({ highlightedError: highlightedError, isSimple: true }), ref = _g.ref, errorClassName = _g.errorClassName;
|
|
96
97
|
(0, react_1.useEffect)(function () {
|
|
97
98
|
// when editor is empty but has default lookup code, onChangeAttribute will be called by useLookupsResolver
|
|
98
99
|
if (isEmptyEditor && (0, mdm_sdk_1.isDependentLookupAttrType)(attributeType) && !(0, ramda_1.has)('lookupCode', attributeValue)) {
|
|
@@ -118,7 +119,13 @@ var SimpleAttributeEditor = function (_a) {
|
|
|
118
119
|
deactivateError();
|
|
119
120
|
}
|
|
120
121
|
};
|
|
121
|
-
var
|
|
122
|
+
var maxCardinalityIsOne = ((_d = attributeType === null || attributeType === void 0 ? void 0 : attributeType.cardinality) === null || _d === void 0 ? void 0 : _d.maxValue) === 1;
|
|
123
|
+
var showAddButton = !!onAddOneMore &&
|
|
124
|
+
canCreate &&
|
|
125
|
+
!attributeType.singleValue &&
|
|
126
|
+
!attributeValue.masked &&
|
|
127
|
+
mode !== mdm_sdk_1.Mode.Viewing &&
|
|
128
|
+
!maxCardinalityIsOne;
|
|
122
129
|
var showDeleteButton = !deleted && !!onDeleteAttribute && canDelete && !attributeValue.masked && mode !== mdm_sdk_1.Mode.Viewing;
|
|
123
130
|
var hasError = !!errorMessage;
|
|
124
131
|
var deletedProps = deleted ? { disabled: true, isCrossedOut: true } : {};
|
|
@@ -85,28 +85,112 @@ exports.MaskedAttributesContext = (0, react_context_selector_1.createContext)({
|
|
|
85
85
|
var MaskedAttributesProvider = function (_a) {
|
|
86
86
|
var children = _a.children;
|
|
87
87
|
var _b = (0, react_1.useState)({}), unmaskedAttributes = _b[0], setUnmaskedAttributes = _b[1];
|
|
88
|
+
var _c = (0, react_1.useState)({}), unmaskedEntities = _c[0], setUnmaskedEntities = _c[1];
|
|
89
|
+
var _d = (0, react_1.useState)(null), unmaskedCurrentEntity = _d[0], setUnmaskedCurrentEntity = _d[1];
|
|
88
90
|
var profileLastLoadedTime = (0, MdmModuleContext_1.useMdmProfileLastLoadedTime)();
|
|
91
|
+
var historyMode = (0, MdmModuleContext_1.useMdmHistoryMode)();
|
|
92
|
+
var entityUri = (0, MdmModuleContext_1.useMdmEntityUri)();
|
|
93
|
+
var historyEvent = (0, MdmModuleContext_1.useMdmHistoryEvent)();
|
|
89
94
|
var unmaskedAttributesRef = (0, react_1.useRef)(unmaskedAttributes);
|
|
90
95
|
//performance optimization to avoid unnecessary re-renders
|
|
91
96
|
unmaskedAttributesRef.current = unmaskedAttributes;
|
|
92
97
|
(0, react_1.useEffect)(function () {
|
|
93
98
|
setUnmaskedAttributes({});
|
|
94
|
-
}, [profileLastLoadedTime]);
|
|
99
|
+
}, [profileLastLoadedTime, historyEvent]);
|
|
100
|
+
(0, react_1.useEffect)(function () {
|
|
101
|
+
setUnmaskedEntities({});
|
|
102
|
+
setUnmaskedCurrentEntity(null);
|
|
103
|
+
}, [entityUri]);
|
|
104
|
+
var getUnmaskedEntity = (0, react_1.useCallback)(function (timestamp) { return __awaiter(void 0, void 0, void 0, function () {
|
|
105
|
+
var unmaskedEntity_1, _a, unmaskedEntity, _b;
|
|
106
|
+
var _c;
|
|
107
|
+
return __generator(this, function (_d) {
|
|
108
|
+
switch (_d.label) {
|
|
109
|
+
case 0:
|
|
110
|
+
if (!!timestamp) return [3 /*break*/, 4];
|
|
111
|
+
if (!(unmaskedCurrentEntity !== null && unmaskedCurrentEntity !== void 0)) return [3 /*break*/, 1];
|
|
112
|
+
_a = unmaskedCurrentEntity;
|
|
113
|
+
return [3 /*break*/, 3];
|
|
114
|
+
case 1: return [4 /*yield*/, (0, mdm_sdk_1.getEntity)(entityUri)];
|
|
115
|
+
case 2:
|
|
116
|
+
_a = (_d.sent());
|
|
117
|
+
_d.label = 3;
|
|
118
|
+
case 3:
|
|
119
|
+
unmaskedEntity_1 = _a;
|
|
120
|
+
if (!unmaskedCurrentEntity) {
|
|
121
|
+
setUnmaskedCurrentEntity(unmaskedEntity_1);
|
|
122
|
+
}
|
|
123
|
+
return [2 /*return*/, unmaskedEntity_1];
|
|
124
|
+
case 4:
|
|
125
|
+
if (!((_c = unmaskedEntities[timestamp]) !== null && _c !== void 0)) return [3 /*break*/, 5];
|
|
126
|
+
_b = _c;
|
|
127
|
+
return [3 /*break*/, 7];
|
|
128
|
+
case 5: return [4 /*yield*/, (0, mdm_sdk_1.getEntityTimeSlice)(entityUri, timestamp)];
|
|
129
|
+
case 6:
|
|
130
|
+
_b = (_d.sent());
|
|
131
|
+
_d.label = 7;
|
|
132
|
+
case 7:
|
|
133
|
+
unmaskedEntity = _b;
|
|
134
|
+
if (!unmaskedEntities[timestamp]) {
|
|
135
|
+
setUnmaskedEntities(function (prev) {
|
|
136
|
+
var _a;
|
|
137
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[timestamp] = unmaskedEntity, _a)));
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return [2 /*return*/, unmaskedEntity];
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}); }, [entityUri, unmaskedEntities, unmaskedCurrentEntity]);
|
|
144
|
+
var unmaskAttributeValueFromEntity = (0, react_1.useCallback)(function (attributeValueUri) { return __awaiter(void 0, void 0, void 0, function () {
|
|
145
|
+
var unmaskedEntity, attributeValue, _a;
|
|
146
|
+
return __generator(this, function (_b) {
|
|
147
|
+
switch (_b.label) {
|
|
148
|
+
case 0: return [4 /*yield*/, getUnmaskedEntity(historyEvent === null || historyEvent === void 0 ? void 0 : historyEvent.aStamp)];
|
|
149
|
+
case 1:
|
|
150
|
+
unmaskedEntity = _b.sent();
|
|
151
|
+
attributeValue = (0, mdm_sdk_1.findAttributeValueByUri)(unmaskedEntity, attributeValueUri);
|
|
152
|
+
if (attributeValue) {
|
|
153
|
+
return [2 /*return*/, attributeValue];
|
|
154
|
+
}
|
|
155
|
+
if (!(historyMode === mdm_sdk_1.HistoryMode.Current)) return [3 /*break*/, 3];
|
|
156
|
+
return [4 /*yield*/, getUnmaskedEntity()];
|
|
157
|
+
case 2:
|
|
158
|
+
_a = _b.sent();
|
|
159
|
+
return [3 /*break*/, 5];
|
|
160
|
+
case 3: return [4 /*yield*/, getUnmaskedEntity(historyEvent === null || historyEvent === void 0 ? void 0 : historyEvent.bStamp)];
|
|
161
|
+
case 4:
|
|
162
|
+
_a = _b.sent();
|
|
163
|
+
_b.label = 5;
|
|
164
|
+
case 5:
|
|
165
|
+
unmaskedEntity = _a;
|
|
166
|
+
attributeValue = (0, mdm_sdk_1.findAttributeValueByUri)(unmaskedEntity, attributeValueUri);
|
|
167
|
+
return [2 /*return*/, attributeValue];
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}); }, [getUnmaskedEntity, historyEvent === null || historyEvent === void 0 ? void 0 : historyEvent.aStamp, historyEvent === null || historyEvent === void 0 ? void 0 : historyEvent.bStamp, historyMode]);
|
|
95
171
|
var unmaskAttributeValue = (0, react_1.useCallback)(function (attributeValueUri) { return __awaiter(void 0, void 0, void 0, function () {
|
|
96
|
-
var unmaskedAttributes_1, unmaskedAttributeValue_1, error_1;
|
|
97
|
-
return __generator(this, function (
|
|
98
|
-
switch (
|
|
172
|
+
var unmaskedAttributes_1, unmaskedAttributeValue_1, _a, error_1;
|
|
173
|
+
return __generator(this, function (_b) {
|
|
174
|
+
switch (_b.label) {
|
|
99
175
|
case 0:
|
|
100
|
-
|
|
176
|
+
_b.trys.push([0, 7, , 8]);
|
|
101
177
|
unmaskedAttributes_1 = unmaskedAttributesRef.current;
|
|
102
|
-
if (!!unmaskedAttributes_1[attributeValueUri]) return [3 /*break*/,
|
|
178
|
+
if (!!unmaskedAttributes_1[attributeValueUri]) return [3 /*break*/, 5];
|
|
103
179
|
setUnmaskedAttributes(function (prev) {
|
|
104
180
|
var _a;
|
|
105
181
|
return (__assign(__assign({}, prev), (_a = {}, _a[attributeValueUri] = __assign(__assign({}, prev[attributeValueUri]), { loading: true }), _a)));
|
|
106
182
|
});
|
|
107
|
-
return [
|
|
183
|
+
if (!historyEvent) return [3 /*break*/, 2];
|
|
184
|
+
return [4 /*yield*/, unmaskAttributeValueFromEntity(attributeValueUri)];
|
|
108
185
|
case 1:
|
|
109
|
-
|
|
186
|
+
_a = _b.sent();
|
|
187
|
+
return [3 /*break*/, 4];
|
|
188
|
+
case 2: return [4 /*yield*/, (0, mdm_sdk_1.getUnmaskedAttributeValue)(attributeValueUri)];
|
|
189
|
+
case 3:
|
|
190
|
+
_a = _b.sent();
|
|
191
|
+
_b.label = 4;
|
|
192
|
+
case 4:
|
|
193
|
+
unmaskedAttributeValue_1 = _a;
|
|
110
194
|
setUnmaskedAttributes(function (prev) {
|
|
111
195
|
var _a;
|
|
112
196
|
return (__assign(__assign({}, prev), (_a = {}, _a[attributeValueUri] = {
|
|
@@ -116,21 +200,21 @@ var MaskedAttributesProvider = function (_a) {
|
|
|
116
200
|
}, _a)));
|
|
117
201
|
});
|
|
118
202
|
return [2 /*return*/, unmaskedAttributeValue_1];
|
|
119
|
-
case
|
|
203
|
+
case 5:
|
|
120
204
|
setUnmaskedAttributes(function (prev) {
|
|
121
205
|
var _a;
|
|
122
206
|
return (__assign(__assign({}, prev), (_a = {}, _a[attributeValueUri] = __assign(__assign({}, prev[attributeValueUri]), { isUnmasked: true }), _a)));
|
|
123
207
|
});
|
|
124
208
|
return [2 /*return*/, unmaskedAttributes_1[attributeValueUri].attributeValue];
|
|
125
|
-
case
|
|
126
|
-
case
|
|
127
|
-
error_1 =
|
|
209
|
+
case 6: return [3 /*break*/, 8];
|
|
210
|
+
case 7:
|
|
211
|
+
error_1 = _b.sent();
|
|
128
212
|
(0, errors_1.showErrorMessage)(error_1);
|
|
129
213
|
return [2 /*return*/, null];
|
|
130
|
-
case
|
|
214
|
+
case 8: return [2 /*return*/];
|
|
131
215
|
}
|
|
132
216
|
});
|
|
133
|
-
}); }, []);
|
|
217
|
+
}); }, [historyEvent, unmaskAttributeValueFromEntity]);
|
|
134
218
|
var maskAttributeValue = (0, react_1.useCallback)(function (attributeValueUri) {
|
|
135
219
|
setUnmaskedAttributes(function (prev) {
|
|
136
220
|
var _a;
|
|
@@ -47,9 +47,9 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
47
47
|
};
|
|
48
48
|
import React, { useState, useCallback, useEffect, useRef } from 'react';
|
|
49
49
|
import { createContext } from '@fluentui/react-context-selector';
|
|
50
|
-
import { getUnmaskedAttributeValue } from '@reltio/mdm-sdk';
|
|
50
|
+
import { HistoryMode, findAttributeValueByUri, getEntity, getEntityTimeSlice, getUnmaskedAttributeValue } from '@reltio/mdm-sdk';
|
|
51
51
|
import { showErrorMessage } from '../../helpers/errors';
|
|
52
|
-
import { useMdmProfileLastLoadedTime } from '../MdmModuleContext';
|
|
52
|
+
import { useMdmEntityUri, useMdmHistoryEvent, useMdmHistoryMode, useMdmProfileLastLoadedTime } from '../MdmModuleContext';
|
|
53
53
|
export var MaskedAttributesContext = createContext({
|
|
54
54
|
unmaskedAttributes: {},
|
|
55
55
|
unmaskAttributeValue: undefined,
|
|
@@ -59,28 +59,112 @@ export var MaskedAttributesContext = createContext({
|
|
|
59
59
|
export var MaskedAttributesProvider = function (_a) {
|
|
60
60
|
var children = _a.children;
|
|
61
61
|
var _b = useState({}), unmaskedAttributes = _b[0], setUnmaskedAttributes = _b[1];
|
|
62
|
+
var _c = useState({}), unmaskedEntities = _c[0], setUnmaskedEntities = _c[1];
|
|
63
|
+
var _d = useState(null), unmaskedCurrentEntity = _d[0], setUnmaskedCurrentEntity = _d[1];
|
|
62
64
|
var profileLastLoadedTime = useMdmProfileLastLoadedTime();
|
|
65
|
+
var historyMode = useMdmHistoryMode();
|
|
66
|
+
var entityUri = useMdmEntityUri();
|
|
67
|
+
var historyEvent = useMdmHistoryEvent();
|
|
63
68
|
var unmaskedAttributesRef = useRef(unmaskedAttributes);
|
|
64
69
|
//performance optimization to avoid unnecessary re-renders
|
|
65
70
|
unmaskedAttributesRef.current = unmaskedAttributes;
|
|
66
71
|
useEffect(function () {
|
|
67
72
|
setUnmaskedAttributes({});
|
|
68
|
-
}, [profileLastLoadedTime]);
|
|
73
|
+
}, [profileLastLoadedTime, historyEvent]);
|
|
74
|
+
useEffect(function () {
|
|
75
|
+
setUnmaskedEntities({});
|
|
76
|
+
setUnmaskedCurrentEntity(null);
|
|
77
|
+
}, [entityUri]);
|
|
78
|
+
var getUnmaskedEntity = useCallback(function (timestamp) { return __awaiter(void 0, void 0, void 0, function () {
|
|
79
|
+
var unmaskedEntity_1, _a, unmaskedEntity, _b;
|
|
80
|
+
var _c;
|
|
81
|
+
return __generator(this, function (_d) {
|
|
82
|
+
switch (_d.label) {
|
|
83
|
+
case 0:
|
|
84
|
+
if (!!timestamp) return [3 /*break*/, 4];
|
|
85
|
+
if (!(unmaskedCurrentEntity !== null && unmaskedCurrentEntity !== void 0)) return [3 /*break*/, 1];
|
|
86
|
+
_a = unmaskedCurrentEntity;
|
|
87
|
+
return [3 /*break*/, 3];
|
|
88
|
+
case 1: return [4 /*yield*/, getEntity(entityUri)];
|
|
89
|
+
case 2:
|
|
90
|
+
_a = (_d.sent());
|
|
91
|
+
_d.label = 3;
|
|
92
|
+
case 3:
|
|
93
|
+
unmaskedEntity_1 = _a;
|
|
94
|
+
if (!unmaskedCurrentEntity) {
|
|
95
|
+
setUnmaskedCurrentEntity(unmaskedEntity_1);
|
|
96
|
+
}
|
|
97
|
+
return [2 /*return*/, unmaskedEntity_1];
|
|
98
|
+
case 4:
|
|
99
|
+
if (!((_c = unmaskedEntities[timestamp]) !== null && _c !== void 0)) return [3 /*break*/, 5];
|
|
100
|
+
_b = _c;
|
|
101
|
+
return [3 /*break*/, 7];
|
|
102
|
+
case 5: return [4 /*yield*/, getEntityTimeSlice(entityUri, timestamp)];
|
|
103
|
+
case 6:
|
|
104
|
+
_b = (_d.sent());
|
|
105
|
+
_d.label = 7;
|
|
106
|
+
case 7:
|
|
107
|
+
unmaskedEntity = _b;
|
|
108
|
+
if (!unmaskedEntities[timestamp]) {
|
|
109
|
+
setUnmaskedEntities(function (prev) {
|
|
110
|
+
var _a;
|
|
111
|
+
return (__assign(__assign({}, prev), (_a = {}, _a[timestamp] = unmaskedEntity, _a)));
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return [2 /*return*/, unmaskedEntity];
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}); }, [entityUri, unmaskedEntities, unmaskedCurrentEntity]);
|
|
118
|
+
var unmaskAttributeValueFromEntity = useCallback(function (attributeValueUri) { return __awaiter(void 0, void 0, void 0, function () {
|
|
119
|
+
var unmaskedEntity, attributeValue, _a;
|
|
120
|
+
return __generator(this, function (_b) {
|
|
121
|
+
switch (_b.label) {
|
|
122
|
+
case 0: return [4 /*yield*/, getUnmaskedEntity(historyEvent === null || historyEvent === void 0 ? void 0 : historyEvent.aStamp)];
|
|
123
|
+
case 1:
|
|
124
|
+
unmaskedEntity = _b.sent();
|
|
125
|
+
attributeValue = findAttributeValueByUri(unmaskedEntity, attributeValueUri);
|
|
126
|
+
if (attributeValue) {
|
|
127
|
+
return [2 /*return*/, attributeValue];
|
|
128
|
+
}
|
|
129
|
+
if (!(historyMode === HistoryMode.Current)) return [3 /*break*/, 3];
|
|
130
|
+
return [4 /*yield*/, getUnmaskedEntity()];
|
|
131
|
+
case 2:
|
|
132
|
+
_a = _b.sent();
|
|
133
|
+
return [3 /*break*/, 5];
|
|
134
|
+
case 3: return [4 /*yield*/, getUnmaskedEntity(historyEvent === null || historyEvent === void 0 ? void 0 : historyEvent.bStamp)];
|
|
135
|
+
case 4:
|
|
136
|
+
_a = _b.sent();
|
|
137
|
+
_b.label = 5;
|
|
138
|
+
case 5:
|
|
139
|
+
unmaskedEntity = _a;
|
|
140
|
+
attributeValue = findAttributeValueByUri(unmaskedEntity, attributeValueUri);
|
|
141
|
+
return [2 /*return*/, attributeValue];
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}); }, [getUnmaskedEntity, historyEvent === null || historyEvent === void 0 ? void 0 : historyEvent.aStamp, historyEvent === null || historyEvent === void 0 ? void 0 : historyEvent.bStamp, historyMode]);
|
|
69
145
|
var unmaskAttributeValue = useCallback(function (attributeValueUri) { return __awaiter(void 0, void 0, void 0, function () {
|
|
70
|
-
var unmaskedAttributes_1, unmaskedAttributeValue_1, error_1;
|
|
71
|
-
return __generator(this, function (
|
|
72
|
-
switch (
|
|
146
|
+
var unmaskedAttributes_1, unmaskedAttributeValue_1, _a, error_1;
|
|
147
|
+
return __generator(this, function (_b) {
|
|
148
|
+
switch (_b.label) {
|
|
73
149
|
case 0:
|
|
74
|
-
|
|
150
|
+
_b.trys.push([0, 7, , 8]);
|
|
75
151
|
unmaskedAttributes_1 = unmaskedAttributesRef.current;
|
|
76
|
-
if (!!unmaskedAttributes_1[attributeValueUri]) return [3 /*break*/,
|
|
152
|
+
if (!!unmaskedAttributes_1[attributeValueUri]) return [3 /*break*/, 5];
|
|
77
153
|
setUnmaskedAttributes(function (prev) {
|
|
78
154
|
var _a;
|
|
79
155
|
return (__assign(__assign({}, prev), (_a = {}, _a[attributeValueUri] = __assign(__assign({}, prev[attributeValueUri]), { loading: true }), _a)));
|
|
80
156
|
});
|
|
81
|
-
return [
|
|
157
|
+
if (!historyEvent) return [3 /*break*/, 2];
|
|
158
|
+
return [4 /*yield*/, unmaskAttributeValueFromEntity(attributeValueUri)];
|
|
82
159
|
case 1:
|
|
83
|
-
|
|
160
|
+
_a = _b.sent();
|
|
161
|
+
return [3 /*break*/, 4];
|
|
162
|
+
case 2: return [4 /*yield*/, getUnmaskedAttributeValue(attributeValueUri)];
|
|
163
|
+
case 3:
|
|
164
|
+
_a = _b.sent();
|
|
165
|
+
_b.label = 4;
|
|
166
|
+
case 4:
|
|
167
|
+
unmaskedAttributeValue_1 = _a;
|
|
84
168
|
setUnmaskedAttributes(function (prev) {
|
|
85
169
|
var _a;
|
|
86
170
|
return (__assign(__assign({}, prev), (_a = {}, _a[attributeValueUri] = {
|
|
@@ -90,21 +174,21 @@ export var MaskedAttributesProvider = function (_a) {
|
|
|
90
174
|
}, _a)));
|
|
91
175
|
});
|
|
92
176
|
return [2 /*return*/, unmaskedAttributeValue_1];
|
|
93
|
-
case
|
|
177
|
+
case 5:
|
|
94
178
|
setUnmaskedAttributes(function (prev) {
|
|
95
179
|
var _a;
|
|
96
180
|
return (__assign(__assign({}, prev), (_a = {}, _a[attributeValueUri] = __assign(__assign({}, prev[attributeValueUri]), { isUnmasked: true }), _a)));
|
|
97
181
|
});
|
|
98
182
|
return [2 /*return*/, unmaskedAttributes_1[attributeValueUri].attributeValue];
|
|
99
|
-
case
|
|
100
|
-
case
|
|
101
|
-
error_1 =
|
|
183
|
+
case 6: return [3 /*break*/, 8];
|
|
184
|
+
case 7:
|
|
185
|
+
error_1 = _b.sent();
|
|
102
186
|
showErrorMessage(error_1);
|
|
103
187
|
return [2 /*return*/, null];
|
|
104
|
-
case
|
|
188
|
+
case 8: return [2 /*return*/];
|
|
105
189
|
}
|
|
106
190
|
});
|
|
107
|
-
}); }, []);
|
|
191
|
+
}); }, [historyEvent, unmaskAttributeValueFromEntity]);
|
|
108
192
|
var maskAttributeValue = useCallback(function (attributeValueUri) {
|
|
109
193
|
setUnmaskedAttributes(function (prev) {
|
|
110
194
|
var _a;
|