@wise/dynamic-flow-client 4.6.0 → 4.7.1
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 +504 -596
- package/build/main.mjs +504 -596
- package/build/types/revamp/domain/components/BooleanInputComponent.d.ts +5 -7
- package/build/types/revamp/domain/components/DateInputComponent.d.ts +5 -7
- package/build/types/revamp/domain/components/IntegerInputComponent.d.ts +5 -7
- package/build/types/revamp/domain/components/MultiSelectInputComponent.d.ts +2 -2
- package/build/types/revamp/domain/components/NumberInputComponent.d.ts +5 -7
- package/build/types/revamp/domain/components/PersistAsyncComponent.d.ts +18 -0
- package/build/types/revamp/domain/components/SelectInputComponent.d.ts +3 -3
- package/build/types/revamp/domain/components/TextInputComponent.d.ts +5 -7
- package/build/types/revamp/domain/components/UploadInputComponent.d.ts +6 -8
- package/build/types/revamp/domain/features/persistAsync/getComponentMultiPersistAsync.d.ts +9 -0
- package/build/types/revamp/domain/features/schema-on-change/getDebouncedSchemaOnChange.d.ts +10 -0
- package/build/types/revamp/domain/features/schema-on-change/getSchemaOnChange.d.ts +7 -0
- package/build/types/revamp/domain/mappers/schema/arraySchemaToComponent/arraySchemaToMultiUploadComponent.d.ts +1 -1
- package/build/types/revamp/domain/mappers/schema/persistAsyncSchemaToComponent.d.ts +6 -0
- package/build/types/revamp/domain/mappers/schema/tests/test-utils.d.ts +1 -0
- package/build/types/revamp/domain/mappers/schema/types.d.ts +1 -0
- package/build/types/revamp/domain/mappers/schema/utils/getPerformPersistAsyncFn.d.ts +4 -0
- package/build/types/revamp/domain/mappers/schema/utils/mapCommonSchemaProps.d.ts +1 -0
- package/build/types/revamp/domain/mappers/utils/behavior-utils.d.ts +1 -0
- package/build/types/revamp/domain/types.d.ts +9 -3
- package/build/types/revamp/flow/executeRefresh.d.ts +2 -2
- package/build/types/revamp/flow/executeSubmission.d.ts +5 -2
- package/build/types/revamp/flow/response-utils.d.ts +1 -0
- package/build/types/revamp/renderers/mappers/persistAsyncComponentToProps.d.ts +3 -0
- package/build/types/revamp/utils/type-utils.d.ts +1 -2
- package/package.json +15 -15
- package/build/types/revamp/domain/features/persistAsync/getComponentPersistAsync.d.ts +0 -21
- package/build/types/revamp/domain/features/refresh/getPerformRefresh.d.ts +0 -12
- package/build/types/revamp/domain/mappers/schema/utils/getPersistAsyncInitialState.d.ts +0 -5
package/build/main.mjs
CHANGED
|
@@ -1530,6 +1530,17 @@ var objectComponentToProps = (component, rendererMapperProps) => {
|
|
|
1530
1530
|
// src/revamp/renderers/mappers/paragraphComponentToProps.ts
|
|
1531
1531
|
var paragraphComponentToProps = (component, rendererMapperProps) => __spreadValues(__spreadValues({}, pick(component, "uid", "type", "align", "control", "margin", "text")), rendererMapperProps);
|
|
1532
1532
|
|
|
1533
|
+
// src/revamp/renderers/mappers/persistAsyncComponentToProps.ts
|
|
1534
|
+
var persistAsyncComponentToProps = (component, rendererMapperProps) => {
|
|
1535
|
+
const props = componentToRendererProps(component.component, rendererMapperProps);
|
|
1536
|
+
if ("validationState" in props && component.errors.length > 0) {
|
|
1537
|
+
return __spreadProps(__spreadValues({}, props), {
|
|
1538
|
+
validationState: { status: "invalid", message: component.errors[0] }
|
|
1539
|
+
});
|
|
1540
|
+
}
|
|
1541
|
+
return props;
|
|
1542
|
+
};
|
|
1543
|
+
|
|
1533
1544
|
// src/revamp/renderers/mappers/repeatableComponentToProps.ts
|
|
1534
1545
|
var repeatableComponentToProps = (component, rendererMapperProps) => {
|
|
1535
1546
|
const {
|
|
@@ -1833,6 +1844,8 @@ var getComponentProps = (component, rendererMapperProps) => {
|
|
|
1833
1844
|
return tupleComponentToProps(component, rendererMapperProps);
|
|
1834
1845
|
case "upload":
|
|
1835
1846
|
return uploadInputComponentToProps(component, rendererMapperProps);
|
|
1847
|
+
case "persist-async":
|
|
1848
|
+
return persistAsyncComponentToProps(component, rendererMapperProps);
|
|
1836
1849
|
default:
|
|
1837
1850
|
throw new Error("Unknown component type");
|
|
1838
1851
|
}
|
|
@@ -3038,26 +3051,44 @@ var getStepRefreshAfter = ({ refreshAfter, onBehavior }) => {
|
|
|
3038
3051
|
}
|
|
3039
3052
|
const timeLeft = Math.max(targetTime - Date.now(), ONE_SECOND);
|
|
3040
3053
|
const timeout = setTimeout(() => {
|
|
3041
|
-
void onBehavior({ type: "refresh",
|
|
3054
|
+
void onBehavior({ type: "refresh", analytics: { schema: "refreshAfter" } });
|
|
3042
3055
|
}, timeLeft);
|
|
3043
3056
|
return {
|
|
3044
3057
|
stop: () => clearTimeout(timeout)
|
|
3045
3058
|
};
|
|
3046
3059
|
};
|
|
3047
3060
|
|
|
3048
|
-
// src/revamp/domain/components/utils/
|
|
3049
|
-
var
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3061
|
+
// src/revamp/domain/components/utils/isOrWasValid.ts
|
|
3062
|
+
var isOrWasValid = (getErrors, previous, current) => {
|
|
3063
|
+
const wasValid = getErrors(previous).length === 0 && previous !== null;
|
|
3064
|
+
const isValid = getErrors(current).length === 0;
|
|
3065
|
+
return wasValid || isValid;
|
|
3066
|
+
};
|
|
3067
|
+
|
|
3068
|
+
// src/revamp/domain/features/schema-on-change/getDebouncedSchemaOnChange.ts
|
|
3069
|
+
var getDebouncedSchemaOnChange = (onChange, getValidationErrors) => {
|
|
3070
|
+
if (!onChange) {
|
|
3071
|
+
return void 0;
|
|
3057
3072
|
}
|
|
3058
|
-
|
|
3073
|
+
const debouncedOnChange = debounce(onChange, 1e3);
|
|
3074
|
+
return onChange.behaviorType === "refresh" ? getSelectiveDebouncedSchemaOnChange(debouncedOnChange, getValidationErrors) : debouncedOnChange;
|
|
3075
|
+
};
|
|
3076
|
+
var getSelectiveDebouncedSchemaOnChange = (debouncedOnChange, getValidationErrors) => {
|
|
3077
|
+
const debouncedFn = (prevValue, updatedValue) => {
|
|
3078
|
+
if (isOrWasValid(getValidationErrors, prevValue, updatedValue) || (debouncedOnChange == null ? void 0 : debouncedOnChange.isPending())) {
|
|
3079
|
+
debouncedOnChange == null ? void 0 : debouncedOnChange();
|
|
3080
|
+
}
|
|
3081
|
+
};
|
|
3082
|
+
debouncedFn.flush = () => debouncedOnChange.flush();
|
|
3083
|
+
debouncedFn.cancel = () => debouncedOnChange.cancel();
|
|
3084
|
+
debouncedFn.isPending = () => debouncedOnChange.isPending();
|
|
3085
|
+
return debouncedFn;
|
|
3059
3086
|
};
|
|
3060
3087
|
|
|
3088
|
+
// src/revamp/domain/features/validation/validation-functions.ts
|
|
3089
|
+
var validateComponents = (components) => components.reduce((acc, component) => component.validate() && acc, true);
|
|
3090
|
+
var getLocalValueValidator = (checks) => (currentValue) => checks.map((check) => check(currentValue)).filter(isString);
|
|
3091
|
+
|
|
3061
3092
|
// src/revamp/domain/features/utils/http-utils.ts
|
|
3062
3093
|
function constructPayload({
|
|
3063
3094
|
value,
|
|
@@ -3085,143 +3116,6 @@ var abortAndResetController = (abortController) => {
|
|
|
3085
3116
|
return new AbortController();
|
|
3086
3117
|
};
|
|
3087
3118
|
|
|
3088
|
-
// src/revamp/domain/features/persistAsync/getComponentPersistAsync.ts
|
|
3089
|
-
var getComponentPersistAsync = (update, performPersistAsync) => (
|
|
3090
|
-
/**
|
|
3091
|
-
* Will update the persistedState when a new request is made, and will update
|
|
3092
|
-
* the value or set errors when the request completes.
|
|
3093
|
-
*/
|
|
3094
|
-
async (component, currentValue) => {
|
|
3095
|
-
const { abortController, lastSubmitted, submission } = component.persistedState;
|
|
3096
|
-
if (isExactLocalValueMatch(lastSubmitted, currentValue)) {
|
|
3097
|
-
return submission;
|
|
3098
|
-
}
|
|
3099
|
-
const newAbortController = abortAndResetController(abortController);
|
|
3100
|
-
if (isNullish(currentValue) || currentValue === "") {
|
|
3101
|
-
const resolvedNull = Promise.resolve(null);
|
|
3102
|
-
update(component, (draft) => {
|
|
3103
|
-
draft.persistedState.abortController = newAbortController;
|
|
3104
|
-
draft.persistedState.lastResponse = null;
|
|
3105
|
-
draft.persistedState.lastSubmitted = currentValue;
|
|
3106
|
-
draft.persistedState.submission = resolvedNull;
|
|
3107
|
-
});
|
|
3108
|
-
return resolvedNull;
|
|
3109
|
-
}
|
|
3110
|
-
const { signal } = newAbortController;
|
|
3111
|
-
const newSubmission = performPersistAsync({ value: currentValue, signal }).then((newValue) => {
|
|
3112
|
-
update(component, (draft) => {
|
|
3113
|
-
draft.persistedState.lastResponse = newValue;
|
|
3114
|
-
});
|
|
3115
|
-
return newValue;
|
|
3116
|
-
}).catch((error) => {
|
|
3117
|
-
if (error instanceof DOMException && error.name === "AbortError") {
|
|
3118
|
-
return null;
|
|
3119
|
-
}
|
|
3120
|
-
update(component, (draft) => {
|
|
3121
|
-
draft.errors = [error.message];
|
|
3122
|
-
draft.persistedState.lastResponse = null;
|
|
3123
|
-
draft.persistedState.lastSubmitted = null;
|
|
3124
|
-
});
|
|
3125
|
-
throw error;
|
|
3126
|
-
});
|
|
3127
|
-
update(component, (draft) => {
|
|
3128
|
-
draft.persistedState = {
|
|
3129
|
-
abortController: newAbortController,
|
|
3130
|
-
lastResponse: null,
|
|
3131
|
-
lastSubmitted: currentValue,
|
|
3132
|
-
submission: newSubmission
|
|
3133
|
-
};
|
|
3134
|
-
});
|
|
3135
|
-
return newSubmission;
|
|
3136
|
-
}
|
|
3137
|
-
);
|
|
3138
|
-
var getComponentMultiPersistAsync = (update, performPersistAsync) => (
|
|
3139
|
-
/**
|
|
3140
|
-
* Will update the persistedState when a new request is made, and will update
|
|
3141
|
-
* the value or set errors when the request completes.
|
|
3142
|
-
*/
|
|
3143
|
-
async (component, index, value) => {
|
|
3144
|
-
if (isNullish(value)) {
|
|
3145
|
-
throw new Error("Value must be a file or base64 string.");
|
|
3146
|
-
}
|
|
3147
|
-
const newAbortController = new AbortController();
|
|
3148
|
-
const { signal } = newAbortController;
|
|
3149
|
-
const newSubmission = performPersistAsync({ value, signal }).then((newValue) => {
|
|
3150
|
-
update(component, (draft) => {
|
|
3151
|
-
draft.persistedState[index].lastResponse = newValue;
|
|
3152
|
-
});
|
|
3153
|
-
return newValue;
|
|
3154
|
-
}).catch((error) => {
|
|
3155
|
-
update(component, (draft) => {
|
|
3156
|
-
draft.persistedState = [
|
|
3157
|
-
...draft.persistedState.slice(0, index),
|
|
3158
|
-
...draft.persistedState.slice(index + 1)
|
|
3159
|
-
];
|
|
3160
|
-
draft.value.splice(index, 1);
|
|
3161
|
-
draft.files.splice(index, 1);
|
|
3162
|
-
});
|
|
3163
|
-
throw error;
|
|
3164
|
-
});
|
|
3165
|
-
update(component, (draft) => {
|
|
3166
|
-
draft.persistedState = [
|
|
3167
|
-
...draft.persistedState.slice(0, index),
|
|
3168
|
-
{
|
|
3169
|
-
id: getRandomId(),
|
|
3170
|
-
abortController: newAbortController,
|
|
3171
|
-
lastResponse: null,
|
|
3172
|
-
lastSubmitted: null,
|
|
3173
|
-
submission: newSubmission
|
|
3174
|
-
},
|
|
3175
|
-
...draft.persistedState.slice(index)
|
|
3176
|
-
];
|
|
3177
|
-
});
|
|
3178
|
-
return newSubmission;
|
|
3179
|
-
}
|
|
3180
|
-
);
|
|
3181
|
-
|
|
3182
|
-
// src/revamp/domain/components/utils/isOrWasValid.ts
|
|
3183
|
-
var isOrWasValid = (getErrors, previous, current) => {
|
|
3184
|
-
const wasValid = getErrors(previous).length === 0 && previous !== null;
|
|
3185
|
-
const isValid = getErrors(current).length === 0;
|
|
3186
|
-
return wasValid || isValid;
|
|
3187
|
-
};
|
|
3188
|
-
|
|
3189
|
-
// src/revamp/domain/features/refresh/getPerformRefresh.ts
|
|
3190
|
-
var getPerformRefresh = (schema, onBehavior) => {
|
|
3191
|
-
var _a, _b;
|
|
3192
|
-
if ("refreshStepOnChange" in schema && ((_a = schema.refreshStepOnChange) != null ? _a : false) || "refreshFormOnChange" in schema && ((_b = schema.refreshFormOnChange) != null ? _b : false)) {
|
|
3193
|
-
const { $id, analyticsId, refreshUrl, refreshFormUrl } = schema;
|
|
3194
|
-
const schemaId = analyticsId != null ? analyticsId : $id;
|
|
3195
|
-
return () => {
|
|
3196
|
-
void onBehavior({
|
|
3197
|
-
type: "refresh",
|
|
3198
|
-
schemaId,
|
|
3199
|
-
url: refreshUrl != null ? refreshUrl : refreshFormUrl
|
|
3200
|
-
});
|
|
3201
|
-
};
|
|
3202
|
-
}
|
|
3203
|
-
return void 0;
|
|
3204
|
-
};
|
|
3205
|
-
var getDebouncedPerformRefresh = (performRefresh, getValidationErrors) => {
|
|
3206
|
-
if (!performRefresh) {
|
|
3207
|
-
return void 0;
|
|
3208
|
-
}
|
|
3209
|
-
const performDebouncedRefresh = debounce(performRefresh, 1e3);
|
|
3210
|
-
const debouncedFn = (prevValue, updatedValue) => {
|
|
3211
|
-
if (isOrWasValid(getValidationErrors, prevValue, updatedValue) || (performDebouncedRefresh == null ? void 0 : performDebouncedRefresh.isPending())) {
|
|
3212
|
-
performDebouncedRefresh == null ? void 0 : performDebouncedRefresh();
|
|
3213
|
-
}
|
|
3214
|
-
};
|
|
3215
|
-
debouncedFn.flush = () => performDebouncedRefresh.flush();
|
|
3216
|
-
debouncedFn.cancel = () => performDebouncedRefresh.cancel();
|
|
3217
|
-
debouncedFn.isPending = () => performDebouncedRefresh.isPending();
|
|
3218
|
-
return debouncedFn;
|
|
3219
|
-
};
|
|
3220
|
-
|
|
3221
|
-
// src/revamp/domain/features/validation/validation-functions.ts
|
|
3222
|
-
var validateComponents = (components) => components.reduce((acc, component) => component.validate() && acc, true);
|
|
3223
|
-
var getLocalValueValidator = (checks) => (currentValue) => checks.map((check) => check(currentValue)).filter(isString);
|
|
3224
|
-
|
|
3225
3119
|
// src/revamp/domain/features/validationAsync/getComponentValidationAsync.ts
|
|
3226
3120
|
var getComponentValidationAsync = (update, performValidationAsync) => (
|
|
3227
3121
|
/**
|
|
@@ -3275,24 +3169,25 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
|
|
|
3275
3169
|
uid,
|
|
3276
3170
|
id,
|
|
3277
3171
|
checks,
|
|
3278
|
-
|
|
3279
|
-
performRefresh,
|
|
3172
|
+
schemaOnChange,
|
|
3280
3173
|
performValidationAsync,
|
|
3281
3174
|
onValueChange,
|
|
3175
|
+
onPersistAsync,
|
|
3282
3176
|
summariser
|
|
3283
3177
|
} = _a, rest = __objRest(_a, [
|
|
3284
3178
|
"uid",
|
|
3285
3179
|
"id",
|
|
3286
3180
|
"checks",
|
|
3287
|
-
"
|
|
3288
|
-
"performRefresh",
|
|
3181
|
+
"schemaOnChange",
|
|
3289
3182
|
"performValidationAsync",
|
|
3290
3183
|
"onValueChange",
|
|
3184
|
+
"onPersistAsync",
|
|
3291
3185
|
"summariser"
|
|
3292
3186
|
]);
|
|
3293
3187
|
const update = getInputUpdateFunction(updateComponent);
|
|
3294
3188
|
const getValidationErrors = getLocalValueValidator(checks);
|
|
3295
|
-
const
|
|
3189
|
+
const performOnChange = getDebouncedSchemaOnChange(schemaOnChange, getValidationErrors);
|
|
3190
|
+
const validateAsync = performValidationAsync ? getDebouncedComponentValidationAsync(update, performValidationAsync) : void 0;
|
|
3296
3191
|
const numberComponent = __spreadValues({
|
|
3297
3192
|
type: "number",
|
|
3298
3193
|
uid,
|
|
@@ -3301,8 +3196,12 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
|
|
|
3301
3196
|
update(this, updateFn);
|
|
3302
3197
|
},
|
|
3303
3198
|
onBlur() {
|
|
3304
|
-
this.validate();
|
|
3305
|
-
|
|
3199
|
+
const isValid = this.validate();
|
|
3200
|
+
performOnChange == null ? void 0 : performOnChange.flush();
|
|
3201
|
+
if (isValid) {
|
|
3202
|
+
onPersistAsync == null ? void 0 : onPersistAsync();
|
|
3203
|
+
validateAsync == null ? void 0 : validateAsync.flush();
|
|
3204
|
+
}
|
|
3306
3205
|
},
|
|
3307
3206
|
onFocus() {
|
|
3308
3207
|
},
|
|
@@ -3314,7 +3213,11 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
|
|
|
3314
3213
|
draft.validationAsyncState.messages = {};
|
|
3315
3214
|
draft.value = updatedValue;
|
|
3316
3215
|
});
|
|
3317
|
-
|
|
3216
|
+
performOnChange == null ? void 0 : performOnChange(prevValue, updatedValue);
|
|
3217
|
+
const isValid = getValidationErrors(updatedValue).length === 0;
|
|
3218
|
+
if (isValid) {
|
|
3219
|
+
validateAsync == null ? void 0 : validateAsync(this, updatedValue);
|
|
3220
|
+
}
|
|
3318
3221
|
onValueChange();
|
|
3319
3222
|
},
|
|
3320
3223
|
async getSubmittableValue() {
|
|
@@ -3338,43 +3241,44 @@ var createNumberInputComponent = (numberInputProps, updateComponent) => {
|
|
|
3338
3241
|
return errors.length === 0;
|
|
3339
3242
|
}
|
|
3340
3243
|
}, rest);
|
|
3341
|
-
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
return persist(this, this.getLocalValue());
|
|
3355
|
-
},
|
|
3356
|
-
getSubmittableValueSync() {
|
|
3357
|
-
return this.persistedState.lastResponse;
|
|
3358
|
-
}
|
|
3359
|
-
});
|
|
3244
|
+
return numberComponent;
|
|
3245
|
+
};
|
|
3246
|
+
|
|
3247
|
+
// src/revamp/domain/features/schema-on-change/getSchemaOnChange.ts
|
|
3248
|
+
var getSchemaOnChange = (schema, onBehavior) => {
|
|
3249
|
+
var _a, _b;
|
|
3250
|
+
const behavior = (_b = (_a = getBehaviorFromSchemaOnChange(schema)) != null ? _a : getBehaviorFromSchemaRefreshStepOnChange(schema)) != null ? _b : void 0;
|
|
3251
|
+
if (behavior) {
|
|
3252
|
+
const onChange = () => {
|
|
3253
|
+
void onBehavior(behavior);
|
|
3254
|
+
};
|
|
3255
|
+
onChange.behaviorType = behavior.type;
|
|
3256
|
+
return onChange;
|
|
3360
3257
|
}
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
},
|
|
3369
|
-
onChange(updatedValue) {
|
|
3370
|
-
numberComponent.onChange.call(this, updatedValue);
|
|
3371
|
-
if (getValidationErrors(updatedValue).length === 0) {
|
|
3372
|
-
validateAsync(this, updatedValue);
|
|
3373
|
-
}
|
|
3374
|
-
}
|
|
3258
|
+
return void 0;
|
|
3259
|
+
};
|
|
3260
|
+
var getBehaviorFromSchemaOnChange = (schema) => {
|
|
3261
|
+
if ("onChange" in schema && schema.onChange) {
|
|
3262
|
+
const { $id, analyticsId, onChange } = schema;
|
|
3263
|
+
const behavior = __spreadProps(__spreadValues({}, normaliseBehavior(onChange, [])), {
|
|
3264
|
+
analytics: { schema: analyticsId != null ? analyticsId : $id }
|
|
3375
3265
|
});
|
|
3266
|
+
return behavior;
|
|
3376
3267
|
}
|
|
3377
|
-
return
|
|
3268
|
+
return void 0;
|
|
3269
|
+
};
|
|
3270
|
+
var getBehaviorFromSchemaRefreshStepOnChange = (schema) => {
|
|
3271
|
+
var _a, _b;
|
|
3272
|
+
if ("refreshStepOnChange" in schema && ((_a = schema.refreshStepOnChange) != null ? _a : false) || "refreshFormOnChange" in schema && ((_b = schema.refreshFormOnChange) != null ? _b : false)) {
|
|
3273
|
+
const { $id, analyticsId, refreshUrl, refreshFormUrl } = schema;
|
|
3274
|
+
const behavior = {
|
|
3275
|
+
type: "refresh",
|
|
3276
|
+
analytics: { schema: analyticsId != null ? analyticsId : $id },
|
|
3277
|
+
url: refreshUrl != null ? refreshUrl : refreshFormUrl
|
|
3278
|
+
};
|
|
3279
|
+
return behavior;
|
|
3280
|
+
}
|
|
3281
|
+
return void 0;
|
|
3378
3282
|
};
|
|
3379
3283
|
|
|
3380
3284
|
// src/revamp/domain/features/validation/validateStringPattern.ts
|
|
@@ -3595,6 +3499,13 @@ var parseResponseBodyAsJsonElement = async (response) => {
|
|
|
3595
3499
|
return null;
|
|
3596
3500
|
}
|
|
3597
3501
|
};
|
|
3502
|
+
var parseResponseBodyAsText = async (response) => {
|
|
3503
|
+
try {
|
|
3504
|
+
return await response.text();
|
|
3505
|
+
} catch (e) {
|
|
3506
|
+
return null;
|
|
3507
|
+
}
|
|
3508
|
+
};
|
|
3598
3509
|
function isActionResponseBody(body) {
|
|
3599
3510
|
return validateActionResponse(body).valid;
|
|
3600
3511
|
}
|
|
@@ -3635,93 +3546,6 @@ var getAnalyticsFromErrorResponse = (json) => {
|
|
|
3635
3546
|
return isObject(analytics) ? analytics : void 0;
|
|
3636
3547
|
};
|
|
3637
3548
|
|
|
3638
|
-
// src/revamp/domain/features/persistAsync/getPerformPersistAsync.ts
|
|
3639
|
-
var getPerformPersistAsync = ({
|
|
3640
|
-
genericErrorMessage,
|
|
3641
|
-
httpClient,
|
|
3642
|
-
persistAsyncConfig,
|
|
3643
|
-
schemaId,
|
|
3644
|
-
logEvent,
|
|
3645
|
-
trackEvent
|
|
3646
|
-
}) => {
|
|
3647
|
-
const { idProperty, param, method, url } = persistAsyncConfig;
|
|
3648
|
-
const trackFailure = (json) => {
|
|
3649
|
-
const analytics = getAnalyticsFromErrorResponse(json);
|
|
3650
|
-
trackEvent("PersistAsync Failed", __spreadValues({ schema: schemaId }, analytics));
|
|
3651
|
-
};
|
|
3652
|
-
return async function performPersistAsync({ value, signal }) {
|
|
3653
|
-
let response;
|
|
3654
|
-
let json;
|
|
3655
|
-
try {
|
|
3656
|
-
trackEvent("PersistAsync Triggered", { schema: schemaId });
|
|
3657
|
-
response = await httpClient(
|
|
3658
|
-
url,
|
|
3659
|
-
constructPayload({ value, signal, requestConfig: { method, param } })
|
|
3660
|
-
);
|
|
3661
|
-
json = await response.json();
|
|
3662
|
-
if (response.ok && isObject(json)) {
|
|
3663
|
-
trackEvent("PersistAsync Succeeded", { schema: schemaId });
|
|
3664
|
-
if (json[idProperty] === void 0) {
|
|
3665
|
-
logEvent(
|
|
3666
|
-
"error",
|
|
3667
|
-
`Response from persist async did not contain expected property ${idProperty}.`
|
|
3668
|
-
);
|
|
3669
|
-
throw new Error(genericErrorMessage);
|
|
3670
|
-
}
|
|
3671
|
-
return json[idProperty];
|
|
3672
|
-
}
|
|
3673
|
-
} catch (e) {
|
|
3674
|
-
trackFailure();
|
|
3675
|
-
throw new Error(genericErrorMessage);
|
|
3676
|
-
}
|
|
3677
|
-
const validationError = !response.ok && isObject(json) ? getValidationError(param, json) : null;
|
|
3678
|
-
trackFailure(json);
|
|
3679
|
-
throw new Error(validationError != null ? validationError : genericErrorMessage);
|
|
3680
|
-
};
|
|
3681
|
-
};
|
|
3682
|
-
var getValidationError = (param, response) => {
|
|
3683
|
-
var _a;
|
|
3684
|
-
const message = (_a = response.validation) == null ? void 0 : _a[param];
|
|
3685
|
-
return isString(message) ? message : null;
|
|
3686
|
-
};
|
|
3687
|
-
|
|
3688
|
-
// src/revamp/domain/features/persistAsync/getInitialPersistedState.ts
|
|
3689
|
-
var getInitialPersistedState = (lastSubmitted, model) => ({
|
|
3690
|
-
abortController: new AbortController(),
|
|
3691
|
-
lastSubmitted: !isNullish(model) ? lastSubmitted != null ? lastSubmitted : null : null,
|
|
3692
|
-
lastResponse: model != null ? model : null,
|
|
3693
|
-
submission: Promise.resolve(model != null ? model : null)
|
|
3694
|
-
});
|
|
3695
|
-
|
|
3696
|
-
// src/revamp/domain/mappers/schema/utils/getPersistAsyncInitialState.ts
|
|
3697
|
-
var getPersistAsyncInitialState = (schemaMapperProps, mapperProps) => {
|
|
3698
|
-
const { localValue, model } = schemaMapperProps;
|
|
3699
|
-
const performPersistAsync = getPerformPersisAsyncFn(schemaMapperProps, mapperProps);
|
|
3700
|
-
const persistedState = performPersistAsync ? getInitialPersistedState(localValue, model) : getInitialPersistedState();
|
|
3701
|
-
return { performPersistAsync, persistedState };
|
|
3702
|
-
};
|
|
3703
|
-
var getPerformPersisAsyncFn = (schemaMapperProps, mapperProps) => {
|
|
3704
|
-
const { schema, persistAsyncConfig } = schemaMapperProps;
|
|
3705
|
-
const { trackEvent, logEvent } = mapperProps;
|
|
3706
|
-
if (!persistAsyncConfig) {
|
|
3707
|
-
return void 0;
|
|
3708
|
-
}
|
|
3709
|
-
const { $id, analyticsId } = schema;
|
|
3710
|
-
const { getErrorMessageFunctions, httpClient } = mapperProps;
|
|
3711
|
-
const validationMessages = schemaHasValidationMessages(schema) ? schema.validationMessages : void 0;
|
|
3712
|
-
const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
|
|
3713
|
-
const persistAsyncError = errorMessageFunctions.genericError();
|
|
3714
|
-
return getPerformPersistAsync({
|
|
3715
|
-
genericErrorMessage: persistAsyncError,
|
|
3716
|
-
httpClient,
|
|
3717
|
-
logEvent,
|
|
3718
|
-
persistAsyncConfig,
|
|
3719
|
-
schemaId: analyticsId != null ? analyticsId : $id,
|
|
3720
|
-
trackEvent
|
|
3721
|
-
});
|
|
3722
|
-
};
|
|
3723
|
-
var schemaHasValidationMessages = (schema) => Boolean("validationMessages" in schema && schema.validationMessages);
|
|
3724
|
-
|
|
3725
3549
|
// src/revamp/domain/features/validationAsync/getPerformValidationAsync.ts
|
|
3726
3550
|
var getPerformValidationAsync = ({
|
|
3727
3551
|
httpClient,
|
|
@@ -3838,7 +3662,7 @@ var summaryIfProvides = (summary, { value, icon, image }) => {
|
|
|
3838
3662
|
// src/revamp/domain/mappers/schema/utils/mapCommonSchemaProps.ts
|
|
3839
3663
|
var mapCommonSchemaProps = (schemaMapperProps) => {
|
|
3840
3664
|
var _a;
|
|
3841
|
-
const { uid, schemaId, schema, required, validationErrors } = schemaMapperProps;
|
|
3665
|
+
const { uid, schemaId, schema, required, validationErrors, onPersistAsync } = schemaMapperProps;
|
|
3842
3666
|
const { $id, analyticsId, control, description, icon, image, keywords, title, hidden } = schema;
|
|
3843
3667
|
return __spreadValues(__spreadValues(__spreadValues({
|
|
3844
3668
|
uid,
|
|
@@ -3855,6 +3679,7 @@ var mapCommonSchemaProps = (schemaMapperProps) => {
|
|
|
3855
3679
|
keywords,
|
|
3856
3680
|
required: Boolean(required),
|
|
3857
3681
|
title,
|
|
3682
|
+
onPersistAsync,
|
|
3858
3683
|
summariser: getSummariser(schema)
|
|
3859
3684
|
}, schemaHasHelp(schema) ? { help: schema.help.markdown } : {}), schemaHasPlaceholder(schema) ? { placeholder: schema.placeholder } : {}), schema.alert ? { alert: mapSchemaAlert(schema.alert) } : {});
|
|
3860
3685
|
};
|
|
@@ -3864,21 +3689,17 @@ var schemaHasPlaceholder = (schema) => Boolean("placeholder" in schema && schema
|
|
|
3864
3689
|
|
|
3865
3690
|
// src/revamp/domain/mappers/schema/numberSchemaToComponent.ts
|
|
3866
3691
|
var numberSchemaToComponent = (schemaMapperProps, mapperProps) => {
|
|
3867
|
-
const { schema, model, localValue, required = false } = schemaMapperProps;
|
|
3692
|
+
const { schema, model, localValue, required = false, onPersistAsync } = schemaMapperProps;
|
|
3868
3693
|
const { autocompleteHint, validationMessages, default: defaultValue, maximum, minimum } = schema;
|
|
3869
3694
|
const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
|
|
3870
3695
|
const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
|
|
3871
|
-
const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
|
|
3872
|
-
schemaMapperProps,
|
|
3873
|
-
mapperProps
|
|
3874
|
-
);
|
|
3875
3696
|
const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
|
|
3876
3697
|
schemaMapperProps,
|
|
3877
3698
|
mapperProps
|
|
3878
3699
|
);
|
|
3879
3700
|
const validLocalValue = isNumber(localValue) ? localValue : null;
|
|
3880
3701
|
const validModel = isNumber(model) ? model : defaultValue != null ? defaultValue : null;
|
|
3881
|
-
const value =
|
|
3702
|
+
const value = onPersistAsync ? validLocalValue : validModel;
|
|
3882
3703
|
return createNumberInputComponent(
|
|
3883
3704
|
__spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
|
|
3884
3705
|
autoComplete: getAutocompleteString(autocompleteHint),
|
|
@@ -3890,10 +3711,8 @@ var numberSchemaToComponent = (schemaMapperProps, mapperProps) => {
|
|
|
3890
3711
|
value,
|
|
3891
3712
|
maximum,
|
|
3892
3713
|
minimum,
|
|
3893
|
-
persistedState,
|
|
3894
3714
|
validationAsyncState,
|
|
3895
|
-
|
|
3896
|
-
performRefresh: getPerformRefresh(schema, onBehavior),
|
|
3715
|
+
schemaOnChange: getSchemaOnChange(schema, onBehavior),
|
|
3897
3716
|
performValidationAsync,
|
|
3898
3717
|
onValueChange
|
|
3899
3718
|
}),
|
|
@@ -4170,8 +3989,53 @@ var localValueToJsonElement = (localValue) => {
|
|
|
4170
3989
|
};
|
|
4171
3990
|
var getRandomInt = () => Math.floor(Math.random() * 1e8);
|
|
4172
3991
|
|
|
4173
|
-
// src/revamp/domain/
|
|
4174
|
-
var
|
|
3992
|
+
// src/revamp/domain/features/persistAsync/getComponentMultiPersistAsync.ts
|
|
3993
|
+
var getComponentMultiPersistAsync = (update, performPersistAsync) => (
|
|
3994
|
+
/**
|
|
3995
|
+
* Will update the persistedState when a new request is made, and will update
|
|
3996
|
+
* the value or set errors when the request completes.
|
|
3997
|
+
*/
|
|
3998
|
+
async (component, index, value) => {
|
|
3999
|
+
if (isNullish(value)) {
|
|
4000
|
+
throw new Error("Value must be a file or base64 string.");
|
|
4001
|
+
}
|
|
4002
|
+
const newAbortController = new AbortController();
|
|
4003
|
+
const { signal } = newAbortController;
|
|
4004
|
+
const newSubmission = performPersistAsync({ value, signal }).then((newValue) => {
|
|
4005
|
+
update(component, (draft) => {
|
|
4006
|
+
draft.persistedState[index].lastResponse = newValue;
|
|
4007
|
+
});
|
|
4008
|
+
return newValue;
|
|
4009
|
+
}).catch((error) => {
|
|
4010
|
+
update(component, (draft) => {
|
|
4011
|
+
draft.persistedState = [
|
|
4012
|
+
...draft.persistedState.slice(0, index),
|
|
4013
|
+
...draft.persistedState.slice(index + 1)
|
|
4014
|
+
];
|
|
4015
|
+
draft.value.splice(index, 1);
|
|
4016
|
+
draft.files.splice(index, 1);
|
|
4017
|
+
});
|
|
4018
|
+
throw error;
|
|
4019
|
+
});
|
|
4020
|
+
update(component, (draft) => {
|
|
4021
|
+
draft.persistedState = [
|
|
4022
|
+
...draft.persistedState.slice(0, index),
|
|
4023
|
+
{
|
|
4024
|
+
id: getRandomId(),
|
|
4025
|
+
abortController: newAbortController,
|
|
4026
|
+
lastResponse: null,
|
|
4027
|
+
lastSubmitted: null,
|
|
4028
|
+
submission: newSubmission
|
|
4029
|
+
},
|
|
4030
|
+
...draft.persistedState.slice(index)
|
|
4031
|
+
];
|
|
4032
|
+
});
|
|
4033
|
+
return newSubmission;
|
|
4034
|
+
}
|
|
4035
|
+
);
|
|
4036
|
+
|
|
4037
|
+
// src/revamp/domain/components/utils/file-utils.ts
|
|
4038
|
+
var toBase64 = async (file) => new Promise((resolve, reject) => {
|
|
4175
4039
|
const reader = new FileReader();
|
|
4176
4040
|
reader.addEventListener("load", () => resolve(reader.result));
|
|
4177
4041
|
reader.addEventListener("error", reject);
|
|
@@ -4298,6 +4162,82 @@ var createMultiUploadInputComponent = (uploadInputProps, updateComponent) => {
|
|
|
4298
4162
|
});
|
|
4299
4163
|
};
|
|
4300
4164
|
|
|
4165
|
+
// src/revamp/domain/features/persistAsync/getInitialPersistedState.ts
|
|
4166
|
+
var getInitialPersistedState = (lastSubmitted, model) => ({
|
|
4167
|
+
abortController: new AbortController(),
|
|
4168
|
+
lastSubmitted: !isNullish(model) ? lastSubmitted != null ? lastSubmitted : null : null,
|
|
4169
|
+
lastResponse: model != null ? model : null,
|
|
4170
|
+
submission: Promise.resolve(model != null ? model : null)
|
|
4171
|
+
});
|
|
4172
|
+
|
|
4173
|
+
// src/revamp/domain/features/persistAsync/getPerformPersistAsync.ts
|
|
4174
|
+
var getPerformPersistAsync = ({
|
|
4175
|
+
genericErrorMessage,
|
|
4176
|
+
httpClient,
|
|
4177
|
+
persistAsyncConfig,
|
|
4178
|
+
schemaId,
|
|
4179
|
+
logEvent,
|
|
4180
|
+
trackEvent
|
|
4181
|
+
}) => {
|
|
4182
|
+
const { idProperty, param, method, url } = persistAsyncConfig;
|
|
4183
|
+
const trackFailure = (json) => {
|
|
4184
|
+
const analytics = getAnalyticsFromErrorResponse(json);
|
|
4185
|
+
trackEvent("PersistAsync Failed", __spreadValues({ schema: schemaId }, analytics));
|
|
4186
|
+
};
|
|
4187
|
+
return async function performPersistAsync({ value, signal }) {
|
|
4188
|
+
let response;
|
|
4189
|
+
let json;
|
|
4190
|
+
try {
|
|
4191
|
+
trackEvent("PersistAsync Triggered", { schema: schemaId });
|
|
4192
|
+
response = await httpClient(
|
|
4193
|
+
url,
|
|
4194
|
+
constructPayload({ value, signal, requestConfig: { method, param } })
|
|
4195
|
+
);
|
|
4196
|
+
json = await response.json();
|
|
4197
|
+
if (response.ok && isObject(json)) {
|
|
4198
|
+
trackEvent("PersistAsync Succeeded", { schema: schemaId });
|
|
4199
|
+
if (json[idProperty] === void 0) {
|
|
4200
|
+
logEvent(
|
|
4201
|
+
"error",
|
|
4202
|
+
`Response from persist async did not contain expected property ${idProperty}.`
|
|
4203
|
+
);
|
|
4204
|
+
throw new Error(genericErrorMessage);
|
|
4205
|
+
}
|
|
4206
|
+
return json[idProperty];
|
|
4207
|
+
}
|
|
4208
|
+
} catch (e) {
|
|
4209
|
+
trackFailure();
|
|
4210
|
+
throw new Error(genericErrorMessage);
|
|
4211
|
+
}
|
|
4212
|
+
const validationError = !response.ok && isObject(json) ? getValidationError(param, json) : null;
|
|
4213
|
+
trackFailure(json);
|
|
4214
|
+
throw new Error(validationError != null ? validationError : genericErrorMessage);
|
|
4215
|
+
};
|
|
4216
|
+
};
|
|
4217
|
+
var getValidationError = (param, response) => {
|
|
4218
|
+
var _a;
|
|
4219
|
+
const message = (_a = response.validation) == null ? void 0 : _a[param];
|
|
4220
|
+
return isString(message) ? message : null;
|
|
4221
|
+
};
|
|
4222
|
+
|
|
4223
|
+
// src/revamp/domain/mappers/schema/utils/getPerformPersistAsyncFn.ts
|
|
4224
|
+
var getPerformPersistAsyncFn = (schema, persistAsyncConfig, mapperProps) => {
|
|
4225
|
+
const { getErrorMessageFunctions, httpClient, trackEvent, logEvent } = mapperProps;
|
|
4226
|
+
const { $id, analyticsId } = schema;
|
|
4227
|
+
const validationMessages = schemaHasValidationMessages(schema) ? schema.validationMessages : void 0;
|
|
4228
|
+
const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
|
|
4229
|
+
const persistAsyncError = errorMessageFunctions.genericError();
|
|
4230
|
+
return getPerformPersistAsync({
|
|
4231
|
+
genericErrorMessage: persistAsyncError,
|
|
4232
|
+
httpClient,
|
|
4233
|
+
logEvent,
|
|
4234
|
+
persistAsyncConfig,
|
|
4235
|
+
schemaId: analyticsId != null ? analyticsId : $id,
|
|
4236
|
+
trackEvent
|
|
4237
|
+
});
|
|
4238
|
+
};
|
|
4239
|
+
var schemaHasValidationMessages = (schema) => Boolean("validationMessages" in schema && schema.validationMessages);
|
|
4240
|
+
|
|
4301
4241
|
// src/revamp/domain/mappers/schema/arraySchemaToComponent/arraySchemaToMultiUploadComponent.ts
|
|
4302
4242
|
var arraySchemaToMultiUploadComponent = (schemaMapperProps, mapperProps) => {
|
|
4303
4243
|
var _a;
|
|
@@ -4324,7 +4264,7 @@ var arraySchemaToMultiUploadComponent = (schemaMapperProps, mapperProps) => {
|
|
|
4324
4264
|
schema: __spreadProps(__spreadValues({}, uploadSchema), { hidden: (_a = schema.hidden) != null ? _a : uploadSchema.hidden, alert: schema.alert })
|
|
4325
4265
|
});
|
|
4326
4266
|
const { onValueChange } = mapperProps;
|
|
4327
|
-
const
|
|
4267
|
+
const performPersistAsync = persistAsyncConfig ? getPerformPersistAsyncFn(combinedSchemaProps.schema, persistAsyncConfig, mapperProps) : void 0;
|
|
4328
4268
|
const value = performPersistAsync ? getValueForPersistAsync(localValue) : [];
|
|
4329
4269
|
const persistedState = performPersistAsync && isArray(model) ? model.map((itemModel) => getInitialPersistedState(null, itemModel)) : [];
|
|
4330
4270
|
return createMultiUploadInputComponent(
|
|
@@ -4380,7 +4320,7 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
|
|
|
4380
4320
|
options,
|
|
4381
4321
|
initialValue,
|
|
4382
4322
|
performValidationAsync,
|
|
4383
|
-
|
|
4323
|
+
schemaOnChange,
|
|
4384
4324
|
onValueChange
|
|
4385
4325
|
} = _a, rest = __objRest(_a, [
|
|
4386
4326
|
"uid",
|
|
@@ -4388,13 +4328,14 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
|
|
|
4388
4328
|
"options",
|
|
4389
4329
|
"initialValue",
|
|
4390
4330
|
"performValidationAsync",
|
|
4391
|
-
"
|
|
4331
|
+
"schemaOnChange",
|
|
4392
4332
|
"onValueChange"
|
|
4393
4333
|
]);
|
|
4394
4334
|
const update = getInputUpdateFunction(updateComponent);
|
|
4395
4335
|
const children = options.map((option) => option.component);
|
|
4396
4336
|
const selectedIndices = getInitialModelIndices(initialValue, children);
|
|
4397
4337
|
const getValidationErrors = getLocalValueValidator(checks);
|
|
4338
|
+
const validateAsync = performValidationAsync ? getComponentValidationAsync(update, performValidationAsync) : void 0;
|
|
4398
4339
|
const component = __spreadProps(__spreadValues({
|
|
4399
4340
|
uid,
|
|
4400
4341
|
type: "multi-select",
|
|
@@ -4411,12 +4352,16 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
|
|
|
4411
4352
|
draft.selectedIndices = indices;
|
|
4412
4353
|
draft.errors = [];
|
|
4413
4354
|
});
|
|
4414
|
-
|
|
4415
|
-
onValueChange();
|
|
4355
|
+
schemaOnChange == null ? void 0 : schemaOnChange();
|
|
4416
4356
|
const errors = getValidationErrors(this.getLocalValue());
|
|
4417
4357
|
this._update((draft) => {
|
|
4418
4358
|
draft.errors = errors;
|
|
4419
4359
|
});
|
|
4360
|
+
if (this.validate()) {
|
|
4361
|
+
validateAsync == null ? void 0 : validateAsync(this, this.getLocalValue()).catch(() => {
|
|
4362
|
+
});
|
|
4363
|
+
}
|
|
4364
|
+
onValueChange();
|
|
4420
4365
|
},
|
|
4421
4366
|
onBlur() {
|
|
4422
4367
|
},
|
|
@@ -4454,21 +4399,6 @@ var createMultiSelectComponent = (multiSelectProps, updateComponent) => {
|
|
|
4454
4399
|
return this.selectedIndices.map((i) => this.children[i]);
|
|
4455
4400
|
}
|
|
4456
4401
|
});
|
|
4457
|
-
if (performRefresh) {
|
|
4458
|
-
return component;
|
|
4459
|
-
}
|
|
4460
|
-
if (performValidationAsync) {
|
|
4461
|
-
const validateAsync = getComponentValidationAsync(update, performValidationAsync);
|
|
4462
|
-
return __spreadProps(__spreadValues({}, component), {
|
|
4463
|
-
onSelect(indices) {
|
|
4464
|
-
component.onSelect.call(this, indices);
|
|
4465
|
-
if (this.validate()) {
|
|
4466
|
-
validateAsync(this, this.getLocalValue()).catch(() => {
|
|
4467
|
-
});
|
|
4468
|
-
}
|
|
4469
|
-
}
|
|
4470
|
-
});
|
|
4471
|
-
}
|
|
4472
4402
|
return component;
|
|
4473
4403
|
};
|
|
4474
4404
|
var getInitialModelIndices = (model, options) => {
|
|
@@ -4535,7 +4465,7 @@ var arraySchemaToMultiSelectComponent = (schemaMapperProps, mapperProps) => {
|
|
|
4535
4465
|
title,
|
|
4536
4466
|
validationAsyncState,
|
|
4537
4467
|
performValidationAsync,
|
|
4538
|
-
|
|
4468
|
+
schemaOnChange: getSchemaOnChange(schema, onBehavior),
|
|
4539
4469
|
onValueChange
|
|
4540
4470
|
}),
|
|
4541
4471
|
updateComponent
|
|
@@ -4655,9 +4585,9 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
|
|
|
4655
4585
|
checks,
|
|
4656
4586
|
format,
|
|
4657
4587
|
value,
|
|
4658
|
-
|
|
4659
|
-
performRefresh,
|
|
4588
|
+
schemaOnChange,
|
|
4660
4589
|
onValueChange,
|
|
4590
|
+
onPersistAsync,
|
|
4661
4591
|
summariser
|
|
4662
4592
|
} = _a, rest = __objRest(_a, [
|
|
4663
4593
|
"uid",
|
|
@@ -4665,9 +4595,9 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
|
|
|
4665
4595
|
"checks",
|
|
4666
4596
|
"format",
|
|
4667
4597
|
"value",
|
|
4668
|
-
"
|
|
4669
|
-
"performRefresh",
|
|
4598
|
+
"schemaOnChange",
|
|
4670
4599
|
"onValueChange",
|
|
4600
|
+
"onPersistAsync",
|
|
4671
4601
|
"summariser"
|
|
4672
4602
|
]);
|
|
4673
4603
|
const update = getInputUpdateFunction(updateComponent);
|
|
@@ -4676,7 +4606,7 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
|
|
|
4676
4606
|
type: "upload",
|
|
4677
4607
|
uid,
|
|
4678
4608
|
id,
|
|
4679
|
-
format
|
|
4609
|
+
format,
|
|
4680
4610
|
value,
|
|
4681
4611
|
_update(updateFn) {
|
|
4682
4612
|
update(this, updateFn);
|
|
@@ -4692,12 +4622,16 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
|
|
|
4692
4622
|
draft.errors = [];
|
|
4693
4623
|
draft.value = updatedValue;
|
|
4694
4624
|
});
|
|
4695
|
-
|
|
4625
|
+
schemaOnChange == null ? void 0 : schemaOnChange();
|
|
4696
4626
|
onValueChange();
|
|
4627
|
+
onPersistAsync == null ? void 0 : onPersistAsync();
|
|
4697
4628
|
},
|
|
4698
4629
|
async getSubmittableValue() {
|
|
4699
4630
|
const file = this.getLocalValue();
|
|
4700
|
-
|
|
4631
|
+
if (this.format === "base64" && file) {
|
|
4632
|
+
return toBase64(file);
|
|
4633
|
+
}
|
|
4634
|
+
return null;
|
|
4701
4635
|
},
|
|
4702
4636
|
getSubmittableValueSync() {
|
|
4703
4637
|
return null;
|
|
@@ -4717,50 +4651,17 @@ var createUploadInputComponent = (uploadInputProps, updateComponent) => {
|
|
|
4717
4651
|
return errors.length === 0;
|
|
4718
4652
|
}
|
|
4719
4653
|
}, rest);
|
|
4720
|
-
|
|
4721
|
-
return uploadComponent;
|
|
4722
|
-
}
|
|
4723
|
-
const persist = getComponentPersistAsync(update, performPersistAsync);
|
|
4724
|
-
return __spreadProps(__spreadValues({}, uploadComponent), {
|
|
4725
|
-
format,
|
|
4726
|
-
async onUpload(file) {
|
|
4727
|
-
this._update((draft) => {
|
|
4728
|
-
draft.errors = [];
|
|
4729
|
-
draft.value = file;
|
|
4730
|
-
});
|
|
4731
|
-
onValueChange();
|
|
4732
|
-
const submission = format === "base64" && file ? await toBase64(file) : file;
|
|
4733
|
-
await persist(this, submission).catch((error) => {
|
|
4734
|
-
this._update((draft) => {
|
|
4735
|
-
draft.persistedState.lastResponse = null;
|
|
4736
|
-
draft.persistedState.lastSubmitted = null;
|
|
4737
|
-
draft.persistedState.submission = Promise.resolve(null);
|
|
4738
|
-
draft.errors = [];
|
|
4739
|
-
draft.value = null;
|
|
4740
|
-
});
|
|
4741
|
-
throw error;
|
|
4742
|
-
});
|
|
4743
|
-
onValueChange();
|
|
4744
|
-
},
|
|
4745
|
-
async getSubmittableValue() {
|
|
4746
|
-
return this.persistedState.submission;
|
|
4747
|
-
},
|
|
4748
|
-
getSubmittableValueSync() {
|
|
4749
|
-
return this.persistedState.lastResponse;
|
|
4750
|
-
}
|
|
4751
|
-
});
|
|
4654
|
+
return uploadComponent;
|
|
4752
4655
|
};
|
|
4753
4656
|
|
|
4754
4657
|
// src/revamp/domain/mappers/schema/blobSchemaToComponent.ts
|
|
4755
4658
|
var blobSchemaToComponent = (schemaMapperProps, mapperProps) => {
|
|
4756
|
-
const { schema, localValue,
|
|
4659
|
+
const { schema, localValue, required = false, onPersistAsync } = schemaMapperProps;
|
|
4757
4660
|
const { accepts, cameraConfig, maxSize, source, validationMessages } = schema;
|
|
4758
4661
|
const { getErrorMessageFunctions, updateComponent, onValueChange } = mapperProps;
|
|
4759
4662
|
const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
|
|
4760
|
-
const { performPersistAsync } = getPersistAsyncInitialState(schemaMapperProps, mapperProps);
|
|
4761
|
-
const persistedState = performPersistAsync ? getInitialPersistedState(null, model) : getInitialPersistedState();
|
|
4762
4663
|
const validLocalValue = isFile(localValue) ? localValue : null;
|
|
4763
|
-
const value =
|
|
4664
|
+
const value = onPersistAsync ? validLocalValue : null;
|
|
4764
4665
|
return createUploadInputComponent(
|
|
4765
4666
|
__spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
|
|
4766
4667
|
accepts,
|
|
@@ -4770,9 +4671,8 @@ var blobSchemaToComponent = (schemaMapperProps, mapperProps) => {
|
|
|
4770
4671
|
maxSize,
|
|
4771
4672
|
source,
|
|
4772
4673
|
value,
|
|
4773
|
-
persistedState,
|
|
4774
|
-
performPersistAsync,
|
|
4775
4674
|
checks: schema.hidden ? [] : [getRequiredCheck(required, errorMessageFunctions)],
|
|
4675
|
+
schemaOnChange: void 0,
|
|
4776
4676
|
onValueChange
|
|
4777
4677
|
}),
|
|
4778
4678
|
updateComponent
|
|
@@ -4785,22 +4685,23 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
|
|
|
4785
4685
|
uid,
|
|
4786
4686
|
id,
|
|
4787
4687
|
value,
|
|
4788
|
-
|
|
4789
|
-
performRefresh,
|
|
4688
|
+
schemaOnChange,
|
|
4790
4689
|
performValidationAsync,
|
|
4791
4690
|
onValueChange,
|
|
4691
|
+
onPersistAsync,
|
|
4792
4692
|
summariser
|
|
4793
4693
|
} = _a, rest = __objRest(_a, [
|
|
4794
4694
|
"uid",
|
|
4795
4695
|
"id",
|
|
4796
4696
|
"value",
|
|
4797
|
-
"
|
|
4798
|
-
"performRefresh",
|
|
4697
|
+
"schemaOnChange",
|
|
4799
4698
|
"performValidationAsync",
|
|
4800
4699
|
"onValueChange",
|
|
4700
|
+
"onPersistAsync",
|
|
4801
4701
|
"summariser"
|
|
4802
4702
|
]);
|
|
4803
4703
|
const update = getInputUpdateFunction(updateComponent);
|
|
4704
|
+
const validateAsync = performValidationAsync ? getComponentValidationAsync(update, performValidationAsync) : void 0;
|
|
4804
4705
|
const booleanComponent = __spreadValues({
|
|
4805
4706
|
type: "boolean",
|
|
4806
4707
|
uid,
|
|
@@ -4821,7 +4722,10 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
|
|
|
4821
4722
|
draft.errors = [];
|
|
4822
4723
|
draft.value = updatedValue;
|
|
4823
4724
|
});
|
|
4824
|
-
|
|
4725
|
+
schemaOnChange == null ? void 0 : schemaOnChange();
|
|
4726
|
+
onPersistAsync == null ? void 0 : onPersistAsync();
|
|
4727
|
+
validateAsync == null ? void 0 : validateAsync(this, this.getLocalValue()).catch(() => {
|
|
4728
|
+
});
|
|
4825
4729
|
onValueChange();
|
|
4826
4730
|
},
|
|
4827
4731
|
async getSubmittableValue() {
|
|
@@ -4838,62 +4742,27 @@ var createBooleanInputComponent = (booleanInputProps, updateComponent) => {
|
|
|
4838
4742
|
},
|
|
4839
4743
|
validate: () => true
|
|
4840
4744
|
}, rest);
|
|
4841
|
-
if (performRefresh) {
|
|
4842
|
-
return booleanComponent;
|
|
4843
|
-
}
|
|
4844
|
-
if (performPersistAsync) {
|
|
4845
|
-
const persist = getComponentPersistAsync(update, performPersistAsync);
|
|
4846
|
-
return __spreadProps(__spreadValues({}, booleanComponent), {
|
|
4847
|
-
onChange(updatedValue) {
|
|
4848
|
-
booleanComponent.onChange.call(this, updatedValue);
|
|
4849
|
-
persist(this, this.getLocalValue()).catch(() => {
|
|
4850
|
-
});
|
|
4851
|
-
},
|
|
4852
|
-
async getSubmittableValue() {
|
|
4853
|
-
return persist(this, this.getLocalValue());
|
|
4854
|
-
},
|
|
4855
|
-
getSubmittableValueSync() {
|
|
4856
|
-
return this.persistedState.lastResponse;
|
|
4857
|
-
}
|
|
4858
|
-
});
|
|
4859
|
-
}
|
|
4860
|
-
if (performValidationAsync) {
|
|
4861
|
-
const validateAsync = getComponentValidationAsync(update, performValidationAsync);
|
|
4862
|
-
return __spreadProps(__spreadValues({}, booleanComponent), {
|
|
4863
|
-
onChange(updatedValue) {
|
|
4864
|
-
booleanComponent.onChange.call(this, updatedValue);
|
|
4865
|
-
validateAsync(this, this.getLocalValue()).catch(() => {
|
|
4866
|
-
});
|
|
4867
|
-
}
|
|
4868
|
-
});
|
|
4869
|
-
}
|
|
4870
4745
|
return booleanComponent;
|
|
4871
4746
|
};
|
|
4872
4747
|
|
|
4873
4748
|
// src/revamp/domain/mappers/schema/booleanSchemaToComponent.ts
|
|
4874
4749
|
var booleanSchemaToComponent = (schemaMapperProps, mapperProps) => {
|
|
4875
|
-
const { schema, localValue, model } = schemaMapperProps;
|
|
4750
|
+
const { schema, localValue, model, onPersistAsync } = schemaMapperProps;
|
|
4876
4751
|
const { default: defaultValue } = schema;
|
|
4877
4752
|
const { updateComponent, onBehavior, onValueChange } = mapperProps;
|
|
4878
|
-
const
|
|
4879
|
-
const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
|
|
4880
|
-
schemaMapperProps,
|
|
4881
|
-
mapperProps
|
|
4882
|
-
);
|
|
4753
|
+
const schemaOnChange = getSchemaOnChange(schema, onBehavior);
|
|
4883
4754
|
const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
|
|
4884
4755
|
schemaMapperProps,
|
|
4885
4756
|
mapperProps
|
|
4886
4757
|
);
|
|
4887
4758
|
const validLocalValue = isBoolean(localValue) ? localValue : false;
|
|
4888
4759
|
const validModel = getValidModel(model, defaultValue);
|
|
4889
|
-
const value =
|
|
4760
|
+
const value = onPersistAsync ? validLocalValue : validModel;
|
|
4890
4761
|
return createBooleanInputComponent(
|
|
4891
4762
|
__spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
|
|
4892
4763
|
value: value != null ? value : false,
|
|
4893
|
-
persistedState,
|
|
4894
4764
|
validationAsyncState,
|
|
4895
|
-
|
|
4896
|
-
performRefresh,
|
|
4765
|
+
schemaOnChange,
|
|
4897
4766
|
performValidationAsync,
|
|
4898
4767
|
onValueChange
|
|
4899
4768
|
}),
|
|
@@ -4949,25 +4818,26 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
|
|
|
4949
4818
|
id,
|
|
4950
4819
|
checks,
|
|
4951
4820
|
value,
|
|
4952
|
-
|
|
4953
|
-
performRefresh,
|
|
4821
|
+
schemaOnChange,
|
|
4954
4822
|
performValidationAsync,
|
|
4955
4823
|
onValueChange,
|
|
4824
|
+
onPersistAsync,
|
|
4956
4825
|
summariser
|
|
4957
4826
|
} = _a, rest = __objRest(_a, [
|
|
4958
4827
|
"uid",
|
|
4959
4828
|
"id",
|
|
4960
4829
|
"checks",
|
|
4961
4830
|
"value",
|
|
4962
|
-
"
|
|
4963
|
-
"performRefresh",
|
|
4831
|
+
"schemaOnChange",
|
|
4964
4832
|
"performValidationAsync",
|
|
4965
4833
|
"onValueChange",
|
|
4834
|
+
"onPersistAsync",
|
|
4966
4835
|
"summariser"
|
|
4967
4836
|
]);
|
|
4968
4837
|
const update = getInputUpdateFunction(updateComponent);
|
|
4969
4838
|
const getValidationErrors = getLocalValueValidator(checks);
|
|
4970
|
-
const
|
|
4839
|
+
const performOnChange = getDebouncedSchemaOnChange(schemaOnChange, getValidationErrors);
|
|
4840
|
+
const validateAsync = performValidationAsync ? getDebouncedComponentValidationAsync(update, performValidationAsync) : void 0;
|
|
4971
4841
|
const integerComponent = __spreadValues({
|
|
4972
4842
|
type: "integer",
|
|
4973
4843
|
uid,
|
|
@@ -4977,8 +4847,12 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
|
|
|
4977
4847
|
update(this, updateFn);
|
|
4978
4848
|
},
|
|
4979
4849
|
onBlur() {
|
|
4980
|
-
this.validate();
|
|
4981
|
-
|
|
4850
|
+
const isValid = this.validate();
|
|
4851
|
+
performOnChange == null ? void 0 : performOnChange.flush();
|
|
4852
|
+
if (isValid) {
|
|
4853
|
+
onPersistAsync == null ? void 0 : onPersistAsync();
|
|
4854
|
+
validateAsync == null ? void 0 : validateAsync.flush();
|
|
4855
|
+
}
|
|
4982
4856
|
},
|
|
4983
4857
|
onFocus() {
|
|
4984
4858
|
},
|
|
@@ -4990,7 +4864,11 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
|
|
|
4990
4864
|
draft.validationAsyncState.messages = {};
|
|
4991
4865
|
draft.value = updatedValue;
|
|
4992
4866
|
});
|
|
4993
|
-
|
|
4867
|
+
performOnChange == null ? void 0 : performOnChange(prevValue, updatedValue);
|
|
4868
|
+
const isValid = getValidationErrors(updatedValue).length === 0;
|
|
4869
|
+
if (isValid) {
|
|
4870
|
+
validateAsync == null ? void 0 : validateAsync(this, updatedValue);
|
|
4871
|
+
}
|
|
4994
4872
|
onValueChange();
|
|
4995
4873
|
},
|
|
4996
4874
|
async getSubmittableValue() {
|
|
@@ -5014,62 +4892,22 @@ var createIntegerInputComponent = (integerInputProps, updateComponent) => {
|
|
|
5014
4892
|
return errors.length === 0;
|
|
5015
4893
|
}
|
|
5016
4894
|
}, rest);
|
|
5017
|
-
if (performRefresh) {
|
|
5018
|
-
return integerComponent;
|
|
5019
|
-
}
|
|
5020
|
-
if (performPersistAsync) {
|
|
5021
|
-
const persist = getComponentPersistAsync(update, performPersistAsync);
|
|
5022
|
-
return __spreadProps(__spreadValues({}, integerComponent), {
|
|
5023
|
-
onBlur() {
|
|
5024
|
-
if (this.validate()) {
|
|
5025
|
-
persist(this, this.getLocalValue()).catch(() => {
|
|
5026
|
-
});
|
|
5027
|
-
}
|
|
5028
|
-
},
|
|
5029
|
-
async getSubmittableValue() {
|
|
5030
|
-
return persist(this, this.getLocalValue());
|
|
5031
|
-
},
|
|
5032
|
-
getSubmittableValueSync() {
|
|
5033
|
-
return this.persistedState.lastResponse;
|
|
5034
|
-
}
|
|
5035
|
-
});
|
|
5036
|
-
}
|
|
5037
|
-
if (performValidationAsync) {
|
|
5038
|
-
const validateAsync = getDebouncedComponentValidationAsync(update, performValidationAsync);
|
|
5039
|
-
return __spreadProps(__spreadValues({}, integerComponent), {
|
|
5040
|
-
onBlur() {
|
|
5041
|
-
if (this.validate()) {
|
|
5042
|
-
validateAsync.flush();
|
|
5043
|
-
}
|
|
5044
|
-
},
|
|
5045
|
-
onChange(updatedValue) {
|
|
5046
|
-
integerComponent.onChange.call(this, updatedValue);
|
|
5047
|
-
if (getValidationErrors(updatedValue).length === 0) {
|
|
5048
|
-
validateAsync(this, updatedValue);
|
|
5049
|
-
}
|
|
5050
|
-
}
|
|
5051
|
-
});
|
|
5052
|
-
}
|
|
5053
4895
|
return integerComponent;
|
|
5054
4896
|
};
|
|
5055
4897
|
|
|
5056
4898
|
// src/revamp/domain/mappers/schema/integerSchemaToComponent.ts
|
|
5057
4899
|
var integerSchemaToComponent = (schemaMapperProps, mapperProps) => {
|
|
5058
|
-
const { schema, localValue, model, required = false } = schemaMapperProps;
|
|
4900
|
+
const { schema, localValue, model, required = false, onPersistAsync } = schemaMapperProps;
|
|
5059
4901
|
const { autocompleteHint, validationMessages, default: defaultValue, maximum, minimum } = schema;
|
|
5060
4902
|
const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
|
|
5061
4903
|
const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
|
|
5062
|
-
const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
|
|
5063
|
-
schemaMapperProps,
|
|
5064
|
-
mapperProps
|
|
5065
|
-
);
|
|
5066
4904
|
const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
|
|
5067
4905
|
schemaMapperProps,
|
|
5068
4906
|
mapperProps
|
|
5069
4907
|
);
|
|
5070
4908
|
const validLocalValue = isInteger(localValue) ? localValue : null;
|
|
5071
4909
|
const validModel = isInteger(model) ? model : defaultValue != null ? defaultValue : null;
|
|
5072
|
-
const value =
|
|
4910
|
+
const value = onPersistAsync ? validLocalValue : validModel;
|
|
5073
4911
|
const checks = [
|
|
5074
4912
|
getRequiredCheck(required, errorMessageFunctions),
|
|
5075
4913
|
getBelowMinimumCheck(schema, errorMessageFunctions),
|
|
@@ -5081,11 +4919,9 @@ var integerSchemaToComponent = (schemaMapperProps, mapperProps) => {
|
|
|
5081
4919
|
checks,
|
|
5082
4920
|
maximum,
|
|
5083
4921
|
minimum,
|
|
5084
|
-
persistedState,
|
|
5085
4922
|
value,
|
|
5086
4923
|
validationAsyncState,
|
|
5087
|
-
|
|
5088
|
-
performRefresh: getPerformRefresh(schema, onBehavior),
|
|
4924
|
+
schemaOnChange: getSchemaOnChange(schema, onBehavior),
|
|
5089
4925
|
performValidationAsync,
|
|
5090
4926
|
onValueChange
|
|
5091
4927
|
}),
|
|
@@ -5240,7 +5076,7 @@ var nonNullishKeys = (model) => Object.keys(model).filter((key) => !isNullish(mo
|
|
|
5240
5076
|
|
|
5241
5077
|
// src/revamp/domain/components/SelectInputComponent.ts
|
|
5242
5078
|
var createSelectInputComponent = (selectProps, updateComponent) => {
|
|
5243
|
-
const _a = selectProps, { uid, checks, initialModel, options,
|
|
5079
|
+
const _a = selectProps, { uid, checks, initialModel, options, schemaOnChange, onValueChange, summariser } = _a, rest = __objRest(_a, ["uid", "checks", "initialModel", "options", "schemaOnChange", "onValueChange", "summariser"]);
|
|
5244
5080
|
const children = options.map((option) => option.component);
|
|
5245
5081
|
const matchingOptions = options.map(
|
|
5246
5082
|
(option) => isPartialModelMatch(option.component.getSubmittableValueSync(), initialModel)
|
|
@@ -5301,7 +5137,7 @@ var createSelectInputComponent = (selectProps, updateComponent) => {
|
|
|
5301
5137
|
draft.errors = [];
|
|
5302
5138
|
draft.selectedIndex = updatedIndex;
|
|
5303
5139
|
});
|
|
5304
|
-
|
|
5140
|
+
schemaOnChange == null ? void 0 : schemaOnChange();
|
|
5305
5141
|
onValueChange();
|
|
5306
5142
|
},
|
|
5307
5143
|
validate() {
|
|
@@ -5373,7 +5209,7 @@ var oneOfSchemaToComponent = (schemaMapperProps, mapperProps) => {
|
|
|
5373
5209
|
checks: schema.hidden ? [] : [getRequiredCheck(required, errorMessageFunctions)],
|
|
5374
5210
|
options,
|
|
5375
5211
|
initialModel,
|
|
5376
|
-
|
|
5212
|
+
schemaOnChange: getSchemaOnChange(schema, onBehavior),
|
|
5377
5213
|
onValueChange,
|
|
5378
5214
|
trackEvent
|
|
5379
5215
|
}),
|
|
@@ -5392,25 +5228,26 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
|
|
|
5392
5228
|
uid,
|
|
5393
5229
|
id,
|
|
5394
5230
|
checks,
|
|
5395
|
-
|
|
5396
|
-
performRefresh,
|
|
5231
|
+
schemaOnChange,
|
|
5397
5232
|
performValidationAsync,
|
|
5398
5233
|
onValueChange,
|
|
5234
|
+
onPersistAsync,
|
|
5399
5235
|
summariser,
|
|
5400
5236
|
value
|
|
5401
5237
|
} = _a, rest = __objRest(_a, [
|
|
5402
5238
|
"uid",
|
|
5403
5239
|
"id",
|
|
5404
5240
|
"checks",
|
|
5405
|
-
"
|
|
5406
|
-
"performRefresh",
|
|
5241
|
+
"schemaOnChange",
|
|
5407
5242
|
"performValidationAsync",
|
|
5408
5243
|
"onValueChange",
|
|
5244
|
+
"onPersistAsync",
|
|
5409
5245
|
"summariser",
|
|
5410
5246
|
"value"
|
|
5411
5247
|
]);
|
|
5412
5248
|
const update = getInputUpdateFunction(updateComponent);
|
|
5413
5249
|
const getValidationErrors = getLocalValueValidator(checks);
|
|
5250
|
+
const validateAsync = performValidationAsync ? getComponentValidationAsync(update, performValidationAsync) : void 0;
|
|
5414
5251
|
const dateInputComponent = __spreadValues({
|
|
5415
5252
|
type: "date",
|
|
5416
5253
|
uid,
|
|
@@ -5420,7 +5257,11 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
|
|
|
5420
5257
|
update(this, updateFn);
|
|
5421
5258
|
},
|
|
5422
5259
|
onBlur() {
|
|
5423
|
-
this.validate();
|
|
5260
|
+
const isValid = this.validate();
|
|
5261
|
+
if (isValid) {
|
|
5262
|
+
validateAsync == null ? void 0 : validateAsync(this, this.getLocalValue()).catch(() => {
|
|
5263
|
+
});
|
|
5264
|
+
}
|
|
5424
5265
|
},
|
|
5425
5266
|
onFocus() {
|
|
5426
5267
|
},
|
|
@@ -5433,9 +5274,12 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
|
|
|
5433
5274
|
draft.value = updatedValue;
|
|
5434
5275
|
});
|
|
5435
5276
|
if (isOrWasValid(getValidationErrors, prevValue, updatedValue)) {
|
|
5436
|
-
|
|
5277
|
+
schemaOnChange == null ? void 0 : schemaOnChange();
|
|
5437
5278
|
}
|
|
5438
5279
|
onValueChange();
|
|
5280
|
+
if (getValidationErrors(updatedValue).length === 0) {
|
|
5281
|
+
onPersistAsync == null ? void 0 : onPersistAsync();
|
|
5282
|
+
}
|
|
5439
5283
|
},
|
|
5440
5284
|
async getSubmittableValue() {
|
|
5441
5285
|
return this.getSubmittableValueSync();
|
|
@@ -5458,45 +5302,12 @@ var createDateInputComponent = (textInputProps, updateComponent) => {
|
|
|
5458
5302
|
return errors.length === 0;
|
|
5459
5303
|
}
|
|
5460
5304
|
}, rest);
|
|
5461
|
-
if (performRefresh) {
|
|
5462
|
-
return dateInputComponent;
|
|
5463
|
-
}
|
|
5464
|
-
if (performPersistAsync) {
|
|
5465
|
-
const persist = getComponentPersistAsync(update, performPersistAsync);
|
|
5466
|
-
return __spreadProps(__spreadValues({}, dateInputComponent), {
|
|
5467
|
-
onChange(updatedValue) {
|
|
5468
|
-
dateInputComponent.onChange.call(this, updatedValue);
|
|
5469
|
-
const isValid = getValidationErrors(updatedValue).length === 0;
|
|
5470
|
-
if (isValid) {
|
|
5471
|
-
persist(this, this.getLocalValue()).catch(() => {
|
|
5472
|
-
});
|
|
5473
|
-
}
|
|
5474
|
-
},
|
|
5475
|
-
async getSubmittableValue() {
|
|
5476
|
-
return persist(this, this.getLocalValue());
|
|
5477
|
-
},
|
|
5478
|
-
getSubmittableValueSync() {
|
|
5479
|
-
return this.persistedState.lastResponse;
|
|
5480
|
-
}
|
|
5481
|
-
});
|
|
5482
|
-
}
|
|
5483
|
-
if (performValidationAsync) {
|
|
5484
|
-
const validateAsync = getComponentValidationAsync(update, performValidationAsync);
|
|
5485
|
-
return __spreadProps(__spreadValues({}, dateInputComponent), {
|
|
5486
|
-
onBlur() {
|
|
5487
|
-
if (this.validate()) {
|
|
5488
|
-
validateAsync(this, this.getLocalValue()).catch(() => {
|
|
5489
|
-
});
|
|
5490
|
-
}
|
|
5491
|
-
}
|
|
5492
|
-
});
|
|
5493
|
-
}
|
|
5494
5305
|
return dateInputComponent;
|
|
5495
5306
|
};
|
|
5496
5307
|
|
|
5497
5308
|
// src/revamp/domain/mappers/schema/stringSchemaToComponent/stringSchemaToDateInputComponent.ts
|
|
5498
5309
|
var stringSchemaToDateInputComponent = (schemaMapperProps, mapperProps) => {
|
|
5499
|
-
const { schema, localValue, model, required = false } = schemaMapperProps;
|
|
5310
|
+
const { schema, localValue, model, required = false, onPersistAsync } = schemaMapperProps;
|
|
5500
5311
|
const {
|
|
5501
5312
|
autocompleteHint,
|
|
5502
5313
|
default: defaultValue,
|
|
@@ -5506,17 +5317,13 @@ var stringSchemaToDateInputComponent = (schemaMapperProps, mapperProps) => {
|
|
|
5506
5317
|
} = schema;
|
|
5507
5318
|
const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
|
|
5508
5319
|
const errorMessageFunctions = getErrorMessageFunctions(schema.validationMessages);
|
|
5509
|
-
const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
|
|
5510
|
-
schemaMapperProps,
|
|
5511
|
-
mapperProps
|
|
5512
|
-
);
|
|
5513
5320
|
const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
|
|
5514
5321
|
schemaMapperProps,
|
|
5515
5322
|
mapperProps
|
|
5516
5323
|
);
|
|
5517
5324
|
const validLocalValue = isString(localValue) ? localValue : null;
|
|
5518
5325
|
const validModel = isString(model) ? model : defaultValue != null ? defaultValue : null;
|
|
5519
|
-
const value =
|
|
5326
|
+
const value = onPersistAsync ? validLocalValue : validModel;
|
|
5520
5327
|
return createDateInputComponent(
|
|
5521
5328
|
__spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
|
|
5522
5329
|
autoComplete: getAutocompleteString(autocompleteHint),
|
|
@@ -5533,10 +5340,8 @@ var stringSchemaToDateInputComponent = (schemaMapperProps, mapperProps) => {
|
|
|
5533
5340
|
}))
|
|
5534
5341
|
} : void 0,
|
|
5535
5342
|
value,
|
|
5536
|
-
persistedState,
|
|
5537
5343
|
validationAsyncState,
|
|
5538
|
-
|
|
5539
|
-
performRefresh: getPerformRefresh(schema, onBehavior),
|
|
5344
|
+
schemaOnChange: getSchemaOnChange(schema, onBehavior),
|
|
5540
5345
|
performValidationAsync,
|
|
5541
5346
|
onValueChange
|
|
5542
5347
|
}),
|
|
@@ -5551,8 +5356,6 @@ var stringSchemaToUploadInputComponent = (schemaMapperProps, mapperProps) => {
|
|
|
5551
5356
|
const { accepts, autocompleteHint, cameraConfig, hidden, maxSize, source, validationMessages } = schema;
|
|
5552
5357
|
const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange } = mapperProps;
|
|
5553
5358
|
const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
|
|
5554
|
-
const { performPersistAsync } = getPersistAsyncInitialState(schemaMapperProps, mapperProps);
|
|
5555
|
-
const persistedState = performPersistAsync ? getInitialPersistedState(null, model) : getInitialPersistedState();
|
|
5556
5359
|
const validLocalValue = isFile(localValue) ? localValue : null;
|
|
5557
5360
|
const value = (_a = getFileFromModel(model)) != null ? _a : validLocalValue;
|
|
5558
5361
|
const checks = hidden ? [] : [
|
|
@@ -5570,9 +5373,7 @@ var stringSchemaToUploadInputComponent = (schemaMapperProps, mapperProps) => {
|
|
|
5570
5373
|
maxSize,
|
|
5571
5374
|
source,
|
|
5572
5375
|
value,
|
|
5573
|
-
|
|
5574
|
-
performPersistAsync,
|
|
5575
|
-
performRefresh: getPerformRefresh(schema, onBehavior),
|
|
5376
|
+
schemaOnChange: getSchemaOnChange(schema, onBehavior),
|
|
5576
5377
|
onValueChange
|
|
5577
5378
|
}),
|
|
5578
5379
|
updateComponent
|
|
@@ -5586,26 +5387,27 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
|
|
|
5586
5387
|
uid,
|
|
5587
5388
|
id,
|
|
5588
5389
|
checks,
|
|
5589
|
-
|
|
5590
|
-
performRefresh,
|
|
5390
|
+
schemaOnChange,
|
|
5591
5391
|
performValidationAsync,
|
|
5592
5392
|
onValueChange,
|
|
5393
|
+
onPersistAsync,
|
|
5593
5394
|
summariser,
|
|
5594
5395
|
value
|
|
5595
5396
|
} = _a, rest = __objRest(_a, [
|
|
5596
5397
|
"uid",
|
|
5597
5398
|
"id",
|
|
5598
5399
|
"checks",
|
|
5599
|
-
"
|
|
5600
|
-
"performRefresh",
|
|
5400
|
+
"schemaOnChange",
|
|
5601
5401
|
"performValidationAsync",
|
|
5602
5402
|
"onValueChange",
|
|
5403
|
+
"onPersistAsync",
|
|
5603
5404
|
"summariser",
|
|
5604
5405
|
"value"
|
|
5605
5406
|
]);
|
|
5606
5407
|
const update = getInputUpdateFunction(updateComponent);
|
|
5607
5408
|
const getValidationErrors = getLocalValueValidator(checks);
|
|
5608
|
-
const
|
|
5409
|
+
const performOnChange = getDebouncedSchemaOnChange(schemaOnChange, getValidationErrors);
|
|
5410
|
+
const validateAsync = performValidationAsync ? getDebouncedComponentValidationAsync(update, performValidationAsync) : void 0;
|
|
5609
5411
|
const inputComponent = __spreadValues({
|
|
5610
5412
|
type: "text",
|
|
5611
5413
|
uid,
|
|
@@ -5615,8 +5417,12 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
|
|
|
5615
5417
|
update(this, updateFn);
|
|
5616
5418
|
},
|
|
5617
5419
|
onBlur() {
|
|
5618
|
-
this.validate();
|
|
5619
|
-
|
|
5420
|
+
const isValid = this.validate();
|
|
5421
|
+
performOnChange == null ? void 0 : performOnChange.flush();
|
|
5422
|
+
if (isValid) {
|
|
5423
|
+
onPersistAsync == null ? void 0 : onPersistAsync();
|
|
5424
|
+
validateAsync == null ? void 0 : validateAsync.flush();
|
|
5425
|
+
}
|
|
5620
5426
|
},
|
|
5621
5427
|
onFocus() {
|
|
5622
5428
|
},
|
|
@@ -5628,7 +5434,14 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
|
|
|
5628
5434
|
draft.validationAsyncState.messages = {};
|
|
5629
5435
|
draft.value = updatedValue;
|
|
5630
5436
|
});
|
|
5631
|
-
|
|
5437
|
+
performOnChange == null ? void 0 : performOnChange(prevValue, updatedValue);
|
|
5438
|
+
const isValid = getValidationErrors(updatedValue).length === 0;
|
|
5439
|
+
if (isValid) {
|
|
5440
|
+
validateAsync == null ? void 0 : validateAsync(this, updatedValue);
|
|
5441
|
+
}
|
|
5442
|
+
if (!updatedValue) {
|
|
5443
|
+
validateAsync == null ? void 0 : validateAsync.cancel();
|
|
5444
|
+
}
|
|
5632
5445
|
onValueChange();
|
|
5633
5446
|
},
|
|
5634
5447
|
async getSubmittableValue() {
|
|
@@ -5651,51 +5464,12 @@ var createTextInputComponent = (textInputProps, updateComponent) => {
|
|
|
5651
5464
|
return errors.length === 0;
|
|
5652
5465
|
}
|
|
5653
5466
|
}, rest);
|
|
5654
|
-
if (performRefresh) {
|
|
5655
|
-
return inputComponent;
|
|
5656
|
-
}
|
|
5657
|
-
if (performPersistAsync) {
|
|
5658
|
-
const persist = getComponentPersistAsync(update, performPersistAsync);
|
|
5659
|
-
return __spreadProps(__spreadValues({}, inputComponent), {
|
|
5660
|
-
onBlur() {
|
|
5661
|
-
if (this.validate()) {
|
|
5662
|
-
persist(this, this.getLocalValue()).catch(() => {
|
|
5663
|
-
});
|
|
5664
|
-
}
|
|
5665
|
-
},
|
|
5666
|
-
async getSubmittableValue() {
|
|
5667
|
-
return persist(this, this.getLocalValue());
|
|
5668
|
-
},
|
|
5669
|
-
getSubmittableValueSync() {
|
|
5670
|
-
return this.persistedState.lastResponse;
|
|
5671
|
-
}
|
|
5672
|
-
});
|
|
5673
|
-
}
|
|
5674
|
-
if (performValidationAsync) {
|
|
5675
|
-
const validateAsync = getDebouncedComponentValidationAsync(update, performValidationAsync);
|
|
5676
|
-
return __spreadProps(__spreadValues({}, inputComponent), {
|
|
5677
|
-
onBlur() {
|
|
5678
|
-
if (this.validate()) {
|
|
5679
|
-
validateAsync.flush();
|
|
5680
|
-
}
|
|
5681
|
-
},
|
|
5682
|
-
onChange(updatedValue) {
|
|
5683
|
-
inputComponent.onChange.call(this, updatedValue);
|
|
5684
|
-
if (getValidationErrors(updatedValue).length === 0) {
|
|
5685
|
-
validateAsync(this, updatedValue);
|
|
5686
|
-
}
|
|
5687
|
-
if (!updatedValue) {
|
|
5688
|
-
validateAsync.cancel();
|
|
5689
|
-
}
|
|
5690
|
-
}
|
|
5691
|
-
});
|
|
5692
|
-
}
|
|
5693
5467
|
return inputComponent;
|
|
5694
5468
|
};
|
|
5695
5469
|
|
|
5696
5470
|
// src/revamp/domain/mappers/schema/stringSchemaToComponent/stringSchemaToTextInputComponent.ts
|
|
5697
5471
|
var stringSchemaToTextInputComponent = (schemaMapperProps, mapperProps) => {
|
|
5698
|
-
const { schema, localValue, model, required = false } = schemaMapperProps;
|
|
5472
|
+
const { schema, localValue, model, required = false, onPersistAsync } = schemaMapperProps;
|
|
5699
5473
|
const {
|
|
5700
5474
|
autocapitalization,
|
|
5701
5475
|
autocompleteHint,
|
|
@@ -5711,17 +5485,13 @@ var stringSchemaToTextInputComponent = (schemaMapperProps, mapperProps) => {
|
|
|
5711
5485
|
const { getErrorMessageFunctions, updateComponent, onBehavior, onValueChange, logEvent } = mapperProps;
|
|
5712
5486
|
const controlForLegacyFormat = getControlForLegacyFormat(format);
|
|
5713
5487
|
const errorMessageFunctions = getErrorMessageFunctions(validationMessages);
|
|
5714
|
-
const { performPersistAsync, persistedState } = getPersistAsyncInitialState(
|
|
5715
|
-
schemaMapperProps,
|
|
5716
|
-
mapperProps
|
|
5717
|
-
);
|
|
5718
5488
|
const { performValidationAsync, validationAsyncState } = getValidationAsyncInitialState(
|
|
5719
5489
|
schemaMapperProps,
|
|
5720
5490
|
mapperProps
|
|
5721
5491
|
);
|
|
5722
5492
|
const validLocalValue = isString(localValue) ? localValue : null;
|
|
5723
5493
|
const validModel = isString(model) ? model : defaultValue != null ? defaultValue : null;
|
|
5724
|
-
const value =
|
|
5494
|
+
const value = onPersistAsync ? validLocalValue : validModel;
|
|
5725
5495
|
return createTextInputComponent(
|
|
5726
5496
|
__spreadProps(__spreadValues({}, mapCommonSchemaProps(schemaMapperProps)), {
|
|
5727
5497
|
autocapitalization,
|
|
@@ -5742,10 +5512,8 @@ var stringSchemaToTextInputComponent = (schemaMapperProps, mapperProps) => {
|
|
|
5742
5512
|
}))
|
|
5743
5513
|
} : void 0,
|
|
5744
5514
|
value,
|
|
5745
|
-
persistedState,
|
|
5746
5515
|
validationAsyncState,
|
|
5747
|
-
|
|
5748
|
-
performRefresh: getPerformRefresh(schema, onBehavior),
|
|
5516
|
+
schemaOnChange: getSchemaOnChange(schema, onBehavior),
|
|
5749
5517
|
performValidationAsync,
|
|
5750
5518
|
onValueChange
|
|
5751
5519
|
}),
|
|
@@ -5776,6 +5544,136 @@ var isStringSchemaWithBase64 = (schema) => {
|
|
|
5776
5544
|
return schema.format === "base64url" && !("persistAsync" in schema);
|
|
5777
5545
|
};
|
|
5778
5546
|
|
|
5547
|
+
// src/revamp/domain/components/utils/isExactLocalValueMatch.ts
|
|
5548
|
+
var isExactLocalValueMatch = (valueA, valueB) => {
|
|
5549
|
+
if (isArrayLocalValue(valueA) && isArrayLocalValue(valueB)) {
|
|
5550
|
+
return valueA.length === valueB.length && valueA.every((value, index) => isExactLocalValueMatch(value, valueB[index]));
|
|
5551
|
+
}
|
|
5552
|
+
if (isObjectLocalValue(valueA) && isObjectLocalValue(valueB)) {
|
|
5553
|
+
const keysA = Object.keys(valueA);
|
|
5554
|
+
const keysB = Object.keys(valueB);
|
|
5555
|
+
return keysA.length === keysB.length && keysA.every((key) => isExactLocalValueMatch(valueA[key], valueB[key]));
|
|
5556
|
+
}
|
|
5557
|
+
return valueA === valueB;
|
|
5558
|
+
};
|
|
5559
|
+
|
|
5560
|
+
// src/revamp/domain/components/PersistAsyncComponent.ts
|
|
5561
|
+
var createPersistAsyncComponent = (props, performPersistAsync, schemaOnChange, updateComponent) => {
|
|
5562
|
+
const { uid, schemaId, component, hidden, model, localValue } = props;
|
|
5563
|
+
const update = getInputUpdateFunction(updateComponent);
|
|
5564
|
+
const paComponent = {
|
|
5565
|
+
type: "persist-async",
|
|
5566
|
+
uid,
|
|
5567
|
+
schemaId,
|
|
5568
|
+
component,
|
|
5569
|
+
hidden,
|
|
5570
|
+
lastSubmitted: model != null ? localValue != null ? localValue : null : null,
|
|
5571
|
+
lastResponse: model != null ? model : null,
|
|
5572
|
+
submission: Promise.resolve(model != null ? model : null),
|
|
5573
|
+
abortController: new AbortController(),
|
|
5574
|
+
errors: [],
|
|
5575
|
+
_update(updateFn) {
|
|
5576
|
+
update(this, updateFn);
|
|
5577
|
+
},
|
|
5578
|
+
validate() {
|
|
5579
|
+
return this.component.validate();
|
|
5580
|
+
},
|
|
5581
|
+
getLocalValue() {
|
|
5582
|
+
return this.component.getLocalValue();
|
|
5583
|
+
},
|
|
5584
|
+
async getSubmittableValue() {
|
|
5585
|
+
return this.persist();
|
|
5586
|
+
},
|
|
5587
|
+
getSubmittableValueSync() {
|
|
5588
|
+
return this.lastResponse;
|
|
5589
|
+
},
|
|
5590
|
+
getSummary() {
|
|
5591
|
+
return this.component.getSummary();
|
|
5592
|
+
},
|
|
5593
|
+
async persist() {
|
|
5594
|
+
const childLocalValue = this.component.getLocalValue();
|
|
5595
|
+
if (isExactLocalValueMatch(childLocalValue, this.lastSubmitted)) {
|
|
5596
|
+
return this.submission;
|
|
5597
|
+
}
|
|
5598
|
+
const newAbortController = abortAndResetController(this.abortController);
|
|
5599
|
+
if (childLocalValue == null || childLocalValue === "") {
|
|
5600
|
+
const resolvedNull = Promise.resolve(null);
|
|
5601
|
+
this._update((draft) => {
|
|
5602
|
+
draft.abortController = newAbortController;
|
|
5603
|
+
draft.lastResponse = null;
|
|
5604
|
+
draft.lastSubmitted = childLocalValue;
|
|
5605
|
+
draft.submission = resolvedNull;
|
|
5606
|
+
draft.errors = [];
|
|
5607
|
+
});
|
|
5608
|
+
schemaOnChange == null ? void 0 : schemaOnChange();
|
|
5609
|
+
return resolvedNull;
|
|
5610
|
+
}
|
|
5611
|
+
const { signal } = newAbortController;
|
|
5612
|
+
const newSubmission = performPersistAsync({ value: childLocalValue, signal }).then((token) => {
|
|
5613
|
+
this._update((draft) => {
|
|
5614
|
+
draft.lastResponse = token;
|
|
5615
|
+
draft.errors = [];
|
|
5616
|
+
});
|
|
5617
|
+
schemaOnChange == null ? void 0 : schemaOnChange();
|
|
5618
|
+
return token;
|
|
5619
|
+
}).catch((error) => {
|
|
5620
|
+
if (error instanceof DOMException && error.name === "AbortError") {
|
|
5621
|
+
return null;
|
|
5622
|
+
}
|
|
5623
|
+
this._update((draft) => {
|
|
5624
|
+
draft.lastResponse = null;
|
|
5625
|
+
draft.lastSubmitted = null;
|
|
5626
|
+
draft.errors = error instanceof Error ? [error.message] : [];
|
|
5627
|
+
});
|
|
5628
|
+
throw error;
|
|
5629
|
+
});
|
|
5630
|
+
this._update((draft) => {
|
|
5631
|
+
draft.abortController = newAbortController;
|
|
5632
|
+
draft.lastSubmitted = childLocalValue;
|
|
5633
|
+
draft.lastResponse = null;
|
|
5634
|
+
draft.submission = newSubmission;
|
|
5635
|
+
draft.errors = [];
|
|
5636
|
+
});
|
|
5637
|
+
return newSubmission;
|
|
5638
|
+
}
|
|
5639
|
+
};
|
|
5640
|
+
return paComponent;
|
|
5641
|
+
};
|
|
5642
|
+
|
|
5643
|
+
// src/revamp/domain/mappers/schema/persistAsyncSchemaToComponent.ts
|
|
5644
|
+
var isSupported = (type) => ["boolean", "text", "date", "integer", "number", "upload"].includes(type);
|
|
5645
|
+
var persistAsyncSchemaToComponent = (schemaMapperProps, mapperProps) => {
|
|
5646
|
+
var _a;
|
|
5647
|
+
const { uid, schema, model, localValue } = schemaMapperProps;
|
|
5648
|
+
const { persistAsync } = schema;
|
|
5649
|
+
const performPersistAsync = getPerformPersistAsyncFn(schema, persistAsync, mapperProps);
|
|
5650
|
+
const onPersistAsync = () => {
|
|
5651
|
+
void paComponent.persist().catch(() => {
|
|
5652
|
+
});
|
|
5653
|
+
};
|
|
5654
|
+
const childComponent = mapSchemaToComponent(
|
|
5655
|
+
__spreadProps(__spreadValues({}, schemaMapperProps), { uid: `${uid}-persist`, schema: persistAsync.schema, onPersistAsync }),
|
|
5656
|
+
mapperProps
|
|
5657
|
+
);
|
|
5658
|
+
if (!isSupported(childComponent.type)) {
|
|
5659
|
+
return childComponent;
|
|
5660
|
+
}
|
|
5661
|
+
const paComponent = createPersistAsyncComponent(
|
|
5662
|
+
{
|
|
5663
|
+
uid,
|
|
5664
|
+
hidden: (_a = schema.hidden) != null ? _a : false,
|
|
5665
|
+
component: childComponent,
|
|
5666
|
+
schemaId: schema.$id,
|
|
5667
|
+
model,
|
|
5668
|
+
localValue
|
|
5669
|
+
},
|
|
5670
|
+
performPersistAsync,
|
|
5671
|
+
getSchemaOnChange(schema, mapperProps.onBehavior),
|
|
5672
|
+
mapperProps.updateComponent
|
|
5673
|
+
);
|
|
5674
|
+
return paComponent;
|
|
5675
|
+
};
|
|
5676
|
+
|
|
5779
5677
|
// src/revamp/domain/mappers/mapSchemaToComponent.ts
|
|
5780
5678
|
var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
|
|
5781
5679
|
const { uid, schema } = schemaMapperProps;
|
|
@@ -5783,13 +5681,7 @@ var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
|
|
|
5783
5681
|
return constSchemaToComponent(uid, __spreadProps(__spreadValues({}, schemaMapperProps), { schema }));
|
|
5784
5682
|
}
|
|
5785
5683
|
if (isSchemaWithPersistAsync(schema)) {
|
|
5786
|
-
|
|
5787
|
-
const { idProperty, method, param, url } = persistAsync;
|
|
5788
|
-
const persistAsyncConfig = { idProperty, method, param, url };
|
|
5789
|
-
return mapSchemaToComponent(
|
|
5790
|
-
__spreadProps(__spreadValues({}, schemaMapperProps), { persistAsyncConfig, schema: persistAsync.schema }),
|
|
5791
|
-
mapperProps
|
|
5792
|
-
);
|
|
5684
|
+
return persistAsyncSchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
|
|
5793
5685
|
}
|
|
5794
5686
|
if (isAllOfSchema(schema)) {
|
|
5795
5687
|
return allOfSchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
|
|
@@ -5816,7 +5708,7 @@ var mapSchemaToComponent = (schemaMapperProps, mapperProps) => {
|
|
|
5816
5708
|
return arraySchemaToComponent(__spreadProps(__spreadValues({}, schemaMapperProps), { schema }), mapperProps);
|
|
5817
5709
|
}
|
|
5818
5710
|
if (isBlobSchema(schema)) {
|
|
5819
|
-
if (!schemaMapperProps.
|
|
5711
|
+
if (!schemaMapperProps.onPersistAsync) {
|
|
5820
5712
|
throw new Error(
|
|
5821
5713
|
"Blob schemas can only be used as the schema of a persist async configuration."
|
|
5822
5714
|
);
|
|
@@ -6018,8 +5910,8 @@ var executePoll = async (props) => {
|
|
|
6018
5910
|
|
|
6019
5911
|
// src/revamp/flow/executeRefresh.ts
|
|
6020
5912
|
var executeRefresh = async (props) => {
|
|
6021
|
-
const { abortSignal, url, model,
|
|
6022
|
-
trackEvent("Refresh Triggered",
|
|
5913
|
+
const { abortSignal, url, model, etag, analytics, httpClient, trackEvent, logEvent } = props;
|
|
5914
|
+
trackEvent("Refresh Triggered", analytics);
|
|
6023
5915
|
try {
|
|
6024
5916
|
const response = await httpClient(url != null ? url : "", {
|
|
6025
5917
|
method: "POST",
|
|
@@ -6030,34 +5922,34 @@ var executeRefresh = async (props) => {
|
|
|
6030
5922
|
signal: abortSignal
|
|
6031
5923
|
});
|
|
6032
5924
|
if (response.status === 304) {
|
|
6033
|
-
trackEvent("Refresh Succeeded",
|
|
5925
|
+
trackEvent("Refresh Succeeded", analytics);
|
|
6034
5926
|
return { type: "noop" };
|
|
6035
5927
|
}
|
|
6036
5928
|
if (!response.ok) {
|
|
6037
5929
|
const responseBody = await parseResponseBodyAsJsonElement(response).catch(() => ({}));
|
|
6038
5930
|
const body2 = isErrorResponseBody(responseBody) ? responseBody : {};
|
|
6039
|
-
trackEvent("Refresh Failed", __spreadProps(__spreadValues({}, body2.analytics), {
|
|
6040
|
-
|
|
5931
|
+
trackEvent("Refresh Failed", __spreadProps(__spreadValues(__spreadValues({}, analytics), body2.analytics), {
|
|
5932
|
+
statusCode: response.status
|
|
5933
|
+
}));
|
|
5934
|
+
logEvent("error", "Dynamic Flow - Refresh Failed", __spreadProps(__spreadValues({}, analytics), {
|
|
6041
5935
|
statusCode: response.status
|
|
6042
5936
|
}));
|
|
6043
|
-
logEvent("error", "Dynamic Flow - Refresh Failed", { schemaId, statusCode: response.status });
|
|
6044
5937
|
return { type: "error", body: body2, statusCode: response.status };
|
|
6045
5938
|
}
|
|
6046
5939
|
const newEtag = response.headers.get("etag") || null;
|
|
6047
5940
|
const body = await parseResponseBodyAsJsonElement(response);
|
|
6048
5941
|
assertStepResponseBody(body);
|
|
6049
|
-
trackEvent("Refresh Succeeded",
|
|
5942
|
+
trackEvent("Refresh Succeeded", analytics);
|
|
6050
5943
|
return { type: "refresh-step", step: body, etag: newEtag };
|
|
6051
5944
|
} catch (error) {
|
|
6052
5945
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
6053
|
-
trackEvent("Refresh Aborted",
|
|
5946
|
+
trackEvent("Refresh Aborted", analytics);
|
|
6054
5947
|
return { type: "noop" };
|
|
6055
5948
|
}
|
|
6056
|
-
trackEvent("Refresh Failed",
|
|
6057
|
-
logEvent("error", "Dynamic Flow - Refresh Failed", {
|
|
6058
|
-
schemaId,
|
|
5949
|
+
trackEvent("Refresh Failed", analytics);
|
|
5950
|
+
logEvent("error", "Dynamic Flow - Refresh Failed", __spreadProps(__spreadValues({}, analytics), {
|
|
6059
5951
|
errorMessage: getErrorMessage(error)
|
|
6060
|
-
});
|
|
5952
|
+
}));
|
|
6061
5953
|
return { type: "error", body: {} };
|
|
6062
5954
|
}
|
|
6063
5955
|
};
|
|
@@ -6091,7 +5983,7 @@ var executeSubmission = async (props) => {
|
|
|
6091
5983
|
const extra = { actionId, errorMessage: "Network Error" };
|
|
6092
5984
|
trackEvent("Action Failed", extra);
|
|
6093
5985
|
logEvent("error", "Dynamic Flow - Action Failed Unexpectedly", extra);
|
|
6094
|
-
return { type: "error"
|
|
5986
|
+
return { type: "error" };
|
|
6095
5987
|
}
|
|
6096
5988
|
if (!response.ok) {
|
|
6097
5989
|
return handleErrorResponse(response, actionId);
|
|
@@ -6134,16 +6026,27 @@ var executeSubmission = async (props) => {
|
|
|
6134
6026
|
}
|
|
6135
6027
|
};
|
|
6136
6028
|
const handleErrorResponse = async (response, actionId) => {
|
|
6137
|
-
const body = await parseResponseBodyAsJsonElement(response);
|
|
6029
|
+
const body = await parseResponseBodyAsJsonElement(response.clone());
|
|
6138
6030
|
if (isErrorResponseBody(body)) {
|
|
6139
6031
|
const refreshUrl = body.refreshUrl || body.refreshFormUrl;
|
|
6140
6032
|
const { error, validation, analytics } = body;
|
|
6141
6033
|
trackEvent("Action Failed", __spreadProps(__spreadValues({}, analytics), { actionId, statusCode: response.status }));
|
|
6142
6034
|
const errors = { error, validation };
|
|
6143
|
-
return refreshUrl ? { type: "refresh", body: { refreshUrl, errors } } : {
|
|
6035
|
+
return refreshUrl ? { type: "refresh", body: { refreshUrl, errors } } : {
|
|
6036
|
+
type: "error",
|
|
6037
|
+
body: { errors, analytics },
|
|
6038
|
+
httpError: { statusCode: response.status }
|
|
6039
|
+
};
|
|
6144
6040
|
}
|
|
6145
6041
|
trackEvent("Action Failed", { actionId, statusCode: response.status });
|
|
6146
|
-
|
|
6042
|
+
const errorMessage = await parseResponseBodyAsText(response);
|
|
6043
|
+
return {
|
|
6044
|
+
type: "error",
|
|
6045
|
+
httpError: {
|
|
6046
|
+
message: errorMessage || void 0,
|
|
6047
|
+
statusCode: response.status
|
|
6048
|
+
}
|
|
6049
|
+
};
|
|
6147
6050
|
};
|
|
6148
6051
|
return triggerAction(props.action, props.model, props.isInitial);
|
|
6149
6052
|
};
|
|
@@ -6536,7 +6439,7 @@ function useDynamicFlowCore(props) {
|
|
|
6536
6439
|
break;
|
|
6537
6440
|
}
|
|
6538
6441
|
case "refresh": {
|
|
6539
|
-
await onRefresh(behavior.
|
|
6442
|
+
await onRefresh({ refreshUrl: behavior.url, analytics: behavior.analytics });
|
|
6540
6443
|
break;
|
|
6541
6444
|
}
|
|
6542
6445
|
case "link": {
|
|
@@ -6567,7 +6470,7 @@ function useDynamicFlowCore(props) {
|
|
|
6567
6470
|
}
|
|
6568
6471
|
}, []);
|
|
6569
6472
|
const onAction = useCallback2(async (action) => {
|
|
6570
|
-
var _a2;
|
|
6473
|
+
var _a2, _b, _c, _d, _e, _f, _g;
|
|
6571
6474
|
try {
|
|
6572
6475
|
rootComponentRef.current.setLoadingState("submitting");
|
|
6573
6476
|
const model = (_a2 = await rootComponentRef.current.getSubmittableValue()) != null ? _a2 : null;
|
|
@@ -6594,7 +6497,7 @@ function useDynamicFlowCore(props) {
|
|
|
6594
6497
|
}
|
|
6595
6498
|
case "error": {
|
|
6596
6499
|
const genericErrorMessage = getErrorMessageFunctions().genericErrorWithRetry();
|
|
6597
|
-
const
|
|
6500
|
+
const errors = (_c = (_b = command.body) == null ? void 0 : _b.errors) != null ? _c : { error: genericErrorMessage };
|
|
6598
6501
|
if (stepRef.current) {
|
|
6599
6502
|
updateStep(
|
|
6600
6503
|
__spreadProps(__spreadValues({}, stepRef.current), {
|
|
@@ -6611,19 +6514,20 @@ function useDynamicFlowCore(props) {
|
|
|
6611
6514
|
etagRef.current
|
|
6612
6515
|
);
|
|
6613
6516
|
} else {
|
|
6517
|
+
const errorMessage = ((_e = (_d = command.body) == null ? void 0 : _d.errors) == null ? void 0 : _e.error) || ((_f = command.httpError) == null ? void 0 : _f.message) || "Initial request failed";
|
|
6614
6518
|
closeWithError(
|
|
6615
|
-
new Error(
|
|
6519
|
+
new Error(errorMessage, {
|
|
6616
6520
|
cause: `method: ${action.method}, url: ${action.url}`
|
|
6617
6521
|
}),
|
|
6618
6522
|
{},
|
|
6619
|
-
command.statusCode
|
|
6523
|
+
(_g = command.httpError) == null ? void 0 : _g.statusCode
|
|
6620
6524
|
);
|
|
6621
6525
|
}
|
|
6622
6526
|
break;
|
|
6623
6527
|
}
|
|
6624
6528
|
case "refresh": {
|
|
6625
6529
|
const { refreshUrl, errors = {} } = command.body;
|
|
6626
|
-
void onRefresh(
|
|
6530
|
+
void onRefresh({ refreshUrl, errorsOverride: errors });
|
|
6627
6531
|
break;
|
|
6628
6532
|
}
|
|
6629
6533
|
case "behavior": {
|
|
@@ -6637,7 +6541,11 @@ function useDynamicFlowCore(props) {
|
|
|
6637
6541
|
}
|
|
6638
6542
|
}, []);
|
|
6639
6543
|
const onRefresh = useCallback2(
|
|
6640
|
-
async (
|
|
6544
|
+
async ({
|
|
6545
|
+
refreshUrl,
|
|
6546
|
+
errorsOverride,
|
|
6547
|
+
analytics
|
|
6548
|
+
}) => {
|
|
6641
6549
|
var _a2, _b;
|
|
6642
6550
|
try {
|
|
6643
6551
|
rootComponentRef.current.setLoadingState("refreshing");
|
|
@@ -6646,8 +6554,8 @@ function useDynamicFlowCore(props) {
|
|
|
6646
6554
|
abortSignal: abortCurrentAndGetNewAbortSignal(),
|
|
6647
6555
|
url: (_b = refreshUrl != null ? refreshUrl : rootComponentRef.current.getRefreshUrl()) != null ? _b : "",
|
|
6648
6556
|
model,
|
|
6649
|
-
schemaId,
|
|
6650
6557
|
etag: etagRef.current,
|
|
6558
|
+
analytics,
|
|
6651
6559
|
httpClient,
|
|
6652
6560
|
trackEvent: trackCoreEvent,
|
|
6653
6561
|
logEvent
|