@wise/dynamic-flow-client-internal 3.15.2 → 3.15.3-experimental-5473f1c
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/dynamicFlow/DynamicFlow.js +104 -0
- package/build/dynamicFlow/DynamicFlow.test.js +116 -0
- package/build/i18n/index.js +62 -0
- package/build/index.js +5 -0
- package/build/stories/DynamicFlow.story.js +52 -0
- package/build/stories/DynamicFragment.story.js +132 -0
- package/build/stories/Editable.story.js +70 -0
- package/build/stories/Examples.story.js +29 -0
- package/build/stories/Features.story.js +33 -0
- package/build/stories/utils/DynamicFlowSideBySide.js +30 -0
- package/build/stories/utils/fixtureHttpClient.js +119 -0
- package/build/stories/visual-tests/generated.story.js +216 -0
- package/build/stories/visual-tests/layouts.story.js +108 -0
- package/build/stories/visual-tests/schemas.story.js +84 -0
- package/build/stories/visual-tests/step.story.js +30 -0
- package/build/test-utils/NeptuneProviders.js +23 -0
- package/build/test-utils/rtl-utils.js +20 -0
- package/build/tests/renderers/RadioInputRendererComponent.test.js +76 -0
- package/build/tests/renderers/value-utils.test.js +33 -0
- package/build/types/index.d.ts +2 -1
- package/build/types/stories/visual-tests/generated.story.d.ts +39 -0
- package/build/types/stories/visual-tests/layouts.story.d.ts +21 -0
- package/build/types/stories/visual-tests/schemas.story.d.ts +17 -0
- package/build/types/stories/visual-tests/step.story.d.ts +8 -0
- package/package.json +3 -3
|
@@ -0,0 +1,104 @@
|
|
|
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
49
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
50
|
+
if (ar || !(i in from)) {
|
|
51
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
52
|
+
ar[i] = from[i];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
56
|
+
};
|
|
57
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
58
|
+
import { forwardRef, useCallback, useMemo } from 'react';
|
|
59
|
+
import { useIntl } from 'react-intl';
|
|
60
|
+
import { DynamicFlow as DynamicFlowCoreLegacy, DynamicFlowCoreRevamp, DynamicFragmentCore, } from '@wise/dynamic-flow-client';
|
|
61
|
+
import { RendererHttpClientProvider, getWiseRenderers } from '@wise/dynamic-flow-renderers';
|
|
62
|
+
var wiseRenderers = getWiseRenderers();
|
|
63
|
+
export function DynamicFlowLegacy(props) {
|
|
64
|
+
var _a = props.customFetch, customFetch = _a === void 0 ? globalThis.fetch : _a;
|
|
65
|
+
var coreProps = __assign(__assign({}, props), { httpClient: customFetch });
|
|
66
|
+
return _jsx(DynamicFlowCoreLegacy, __assign({}, coreProps));
|
|
67
|
+
}
|
|
68
|
+
export function DynamicFlowRevamp(props) {
|
|
69
|
+
var _a = props.customFetch, customFetch = _a === void 0 ? globalThis.fetch : _a, renderers = props.renderers;
|
|
70
|
+
var httpClient = useWiseHttpClient(customFetch);
|
|
71
|
+
var mergedRenderers = useMemo(function () { return __spreadArray(__spreadArray([], (renderers !== null && renderers !== void 0 ? renderers : []), true), wiseRenderers, true); }, [renderers]);
|
|
72
|
+
var coreProps = __assign(__assign({}, props), { httpClient: httpClient, renderers: mergedRenderers });
|
|
73
|
+
return (_jsx(RendererHttpClientProvider, { httpClient: httpClient, children: _jsx(DynamicFlowCoreRevamp, __assign({}, coreProps)) }));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* DynamicFragment is like DynamicFlowRevamp, but it also accepts a ForwardedRef.
|
|
77
|
+
* This ref conforms to the DynamicFragmentController type, containing two functions: `getValue` and `validate`.
|
|
78
|
+
* @experimental This component may be changed in the future without notice.
|
|
79
|
+
*/
|
|
80
|
+
export var DynamicFragment = forwardRef(function DynamicFragment(props, ref) {
|
|
81
|
+
var _a = props.customFetch, customFetch = _a === void 0 ? globalThis.fetch : _a, renderers = props.renderers;
|
|
82
|
+
var httpClient = useWiseHttpClient(customFetch);
|
|
83
|
+
var mergedRenderers = useMemo(function () { return __spreadArray(__spreadArray([], (renderers !== null && renderers !== void 0 ? renderers : []), true), wiseRenderers, true); }, [renderers]);
|
|
84
|
+
var coreProps = __assign(__assign({}, props), { httpClient: httpClient, renderers: mergedRenderers });
|
|
85
|
+
return (_jsx(RendererHttpClientProvider, { httpClient: httpClient, children: _jsx(DynamicFragmentCore, __assign({}, coreProps, { ref: ref })) }));
|
|
86
|
+
});
|
|
87
|
+
var useWiseHttpClient = function (httpClient) {
|
|
88
|
+
var locale = useIntl().locale;
|
|
89
|
+
return useCallback(function (input_1) {
|
|
90
|
+
var args_1 = [];
|
|
91
|
+
for (var _i = 1; _i < arguments.length; _i++) {
|
|
92
|
+
args_1[_i - 1] = arguments[_i];
|
|
93
|
+
}
|
|
94
|
+
return __awaiter(void 0, __spreadArray([input_1], args_1, true), void 0, function (input, init) {
|
|
95
|
+
var headers;
|
|
96
|
+
if (init === void 0) { init = {}; }
|
|
97
|
+
return __generator(this, function (_a) {
|
|
98
|
+
headers = new Headers(init.headers);
|
|
99
|
+
headers.set('accept-language', locale);
|
|
100
|
+
return [2 /*return*/, httpClient(input, __assign(__assign({}, init), { credentials: 'include', headers: headers }))];
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}, [httpClient, locale]);
|
|
104
|
+
};
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
49
|
+
import { waitFor } from '@testing-library/react';
|
|
50
|
+
import { renderWithProviders } from '../test-utils/rtl-utils';
|
|
51
|
+
import { DynamicFlowLegacy, DynamicFlowRevamp, DynamicFragment } from './DynamicFlow';
|
|
52
|
+
describe.each([
|
|
53
|
+
{ name: 'DynamicFlowLegacy', DFComponent: DynamicFlowLegacy },
|
|
54
|
+
{ name: 'DynamicFlowRevamp', DFComponent: DynamicFlowRevamp },
|
|
55
|
+
{ name: 'DynamicFragment', DFComponent: DynamicFragment },
|
|
56
|
+
])('Wise-Specific Headers', function (_a) {
|
|
57
|
+
var name = _a.name, DFComponent = _a.DFComponent;
|
|
58
|
+
it("".concat(name, " - makes an initial request with additional RequestInit parameters, as specified in the wise-specific fetcher"), function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
59
|
+
var props, customFetch, requestInit, credentials, headers;
|
|
60
|
+
return __generator(this, function (_a) {
|
|
61
|
+
switch (_a.label) {
|
|
62
|
+
case 0:
|
|
63
|
+
props = {
|
|
64
|
+
flowId: 'test',
|
|
65
|
+
initialAction: { url: '/initial' },
|
|
66
|
+
onCompletion: jest.fn(),
|
|
67
|
+
onError: jest.fn(),
|
|
68
|
+
};
|
|
69
|
+
customFetch = jest.fn();
|
|
70
|
+
renderWithProviders(_jsx(DFComponent, __assign({}, props, { customFetch: customFetch })));
|
|
71
|
+
return [4 /*yield*/, waitFor(function () {
|
|
72
|
+
expect(customFetch).toHaveBeenCalledWith('/initial', expect.anything());
|
|
73
|
+
})];
|
|
74
|
+
case 1:
|
|
75
|
+
_a.sent();
|
|
76
|
+
requestInit = customFetch.mock.calls[0][1];
|
|
77
|
+
credentials = requestInit === null || requestInit === void 0 ? void 0 : requestInit.credentials;
|
|
78
|
+
expect(credentials).toBe('include');
|
|
79
|
+
headers = Array.from(new Headers(requestInit === null || requestInit === void 0 ? void 0 : requestInit.headers).entries());
|
|
80
|
+
expect(headers).toContainEqual(['accept-language', 'en-GB']);
|
|
81
|
+
expect(headers).toContainEqual(['content-type', 'application/json']);
|
|
82
|
+
return [2 /*return*/];
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
}); });
|
|
86
|
+
});
|
|
87
|
+
describe('DynamicFlowLegacy', function () {
|
|
88
|
+
describe('when initialised with customFetch', function () {
|
|
89
|
+
it('uses the "correct" casing of Content-Type header', function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
90
|
+
var props, customFetch, requestInit;
|
|
91
|
+
return __generator(this, function (_a) {
|
|
92
|
+
switch (_a.label) {
|
|
93
|
+
case 0:
|
|
94
|
+
props = {
|
|
95
|
+
flowId: 'test',
|
|
96
|
+
initialAction: { url: '/initial' },
|
|
97
|
+
onCompletion: jest.fn(),
|
|
98
|
+
onError: jest.fn(),
|
|
99
|
+
};
|
|
100
|
+
customFetch = jest.fn();
|
|
101
|
+
renderWithProviders(_jsx(DynamicFlowLegacy, __assign({}, props, { customFetch: customFetch })));
|
|
102
|
+
return [4 /*yield*/, waitFor(function () {
|
|
103
|
+
expect(customFetch).toHaveBeenCalledWith('/initial', expect.anything());
|
|
104
|
+
})];
|
|
105
|
+
case 1:
|
|
106
|
+
_a.sent();
|
|
107
|
+
requestInit = customFetch.mock.calls[0][1];
|
|
108
|
+
expect(requestInit === null || requestInit === void 0 ? void 0 : requestInit.headers).toMatchObject({
|
|
109
|
+
'Content-Type': 'application/json',
|
|
110
|
+
});
|
|
111
|
+
return [2 /*return*/];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}); });
|
|
115
|
+
});
|
|
116
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
13
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
14
|
+
if (ar || !(i in from)) {
|
|
15
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
16
|
+
ar[i] = from[i];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
20
|
+
};
|
|
21
|
+
import { translations as coreTranslations } from '@wise/dynamic-flow-client';
|
|
22
|
+
import de from './de.json';
|
|
23
|
+
import en from './en.json';
|
|
24
|
+
import es from './es.json';
|
|
25
|
+
import fr from './fr.json';
|
|
26
|
+
import hu from './hu.json';
|
|
27
|
+
import id from './id.json';
|
|
28
|
+
import it from './it.json';
|
|
29
|
+
import ja from './ja.json';
|
|
30
|
+
import pl from './pl.json';
|
|
31
|
+
import pt from './pt.json';
|
|
32
|
+
import ro from './ro.json';
|
|
33
|
+
import ru from './ru.json';
|
|
34
|
+
import th from './th.json';
|
|
35
|
+
import tr from './tr.json';
|
|
36
|
+
import zhCN from './zh_CN.json';
|
|
37
|
+
import zhHK from './zh_HK.json';
|
|
38
|
+
var wiseTranslations = {
|
|
39
|
+
en: en,
|
|
40
|
+
de: de,
|
|
41
|
+
es: es,
|
|
42
|
+
fr: fr,
|
|
43
|
+
hu: hu,
|
|
44
|
+
id: id,
|
|
45
|
+
it: it,
|
|
46
|
+
ja: ja,
|
|
47
|
+
pl: pl,
|
|
48
|
+
pt: pt,
|
|
49
|
+
ro: ro,
|
|
50
|
+
ru: ru,
|
|
51
|
+
th: th,
|
|
52
|
+
tr: tr,
|
|
53
|
+
zh: zhCN,
|
|
54
|
+
'zh-CN': zhCN,
|
|
55
|
+
'zh-HK': zhHK,
|
|
56
|
+
};
|
|
57
|
+
var languages = Array.from(new Set(__spreadArray(__spreadArray([], Object.keys(coreTranslations), true), Object.keys(wiseTranslations), true)));
|
|
58
|
+
var translations = languages.reduce(function (acc, lang) {
|
|
59
|
+
var _a;
|
|
60
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[lang] = __assign(__assign({}, coreTranslations[lang]), wiseTranslations[lang]), _a)));
|
|
61
|
+
}, {});
|
|
62
|
+
export default translations;
|
package/build/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { makeHttpClient } from '@wise/dynamic-flow-client';
|
|
2
|
+
export { JsonSchemaForm, isValidSchema } from '@wise/dynamic-flow-client';
|
|
3
|
+
export { default as translations } from './i18n';
|
|
4
|
+
export { DynamicFlowLegacy as DynamicFlow, DynamicFlowLegacy, DynamicFlowRevamp, DynamicFragment, } from './dynamicFlow/DynamicFlow';
|
|
5
|
+
export var makeCustomFetch = makeHttpClient;
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { action } from '@storybook/addon-actions';
|
|
14
|
+
import { layouts, features, examples, schemas } from '@wise/dynamic-flow-fixtures';
|
|
15
|
+
import { DynamicFlowLegacy, DynamicFlowRevamp } from '../index';
|
|
16
|
+
import { fixtureHttpClient } from './utils/fixtureHttpClient';
|
|
17
|
+
var fixtures = __assign(__assign(__assign(__assign({}, examples), schemas), layouts), features);
|
|
18
|
+
function DynamicFlowRenderer(_a) {
|
|
19
|
+
var _b = _a.initialStepName, initialStepName = _b === void 0 ? '' : _b, _c = _a.revampEnabled, revampEnabled = _c === void 0 ? false : _c;
|
|
20
|
+
var selectedStep = fixtures[initialStepName] || {};
|
|
21
|
+
var props = {
|
|
22
|
+
flowId: 'storybook',
|
|
23
|
+
customFetch: fixtureHttpClient,
|
|
24
|
+
onCompletion: action('onCompletion'),
|
|
25
|
+
onError: action('onError'),
|
|
26
|
+
onEvent: action('onEvent'),
|
|
27
|
+
onLog: action('onLog'),
|
|
28
|
+
};
|
|
29
|
+
return revampEnabled ? (_jsx(DynamicFlowRevamp, __assign({}, props, { initialAction: { method: 'GET', url: "/steps/".concat(initialStepName) } }), selectedStep.id)) : (_jsx(DynamicFlowLegacy, __assign({}, props, { initialAction: { method: 'GET', url: "/steps/".concat(initialStepName) }, loaderConfig: { size: 'xl', initial: true, submission: false } }), selectedStep.id));
|
|
30
|
+
}
|
|
31
|
+
var meta = {
|
|
32
|
+
title: 'Multi-fixture',
|
|
33
|
+
component: DynamicFlowRenderer,
|
|
34
|
+
};
|
|
35
|
+
export var AllFixtures = {
|
|
36
|
+
argTypes: {
|
|
37
|
+
initialStepName: {
|
|
38
|
+
label: 'Initial Step',
|
|
39
|
+
control: 'select',
|
|
40
|
+
options: Object.keys(fixtures),
|
|
41
|
+
},
|
|
42
|
+
revampEnabled: {
|
|
43
|
+
label: 'Enable revamp',
|
|
44
|
+
control: 'boolean',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
args: { initialStepName: Object.keys(fixtures)[1], revampEnabled: false },
|
|
48
|
+
parameters: {
|
|
49
|
+
chromatic: { disableSnapshot: true },
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
export default meta;
|
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
49
|
+
/* eslint-disable no-nested-ternary */
|
|
50
|
+
import { action } from '@storybook/addon-actions';
|
|
51
|
+
import { Button } from '@transferwise/components';
|
|
52
|
+
import { useRef, useState } from 'react';
|
|
53
|
+
import { DynamicFragment } from '..';
|
|
54
|
+
import { fixtureHttpClient } from './utils/fixtureHttpClient';
|
|
55
|
+
var step = {
|
|
56
|
+
id: 'dynamic-fragment-story',
|
|
57
|
+
title: 'Dynamic Fragment',
|
|
58
|
+
schemas: [
|
|
59
|
+
{
|
|
60
|
+
$id: '#form',
|
|
61
|
+
type: 'object',
|
|
62
|
+
displayOrder: ['name', 'city'],
|
|
63
|
+
required: ['name'],
|
|
64
|
+
properties: {
|
|
65
|
+
name: { type: 'string', title: 'Name', minLength: 2 },
|
|
66
|
+
city: {
|
|
67
|
+
title: 'City',
|
|
68
|
+
oneOf: [
|
|
69
|
+
{ title: 'London', const: 'London', icon: { name: 'flag-gb' } },
|
|
70
|
+
{ title: 'Paris', const: 'Paris', icon: { name: 'flag-fr' } },
|
|
71
|
+
{ title: 'New York', const: 'New York', icon: { name: 'flag-us' } },
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
layout: [
|
|
78
|
+
{
|
|
79
|
+
type: 'form',
|
|
80
|
+
schemaId: '#form',
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
};
|
|
84
|
+
function DynamicFragmentStory() {
|
|
85
|
+
var _this = this;
|
|
86
|
+
var ref = useRef(null);
|
|
87
|
+
var props = {
|
|
88
|
+
flowId: 'storybook',
|
|
89
|
+
analyticsId: 'storybook',
|
|
90
|
+
customFetch: fixtureHttpClient,
|
|
91
|
+
onCompletion: action('onCompletion'),
|
|
92
|
+
onValueChange: action('onValueChange'),
|
|
93
|
+
onError: action('onError'),
|
|
94
|
+
onEvent: action('onEvent'),
|
|
95
|
+
onLog: action('onLog'),
|
|
96
|
+
};
|
|
97
|
+
var _a = useState(''), currentValue = _a[0], setCurrentValue = _a[1];
|
|
98
|
+
var _b = useState(null), isValid = _b[0], setValid = _b[1];
|
|
99
|
+
var backgroundColor = isValid === null ? '#eeeeee' : isValid ? '#eeffee' : '#ffeeee';
|
|
100
|
+
var validityText = isValid === null ? '' : isValid ? '✅ valid\n\n' : '❌ invalid\n\n';
|
|
101
|
+
return (_jsxs(_Fragment, { children: [_jsx(DynamicFragment, __assign({ ref: ref }, props, { initialStep: step, onValueChange: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
102
|
+
var newValue;
|
|
103
|
+
var _a, _b;
|
|
104
|
+
return __generator(this, function (_c) {
|
|
105
|
+
switch (_c.label) {
|
|
106
|
+
case 0: return [4 /*yield*/, ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.getValue())];
|
|
107
|
+
case 1:
|
|
108
|
+
newValue = (_b = (_c.sent())) !== null && _b !== void 0 ? _b : null;
|
|
109
|
+
setCurrentValue(JSON.stringify(newValue, null, 2));
|
|
110
|
+
return [2 /*return*/];
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}); } }), JSON.stringify(step)), _jsx(Button, { onClick: function () { return __awaiter(_this, void 0, void 0, function () {
|
|
114
|
+
var ok;
|
|
115
|
+
var _a, _b;
|
|
116
|
+
return __generator(this, function (_c) {
|
|
117
|
+
ok = (_b = (_a = ref.current) === null || _a === void 0 ? void 0 : _a.validate()) !== null && _b !== void 0 ? _b : false;
|
|
118
|
+
setValid(ok);
|
|
119
|
+
return [2 /*return*/];
|
|
120
|
+
});
|
|
121
|
+
}); }, children: "validate()" }), _jsx("hr", {}), _jsxs("pre", { style: { backgroundColor: backgroundColor }, children: [validityText, currentValue] })] }));
|
|
122
|
+
}
|
|
123
|
+
var meta = {
|
|
124
|
+
title: 'Dynamic Fragment',
|
|
125
|
+
component: DynamicFragmentStory,
|
|
126
|
+
};
|
|
127
|
+
export var AllFixtures = {
|
|
128
|
+
parameters: {
|
|
129
|
+
chromatic: { disableSnapshot: true },
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
export default meta;
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
13
|
+
/* eslint-disable react/forbid-dom-props */
|
|
14
|
+
import { layouts, schemas, examples, features } from '@wise/dynamic-flow-fixtures';
|
|
15
|
+
import { useMemo, useState } from 'react';
|
|
16
|
+
import DynamicFlowSideBySide from './utils/DynamicFlowSideBySide';
|
|
17
|
+
var fixtures = __assign(__assign(__assign(__assign({}, features), schemas), layouts), examples);
|
|
18
|
+
export function Editable(_a) {
|
|
19
|
+
var _b = _a.initialStepName, initialStepName = _b === void 0 ? '' : _b;
|
|
20
|
+
var selectedStep = fixtures[initialStepName] || {};
|
|
21
|
+
var selectedInitialStep = JSON.stringify(selectedStep, null, 2);
|
|
22
|
+
return _jsx(InteractiveDemo, { selectedInitialStep: selectedInitialStep }, selectedInitialStep);
|
|
23
|
+
}
|
|
24
|
+
function InteractiveDemo(_a) {
|
|
25
|
+
var selectedInitialStep = _a.selectedInitialStep;
|
|
26
|
+
var _b = useState(200), initialStatusCode = _b[0], setInitialStatusCode = _b[1];
|
|
27
|
+
var _c = useState(selectedInitialStep), initialStep = _c[0], setInitialStep = _c[1];
|
|
28
|
+
var onTextAreaChange = function (event) {
|
|
29
|
+
setInitialStep(event.target.value);
|
|
30
|
+
};
|
|
31
|
+
return (_jsxs(_Fragment, { children: [_jsxs("div", { children: [_jsx("h3", { children: "Editable Demo" }), _jsx("p", { children: "You can specify a response status code and body, and DF will load your step below." }), _jsxs("fieldset", { children: [_jsx("label", { htmlFor: "status-code", children: "Response Status code: " }), _jsx(StatusCodeSelect, { id: "status-code", state: [initialStatusCode, setInitialStatusCode] })] }), _jsxs("fieldset", { children: [_jsx("label", { htmlFor: "textarea", children: "Response Body:" }), _jsx(InvalidJsonWarning, { initialStep: initialStep }), _jsx("textarea", { id: "textarea", wrap: "off", rows: 40, style: {
|
|
32
|
+
fontFamily: 'monospace',
|
|
33
|
+
fontSize: '0.9em',
|
|
34
|
+
width: '100%',
|
|
35
|
+
maxHeight: '200px',
|
|
36
|
+
}, value: initialStep, onChange: onTextAreaChange })] })] }), isValidJson(initialStep) ? (_jsx(DynamicFlowSideBySide, { initialStep: JSON.parse(initialStep) }, "".concat(initialStep, "-").concat(initialStatusCode))) : null] }));
|
|
37
|
+
}
|
|
38
|
+
function InvalidJsonWarning(_a) {
|
|
39
|
+
var initialStep = _a.initialStep;
|
|
40
|
+
var validJson = useMemo(function () { return isValidJson(initialStep); }, [initialStep]);
|
|
41
|
+
return !validJson ? (_jsx("p", { children: "\u274C Invalid syntax or missing elements are preventing the JSON code you entered from being parsed." })) : null;
|
|
42
|
+
}
|
|
43
|
+
var isValidJson = function (value) {
|
|
44
|
+
try {
|
|
45
|
+
JSON.parse(value);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
catch (_a) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
function StatusCodeSelect(_a) {
|
|
53
|
+
var id = _a.id, _b = _a.state, value = _b[0], setValue = _b[1];
|
|
54
|
+
return (_jsxs("select", { id: id, value: value, onChange: function (event) { return setValue(Number.parseInt(event.target.value, 10)); }, children: [_jsx("option", { children: "200" }), _jsx("option", { children: "400" }), _jsx("option", { children: "500" })] }));
|
|
55
|
+
}
|
|
56
|
+
export default {
|
|
57
|
+
component: Editable,
|
|
58
|
+
title: 'Multi-fixture',
|
|
59
|
+
parameters: {
|
|
60
|
+
chromatic: { disableSnapshot: true },
|
|
61
|
+
},
|
|
62
|
+
argTypes: {
|
|
63
|
+
initialStepName: {
|
|
64
|
+
label: 'Initial Step',
|
|
65
|
+
control: 'select',
|
|
66
|
+
options: Object.keys(fixtures),
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
args: { initialStepName: Object.keys(fixtures)[0] },
|
|
70
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { examples } from '@wise/dynamic-flow-fixtures';
|
|
3
|
+
import DynamicFlowSideBySide from './utils/DynamicFlowSideBySide';
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Examples',
|
|
6
|
+
component: DynamicFlowSideBySide,
|
|
7
|
+
parameters: {
|
|
8
|
+
chromatic: { disableSnapshot: true },
|
|
9
|
+
},
|
|
10
|
+
argTypes: {},
|
|
11
|
+
};
|
|
12
|
+
export var CameraCapture = {
|
|
13
|
+
render: function () { return (_jsx(DynamicFlowSideBySide, { initialStep: examples.cameraCapture }, "camera-capture")); },
|
|
14
|
+
};
|
|
15
|
+
export var RecipientUpdate = {
|
|
16
|
+
render: function () { return (_jsx(DynamicFlowSideBySide, { initialStep: examples.recipientUpdate }, "recipient-update")); },
|
|
17
|
+
};
|
|
18
|
+
export var SingleFileUpload = {
|
|
19
|
+
render: function () { return (_jsx(DynamicFlowSideBySide, { initialStep: examples.singleFileUpload }, "single-file-upload")); },
|
|
20
|
+
};
|
|
21
|
+
export var RecipientCreation = {
|
|
22
|
+
render: function () { return (_jsx(DynamicFlowSideBySide, { initialStep: examples.recipientCreation }, "recipient-creation")); },
|
|
23
|
+
};
|
|
24
|
+
export var StepValidationErrors = {
|
|
25
|
+
render: function () { return (_jsx(DynamicFlowSideBySide, { initialStep: examples.stepValidationErrors }, "step-validation")); },
|
|
26
|
+
};
|
|
27
|
+
export var RecipientCreationWithInitialModel = {
|
|
28
|
+
render: function () { return (_jsx(DynamicFlowSideBySide, { initialStep: examples.recipientCreationWithInitialModel }, "recipient-creation-initial-model")); },
|
|
29
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { features } from '@wise/dynamic-flow-fixtures';
|
|
3
|
+
import DynamicFlowSideBySide from './utils/DynamicFlowSideBySide';
|
|
4
|
+
var meta = {
|
|
5
|
+
component: DynamicFlowSideBySide,
|
|
6
|
+
title: 'Dev Tools/Features',
|
|
7
|
+
parameters: {
|
|
8
|
+
chromatic: { disableSnapshot: true },
|
|
9
|
+
},
|
|
10
|
+
argTypes: {},
|
|
11
|
+
};
|
|
12
|
+
export default meta;
|
|
13
|
+
export var ActionResponse = {
|
|
14
|
+
render: function () { return (_jsx(DynamicFlowSideBySide, { initialStep: features.actionResponse }, "actionResponse")); },
|
|
15
|
+
};
|
|
16
|
+
export var ArrayUploadBase64 = {
|
|
17
|
+
render: function () { return (_jsx(DynamicFlowSideBySide, { initialStep: features.arrayUploadBase64 }, "arrayUploadBase64")); },
|
|
18
|
+
};
|
|
19
|
+
export var External = {
|
|
20
|
+
render: function () { return _jsx(DynamicFlowSideBySide, { initialStep: features.external }, "external"); },
|
|
21
|
+
};
|
|
22
|
+
export var PersistAsync = {
|
|
23
|
+
render: function () { return _jsx(DynamicFlowSideBySide, { initialStep: features.persistAsync }, "persistAsync"); },
|
|
24
|
+
};
|
|
25
|
+
export var Polling = {
|
|
26
|
+
render: function () { return _jsx(DynamicFlowSideBySide, { initialStep: features.polling }, "polling"); },
|
|
27
|
+
};
|
|
28
|
+
export var Search = {
|
|
29
|
+
render: function () { return _jsx(DynamicFlowSideBySide, { initialStep: features.search }, "search"); },
|
|
30
|
+
};
|
|
31
|
+
export var Modal = {
|
|
32
|
+
render: function () { return _jsx(DynamicFlowSideBySide, { initialStep: features.modal }, "modal"); },
|
|
33
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { action } from '@storybook/addon-actions';
|
|
14
|
+
import { DynamicFlowRevamp } from '../../dynamicFlow/DynamicFlow';
|
|
15
|
+
import { fixtureHttpClient } from './fixtureHttpClient';
|
|
16
|
+
import { DynamicFlowLegacy } from '../..';
|
|
17
|
+
function DynamicFlowSideBySide(_a) {
|
|
18
|
+
var key = _a.key, initialStep = _a.initialStep;
|
|
19
|
+
var props = {
|
|
20
|
+
flowId: 'storybook',
|
|
21
|
+
customFetch: fixtureHttpClient,
|
|
22
|
+
features: [],
|
|
23
|
+
onCompletion: action('onCompletion'),
|
|
24
|
+
onError: action('onError'),
|
|
25
|
+
onEvent: action('onEvent'),
|
|
26
|
+
onLog: action('onLog'),
|
|
27
|
+
};
|
|
28
|
+
return (_jsxs("div", { className: "df-side-by-side-container", children: [_jsx("div", { className: "df-side-by-side-column", children: _jsx(DynamicFlowLegacy, __assign({}, props, { loaderConfig: { size: 'xl', initial: true, submission: false }, initialStep: initialStep }), "".concat(key, "-original")) }), _jsx("div", { className: "df-side-by-side-column", children: _jsx(DynamicFlowRevamp, __assign({}, props, { initialStep: initialStep }), "".concat(key, "-revamp")) })] }));
|
|
29
|
+
}
|
|
30
|
+
export default DynamicFlowSideBySide;
|