@headless-adminapp/app 0.0.17-alpha.45 → 0.0.17-alpha.47

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.
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useSearchText = useSearchText;
4
+ const context_1 = require("@headless-adminapp/app/mutable/context");
4
5
  const react_1 = require("react");
5
- const context_1 = require("../context");
6
- const context_2 = require("@headless-adminapp/app/mutable/context");
6
+ const context_2 = require("../context");
7
7
  function useSearchText() {
8
- const searchText = (0, context_2.useContextSelector)(context_1.BoardContext, (context) => context.searchText);
9
- const setValue = (0, context_2.useContextSetValue)(context_1.BoardContext);
8
+ const searchText = (0, context_1.useContextSelector)(context_2.BoardContext, (context) => context.searchText);
9
+ const setValue = (0, context_1.useContextSetValue)(context_2.BoardContext);
10
10
  const setSearchText = (0, react_1.useCallback)((value) => {
11
11
  setValue({ searchText: value });
12
12
  }, [setValue]);
@@ -1 +1 @@
1
- export declare function useProcessFlowSteps(): import("@headless-adminapp/core/experience/form/ProcessFlowInfo").ProcessFlowStep[] | undefined;
1
+ export declare function useProcessFlowSteps(): import("@headless-adminapp/core/experience/form/ProcessFlowInfo").ProcessFlowStep[] | null | undefined;
@@ -1 +1 @@
1
- export declare function useRecordTitle(): string;
1
+ export declare function useRecordTitle(): any;
@@ -5,11 +5,18 @@ const useFormInstance_1 = require("./useFormInstance");
5
5
  const useFormSchema_1 = require("./useFormSchema");
6
6
  const useRecordId_1 = require("./useRecordId");
7
7
  function useRecordTitle() {
8
- var _a;
9
8
  const formInstance = (0, useFormInstance_1.useFormInstance)();
10
9
  const schema = (0, useFormSchema_1.useDataFormSchema)();
11
10
  const recordId = (0, useRecordId_1.useRecordId)();
12
- const primaryAttributeValue = (_a = formInstance.watch(schema.primaryAttribute)) !== null && _a !== void 0 ? _a : '';
11
+ let primaryAttributeValue = formInstance.watch(schema.primaryAttribute);
12
+ const primaryAttribute = schema.attributes[schema.primaryAttribute];
13
+ if ((primaryAttribute === null || primaryAttribute === void 0 ? void 0 : primaryAttribute.type) === 'lookup') {
14
+ // Handle lookup attribute as primary
15
+ primaryAttributeValue = primaryAttributeValue === null || primaryAttributeValue === void 0 ? void 0 : primaryAttributeValue.name;
16
+ }
17
+ if (primaryAttributeValue && typeof primaryAttributeValue !== 'string') {
18
+ return String(primaryAttributeValue);
19
+ }
13
20
  if (primaryAttributeValue) {
14
21
  return primaryAttributeValue;
15
22
  }
@@ -303,7 +303,7 @@ exports.generateValidationSchema = (0, lodash_1.memoize)(function generateValida
303
303
  strings,
304
304
  readonlyAttributes,
305
305
  }));
306
- exports.generateAttributeValidationSchema = (0, lodash_1.memoize)(function generateAttributeValidationSchema(attribute, language, strings) {
306
+ function createAttributeValidationSchema(attribute) {
307
307
  let validationSchema;
308
308
  switch (attribute.type) {
309
309
  case 'string':
@@ -321,44 +321,91 @@ exports.generateAttributeValidationSchema = (0, lodash_1.memoize)(function gener
321
321
  validationSchema = yup.mixed().nullable();
322
322
  break;
323
323
  }
324
- const label = (0, utils_1.localizedLabel)(language, attribute);
324
+ return validationSchema;
325
+ }
326
+ function extendAttributeRequiredValidationSchema({ attribute, validationSchema, label, strings, }) {
325
327
  if (attribute.required) {
326
328
  validationSchema = validationSchema.required(`${label}: ${strings.required}`);
327
329
  }
330
+ return validationSchema;
331
+ }
332
+ function extendAttributeValidationSchema({ attribute, validationSchema, label, strings, }) {
328
333
  switch (attribute.type) {
329
334
  case 'string':
330
- if (attribute.maxLength) {
331
- validationSchema = validationSchema.max(attribute.maxLength, `${label}: ${strings.maxLength}`);
332
- }
333
- if (attribute.minLength) {
334
- validationSchema = validationSchema.min(attribute.minLength, `${label}: ${strings.minLength}`);
335
- }
336
- if (attribute.pattern) {
337
- validationSchema = validationSchema.matches(new RegExp(attribute.pattern), `${label}: ${strings.invalidFormat}`);
338
- }
339
- if (attribute.format === 'email') {
340
- validationSchema = validationSchema.email(`${label}: ${strings.invalidEmail}`);
341
- }
342
- else if (attribute.format === 'phone') {
343
- validationSchema = validationSchema.matches(/^(\+\d{1,2}\s?)?\d{10}$/, `${label}: ${strings.invalidPhoneNumber}`);
344
- }
335
+ validationSchema = extendAttributeStringValidationSchema({
336
+ attribute,
337
+ validationSchema: validationSchema,
338
+ label,
339
+ strings,
340
+ });
345
341
  break;
346
342
  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
- }
343
+ validationSchema = extendAttributeAttachmentsValidationSchema({
344
+ attribute,
345
+ validationSchema: validationSchema,
346
+ label,
347
+ strings,
348
+ });
358
349
  break;
359
350
  default:
360
351
  break;
361
352
  }
353
+ return validationSchema;
354
+ }
355
+ function extendAttributeStringValidationSchema({ attribute, validationSchema, label, strings, }) {
356
+ if (attribute.maxLength) {
357
+ // extend the validation schema with the max length
358
+ validationSchema = validationSchema.max(attribute.maxLength, `${label}: ${strings.maxLength}`);
359
+ }
360
+ if (attribute.minLength) {
361
+ // extend the validation schema with the min length
362
+ validationSchema = validationSchema.min(attribute.minLength, `${label}: ${strings.minLength}`);
363
+ }
364
+ if (attribute.pattern) {
365
+ // extend the validation schema with the pattern
366
+ validationSchema = validationSchema.matches(new RegExp(attribute.pattern), `${label}: ${strings.invalidFormat}`);
367
+ }
368
+ if (attribute.format === 'email') {
369
+ // extend the validation schema with the email format
370
+ validationSchema = validationSchema.email(`${label}: ${strings.invalidEmail}`);
371
+ }
372
+ else if (attribute.format === 'phone') {
373
+ // extend the validation schema with the phone format
374
+ validationSchema = validationSchema.matches(/^(\+\d{1,2}\s?)?\d{10}$/, `${label}: ${strings.invalidPhoneNumber}`);
375
+ }
376
+ return validationSchema;
377
+ }
378
+ function extendAttributeAttachmentsValidationSchema({ attribute, validationSchema, label, strings, }) {
379
+ if (attribute.required) {
380
+ // extend the validation schema with the min length
381
+ validationSchema = validationSchema.min(1, `${label}: ${strings.required}`);
382
+ }
383
+ if (attribute.maxSize) {
384
+ // extend the validation schema with the max size
385
+ validationSchema = validationSchema.test('fileSize', `${label}: ${strings.fileSizeExceeded}`, (value) => {
386
+ if (!value) {
387
+ return true;
388
+ }
389
+ return value.every((file) => (file === null || file === void 0 ? void 0 : file.size) && file.size <= attribute.maxSize);
390
+ });
391
+ }
392
+ return validationSchema;
393
+ }
394
+ exports.generateAttributeValidationSchema = (0, lodash_1.memoize)(function generateAttributeValidationSchema(attribute, language, strings) {
395
+ let validationSchema = createAttributeValidationSchema(attribute);
396
+ const label = (0, utils_1.localizedLabel)(language, attribute);
397
+ validationSchema = extendAttributeRequiredValidationSchema({
398
+ attribute,
399
+ validationSchema,
400
+ label,
401
+ strings,
402
+ });
403
+ validationSchema = extendAttributeValidationSchema({
404
+ attribute,
405
+ validationSchema,
406
+ label,
407
+ strings,
408
+ });
362
409
  validationSchema = validationSchema.transform((value) => {
363
410
  if (value === '') {
364
411
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/app",
3
- "version": "0.0.17-alpha.45",
3
+ "version": "0.0.17-alpha.47",
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": "7538074665d8fa6f67ca2a91e62ea32d09570a31"
42
+ "gitHead": "749a69f512d51c82f33fe27f8bbe5046fdeab4c5"
43
43
  }
@@ -13,5 +13,5 @@ export declare function getAttributeFormattedValue<A extends Attribute = Attribu
13
13
  currencySign?: 'accounting' | 'standard';
14
14
  currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code';
15
15
  timezone?: string;
16
- }): string | null | undefined;
16
+ }): string | null;
17
17
  export {};
@@ -19,89 +19,124 @@ const defaultLocale = 'en-US';
19
19
  const defaultCurrency = 'USD';
20
20
  const defaultCurrencySign = 'accounting';
21
21
  const defaultCurrencyDisplay = 'symbol';
22
+ function getAttributeLookupsFormattedValue(value, options) {
23
+ const items = value === null || value === void 0 ? void 0 : value.map((v) => v.name);
24
+ if ((options === null || options === void 0 ? void 0 : options.maxCount) && (items === null || items === void 0 ? void 0 : items.length) > options.maxCount) {
25
+ return (items.slice(0, options.maxCount).join(', ') +
26
+ ` (+${items.length - options.maxCount})`);
27
+ }
28
+ else {
29
+ return items === null || items === void 0 ? void 0 : items.join(', ');
30
+ }
31
+ }
32
+ function getAttributeAttachmentFormattedValue(value) {
33
+ var _a;
34
+ return (_a = value === null || value === void 0 ? void 0 : value.url) !== null && _a !== void 0 ? _a : null;
35
+ }
36
+ function getAttributeDateFormattedValue(attribute, value, options) {
37
+ var _a, _b;
38
+ const dateFormat = (_a = options === null || options === void 0 ? void 0 : options.dateFormat) !== null && _a !== void 0 ? _a : defaultDateFormat;
39
+ const timeFormat = (_b = options === null || options === void 0 ? void 0 : options.timeFormat) !== null && _b !== void 0 ? _b : defaultTimeFormat;
40
+ if (attribute.format === 'datetime') {
41
+ return (0, dayjs_1.default)(value)
42
+ .tz(options === null || options === void 0 ? void 0 : options.timezone)
43
+ .format(dateFormat + ' ' + timeFormat);
44
+ }
45
+ else {
46
+ return (0, dayjs_1.default)(value)
47
+ .tz(options === null || options === void 0 ? void 0 : options.timezone)
48
+ .format(dateFormat);
49
+ }
50
+ }
51
+ function getAttributeDateRangeFormattedValue(value, options) {
52
+ var _a;
53
+ if (!value)
54
+ return null;
55
+ const dateFormat = (_a = options === null || options === void 0 ? void 0 : options.dateFormat) !== null && _a !== void 0 ? _a : defaultDateFormat;
56
+ const from = value[0];
57
+ const to = value[1];
58
+ if (!from && !to) {
59
+ return null;
60
+ }
61
+ if (from && to) {
62
+ return ((0, dayjs_1.default)(from).tz(options === null || options === void 0 ? void 0 : options.timezone).format(dateFormat) +
63
+ ' - ' +
64
+ (0, dayjs_1.default)(to).tz(options === null || options === void 0 ? void 0 : options.timezone).format(dateFormat));
65
+ }
66
+ if (from) {
67
+ return 'After ' + (0, dayjs_1.default)(from).tz(options === null || options === void 0 ? void 0 : options.timezone).format(dateFormat);
68
+ }
69
+ if (to) {
70
+ return 'Before ' + (0, dayjs_1.default)(to).tz(options === null || options === void 0 ? void 0 : options.timezone).format(dateFormat);
71
+ }
72
+ return null;
73
+ }
74
+ function getAttributeBooleanFormattedValue(attribute, value, options) {
75
+ var _a, _b, _c;
76
+ const strings = (_a = options === null || options === void 0 ? void 0 : options.strings) !== null && _a !== void 0 ? _a : defaultAttributeFormattedValueStrings;
77
+ return value
78
+ ? (_b = attribute.trueLabel) !== null && _b !== void 0 ? _b : strings.yes
79
+ : (_c = attribute.falseLabel) !== null && _c !== void 0 ? _c : strings.no;
80
+ }
81
+ function getAttributeChoiceFormattedValue(attribute, value) {
82
+ var _a;
83
+ return ((_a = attribute.options.find((option) => option.value === value)) !== null && _a !== void 0 ? _a : {
84
+ label: '',
85
+ }).label;
86
+ }
87
+ function getAttributeChoicesFormattedValue(attribute, value) {
88
+ return value
89
+ .map((v) => {
90
+ var _a;
91
+ return ((_a = attribute.options.find((option) => option.value === v)) !== null && _a !== void 0 ? _a : {
92
+ label: '',
93
+ }).label;
94
+ })
95
+ .join(', ');
96
+ }
97
+ function getAttributeLookupFormattedValue(value) {
98
+ return value === null || value === void 0 ? void 0 : value.name;
99
+ }
100
+ function getAttributeMoneyFormattedValue(value, options) {
101
+ var _a, _b, _c, _d;
102
+ const locale = (_a = options === null || options === void 0 ? void 0 : options.locale) !== null && _a !== void 0 ? _a : defaultLocale;
103
+ const currency = (_b = options === null || options === void 0 ? void 0 : options.currency) !== null && _b !== void 0 ? _b : defaultCurrency;
104
+ const currencySign = (_c = options === null || options === void 0 ? void 0 : options.currencySign) !== null && _c !== void 0 ? _c : defaultCurrencySign;
105
+ const currencyDisplay = (_d = options === null || options === void 0 ? void 0 : options.currencyDisplay) !== null && _d !== void 0 ? _d : defaultCurrencyDisplay;
106
+ return new Intl.NumberFormat(locale, {
107
+ style: 'currency',
108
+ currency,
109
+ currencySign,
110
+ currencyDisplay,
111
+ }).format(value);
112
+ }
22
113
  function getAttributeFormattedValue(attribute, value, options) {
23
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
114
+ var _a;
24
115
  if (value === null || value === undefined) {
25
116
  return null;
26
117
  }
27
- const strings = (_a = options === null || options === void 0 ? void 0 : options.strings) !== null && _a !== void 0 ? _a : defaultAttributeFormattedValueStrings;
28
- const dateFormat = (_b = options === null || options === void 0 ? void 0 : options.dateFormat) !== null && _b !== void 0 ? _b : defaultDateFormat;
29
- const timeFormat = (_c = options === null || options === void 0 ? void 0 : options.timeFormat) !== null && _c !== void 0 ? _c : defaultTimeFormat;
30
- const locale = (_d = options === null || options === void 0 ? void 0 : options.locale) !== null && _d !== void 0 ? _d : defaultLocale;
31
- const currency = (_e = options === null || options === void 0 ? void 0 : options.currency) !== null && _e !== void 0 ? _e : defaultCurrency;
32
- const currencySign = (_f = options === null || options === void 0 ? void 0 : options.currencySign) !== null && _f !== void 0 ? _f : defaultCurrencySign;
33
- const currencyDisplay = (_g = options === null || options === void 0 ? void 0 : options.currencyDisplay) !== null && _g !== void 0 ? _g : defaultCurrencyDisplay;
118
+ const locale = (_a = options === null || options === void 0 ? void 0 : options.locale) !== null && _a !== void 0 ? _a : defaultLocale;
34
119
  switch (attribute.type) {
35
120
  case 'boolean':
36
- return value
37
- ? (_h = attribute.trueLabel) !== null && _h !== void 0 ? _h : strings.yes
38
- : (_j = attribute.falseLabel) !== null && _j !== void 0 ? _j : strings.no;
121
+ return getAttributeBooleanFormattedValue(attribute, value, options);
39
122
  case 'choice':
40
- return ((_k = attribute.options.find((option) => option.value === value)) !== null && _k !== void 0 ? _k : {
41
- label: '',
42
- }).label;
123
+ return getAttributeChoiceFormattedValue(attribute, value);
43
124
  case 'choices':
44
- return value
45
- .map((v) => {
46
- var _a;
47
- return ((_a = attribute.options.find((option) => option.value === v)) !== null && _a !== void 0 ? _a : {
48
- label: '',
49
- }).label;
50
- })
51
- .join(', ');
125
+ return getAttributeChoicesFormattedValue(attribute, value);
52
126
  case 'date':
53
- if (attribute.format === 'datetime') {
54
- return (0, dayjs_1.default)(value)
55
- .tz(options === null || options === void 0 ? void 0 : options.timezone)
56
- .format(dateFormat + ' ' + timeFormat);
57
- }
58
- else {
59
- return (0, dayjs_1.default)(value)
60
- .tz(options === null || options === void 0 ? void 0 : options.timezone)
61
- .format(dateFormat);
62
- }
127
+ return getAttributeDateFormattedValue(attribute, value, options);
63
128
  case 'daterange':
64
- if (!value)
65
- return null;
66
- const from = value[0];
67
- const to = value[1];
68
- if (!from && !to) {
69
- return null;
70
- }
71
- if (from && to) {
72
- return ((0, dayjs_1.default)(from).tz(options === null || options === void 0 ? void 0 : options.timezone).format(dateFormat) +
73
- ' - ' +
74
- (0, dayjs_1.default)(to).tz(options === null || options === void 0 ? void 0 : options.timezone).format(dateFormat));
75
- }
76
- if (from) {
77
- return 'After ' + (0, dayjs_1.default)(from).tz(options === null || options === void 0 ? void 0 : options.timezone).format(dateFormat);
78
- }
79
- if (to) {
80
- return 'Before ' + (0, dayjs_1.default)(to).tz(options === null || options === void 0 ? void 0 : options.timezone).format(dateFormat);
81
- }
82
- return null;
129
+ return getAttributeDateRangeFormattedValue(value, options);
83
130
  case 'lookup':
84
- return value === null || value === void 0 ? void 0 : value.name;
131
+ return getAttributeLookupFormattedValue(value);
85
132
  case 'lookups':
86
- const items = value === null || value === void 0 ? void 0 : value.map((v) => v.name);
87
- if ((options === null || options === void 0 ? void 0 : options.maxCount) && (items === null || items === void 0 ? void 0 : items.length) > options.maxCount) {
88
- return (items.slice(0, options.maxCount).join(', ') +
89
- ` (+${items.length - options.maxCount})`);
90
- }
91
- else {
92
- return items === null || items === void 0 ? void 0 : items.join(', ');
93
- }
133
+ return getAttributeLookupsFormattedValue(value, options);
94
134
  case 'money':
95
- return new Intl.NumberFormat(locale, {
96
- style: 'currency',
97
- currency,
98
- currencySign,
99
- currencyDisplay,
100
- }).format(value);
135
+ return getAttributeMoneyFormattedValue(value, options);
101
136
  case 'number':
102
137
  return new Intl.NumberFormat(locale).format(value);
103
138
  case 'attachment':
104
- return (_l = value === null || value === void 0 ? void 0 : value.url) !== null && _l !== void 0 ? _l : null;
139
+ return getAttributeAttachmentFormattedValue(value);
105
140
  default:
106
141
  return typeof value === 'object'
107
142
  ? JSON.stringify(value)