@wise/dynamic-flow-client 3.5.0-experimental-b041af5 → 3.5.0
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/main.js +6 -2
- package/build/main.min.js +1 -1
- package/build/main.mjs +6 -2
- package/build/types/revamp/domain/components/MultiUploadInputComponent.d.ts +1 -1
- package/build/types/revamp/domain/components/UploadInputComponent.d.ts +1 -1
- package/package.json +3 -2
- package/build/common/httpClientContext/HttpClientContext.js +0 -35
- package/build/common/httpClientContext/index.js +0 -1
- package/build/common/makeHttpClient/index.js +0 -1
- package/build/common/makeHttpClient/makeHttpClient.js +0 -34
- package/build/common/messages/generic-error.messages.js +0 -18
- package/build/common/messages/help.messages.js +0 -8
- package/build/common/messages/multi-file-upload.messages.js +0 -18
- package/build/common/messages/multi-select.messages.js +0 -8
- package/build/common/messages/paragraph.messages.js +0 -13
- package/build/common/messages/repeatable.messages.js +0 -23
- package/build/common/messages/validation.array.messages.js +0 -13
- package/build/common/messages/validation.messages.js +0 -53
- package/build/common/utils/api-utils.js +0 -4
- package/build/legacy/common/constants/DateMode.js +0 -4
- package/build/legacy/common/constants/FeatureName.js +0 -4
- package/build/legacy/common/constants/FormControlType.js +0 -21
- package/build/legacy/common/constants/MonthFormat.js +0 -4
- package/build/legacy/common/constants/Size.js +0 -7
- package/build/legacy/common/constants/index.js +0 -4
- package/build/legacy/common/contexts/dynamicFlowContexts/DynamicFlowContexts.js +0 -36
- package/build/legacy/common/contexts/dynamicFlowContexts/usePendingPromiseCounter.js +0 -13
- package/build/legacy/common/contexts/eventsContext/EventsContext.js +0 -38
- package/build/legacy/common/contexts/featureContext/FeatureContext.js +0 -22
- package/build/legacy/common/contexts/index.js +0 -3
- package/build/legacy/common/contexts/logContext/LogContext.js +0 -44
- package/build/legacy/common/hooks/index.js +0 -7
- package/build/legacy/common/hooks/useDebouncedFunction/useDebouncedFunction.js +0 -9
- package/build/legacy/common/hooks/useExternal/useExternal.js +0 -15
- package/build/legacy/common/hooks/useExternalStepPolling/useExternalStepPolling.js +0 -70
- package/build/legacy/common/hooks/usePersistAsync/usePersistAsync.js +0 -172
- package/build/legacy/common/hooks/usePolling/usePolling.js +0 -51
- package/build/legacy/common/hooks/usePrevious/usePrevious.js +0 -8
- package/build/legacy/common/hooks/useStepPolling/useStepPolling.js +0 -43
- package/build/legacy/common/messages.js +0 -8
- package/build/legacy/common/utils/api-utils.js +0 -6
- package/build/legacy/common/utils/date-utils.js +0 -22
- package/build/legacy/common/utils/debounce.js +0 -38
- package/build/legacy/common/utils/file-utils.js +0 -45
- package/build/legacy/common/utils/id-utils.js +0 -5
- package/build/legacy/common/utils/index.js +0 -11
- package/build/legacy/common/utils/is-equal.js +0 -21
- package/build/legacy/common/utils/misc-utils.js +0 -4
- package/build/legacy/common/utils/mobile-utils.js +0 -23
- package/build/legacy/common/utils/model-utils.js +0 -33
- package/build/legacy/common/utils/schema-utils.js +0 -113
- package/build/legacy/common/utils/step-utils.js +0 -32
- package/build/legacy/common/validators/index.js +0 -5
- package/build/legacy/common/validators/models/model-utils.js +0 -119
- package/build/legacy/common/validators/models/model-validators.js +0 -62
- package/build/legacy/common/validators/schemas/schema-validators.js +0 -101
- package/build/legacy/common/validators/types/type-validators.js +0 -14
- package/build/legacy/common/validators/validationFailures/validation-failures.js +0 -139
- package/build/legacy/common/validators/validationFailures/validation-failures.utils.js +0 -40
- package/build/legacy/common/validators/values/value-validators.js +0 -6
- package/build/legacy/dynamic-flow-types.js +0 -1
- package/build/legacy/formControl/FormControl.js +0 -266
- package/build/legacy/formControl/index.js +0 -1
- package/build/legacy/formControl/utils/getAutocompleteString.js +0 -80
- package/build/legacy/formControl/utils/index.js +0 -2
- package/build/legacy/formControl/utils/value-utils.js +0 -108
- package/build/legacy/jsonSchemaForm/allOfSchema/AllOfSchema.js +0 -50
- package/build/legacy/jsonSchemaForm/allOfSchema/index.js +0 -1
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multiSelectSchema/MultiSelectSchema.js +0 -84
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/MultipleFileUploadSchema.js +0 -141
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/index.js +0 -1
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/index.js +0 -2
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/upload-utils.js +0 -79
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/multipleFileUploadSchema/utils/useFormattedDefaultErrorMessages.js +0 -14
- package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/ItemSummary.js +0 -7
- package/build/legacy/jsonSchemaForm/basicTypeSchema/BasicTypeSchema.js +0 -111
- package/build/legacy/jsonSchemaForm/basicTypeSchema/index.js +0 -1
- package/build/legacy/jsonSchemaForm/controlFeedback/ControlFeedback.js +0 -86
- package/build/legacy/jsonSchemaForm/controlFeedback/index.js +0 -1
- package/build/legacy/jsonSchemaForm/help/Help.js +0 -20
- package/build/legacy/jsonSchemaForm/help/index.js +0 -1
- package/build/legacy/jsonSchemaForm/persistAsyncSchema/persistAsyncBasicSchema/PersistAsyncBasicSchema.js +0 -165
- package/build/legacy/jsonSchemaForm/schemaFormControl/SchemaFormControl.js +0 -133
- package/build/legacy/jsonSchemaForm/schemaFormControl/index.js +0 -1
- package/build/legacy/jsonSchemaForm/schemaFormControl/utils/index.js +0 -1
- package/build/legacy/jsonSchemaForm/schemaFormControl/utils/mapping-utils.js +0 -107
- package/build/legacy/layout/DynamicLayout.js +0 -68
- package/build/legacy/layout/alert/DynamicAlert.js +0 -29
- package/build/legacy/layout/box/DynamicBox.js +0 -41
- package/build/legacy/layout/button/DynamicButton.js +0 -27
- package/build/legacy/layout/button/utils.js +0 -45
- package/build/legacy/layout/columns/DynamicColumns.js +0 -38
- package/build/legacy/layout/decision/DynamicDecision.js +0 -21
- package/build/legacy/layout/divider/DynamicDivider.js +0 -9
- package/build/legacy/layout/external/DynamicExternal.js +0 -32
- package/build/legacy/layout/external/DynamicExternal.messages.js +0 -8
- package/build/legacy/layout/form/DynamicForm.js +0 -22
- package/build/legacy/layout/heading/DynamicHeading.js +0 -51
- package/build/legacy/layout/icon/DynamicIcon.js +0 -17
- package/build/legacy/layout/icon/FlagIcon.js +0 -198
- package/build/legacy/layout/icon/NamedIcon.js +0 -19
- package/build/legacy/layout/image/DynamicImage.js +0 -111
- package/build/legacy/layout/index.js +0 -20
- package/build/legacy/layout/instructions/DynamicInstructions.js +0 -30
- package/build/legacy/layout/list/DynamicStatusList.js +0 -37
- package/build/legacy/layout/loadingIndicator/DynamicLoadingIndicator.js +0 -11
- package/build/legacy/layout/markdown/DynamicMarkdown.js +0 -23
- package/build/legacy/layout/modal/DynamicModal.js +0 -26
- package/build/legacy/layout/paragraph/DynamicParagraph.js +0 -46
- package/build/legacy/layout/paragraph/useSnackBarIfAvailable.js +0 -9
- package/build/legacy/layout/review/DynamicReview.js +0 -58
- package/build/legacy/layout/search/DynamicSearch.js +0 -58
- package/build/legacy/layout/search/SearchInput.js +0 -17
- package/build/legacy/layout/search/SearchResults.js +0 -31
- package/build/legacy/layout/search/useSearch.js +0 -137
- package/build/legacy/layout/utils/getNavigationOptionMedia.js +0 -28
- package/build/legacy/layout/utils/index.js +0 -32
- package/build/legacy/step/cameraStep/cameraCapture/CameraCapture.messages.js +0 -58
- package/build/legacy/step/cameraStep/cameraCapture/components/bottomBar/BottomBar.js +0 -28
- package/build/legacy/step/cameraStep/cameraCapture/components/index.js +0 -3
- package/build/legacy/step/cameraStep/cameraCapture/components/orientationLockOverlay/OrientationLockOverlay.js +0 -19
- package/build/legacy/step/cameraStep/cameraCapture/components/orientationLockOverlay/OrientationLockOverlay.messages.js +0 -8
- package/build/legacy/step/cameraStep/cameraCapture/types/index.js +0 -7
- package/build/legacy/step/layoutStep/LayoutStep.js +0 -33
- package/build/legacy/step/layoutStep/index.js +0 -1
- package/build/legacy/step/layoutStep/utils/index.js +0 -2
- package/build/legacy/step/layoutStep/utils/inline-reference-utils.js +0 -105
- package/build/legacy/step/layoutStep/utils/layout-utils.js +0 -212
|
@@ -1,141 +0,0 @@
|
|
|
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 } from "react/jsx-runtime";
|
|
49
|
-
import { Status, UploadInput, } from '@transferwise/components';
|
|
50
|
-
import classNames from 'classnames';
|
|
51
|
-
import { useMemo, useState } from 'react';
|
|
52
|
-
import { useEventDispatcher } from '../../../../common/contexts';
|
|
53
|
-
import { usePersistAsync } from '../../../../common/hooks';
|
|
54
|
-
import { areFilesSame, toKilobytes, generateRandomId, isBlobSchema, } from '../../../../common/utils';
|
|
55
|
-
import { isNumber, isString, getArrayValidationFailures } from '../../../../common/validators';
|
|
56
|
-
import ControlFeedback from '../../../controlFeedback';
|
|
57
|
-
import { constructUploadResponse, constructUploadError, createPayload } from './utils';
|
|
58
|
-
import { useFormattedDefaultErrorMessages } from './utils/useFormattedDefaultErrorMessages';
|
|
59
|
-
function MultipleFileUploadSchema(props) {
|
|
60
|
-
var _this = this;
|
|
61
|
-
var _a, _b;
|
|
62
|
-
var onChange = props.onChange, schema = props.schema;
|
|
63
|
-
var onEvent = useEventDispatcher();
|
|
64
|
-
var defaultErrorMessages = useFormattedDefaultErrorMessages(schema);
|
|
65
|
-
var uid = useMemo(function () { return schema.$id || generateRandomId(); }, [schema.$id]);
|
|
66
|
-
var _c = useState(false), inputChanged = _c[0], setInputChanged = _c[1];
|
|
67
|
-
var _d = useState(function () { return convertFileIdsToComponentFileObjects(props.model || []); }), files = _d[0], setFiles = _d[1];
|
|
68
|
-
var performPersistAsync = usePersistAsync(schema.items.persistAsync);
|
|
69
|
-
var fileSchemaDescriptor = schema.items.persistAsync.schema;
|
|
70
|
-
var isBlob = isBlobSchema(fileSchemaDescriptor);
|
|
71
|
-
var uploadFile = function (userUploadedFile) { return __awaiter(_this, void 0, void 0, function () {
|
|
72
|
-
var payload, response, error_1;
|
|
73
|
-
return __generator(this, function (_a) {
|
|
74
|
-
switch (_a.label) {
|
|
75
|
-
case 0:
|
|
76
|
-
setInputChanged(true);
|
|
77
|
-
_a.label = 1;
|
|
78
|
-
case 1:
|
|
79
|
-
_a.trys.push([1, 4, , 5]);
|
|
80
|
-
return [4 /*yield*/, createPayload(userUploadedFile, isBlob)];
|
|
81
|
-
case 2:
|
|
82
|
-
payload = _a.sent();
|
|
83
|
-
onEvent('Dynamic Flow - PersistAsync', { status: 'pending', schemaId: schema.$id });
|
|
84
|
-
return [4 /*yield*/, performPersistAsync(payload)];
|
|
85
|
-
case 3:
|
|
86
|
-
response = _a.sent();
|
|
87
|
-
onEvent('Dynamic Flow - PersistAsync', { status: 'success', schemaId: schema.$id });
|
|
88
|
-
return [2 /*return*/, constructUploadResponse(response)];
|
|
89
|
-
case 4:
|
|
90
|
-
error_1 = _a.sent();
|
|
91
|
-
onEvent('Dynamic Flow - PersistAsync', { status: 'failure', schemaId: schema.$id });
|
|
92
|
-
return [2 /*return*/, Promise.reject(constructUploadError(error_1))];
|
|
93
|
-
case 5: return [2 /*return*/];
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
}); };
|
|
97
|
-
function onFilesChange(newFiles) {
|
|
98
|
-
if (areFilesSame(newFiles, files)) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
setFiles(newFiles);
|
|
102
|
-
var validFiles = getSuccessfullyProcessedFiles(newFiles);
|
|
103
|
-
var data = validFiles.map(function (file) { return file.id; });
|
|
104
|
-
onChange({
|
|
105
|
-
model: data,
|
|
106
|
-
triggerSchema: schema,
|
|
107
|
-
triggerModel: data
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
var validFiles = getSuccessfullyProcessedFiles(files);
|
|
111
|
-
var fileIds = validFiles.map(function (file) { return file.id; });
|
|
112
|
-
var fileListValidationFailures = getArrayValidationFailures(fileIds, schema, props.required);
|
|
113
|
-
var showError = Boolean(props.errors) ||
|
|
114
|
-
((inputChanged || props.submitted) && Boolean(fileListValidationFailures.length));
|
|
115
|
-
var accepts = 'accepts' in fileSchemaDescriptor && fileSchemaDescriptor.accepts;
|
|
116
|
-
var maxSize = 'maxSize' in fileSchemaDescriptor && fileSchemaDescriptor.maxSize;
|
|
117
|
-
var uploadInputProps = __assign(__assign(__assign({ multiple: true, className: 'form-control', files: files, fileInputName: uid, id: uid }, (accepts ? { fileTypes: accepts } : undefined)), (maxSize ? { sizeLimit: toKilobytes(maxSize) } : undefined)), { sizeLimitErrorMessage: ((_a = fileSchemaDescriptor.validationMessages) === null || _a === void 0 ? void 0 : _a.maxSize) ||
|
|
118
|
-
defaultErrorMessages.maxFileSizeErrorMessage, maxFiles: props.schema.maxItems, maxFilesErrorMessage: ((_b = props.schema.validationMessages) === null || _b === void 0 ? void 0 : _b.maxItems) || defaultErrorMessages.maxItemsErrorMessage, uploadButtonTitle: fileSchemaDescriptor.title, description: fileSchemaDescriptor.description, disabled: props.disabled, onUploadFile: function (formData) { return uploadFile(formData.get(uid)); }, onFilesChange: onFilesChange, onDeleteFile: function () { return Promise.resolve(); } });
|
|
119
|
-
var feedbackId = "".concat(uid, "-feedback");
|
|
120
|
-
return (_jsxs("div", __assign({ className: classNames('form-group', { 'has-error': showError }) }, { children: [_jsx("label", __assign({ className: "d-block control-label", htmlFor: uid }, { children: props.schema.title })), _jsx("div", __assign({ "aria-describedby": feedbackId }, { children: _jsx(UploadInput, __assign({}, uploadInputProps)) })), _jsx(ControlFeedback, { id: feedbackId, changed: inputChanged, submitted: props.submitted, errors: props.errors, schema: props.schema, validations: fileListValidationFailures, validationMessages: getValidationMessages(schema, Boolean(props.required), defaultErrorMessages), infoMessage: null, focused: false, blurred: true })] })));
|
|
121
|
-
}
|
|
122
|
-
MultipleFileUploadSchema.defaultProps = {
|
|
123
|
-
errors: null,
|
|
124
|
-
required: false
|
|
125
|
-
};
|
|
126
|
-
export default MultipleFileUploadSchema;
|
|
127
|
-
function getSuccessfullyProcessedFiles(allFiles) {
|
|
128
|
-
return allFiles.filter(function (file) { return !file.error && file.status === 'succeeded'; });
|
|
129
|
-
}
|
|
130
|
-
function convertFileIdsToComponentFileObjects(fileIds) {
|
|
131
|
-
return fileIds
|
|
132
|
-
.map(function (id) { return (isValidId(id) ? { id: id, status: Status.SUCCEEDED } : null); })
|
|
133
|
-
.filter(function (item) { return item !== null; });
|
|
134
|
-
}
|
|
135
|
-
function isValidId(id) {
|
|
136
|
-
return isNumber(id) || isString(id);
|
|
137
|
-
}
|
|
138
|
-
function getValidationMessages(schema, required, defaultErrorMessages) {
|
|
139
|
-
var minItems = schema.minItems, maxItems = schema.maxItems;
|
|
140
|
-
return __assign(__assign(__assign({}, (required && { required: defaultErrorMessages.requiredMessage })), (minItems && { minItems: defaultErrorMessages.minItemsErrorMessage })), (maxItems && { maxItems: defaultErrorMessages.maxItemsErrorMessage }));
|
|
141
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './MultipleFileUploadSchema';
|
|
@@ -1,79 +0,0 @@
|
|
|
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 { toBase64, generateRandomId } from '../../../../../common/utils';
|
|
49
|
-
import { isObject, isString } from '../../../../../common/validators';
|
|
50
|
-
export function createPayload(userUploadedFile, isBlobSchema) {
|
|
51
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
52
|
-
return __generator(this, function (_a) {
|
|
53
|
-
if (isBlobSchema) {
|
|
54
|
-
return [2 /*return*/, userUploadedFile];
|
|
55
|
-
}
|
|
56
|
-
if (userUploadedFile instanceof Blob) {
|
|
57
|
-
return [2 /*return*/, toBase64(userUploadedFile)];
|
|
58
|
-
}
|
|
59
|
-
throw new Error('Error creating payload for MultipleFileUploadSchema. Uploaded file is not an instance of Blob.');
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
export function constructUploadResponse(response) {
|
|
64
|
-
var id = response.data;
|
|
65
|
-
return __assign({ id: id }, response);
|
|
66
|
-
}
|
|
67
|
-
export function constructUploadError(response) {
|
|
68
|
-
var isError = response instanceof Error;
|
|
69
|
-
var hasValidData = isObject(response) && 'data' in response;
|
|
70
|
-
var isInvalidResponseData = !hasValidData && !isError;
|
|
71
|
-
if (isInvalidResponseData) {
|
|
72
|
-
return isString(response) ? response : undefined;
|
|
73
|
-
}
|
|
74
|
-
if (isError) {
|
|
75
|
-
var error = response;
|
|
76
|
-
return { id: generateRandomId(), message: error.message };
|
|
77
|
-
}
|
|
78
|
-
return __assign({ message: isString(response.message) ? response.message : '' }, response);
|
|
79
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { useIntl } from 'react-intl';
|
|
2
|
-
import CommonMessages from '../../../../../common/messages';
|
|
3
|
-
import MultiFileUploadMessages from '../../../../../../common/messages/multi-file-upload.messages';
|
|
4
|
-
export function useFormattedDefaultErrorMessages(_a) {
|
|
5
|
-
var maxItems = _a.maxItems, minItems = _a.minItems;
|
|
6
|
-
var formatMessage = useIntl().formatMessage;
|
|
7
|
-
var maxFileSizeError = MultiFileUploadMessages.maxFileSizeError, maxItemsError = MultiFileUploadMessages.maxItemsError, minItemsError = MultiFileUploadMessages.minItemsError;
|
|
8
|
-
return {
|
|
9
|
-
maxFileSizeErrorMessage: formatMessage(maxFileSizeError),
|
|
10
|
-
maxItemsErrorMessage: formatMessage(maxItemsError, { maxItems: maxItems }),
|
|
11
|
-
minItemsErrorMessage: formatMessage(minItemsError, { minItems: minItems }),
|
|
12
|
-
requiredMessage: formatMessage(CommonMessages.required)
|
|
13
|
-
};
|
|
14
|
-
}
|
package/build/legacy/jsonSchemaForm/arrayTypeSchema/arrayListSchema/repeatableSchema/ItemSummary.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { NavigationOption } from '@transferwise/components';
|
|
3
|
-
import { getNavigationOptionMedia } from '../../../../layout/utils';
|
|
4
|
-
export function ItemSummaryOption(_a) {
|
|
5
|
-
var item = _a.item, onClick = _a.onClick;
|
|
6
|
-
return (_jsx(NavigationOption, { media: getNavigationOptionMedia(item), title: item.title, content: item.description, showMediaAtAllSizes: true, onClick: onClick }));
|
|
7
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
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
|
-
import classNames from 'classnames';
|
|
14
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
15
|
-
import { generateRandomId } from '../../common/utils';
|
|
16
|
-
import { getValidBasicModelOrNull, getValidationFailures, isNull, isUndefined, } from '../../common/validators';
|
|
17
|
-
import { DynamicAlert } from '../../layout';
|
|
18
|
-
import ControlFeedback from '../controlFeedback';
|
|
19
|
-
import Help from '../help';
|
|
20
|
-
import SchemaFormControl from '../schemaFormControl';
|
|
21
|
-
var isNullish = function (value) {
|
|
22
|
-
return isNull(value) || isUndefined(value);
|
|
23
|
-
};
|
|
24
|
-
var getDefaultValue = function (schema) {
|
|
25
|
-
return schema.type === 'boolean' && isNullish(schema["default"]) ? false : schema["default"];
|
|
26
|
-
};
|
|
27
|
-
var BasicTypeSchema = function (props) {
|
|
28
|
-
var _a, _b, _c;
|
|
29
|
-
var onChange = function (newModel, _type, metadata) {
|
|
30
|
-
setChanged(true);
|
|
31
|
-
setModelAndBroadcast(sanitiseModel(newModel), 'user', metadata);
|
|
32
|
-
};
|
|
33
|
-
var getValidationKeys = function (newModel) {
|
|
34
|
-
return getValidationFailures(newModel, props.schema, props.required);
|
|
35
|
-
}; // TODO: LOW avoid type assertion
|
|
36
|
-
var setModelAndBroadcast = function (newModel, type, metadata) {
|
|
37
|
-
setModel(newModel);
|
|
38
|
-
var validationKeys = getValidationKeys(newModel);
|
|
39
|
-
setValidations(validationKeys);
|
|
40
|
-
var broadcastModel = newModel;
|
|
41
|
-
setLastModel(broadcastModel);
|
|
42
|
-
if (broadcastModel !== lastModel) {
|
|
43
|
-
props.onChange({
|
|
44
|
-
model: broadcastModel,
|
|
45
|
-
triggerSchema: props.schema,
|
|
46
|
-
triggerModel: broadcastModel,
|
|
47
|
-
lastTriggerModel: lastModel,
|
|
48
|
-
type: type,
|
|
49
|
-
metadata: metadata
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
var sanitiseModel = function (newModel) {
|
|
54
|
-
return getValidBasicModelOrNull(newModel, props.schema);
|
|
55
|
-
};
|
|
56
|
-
var onFocus = function () { return setFocused(true); };
|
|
57
|
-
var onBlur = function () {
|
|
58
|
-
setFocused(false);
|
|
59
|
-
setBlurred(true);
|
|
60
|
-
if (props.onBlur) {
|
|
61
|
-
props.onBlur();
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
var _d = useState((_a = props.model) !== null && _a !== void 0 ? _a : null), model = _d[0], setModel = _d[1];
|
|
65
|
-
var _e = useState((_b = props.model) !== null && _b !== void 0 ? _b : null), lastModel = _e[0], setLastModel = _e[1];
|
|
66
|
-
var _f = useState(false), changed = _f[0], setChanged = _f[1];
|
|
67
|
-
var _g = useState(false), focused = _g[0], setFocused = _g[1];
|
|
68
|
-
var _h = useState(false), blurred = _h[0], setBlurred = _h[1];
|
|
69
|
-
var _j = useState([]), validations = _j[0], setValidations = _j[1];
|
|
70
|
-
var id = useMemo(function () { return props.schema.$id || generateRandomId(); }, [props.schema.$id]);
|
|
71
|
-
var onSchemaChange = function () {
|
|
72
|
-
var defaultValue = getDefaultValue(props.schema);
|
|
73
|
-
// if no model, change to the default, only run this when the schema changes
|
|
74
|
-
if (isNullish(model) && !isNullish(defaultValue)) {
|
|
75
|
-
setModelAndBroadcast(defaultValue, 'init');
|
|
76
|
-
}
|
|
77
|
-
if (props.schema["const"]) {
|
|
78
|
-
setModelAndBroadcast(props.schema["const"], 'init');
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
var refreshValidations = function () {
|
|
82
|
-
setValidations(getValidationKeys(model));
|
|
83
|
-
};
|
|
84
|
-
var isConst = props.schema["const"];
|
|
85
|
-
var isHidden = props.schema.hidden || isConst;
|
|
86
|
-
useEffect(refreshValidations, [props.model, props.submitted]);
|
|
87
|
-
useEffect(onSchemaChange, [props.schema]);
|
|
88
|
-
useEffect(function () {
|
|
89
|
-
var _a;
|
|
90
|
-
var newModel = (_a = props.model) !== null && _a !== void 0 ? _a : null;
|
|
91
|
-
if (newModel !== model) {
|
|
92
|
-
setModel(newModel);
|
|
93
|
-
}
|
|
94
|
-
}, [props.model]);
|
|
95
|
-
var formGroupClasses = {
|
|
96
|
-
'form-group': true,
|
|
97
|
-
'has-error': ((props.submitted || !changed) && !!props.errors) ||
|
|
98
|
-
((props.submitted || (changed && blurred)) && !!validations.length),
|
|
99
|
-
'has-info': !!props.schema.description || !!props.infoMessage
|
|
100
|
-
};
|
|
101
|
-
var showLabel = props.schema.format !== 'file' && props.schema.type !== 'boolean';
|
|
102
|
-
var schemaHelp = props.schema.help;
|
|
103
|
-
var feedbackId = "".concat(id, "-feedback");
|
|
104
|
-
return !isHidden ? (_jsxs(_Fragment, { children: [props.schema.alert && _jsx(DynamicAlert, { component: props.schema.alert }), _jsxs("div", __assign({ className: classNames(formGroupClasses) }, { children: [showLabel && (_jsxs("div", __assign({ className: "d-inline-block m-b-1" }, { children: [_jsx("label", __assign({ className: "control-label d-inline", htmlFor: id }, { children: props.schema.title })), !!schemaHelp && _jsx(Help, { help: schemaHelp })] }))), !showLabel && !!schemaHelp && _jsx(Help, { help: schemaHelp }), _jsx(SchemaFormControl, { id: id, schema: props.schema, value: model, disabled: !!props.disabled, onChange: onChange, onFocus: onFocus, onBlur: onBlur, describedBy: feedbackId }), _jsx(ControlFeedback, { id: feedbackId, changed: changed, focused: focused, blurred: blurred, submitted: props.submitted, errors: (_c = props.errors) !== null && _c !== void 0 ? _c : null, schema: props.schema, validations: validations, infoMessage: props.infoMessage })] }))] })) : null;
|
|
105
|
-
};
|
|
106
|
-
BasicTypeSchema.defaultProps = {
|
|
107
|
-
required: false,
|
|
108
|
-
disabled: false,
|
|
109
|
-
onBlur: null
|
|
110
|
-
};
|
|
111
|
-
export default BasicTypeSchema;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './BasicTypeSchema';
|
|
@@ -1,86 +0,0 @@
|
|
|
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 { InlineAlert } from '@transferwise/components';
|
|
14
|
-
import { formatDate } from '@transferwise/formatting';
|
|
15
|
-
import { useIntl } from 'react-intl';
|
|
16
|
-
import validationArrayMessages from '../../../common/messages/validation.array.messages';
|
|
17
|
-
import controlFeedbackMessages from '../../../common/messages/validation.messages';
|
|
18
|
-
function ControlFeedback(props) {
|
|
19
|
-
var _a;
|
|
20
|
-
var defaultValidationMessages = useDefaultValidationMessages(props.schema);
|
|
21
|
-
var validationMessages = __assign(__assign(__assign({}, defaultValidationMessages), props.validationMessages), props.schema.validationMessages);
|
|
22
|
-
var isErrorVisible = (props.submitted || !props.changed) && Boolean(props.errors);
|
|
23
|
-
var isValidationVisible = !isErrorVisible &&
|
|
24
|
-
(props.submitted || (props.changed && props.blurred)) &&
|
|
25
|
-
Boolean((_a = props.validations) === null || _a === void 0 ? void 0 : _a.length);
|
|
26
|
-
var isDescriptionVisible = props.schema.description && !isErrorVisible && !isValidationVisible;
|
|
27
|
-
var hasInfoMessage = Boolean(props.infoMessage);
|
|
28
|
-
return (_jsxs("div", __assign({ id: props.id }, { children: [isErrorVisible ? _jsx(InlineAlert, __assign({ type: "error" }, { children: props.errors })) : null, isValidationVisible ? (_jsx(InlineAlert, __assign({ type: "error" }, { children: props.validations.map(function (validation) { return (_jsx("div", { children: validationMessages[validation] }, validation)); }) }))) : null, (isDescriptionVisible || hasInfoMessage) && (_jsxs(InlineAlert, __assign({ type: "info" }, { children: [isDescriptionVisible && _jsx("div", { children: props.schema.description }), hasInfoMessage && _jsx("div", { children: props.infoMessage })] })))] })));
|
|
29
|
-
}
|
|
30
|
-
ControlFeedback.defaultProps = {
|
|
31
|
-
errors: '',
|
|
32
|
-
validations: [],
|
|
33
|
-
validationMessages: {},
|
|
34
|
-
validationAsyncSuccessMessage: null
|
|
35
|
-
};
|
|
36
|
-
// TODO: avoid typre assertions in this function
|
|
37
|
-
function useDefaultValidationMessages(schema) {
|
|
38
|
-
var _a = useIntl(), formatMessage = _a.formatMessage, locale = _a.locale;
|
|
39
|
-
var formattedMessages = {
|
|
40
|
-
type: formatMessage(controlFeedbackMessages.type),
|
|
41
|
-
minimum: formatMessage(controlFeedbackMessages.minimum, {
|
|
42
|
-
minimum: schema.minimum
|
|
43
|
-
}),
|
|
44
|
-
maximum: formatMessage(controlFeedbackMessages.maximum, {
|
|
45
|
-
maximum: schema.maximum
|
|
46
|
-
}),
|
|
47
|
-
minLength: formatMessage(controlFeedbackMessages.minLength, {
|
|
48
|
-
minLength: schema.minLength
|
|
49
|
-
}),
|
|
50
|
-
maxLength: formatMessage(controlFeedbackMessages.maxLength, {
|
|
51
|
-
maxLength: schema.maxLength
|
|
52
|
-
}),
|
|
53
|
-
minItems: formatMessage(validationArrayMessages.minItemsError, {
|
|
54
|
-
minItems: schema.minItems
|
|
55
|
-
}),
|
|
56
|
-
maxItems: formatMessage(validationArrayMessages.maxItemsError, {
|
|
57
|
-
maxItems: schema.maxItems
|
|
58
|
-
}),
|
|
59
|
-
pattern: formatMessage(controlFeedbackMessages.pattern),
|
|
60
|
-
required: formatMessage(controlFeedbackMessages.required)
|
|
61
|
-
};
|
|
62
|
-
if (schema.format === 'date') {
|
|
63
|
-
var dateOverrides = {
|
|
64
|
-
pattern: formatMessage(controlFeedbackMessages.patternDate),
|
|
65
|
-
minimum: schema.minimum
|
|
66
|
-
? formatMessage(controlFeedbackMessages.minimumDate, {
|
|
67
|
-
minimum: formatDate(new Date(schema.minimum), locale, {
|
|
68
|
-
timeZone: 'UTC',
|
|
69
|
-
dateStyle: 'long'
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
: undefined,
|
|
73
|
-
maximum: schema.maximum
|
|
74
|
-
? formatMessage(controlFeedbackMessages.maximumDate, {
|
|
75
|
-
maximum: formatDate(new Date(schema.maximum), locale, {
|
|
76
|
-
timeZone: 'UTC',
|
|
77
|
-
dateStyle: 'long'
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
: undefined
|
|
81
|
-
};
|
|
82
|
-
return __assign(__assign({}, formattedMessages), dateOverrides);
|
|
83
|
-
}
|
|
84
|
-
return formattedMessages;
|
|
85
|
-
}
|
|
86
|
-
export default ControlFeedback;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './ControlFeedback';
|
|
@@ -1,20 +0,0 @@
|
|
|
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 { Markdown, Info } from '@transferwise/components';
|
|
14
|
-
import { useIntl } from 'react-intl';
|
|
15
|
-
import helpMessages from '../../../common/messages/help.messages';
|
|
16
|
-
function Help(props) {
|
|
17
|
-
var intl = useIntl();
|
|
18
|
-
return (_jsx(Info, { className: "m-l-1", content: _jsx(Markdown, __assign({ config: { link: { target: '_blank' } } }, { children: props.help.markdown })), presentation: "POPOVER", size: "sm", "aria-label": intl.formatMessage(helpMessages.helpAria) }));
|
|
19
|
-
}
|
|
20
|
-
export default Help;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from './Help';
|
|
@@ -1,165 +0,0 @@
|
|
|
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
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
38
|
-
import { useEffect, useState } from 'react';
|
|
39
|
-
import { useIntl } from 'react-intl';
|
|
40
|
-
import { FormControlType } from '../../../common/constants';
|
|
41
|
-
import { useEventDispatcher } from '../../../common/contexts';
|
|
42
|
-
import { usePrevious } from '../../../common/hooks';
|
|
43
|
-
import { isEqual, isStatus2xx, isStatus422 } from '../../../common/utils';
|
|
44
|
-
import { isValidSchema, isNull, isObject } from '../../../common/validators';
|
|
45
|
-
import BasicTypeSchema from '../../basicTypeSchema';
|
|
46
|
-
import { getControlType } from '../../schemaFormControl/SchemaFormControl';
|
|
47
|
-
import messages from '../../../../common/messages/generic-error.messages';
|
|
48
|
-
import { useHttpClient } from '../../../../common/httpClientContext';
|
|
49
|
-
// TODO: LOW avoid type assertion below -- consider throwing if return value is not the expected type
|
|
50
|
-
export var getIdFromResponse = function (idProperty, response) {
|
|
51
|
-
return response[idProperty];
|
|
52
|
-
};
|
|
53
|
-
export var getErrorFromResponse = function (errorProperty, response) { var _a; return (_a = response.validation) === null || _a === void 0 ? void 0 : _a[errorProperty]; };
|
|
54
|
-
var controlTypesWithPersistOnChange = new Set([
|
|
55
|
-
FormControlType.RADIO,
|
|
56
|
-
FormControlType.SELECT,
|
|
57
|
-
FormControlType.DATELOOKUP,
|
|
58
|
-
FormControlType.FILE,
|
|
59
|
-
FormControlType.UPLOAD,
|
|
60
|
-
]);
|
|
61
|
-
function PersistAsyncBasicSchema(props) {
|
|
62
|
-
var _this = this;
|
|
63
|
-
var schema = props.schema, required = props.required, submitted = props.submitted, errors = props.errors, onChange = props.onChange, onPersistAsync = props.onPersistAsync;
|
|
64
|
-
var intl = useIntl();
|
|
65
|
-
var httpClient = useHttpClient();
|
|
66
|
-
var onEvent = useEventDispatcher();
|
|
67
|
-
var _a = useState(null), persistAsyncModel = _a[0], setPersistAsyncModel = _a[1];
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
69
|
-
var previousPersistAsyncModel = usePrevious(persistAsyncModel);
|
|
70
|
-
var _b = useState(null), persistAsyncError = _b[0], setPersistAsyncError = _b[1];
|
|
71
|
-
var _c = useState(false), fieldSubmitted = _c[0], setFieldSubmitted = _c[1];
|
|
72
|
-
var _d = useState(null), abortController = _d[0], setAbortController = _d[1];
|
|
73
|
-
useEffect(function () {
|
|
74
|
-
if (controlTypesWithPersistOnChange.has(
|
|
75
|
-
// TODO: LOW avoid type assertion below -- control type may be nullish. consider ?? ''
|
|
76
|
-
getControlType(schema.persistAsync.schema))) {
|
|
77
|
-
persistAsyncIfValid();
|
|
78
|
-
}
|
|
79
|
-
}, [persistAsyncModel]);
|
|
80
|
-
var setGenericPersistAsyncError = function () {
|
|
81
|
-
return setPersistAsyncError(intl.formatMessage(messages.genericErrorRetryHint));
|
|
82
|
-
};
|
|
83
|
-
var getPersistAsyncResponse = function (currentPersistAsyncModel, persistAsyncSpec) { return __awaiter(_this, void 0, void 0, function () {
|
|
84
|
-
var signal, requestBody, persistAsyncFetch, response, responseBody, _a, idProperty, param, id, validation, error, _b;
|
|
85
|
-
var _c;
|
|
86
|
-
return __generator(this, function (_d) {
|
|
87
|
-
switch (_d.label) {
|
|
88
|
-
case 0:
|
|
89
|
-
signal = abortCurrentRequestAndGetNewAbortSignal();
|
|
90
|
-
requestBody = (_c = {}, _c[persistAsyncSpec.param] = currentPersistAsyncModel, _c);
|
|
91
|
-
setFieldSubmitted(true); // persist async initiated implied the field has been submitted
|
|
92
|
-
_d.label = 1;
|
|
93
|
-
case 1:
|
|
94
|
-
_d.trys.push([1, 4, , 5]);
|
|
95
|
-
onEvent('Dynamic Flow - PersistAsync', { status: 'pending', schemaId: schema.$id });
|
|
96
|
-
persistAsyncFetch = httpClient(persistAsyncSpec.url, {
|
|
97
|
-
method: persistAsyncSpec.method,
|
|
98
|
-
headers: { 'Content-Type': 'application/json' },
|
|
99
|
-
body: JSON.stringify(requestBody),
|
|
100
|
-
signal: signal
|
|
101
|
-
});
|
|
102
|
-
onPersistAsync(persistAsyncFetch);
|
|
103
|
-
return [4 /*yield*/, persistAsyncFetch];
|
|
104
|
-
case 2:
|
|
105
|
-
response = _d.sent();
|
|
106
|
-
return [4 /*yield*/, response.json()];
|
|
107
|
-
case 3:
|
|
108
|
-
responseBody = _d.sent();
|
|
109
|
-
if (!isObject(responseBody)) {
|
|
110
|
-
throw new Error('Response is not an object');
|
|
111
|
-
}
|
|
112
|
-
_a = schema.persistAsync, idProperty = _a.idProperty, param = _a.param;
|
|
113
|
-
if (isStatus2xx(response.status)) {
|
|
114
|
-
id = getIdFromResponse(idProperty, responseBody);
|
|
115
|
-
onChange({ model: id, triggerSchema: schema, triggerModel: id });
|
|
116
|
-
}
|
|
117
|
-
else if (isStatus422(response.status)) {
|
|
118
|
-
validation = responseBody.validation;
|
|
119
|
-
error = (isObject(validation) && (validation === null || validation === void 0 ? void 0 : validation[param])) || null;
|
|
120
|
-
setPersistAsyncError(error);
|
|
121
|
-
onChange({ model: null, triggerSchema: schema, triggerModel: null });
|
|
122
|
-
}
|
|
123
|
-
else {
|
|
124
|
-
setGenericPersistAsyncError();
|
|
125
|
-
}
|
|
126
|
-
onEvent('Dynamic Flow - PersistAsync', { status: 'success', schemaId: schema.$id });
|
|
127
|
-
return [3 /*break*/, 5];
|
|
128
|
-
case 4:
|
|
129
|
-
_b = _d.sent();
|
|
130
|
-
onEvent('Dynamic Flow - PersistAsync', { status: 'failure', schemaId: schema.$id });
|
|
131
|
-
setGenericPersistAsyncError();
|
|
132
|
-
return [3 /*break*/, 5];
|
|
133
|
-
case 5: return [2 /*return*/];
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}); };
|
|
137
|
-
var abortCurrentRequestAndGetNewAbortSignal = function () {
|
|
138
|
-
if (abortController) {
|
|
139
|
-
abortController.abort();
|
|
140
|
-
}
|
|
141
|
-
var newAbortController = new AbortController();
|
|
142
|
-
setAbortController(newAbortController);
|
|
143
|
-
return newAbortController.signal;
|
|
144
|
-
};
|
|
145
|
-
var persistAsyncIfValid = function () {
|
|
146
|
-
if (!isNull(persistAsyncModel) && !isEqual(persistAsyncModel, previousPersistAsyncModel)) {
|
|
147
|
-
void getPersistAsyncResponse(persistAsyncModel, schema.persistAsync);
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
var onBlur = function () {
|
|
151
|
-
persistAsyncIfValid();
|
|
152
|
-
};
|
|
153
|
-
var persistAsyncOnChange = function (_a) {
|
|
154
|
-
var newPersistAsyncModel = _a.model;
|
|
155
|
-
setPersistAsyncError(null);
|
|
156
|
-
if (isValidSchema(newPersistAsyncModel, schema.persistAsync.schema)) {
|
|
157
|
-
setPersistAsyncModel(newPersistAsyncModel);
|
|
158
|
-
}
|
|
159
|
-
};
|
|
160
|
-
return (_jsx(BasicTypeSchema, { required: required, submitted: submitted || fieldSubmitted, schema: schema.persistAsync.schema, errors: persistAsyncError || errors, model: null, infoMessage: null, onChange: persistAsyncOnChange, onBlur: onBlur }));
|
|
161
|
-
}
|
|
162
|
-
PersistAsyncBasicSchema.defaultProps = {
|
|
163
|
-
required: false
|
|
164
|
-
};
|
|
165
|
-
export default PersistAsyncBasicSchema;
|