@wise/dynamic-flow-client 3.9.0-experimental-bd037e3 → 3.9.0-experimental-90bdf26
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/build/index.js +1 -0
- package/build/main.js +5594 -5539
- package/build/main.min.js +1 -1
- package/build/main.mjs +7068 -7021
- package/build/revamp/DynamicFlowCore.js +11 -295
- package/build/revamp/DynamicFlowWise.js +10 -9
- package/build/revamp/DynamicFragmentWise.js +83 -0
- package/build/revamp/domain/components/utils/isPartialLocalValueMatch.js +15 -2
- package/build/revamp/tests/OneOfInitialisation.spec.js +100 -0
- package/build/revamp/tests/Rerendering.spec.js +156 -0
- package/build/revamp/useDynamicFlowCore.js +285 -0
- package/build/revamp/utils/type-utils.js +3 -0
- package/build/types/index.d.ts +2 -1
- package/build/types/legacy/common/utils/schema-utils.d.ts +1 -1
- package/build/types/legacy/layout/utils/index.d.ts +1 -1
- package/build/types/revamp/DynamicFlowCore.d.ts +2 -4
- package/build/types/revamp/DynamicFlowWise.d.ts +3 -4
- package/build/types/revamp/DynamicFragmentWise.d.ts +12 -0
- package/build/types/revamp/types.d.ts +7 -1
- package/build/types/revamp/useDynamicFlowCore.d.ts +11 -0
- package/build/types/revamp/utils/type-utils.d.ts +4 -3
- package/build/types/revamp/wise/renderers/utils/layout-utils.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,61 +1,3 @@
|
|
|
1
|
-
var __assign = (this && this.__assign) || function () {
|
|
2
|
-
__assign = Object.assign || function(t) {
|
|
3
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
-
s = arguments[i];
|
|
5
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
-
t[p] = s[p];
|
|
7
|
-
}
|
|
8
|
-
return t;
|
|
9
|
-
};
|
|
10
|
-
return __assign.apply(this, arguments);
|
|
11
|
-
};
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
-
function step(op) {
|
|
26
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
28
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
-
switch (op[0]) {
|
|
31
|
-
case 0: case 1: t = op; break;
|
|
32
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
-
default:
|
|
36
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
-
if (t[2]) _.ops.pop();
|
|
41
|
-
_.trys.pop(); continue;
|
|
42
|
-
}
|
|
43
|
-
op = body.call(thisArg, _);
|
|
44
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
49
|
-
var t = {};
|
|
50
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
51
|
-
t[p] = s[p];
|
|
52
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
53
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
54
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
55
|
-
t[p[i]] = s[p[i]];
|
|
56
|
-
}
|
|
57
|
-
return t;
|
|
58
|
-
};
|
|
59
1
|
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
60
2
|
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
61
3
|
if (ar || !(i in from)) {
|
|
@@ -66,245 +8,19 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
66
8
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
67
9
|
};
|
|
68
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
69
|
-
import {
|
|
70
|
-
import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState, } from 'react';
|
|
71
|
-
import { useIntl } from 'react-intl';
|
|
72
|
-
import ErrorBoundary from '../common/errorBoundary/ErrorBoundary';
|
|
73
|
-
import { mapStepToComponent } from './domain/mappers/mapStepToComponent';
|
|
74
|
-
import { executeRefresh } from './flow/executeRefresh';
|
|
75
|
-
import { executeSubmission } from './flow/executeSubmission';
|
|
11
|
+
import { useMemo } from 'react';
|
|
76
12
|
import { CoreContainerRenderer } from './renderers/CoreContainerRenderer';
|
|
77
13
|
import { getRenderFunction } from './renderers/getRenderFunction';
|
|
78
|
-
import { getSchemaErrorMessageFunction } from './renderers/getSchemaErrorMessageFunction';
|
|
79
14
|
import { StepRenderer } from './renderers/step/StepRenderer';
|
|
80
|
-
import {
|
|
81
|
-
import
|
|
82
|
-
|
|
83
|
-
var
|
|
84
|
-
var
|
|
85
|
-
var httpClient = useStableCallback(rest.httpClient);
|
|
86
|
-
var onCompletion = useStableCallback(rest.onCompletion);
|
|
87
|
-
var onError = useStableCallback(rest.onError);
|
|
88
|
-
var onEvent = useStableCallback(rest.onEvent);
|
|
89
|
-
var onLog = useStableCallback(rest.onLog);
|
|
90
|
-
var _b = useIntl(), formatMessage = _b.formatMessage, locale = _b.locale;
|
|
91
|
-
var getErrorMessageFunctions = useMemo(function () { return getSchemaErrorMessageFunction(formatMessage, locale); }, [formatMessage, locale]);
|
|
92
|
-
var _c = useState(null), stepComponent = _c[0], setStepComponent = _c[1];
|
|
93
|
-
var stepComponentRef = useRef(null);
|
|
94
|
-
var stepRef = useRef(initialStep !== null && initialStep !== void 0 ? initialStep : null);
|
|
95
|
-
var etagRef = useRef(null);
|
|
96
|
-
var abortControllerRef = useRef(new AbortController());
|
|
97
|
-
var abortCurrentAndGetNewAbortSignal = function () {
|
|
98
|
-
abortControllerRef.current.abort();
|
|
99
|
-
abortControllerRef.current = new AbortController();
|
|
100
|
-
return abortControllerRef.current.signal;
|
|
101
|
-
};
|
|
102
|
-
useEffect(function () {
|
|
103
|
-
// Initialise Flow
|
|
104
|
-
trackCoreEvent('Initiated');
|
|
105
|
-
if (!initialStep && initialAction) {
|
|
106
|
-
void onAction(__assign({ method: 'GET' }, initialAction));
|
|
107
|
-
}
|
|
108
|
-
if (initialStep && !initialAction) {
|
|
109
|
-
initialiseWithStep(initialStep, null);
|
|
110
|
-
trackCoreEvent('Step Shown', { isFirstStep: true });
|
|
111
|
-
}
|
|
112
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
113
|
-
}, []);
|
|
114
|
-
useImperativeHandle(ref, function () { return ({
|
|
115
|
-
getValue: function () { return __awaiter(_this, void 0, void 0, function () { var _a, _b; return __generator(this, function (_c) {
|
|
116
|
-
switch (_c.label) {
|
|
117
|
-
case 0: return [4 /*yield*/, ((_a = stepComponentRef.current) === null || _a === void 0 ? void 0 : _a.getSubmittableValue())];
|
|
118
|
-
case 1: return [2 /*return*/, (_b = (_c.sent())) !== null && _b !== void 0 ? _b : null];
|
|
119
|
-
}
|
|
120
|
-
}); }); },
|
|
121
|
-
validate: function () { var _a, _b; return (_b = (_a = stepComponentRef.current) === null || _a === void 0 ? void 0 : _a.validate()) !== null && _b !== void 0 ? _b : false; },
|
|
122
|
-
}); }, []);
|
|
123
|
-
var initialiseWithStep = useCallback(function (newStep, etag) {
|
|
124
|
-
var _a, _b, _c;
|
|
125
|
-
(_a = stepComponentRef.current) === null || _a === void 0 ? void 0 : _a.stop();
|
|
126
|
-
stepRef.current = newStep;
|
|
127
|
-
etagRef.current = etag;
|
|
128
|
-
var validationResult = validateStep(newStep);
|
|
129
|
-
if (!validationResult.valid) {
|
|
130
|
-
logEvent('warning', 'Invalid step.', { errors: validationResult.errors });
|
|
131
|
-
}
|
|
132
|
-
var updateComponent = function (id, update) {
|
|
133
|
-
var currentStepComponent = stepComponentRef.current;
|
|
134
|
-
if (currentStepComponent) {
|
|
135
|
-
update(findComponent([currentStepComponent], id));
|
|
136
|
-
setStepComponent(function () {
|
|
137
|
-
var newStepDomainComponent = __assign({}, currentStepComponent);
|
|
138
|
-
stepComponentRef.current = newStepDomainComponent;
|
|
139
|
-
return newStepDomainComponent;
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
try {
|
|
144
|
-
var newStepComponent_1 = mapStepToComponent({
|
|
145
|
-
stepLocalValue: (_c = (_b = stepComponentRef.current) === null || _b === void 0 ? void 0 : _b.getLocalValue()) !== null && _c !== void 0 ? _c : null,
|
|
146
|
-
step: newStep,
|
|
147
|
-
displayStepTitle: displayStepTitle,
|
|
148
|
-
loadingState: 'idle',
|
|
149
|
-
updateComponent: updateComponent,
|
|
150
|
-
getErrorMessageFunctions: getErrorMessageFunctions,
|
|
151
|
-
trackEvent: trackEvent,
|
|
152
|
-
logEvent: logEvent,
|
|
153
|
-
httpClient: httpClient,
|
|
154
|
-
onAction: onAction,
|
|
155
|
-
onRefresh: onRefresh,
|
|
156
|
-
onValueChange: ref ? function () { return trackEvent('Value Changed'); } : function () { },
|
|
157
|
-
});
|
|
158
|
-
setStepComponent(function () {
|
|
159
|
-
stepComponentRef.current = newStepComponent_1;
|
|
160
|
-
return newStepComponent_1;
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
catch (error) {
|
|
164
|
-
closeWithError(error);
|
|
165
|
-
}
|
|
166
|
-
},
|
|
167
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
168
|
-
[]);
|
|
169
|
-
var trackEvent = useCallback(function (eventName, properties) {
|
|
170
|
-
var _a, _b, _c, _d;
|
|
171
|
-
var stepId = (_b = (_a = stepRef.current) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : (_c = stepRef.current) === null || _c === void 0 ? void 0 : _c.key;
|
|
172
|
-
var analytics = (_d = stepRef.current) === null || _d === void 0 ? void 0 : _d.analytics;
|
|
173
|
-
var metadata = __assign(__assign(__assign({ flowId: flowId }, (stepId ? { stepId: stepId } : {})), analytics), properties);
|
|
174
|
-
try {
|
|
175
|
-
onEvent === null || onEvent === void 0 ? void 0 : onEvent("Dynamic Flow - ".concat(eventName), __assign({}, metadata));
|
|
176
|
-
}
|
|
177
|
-
catch (_e) { }
|
|
178
|
-
},
|
|
179
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
180
|
-
[]);
|
|
181
|
-
var trackCoreEvent = trackEvent;
|
|
182
|
-
var logEvent = useCallback(function (level, message, properties) {
|
|
183
|
-
var _a, _b, _c;
|
|
184
|
-
try {
|
|
185
|
-
onLog === null || onLog === void 0 ? void 0 : onLog(level, message, __assign(__assign({}, properties), { flowId: flowId, stepId: (_b = (_a = stepRef.current) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : (_c = stepRef.current) === null || _c === void 0 ? void 0 : _c.key }));
|
|
186
|
-
}
|
|
187
|
-
catch (_d) { }
|
|
188
|
-
},
|
|
189
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
190
|
-
[]);
|
|
191
|
-
var closeWithError = useCallback(function (error, analytics) {
|
|
192
|
-
trackCoreEvent('Failed', __assign({}, analytics));
|
|
193
|
-
onError(error);
|
|
194
|
-
},
|
|
195
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
196
|
-
[]);
|
|
197
|
-
var onAction = useCallback(function (action) { return __awaiter(_this, void 0, void 0, function () {
|
|
198
|
-
var model, command, isFirstStep, genericErrorMessage, _a, errors, _b, refreshUrl, _c, errors, error_1;
|
|
199
|
-
var _d, _e, _f;
|
|
200
|
-
return __generator(this, function (_g) {
|
|
201
|
-
switch (_g.label) {
|
|
202
|
-
case 0:
|
|
203
|
-
_g.trys.push([0, 3, , 4]);
|
|
204
|
-
(_d = stepComponentRef.current) === null || _d === void 0 ? void 0 : _d.setLoadingState('loading');
|
|
205
|
-
return [4 /*yield*/, ((_e = stepComponentRef.current) === null || _e === void 0 ? void 0 : _e.getSubmittableValue())];
|
|
206
|
-
case 1:
|
|
207
|
-
model = (_f = (_g.sent())) !== null && _f !== void 0 ? _f : null;
|
|
208
|
-
return [4 /*yield*/, executeSubmission({
|
|
209
|
-
action: action,
|
|
210
|
-
model: model,
|
|
211
|
-
isInitial: stepRef.current === null,
|
|
212
|
-
httpClient: httpClient,
|
|
213
|
-
trackEvent: trackCoreEvent,
|
|
214
|
-
})];
|
|
215
|
-
case 2:
|
|
216
|
-
command = _g.sent();
|
|
217
|
-
switch (command.type) {
|
|
218
|
-
case 'complete': {
|
|
219
|
-
onCompletion(command.result);
|
|
220
|
-
trackCoreEvent('Succeeded');
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
case 'replace-step': {
|
|
224
|
-
isFirstStep = stepRef.current === null;
|
|
225
|
-
initialiseWithStep(command.step, command.etag);
|
|
226
|
-
trackCoreEvent('Step Shown', { isFirstStep: isFirstStep });
|
|
227
|
-
break;
|
|
228
|
-
}
|
|
229
|
-
case 'error': {
|
|
230
|
-
genericErrorMessage = getErrorMessageFunctions().genericErrorWithRetry();
|
|
231
|
-
_a = command.body.errors, errors = _a === void 0 ? { error: genericErrorMessage } : _a;
|
|
232
|
-
if (stepRef.current) {
|
|
233
|
-
initialiseWithStep(__assign(__assign({}, stepRef.current), { errors: errors, model: model }), etagRef.current);
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
closeWithError(new Error('Initial request failed'), {});
|
|
237
|
-
}
|
|
238
|
-
break;
|
|
239
|
-
}
|
|
240
|
-
case 'refresh': {
|
|
241
|
-
_b = command.body, refreshUrl = _b.refreshUrl, _c = _b.errors, errors = _c === void 0 ? {} : _c;
|
|
242
|
-
void onRefresh(undefined, refreshUrl, errors);
|
|
243
|
-
break;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
return [3 /*break*/, 4];
|
|
247
|
-
case 3:
|
|
248
|
-
error_1 = _g.sent();
|
|
249
|
-
closeWithError(error_1);
|
|
250
|
-
return [3 /*break*/, 4];
|
|
251
|
-
case 4: return [2 /*return*/];
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
}); }, []);
|
|
255
|
-
var onRefresh = useCallback(function (schemaId, refreshUrl, errorsOverride) {
|
|
256
|
-
if (refreshUrl === void 0) { refreshUrl = ''; }
|
|
257
|
-
return __awaiter(_this, void 0, void 0, function () {
|
|
258
|
-
var model, command, errors, error_2;
|
|
259
|
-
var _a, _b, _c, _d;
|
|
260
|
-
return __generator(this, function (_e) {
|
|
261
|
-
switch (_e.label) {
|
|
262
|
-
case 0:
|
|
263
|
-
_e.trys.push([0, 3, , 4]);
|
|
264
|
-
(_a = stepComponentRef.current) === null || _a === void 0 ? void 0 : _a.setLoadingState('loading');
|
|
265
|
-
return [4 /*yield*/, ((_b = stepComponentRef.current) === null || _b === void 0 ? void 0 : _b.getSubmittableValue())];
|
|
266
|
-
case 1:
|
|
267
|
-
model = (_c = (_e.sent())) !== null && _c !== void 0 ? _c : null;
|
|
268
|
-
return [4 /*yield*/, executeRefresh({
|
|
269
|
-
abortSignal: abortCurrentAndGetNewAbortSignal(),
|
|
270
|
-
url: refreshUrl,
|
|
271
|
-
model: model,
|
|
272
|
-
schemaId: schemaId,
|
|
273
|
-
etag: etagRef.current,
|
|
274
|
-
httpClient: httpClient,
|
|
275
|
-
trackEvent: trackCoreEvent,
|
|
276
|
-
})];
|
|
277
|
-
case 2:
|
|
278
|
-
command = _e.sent();
|
|
279
|
-
switch (command.type) {
|
|
280
|
-
case 'refresh-step':
|
|
281
|
-
{
|
|
282
|
-
errors = errorsOverride !== null && errorsOverride !== void 0 ? errorsOverride : command.step.errors;
|
|
283
|
-
initialiseWithStep(__assign(__assign({}, command.step), { errors: errors }), command.etag);
|
|
284
|
-
}
|
|
285
|
-
break;
|
|
286
|
-
case 'error': {
|
|
287
|
-
closeWithError(new Error('Failed to refresh'), command.body.analytics);
|
|
288
|
-
break;
|
|
289
|
-
}
|
|
290
|
-
case 'noop':
|
|
291
|
-
(_d = stepComponentRef.current) === null || _d === void 0 ? void 0 : _d.setLoadingState('idle');
|
|
292
|
-
break;
|
|
293
|
-
}
|
|
294
|
-
return [3 /*break*/, 4];
|
|
295
|
-
case 3:
|
|
296
|
-
error_2 = _e.sent();
|
|
297
|
-
closeWithError(error_2, undefined);
|
|
298
|
-
return [3 /*break*/, 4];
|
|
299
|
-
case 4: return [2 /*return*/];
|
|
300
|
-
}
|
|
301
|
-
});
|
|
302
|
-
});
|
|
303
|
-
},
|
|
304
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
305
|
-
[]);
|
|
15
|
+
import { useDynamicFlowCore } from './useDynamicFlowCore';
|
|
16
|
+
import ErrorBoundary from '../common/errorBoundary/ErrorBoundary';
|
|
17
|
+
export function DynamicFlowCore(props) {
|
|
18
|
+
var stepComponentRef = useDynamicFlowCore(props).stepComponentRef;
|
|
19
|
+
var renderers = props.renderers, onEvent = props.onEvent, onError = props.onError;
|
|
306
20
|
var render = useMemo(function () { return getRenderFunction(__spreadArray(__spreadArray([CoreContainerRenderer], renderers, true), [StepRenderer], false)); }, [renderers]);
|
|
307
|
-
return (_jsx(ErrorBoundary, { onError:
|
|
21
|
+
return (_jsx(ErrorBoundary, { onError: function (error) {
|
|
22
|
+
onEvent === null || onEvent === void 0 ? void 0 : onEvent('Dynamic Flow - Failed', { error: error });
|
|
23
|
+
onError === null || onError === void 0 ? void 0 : onError(error);
|
|
24
|
+
}, children: stepComponentRef.current ? render(stepComponentRef.current) : null // TODO: render loader instead?
|
|
308
25
|
}));
|
|
309
|
-
}
|
|
310
|
-
export default DynamicFlowCore;
|
|
26
|
+
}
|
|
@@ -55,20 +55,21 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
55
55
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
56
|
};
|
|
57
57
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
58
|
-
import {
|
|
58
|
+
import { useMemo } from 'react';
|
|
59
59
|
import { useIntl } from 'react-intl';
|
|
60
60
|
import { HttpClientProvider } from '../common/httpClientContext';
|
|
61
|
-
import { getWiseRenderers } from './wise/renderers/getWiseRenderers';
|
|
62
61
|
import { mergeRequestInit } from '../common/makeHttpClient';
|
|
63
|
-
import DynamicFlowCore from './DynamicFlowCore';
|
|
64
|
-
|
|
65
|
-
var
|
|
66
|
-
|
|
62
|
+
import { DynamicFlowCore } from './DynamicFlowCore';
|
|
63
|
+
import { getWiseRenderers } from './wise/renderers/getWiseRenderers';
|
|
64
|
+
var wiseRenderers = getWiseRenderers();
|
|
65
|
+
function DynamicFlowWise(props) {
|
|
66
|
+
var httpClient = props.httpClient, renderers = props.renderers;
|
|
67
67
|
var locale = useIntl().locale;
|
|
68
68
|
var wiseHttpClient = useMemo(function () { return makeWiseHttpClient(httpClient, locale); }, [httpClient, locale]);
|
|
69
|
-
|
|
70
|
-
});
|
|
71
|
-
|
|
69
|
+
var mergedRenderers = useMemo(function () { return __spreadArray(__spreadArray([], (renderers !== null && renderers !== void 0 ? renderers : []), true), wiseRenderers, true); }, [renderers]);
|
|
70
|
+
return (_jsx(HttpClientProvider, { httpClient: wiseHttpClient, children: _jsx(DynamicFlowCore, __assign({}, props, { renderers: mergedRenderers })) }));
|
|
71
|
+
}
|
|
72
|
+
export default DynamicFlowWise;
|
|
72
73
|
var makeWiseHttpClient = function (httpClient, locale) {
|
|
73
74
|
return function (input, init) { return __awaiter(void 0, void 0, void 0, function () {
|
|
74
75
|
return __generator(this, function (_a) {
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
12
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
38
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
39
|
+
if (ar || !(i in from)) {
|
|
40
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
41
|
+
ar[i] = from[i];
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
45
|
+
};
|
|
46
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
47
|
+
import { forwardRef, useImperativeHandle, useMemo } from 'react';
|
|
48
|
+
import ErrorBoundary from '../common/errorBoundary/ErrorBoundary';
|
|
49
|
+
import { HttpClientProvider } from '../common/httpClientContext';
|
|
50
|
+
import { CoreContainerRenderer } from './renderers/CoreContainerRenderer';
|
|
51
|
+
import { getRenderFunction } from './renderers/getRenderFunction';
|
|
52
|
+
import { StepRenderer } from './renderers/step/StepRenderer';
|
|
53
|
+
import { useDynamicFlowCore } from './useDynamicFlowCore';
|
|
54
|
+
import { getWiseRenderers } from './wise/renderers/getWiseRenderers';
|
|
55
|
+
var wiseRenderers = getWiseRenderers();
|
|
56
|
+
/**
|
|
57
|
+
* DynamicFragmentWise is like DynamicFlowWise, but it also accepts a ForwardedRef.
|
|
58
|
+
* This ref conforms to the DynamicFragmentController type, containing two functions: `getValue` and `validate`.
|
|
59
|
+
* @experimental This component may be changed in the future without notice.
|
|
60
|
+
*/
|
|
61
|
+
var DynamicFragmentWise = forwardRef(function DynamicFragmentWise(props, ref) {
|
|
62
|
+
var _this = this;
|
|
63
|
+
var httpClient = props.httpClient, onEvent = props.onEvent, onError = props.onError, renderers = props.renderers;
|
|
64
|
+
var mergedRenderers = useMemo(function () { return __spreadArray(__spreadArray([], (renderers !== null && renderers !== void 0 ? renderers : []), true), wiseRenderers, true); }, [renderers]);
|
|
65
|
+
var stepComponentRef = useDynamicFlowCore(props).stepComponentRef;
|
|
66
|
+
useImperativeHandle(ref, function () { return ({
|
|
67
|
+
getValue: function () { return __awaiter(_this, void 0, void 0, function () { var _a, _b; return __generator(this, function (_c) {
|
|
68
|
+
switch (_c.label) {
|
|
69
|
+
case 0: return [4 /*yield*/, ((_a = stepComponentRef.current) === null || _a === void 0 ? void 0 : _a.getSubmittableValue())];
|
|
70
|
+
case 1: return [2 /*return*/, (_b = (_c.sent())) !== null && _b !== void 0 ? _b : null];
|
|
71
|
+
}
|
|
72
|
+
}); }); },
|
|
73
|
+
validate: function () { var _a, _b; return (_b = (_a = stepComponentRef.current) === null || _a === void 0 ? void 0 : _a.validate()) !== null && _b !== void 0 ? _b : false; },
|
|
74
|
+
}); },
|
|
75
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
76
|
+
[]);
|
|
77
|
+
var render = useMemo(function () { return getRenderFunction(__spreadArray(__spreadArray([CoreContainerRenderer], mergedRenderers, true), [StepRenderer], false)); }, [mergedRenderers]);
|
|
78
|
+
return (_jsx(ErrorBoundary, { onError: function (error) {
|
|
79
|
+
onEvent === null || onEvent === void 0 ? void 0 : onEvent('Dynamic Flow - Failed');
|
|
80
|
+
onError(error);
|
|
81
|
+
}, children: _jsx(HttpClientProvider, { httpClient: httpClient, children: stepComponentRef.current ? render(stepComponentRef.current) : null }) }));
|
|
82
|
+
});
|
|
83
|
+
export default DynamicFragmentWise;
|
|
@@ -7,7 +7,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
7
7
|
}
|
|
8
8
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
9
|
};
|
|
10
|
-
import { isObjectLocalValue } from '../../../utils/type-utils';
|
|
10
|
+
import { isArrayLocalValue, isObjectLocalValue } from '../../../utils/type-utils';
|
|
11
11
|
import { isArray, isNullish } from '../../../utils/type-validators';
|
|
12
12
|
import { getComponentForLocalValueKey } from './getComponentForLocalValueKey';
|
|
13
13
|
export var isPartialLocalValueMatch = function (partialValue, component) {
|
|
@@ -19,6 +19,9 @@ export var isPartialLocalValueMatch = function (partialValue, component) {
|
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
var componentValue = component.getLocalValue();
|
|
22
|
+
if (component.type === 'const') {
|
|
23
|
+
return compareLocalValue(partialValue, componentValue);
|
|
24
|
+
}
|
|
22
25
|
if (isObjectLocalValue(partialValue) && isObjectLocalValue(componentValue)) {
|
|
23
26
|
var allKeys = Array.from(new Set(__spreadArray(__spreadArray([], Object.keys(partialValue), true), Object.keys(componentValue), true)));
|
|
24
27
|
var matchingKeys = allKeys.filter(function (key) { return !isNullish(partialValue[key]) && !isNullish(componentValue[key]); });
|
|
@@ -33,8 +36,18 @@ export var isPartialLocalValueMatch = function (partialValue, component) {
|
|
|
33
36
|
if ('isPersisted' in component && component.isPersisted) {
|
|
34
37
|
return true;
|
|
35
38
|
}
|
|
36
|
-
return partialValue
|
|
39
|
+
return compareLocalValue(partialValue, componentValue);
|
|
37
40
|
};
|
|
38
41
|
var areEquivalentFiles = function (fileA, fileB) {
|
|
39
42
|
return fileA.name === fileB.name && fileA.type === fileB.type && fileA.size === fileB.size;
|
|
40
43
|
};
|
|
44
|
+
var compareLocalValue = function (valueA, valueB) {
|
|
45
|
+
if (isArrayLocalValue(valueA) && isArrayLocalValue(valueB)) {
|
|
46
|
+
return (valueA.length === valueB.length &&
|
|
47
|
+
valueA.every(function (value, index) { return compareLocalValue(value, valueB[index]); }));
|
|
48
|
+
}
|
|
49
|
+
if (isObjectLocalValue(valueA) && isObjectLocalValue(valueB)) {
|
|
50
|
+
return Object.keys(valueA).every(function (key) { return compareLocalValue(valueA[key], valueB[key]); });
|
|
51
|
+
}
|
|
52
|
+
return valueA === valueB;
|
|
53
|
+
};
|
|
@@ -651,4 +651,104 @@ describe('OneOf Initialisation', function () {
|
|
|
651
651
|
}); });
|
|
652
652
|
});
|
|
653
653
|
});
|
|
654
|
+
describe('when the oneOf contains const schemas whose values are objects', function () {
|
|
655
|
+
var contrivedStep = {
|
|
656
|
+
id: 'step-id',
|
|
657
|
+
title: 'Step Title',
|
|
658
|
+
schemas: [
|
|
659
|
+
{
|
|
660
|
+
$id: '#root',
|
|
661
|
+
oneOf: [
|
|
662
|
+
{
|
|
663
|
+
const: {
|
|
664
|
+
frequency: 'ONCE',
|
|
665
|
+
interval: 0,
|
|
666
|
+
letters: ['A', 'B'],
|
|
667
|
+
},
|
|
668
|
+
title: 'Never',
|
|
669
|
+
description: 'On 11 May only',
|
|
670
|
+
},
|
|
671
|
+
{
|
|
672
|
+
const: {
|
|
673
|
+
frequency: 'WEEKLY',
|
|
674
|
+
interval: 1,
|
|
675
|
+
letters: ['A', 'B'],
|
|
676
|
+
},
|
|
677
|
+
title: 'Weekly',
|
|
678
|
+
description: 'Every Saturday',
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
const: {
|
|
682
|
+
frequency: 'WEEKLY',
|
|
683
|
+
interval: 2,
|
|
684
|
+
letters: ['A', 'B'],
|
|
685
|
+
},
|
|
686
|
+
title: 'Biweekly',
|
|
687
|
+
description: 'Every two weeks on Saturday',
|
|
688
|
+
},
|
|
689
|
+
{
|
|
690
|
+
const: {
|
|
691
|
+
frequency: 'MONTHLY',
|
|
692
|
+
interval: 1,
|
|
693
|
+
letters: ['A', 'B'],
|
|
694
|
+
},
|
|
695
|
+
title: 'Monthly',
|
|
696
|
+
description: 'Day 11 of every month',
|
|
697
|
+
},
|
|
698
|
+
{
|
|
699
|
+
const: {
|
|
700
|
+
frequency: 'MONTHLY',
|
|
701
|
+
interval: 3,
|
|
702
|
+
letters: ['A', 'B'],
|
|
703
|
+
},
|
|
704
|
+
title: 'Quarterly',
|
|
705
|
+
description: 'Day 11, every 3 months',
|
|
706
|
+
},
|
|
707
|
+
],
|
|
708
|
+
placeholder: 'Select a frequency',
|
|
709
|
+
title: 'Repeats',
|
|
710
|
+
default: {
|
|
711
|
+
frequency: 'ONCE',
|
|
712
|
+
interval: 0,
|
|
713
|
+
letters: ['A', 'B'],
|
|
714
|
+
},
|
|
715
|
+
},
|
|
716
|
+
],
|
|
717
|
+
layout: [
|
|
718
|
+
{
|
|
719
|
+
type: 'form',
|
|
720
|
+
schemaId: '#root',
|
|
721
|
+
},
|
|
722
|
+
],
|
|
723
|
+
};
|
|
724
|
+
it('should select the correct option based on schema default', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
725
|
+
return __generator(this, function (_a) {
|
|
726
|
+
renderWithProviders(_jsx(DynamicFlowWise, __assign({}, getDefaultProps(), { initialStep: contrivedStep })));
|
|
727
|
+
expect(screen.getByText(/Never/)).toBeInTheDocument();
|
|
728
|
+
return [2 /*return*/];
|
|
729
|
+
});
|
|
730
|
+
}); });
|
|
731
|
+
it('should select the correct option based on step model', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
732
|
+
return __generator(this, function (_a) {
|
|
733
|
+
renderWithProviders(_jsx(DynamicFlowWise, __assign({}, getDefaultProps(), { initialStep: __assign(__assign({}, contrivedStep), { model: {
|
|
734
|
+
frequency: 'MONTHLY',
|
|
735
|
+
interval: 3,
|
|
736
|
+
} }) })));
|
|
737
|
+
expect(screen.getByText(/Quarterly/)).toBeInTheDocument();
|
|
738
|
+
return [2 /*return*/];
|
|
739
|
+
});
|
|
740
|
+
}); });
|
|
741
|
+
it('should NOT select an option based on step model, when it is missing some array elements', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
742
|
+
return __generator(this, function (_a) {
|
|
743
|
+
renderWithProviders(_jsx(DynamicFlowWise, __assign({}, getDefaultProps(), { initialStep: __assign(__assign({}, contrivedStep), { model: {
|
|
744
|
+
frequency: 'MONTHLY',
|
|
745
|
+
interval: 3,
|
|
746
|
+
letters: ['A'],
|
|
747
|
+
} }) })));
|
|
748
|
+
expect(screen.queryByText(/Quarterly/)).not.toBeInTheDocument();
|
|
749
|
+
expect(screen.queryByText(/Monthly/)).not.toBeInTheDocument();
|
|
750
|
+
return [2 /*return*/];
|
|
751
|
+
});
|
|
752
|
+
}); });
|
|
753
|
+
});
|
|
654
754
|
});
|