@headless-adminapp/app 0.0.17-alpha.19 → 0.0.17-alpha.21

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.
@@ -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
  }
@@ -312,6 +312,11 @@ exports.generateAttributeValidationSchema = (0, lodash_1.memoize)(function gener
312
312
  case 'number':
313
313
  validationSchema = yup.number().nullable();
314
314
  break;
315
+ case 'attachments':
316
+ case 'choices':
317
+ case 'lookups':
318
+ validationSchema = yup.array().nullable();
319
+ break;
315
320
  default:
316
321
  validationSchema = yup.mixed().nullable();
317
322
  break;
@@ -338,10 +343,23 @@ exports.generateAttributeValidationSchema = (0, lodash_1.memoize)(function gener
338
343
  validationSchema = validationSchema.matches(/^(\+\d{1,2}\s?)?\d{10}$/, `${label}: ${strings.invalidPhoneNumber}`);
339
344
  }
340
345
  break;
346
+ case 'attachments':
347
+ if (attribute.required) {
348
+ validationSchema = validationSchema.min(1, `${label}: ${strings.required}`);
349
+ }
350
+ if (attribute.maxSize) {
351
+ validationSchema = validationSchema.test('fileSize', `${label}: ${strings.fileSizeExceeded}`, (value) => {
352
+ if (!value) {
353
+ return true;
354
+ }
355
+ return value.every((file) => (file === null || file === void 0 ? void 0 : file.size) && file.size <= attribute.maxSize);
356
+ });
357
+ }
358
+ break;
341
359
  default:
342
360
  break;
343
361
  }
344
- validationSchema = validationSchema.transform(value => {
362
+ validationSchema = validationSchema.transform((value) => {
345
363
  if (value === '') {
346
364
  return null;
347
365
  }
@@ -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.19",
3
+ "version": "0.0.17-alpha.21",
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": "89b5dcafe7018f95dd77861003216f4fa365d15f"
42
+ "gitHead": "559490088acc4f2c5c54a7d6aa913f21747ccee8"
43
43
  }