@headless-adminapp/app 0.0.17-alpha.19 → 0.0.17-alpha.20
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/dataform/utils/index.js
CHANGED
|
@@ -59,8 +59,8 @@ function getModifiedValues(initialValues, values, exclude) {
|
|
|
59
59
|
function saveRecord(_a) {
|
|
60
60
|
return __awaiter(this, arguments, void 0, function* ({ values, form, schema, dataService, initialValues, record, schemaStore, }) {
|
|
61
61
|
const controls = (0, DataResolver_1.getControls)(form);
|
|
62
|
-
const editableGridControls = controls.filter(control => control.type === 'editablegrid');
|
|
63
|
-
const modifiedValues = getModifiedValues(initialValues, values, editableGridControls.map(x => x.attributeName));
|
|
62
|
+
const editableGridControls = controls.filter((control) => control.type === 'editablegrid');
|
|
63
|
+
const modifiedValues = getModifiedValues(initialValues, values, editableGridControls.map((x) => x.attributeName));
|
|
64
64
|
let recordId;
|
|
65
65
|
if (record) {
|
|
66
66
|
recordId = record[schema.idAttribute];
|
|
@@ -77,9 +77,9 @@ function saveRecord(_a) {
|
|
|
77
77
|
const gridSchema = schemaStore.getSchema(control.logicalName);
|
|
78
78
|
const gridRows = values[control.attributeName];
|
|
79
79
|
const initialGridRows = initialValues[control.attributeName];
|
|
80
|
-
const newRows = gridRows.filter(x => !x[gridSchema.idAttribute]);
|
|
81
|
-
const updatedRows = gridRows.filter(x => x[gridSchema.idAttribute]);
|
|
82
|
-
const deletedIds = initialGridRows === null || initialGridRows === void 0 ? void 0 : initialGridRows.map(x => x[gridSchema.idAttribute]).filter(id => !gridRows.find(x => x[gridSchema.idAttribute] === id));
|
|
80
|
+
const newRows = gridRows.filter((x) => !x[gridSchema.idAttribute]);
|
|
81
|
+
const updatedRows = gridRows.filter((x) => x[gridSchema.idAttribute]);
|
|
82
|
+
const deletedIds = initialGridRows === null || initialGridRows === void 0 ? void 0 : initialGridRows.map((x) => x[gridSchema.idAttribute]).filter((id) => !gridRows.find((x) => x[gridSchema.idAttribute] === id));
|
|
83
83
|
for (const row of newRows) {
|
|
84
84
|
operations.push({
|
|
85
85
|
type: 'create',
|
|
@@ -90,7 +90,7 @@ function saveRecord(_a) {
|
|
|
90
90
|
});
|
|
91
91
|
}
|
|
92
92
|
for (const row of updatedRows) {
|
|
93
|
-
const initialRow = initialGridRows.find(x => x[gridSchema.idAttribute] === row[gridSchema.idAttribute]);
|
|
93
|
+
const initialRow = initialGridRows.find((x) => x[gridSchema.idAttribute] === row[gridSchema.idAttribute]);
|
|
94
94
|
if (!initialRow) {
|
|
95
95
|
throw new Error('Initial row not found');
|
|
96
96
|
}
|
|
@@ -154,10 +154,10 @@ function saveRecord(_a) {
|
|
|
154
154
|
}
|
|
155
155
|
function getInitialValues({ cloneRecord, form, record, recordId, defaultParameters, }) {
|
|
156
156
|
const formColumns = (0, DataResolver_1.getColumns)(form);
|
|
157
|
-
const editableGridControls = (0, DataResolver_1.getControls)(form).filter(control => control.type === 'editablegrid');
|
|
157
|
+
const editableGridControls = (0, DataResolver_1.getControls)(form).filter((control) => control.type === 'editablegrid');
|
|
158
158
|
const allColumns = [
|
|
159
159
|
...formColumns,
|
|
160
|
-
...editableGridControls.map(x => x.attributeName),
|
|
160
|
+
...editableGridControls.map((x) => x.attributeName),
|
|
161
161
|
];
|
|
162
162
|
if (!recordId && !record && form.experience.cloneAttributes && cloneRecord) {
|
|
163
163
|
const cloneAttributesObj = form.experience.cloneAttributes.reduce((acc, item) => {
|
|
@@ -217,12 +217,12 @@ exports.formValidator = (0, lodash_1.memoize)(function formValidator({ form, sch
|
|
|
217
217
|
let validator = yup.object().shape({});
|
|
218
218
|
if (!formReadOnly) {
|
|
219
219
|
const activeControls = form.experience.tabs
|
|
220
|
-
.flatMap(tab => tab.tabColumns)
|
|
221
|
-
.flatMap(tabColumn => tabColumn.sections)
|
|
222
|
-
.flatMap(section => {
|
|
220
|
+
.flatMap((tab) => tab.tabColumns)
|
|
221
|
+
.flatMap((tabColumn) => tabColumn.sections)
|
|
222
|
+
.flatMap((section) => {
|
|
223
223
|
return section.controls;
|
|
224
224
|
})
|
|
225
|
-
.filter(control => {
|
|
225
|
+
.filter((control) => {
|
|
226
226
|
if (control.type === 'standard') {
|
|
227
227
|
const attribute = schema.attributes[control.attributeName];
|
|
228
228
|
if (attribute.readonly) {
|
|
@@ -231,15 +231,15 @@ exports.formValidator = (0, lodash_1.memoize)(function formValidator({ form, sch
|
|
|
231
231
|
}
|
|
232
232
|
return true;
|
|
233
233
|
});
|
|
234
|
-
const editableGridControls = activeControls.filter(control => control.type === 'editablegrid');
|
|
234
|
+
const editableGridControls = activeControls.filter((control) => control.type === 'editablegrid');
|
|
235
235
|
const columns = Array.from(new Set([
|
|
236
236
|
schema.primaryAttribute,
|
|
237
237
|
...activeControls
|
|
238
|
-
.filter(control => control.type === 'standard')
|
|
239
|
-
.map(control => control.attributeName),
|
|
238
|
+
.filter((control) => control.type === 'standard')
|
|
239
|
+
.map((control) => control.attributeName),
|
|
240
240
|
]));
|
|
241
241
|
validator = (0, exports.generateValidationSchema)({
|
|
242
|
-
editableGrids: editableGridControls.map(control => {
|
|
242
|
+
editableGrids: editableGridControls.map((control) => {
|
|
243
243
|
if (control.type !== 'editablegrid') {
|
|
244
244
|
throw new Error('Invalid control type');
|
|
245
245
|
}
|
|
@@ -338,10 +338,23 @@ exports.generateAttributeValidationSchema = (0, lodash_1.memoize)(function gener
|
|
|
338
338
|
validationSchema = validationSchema.matches(/^(\+\d{1,2}\s?)?\d{10}$/, `${label}: ${strings.invalidPhoneNumber}`);
|
|
339
339
|
}
|
|
340
340
|
break;
|
|
341
|
+
case 'attachments':
|
|
342
|
+
if (attribute.required) {
|
|
343
|
+
validationSchema = validationSchema.min(1, `${label}: ${strings.required}`);
|
|
344
|
+
}
|
|
345
|
+
if (attribute.maxSize) {
|
|
346
|
+
validationSchema = validationSchema.test('fileSize', `${label}: ${strings.fileSizeExceeded}`, (value) => {
|
|
347
|
+
if (!value) {
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
return value.every((file) => (file === null || file === void 0 ? void 0 : file.size) && file.size <= attribute.maxSize);
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
break;
|
|
341
354
|
default:
|
|
342
355
|
break;
|
|
343
356
|
}
|
|
344
|
-
validationSchema = validationSchema.transform(value => {
|
|
357
|
+
validationSchema = validationSchema.transform((value) => {
|
|
345
358
|
if (value === '') {
|
|
346
359
|
return null;
|
|
347
360
|
}
|
|
@@ -6,6 +6,7 @@ export interface FormValidationStringSet {
|
|
|
6
6
|
invalidEmail: string;
|
|
7
7
|
invalidPhoneNumber: string;
|
|
8
8
|
atLeastOneRowRequired: string;
|
|
9
|
+
fileSizeExceeded: string;
|
|
9
10
|
}
|
|
10
11
|
export declare const defaultFormValidationStrings: FormValidationStringSet;
|
|
11
12
|
export declare const FormValidationStringContext: import("react").Context<FormValidationStringSet>;
|
|
@@ -11,6 +11,7 @@ exports.defaultFormValidationStrings = {
|
|
|
11
11
|
invalidEmail: 'Invalid email.',
|
|
12
12
|
invalidPhoneNumber: 'Invalid phone number.',
|
|
13
13
|
atLeastOneRowRequired: 'At least one row required.',
|
|
14
|
+
fileSizeExceeded: 'File size exceeded.',
|
|
14
15
|
};
|
|
15
16
|
exports.FormValidationStringContext = (0, react_1.createContext)(exports.defaultFormValidationStrings);
|
|
16
17
|
function useFormValidationStrings() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@headless-adminapp/app",
|
|
3
|
-
"version": "0.0.17-alpha.
|
|
3
|
+
"version": "0.0.17-alpha.20",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"react-hook-form": "7.52.2",
|
|
40
40
|
"yup": "^1.4.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "bcc1bcddef884731f72e5e4fedb0d78ad64afbd0"
|
|
43
43
|
}
|