@reltio/components 1.4.2023 → 1.4.2024
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.
|
@@ -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;
|