@headless-adminapp/app 1.4.22 → 1.4.24

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,8 +1,9 @@
1
1
  import type { EventContentArg } from '@fullcalendar/core';
2
2
  import { AuthSession } from '@headless-adminapp/core/experience/auth';
3
3
  import { OpenFormOptions } from '@headless-adminapp/core/experience/command';
4
+ import { RouterInstance } from '@headless-adminapp/core/navigation';
4
5
  import { InferredSchemaType, SchemaAttributes } from '@headless-adminapp/core/schema';
5
- import { InternalRouteResolver, RouterInstance } from '../route/context';
6
+ import { InternalRouteResolver } from '../route/context';
6
7
  export interface CalendarEvent {
7
8
  id: string;
8
9
  title: string;
@@ -12,6 +12,7 @@ const hooks_2 = require("../../metadata/hooks");
12
12
  const hooks_3 = require("../../progress-indicator/hooks");
13
13
  const useOpenToastNotification_1 = require("../../toast-notification/hooks/useOpenToastNotification");
14
14
  const transport_1 = require("../../transport");
15
+ const route_1 = require("@headless-adminapp/app/route");
15
16
  function useUtility() {
16
17
  const { hideProgressIndicator, showProgressIndicator } = (0, hooks_3.useProgressIndicator)();
17
18
  const openAlertDialog = (0, hooks_1.useOpenAlertDialog)();
@@ -39,9 +40,11 @@ function useUtility() {
39
40
  }
40
41
  function useNavigation() {
41
42
  const openForm = (0, navigation_1.useOpenForm)();
43
+ const router = (0, route_1.useRouter)();
42
44
  return (0, react_1.useMemo)(() => ({
43
45
  openForm,
44
- }), [openForm]);
46
+ router,
47
+ }), [openForm, router]);
45
48
  }
46
49
  function useBaseCommandHandlerContext() {
47
50
  const dataService = (0, transport_1.useDataService)();
@@ -54,10 +54,6 @@ const CalculatedField = () => {
54
54
  }
55
55
  const currentValue = formInstanceRef.current.getValues(item.attributeName);
56
56
  const newValue = item.handler(record, relatedRecords);
57
- console.log('Recalculated main record field:', item.attributeName, item, record, relatedRecords, {
58
- currentValue,
59
- newValue,
60
- });
61
57
  if (currentValue !== newValue) {
62
58
  formInstanceRef.current.setValue(item.attributeName, newValue);
63
59
  eventManager.emit(constants_1.EVENT_KEY_ON_FIELD_CHANGE, item.attributeName, newValue, currentValue);
@@ -70,10 +66,6 @@ const CalculatedField = () => {
70
66
  }
71
67
  const currentValue = formInstanceRef.current.getValues(`${alias}.${indexStr}.${item.attributeName}`);
72
68
  const newValue = item.handler(record, {});
73
- console.log('Subgrid row level calculation:', item.attributeName, item, record, {
74
- currentValue,
75
- newValue,
76
- });
77
69
  if (currentValue !== newValue) {
78
70
  formInstanceRef.current.setValue(`${alias}.${indexStr}.${item.attributeName}`, newValue);
79
71
  eventManager.emit(constants_1.EVENT_KEY_ON_FIELD_CHANGE, `${alias}.${indexStr}.${item.attributeName}`, newValue, currentValue);
@@ -1,5 +1,5 @@
1
- import { RouterInstance } from '@headless-adminapp/app/route/context';
2
1
  import { FormExperience } from '@headless-adminapp/core/experience/form';
2
+ import { RouterInstance } from '@headless-adminapp/core/navigation';
3
3
  import { Schema } from '@headless-adminapp/core/schema';
4
4
  export declare function getFormDefaultParameters(schema: Schema, formExperience: FormExperience, router: RouterInstance): {
5
5
  [x: string]: any;
@@ -60,3 +60,23 @@ export declare const generateValidationSchema: (<A extends SchemaAttributes = Sc
60
60
  [x: string]: any;
61
61
  }, "">) & MemoizedFunction;
62
62
  export declare const generateAttributeValidationSchema: ((attribute: Attribute, language: string, strings: FormValidationStringSet, region: string) => yup.Schema<any, any, any, "">) & MemoizedFunction;
63
+ export declare const generateAttributesValidationSchema: (<A extends SchemaAttributes = SchemaAttributes>({ attributes, language, strings, region, }: {
64
+ attributes: A;
65
+ language: string;
66
+ strings: FormValidationStringSet;
67
+ region: string;
68
+ }) => yup.ObjectSchema<{
69
+ [x: string]: any;
70
+ }, yup.AnyObject, {
71
+ [x: string]: any;
72
+ }, "">) & MemoizedFunction;
73
+ export declare const attributesFormValidator: (<A extends SchemaAttributes = SchemaAttributes>({ attributes, language, strings, region, }: {
74
+ attributes: A;
75
+ language: string;
76
+ strings: FormValidationStringSet;
77
+ region: string;
78
+ }) => (values: Record<string, any>, context: any, options: any) => Promise<ResolverResult<{
79
+ [x: string]: any;
80
+ [x: number]: any;
81
+ [x: symbol]: any;
82
+ }>>) & MemoizedFunction;
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.generateAttributeValidationSchema = exports.generateValidationSchema = exports.editableSubgridFormValidator = exports.formValidator = exports.saveRecord = void 0;
26
+ exports.attributesFormValidator = exports.generateAttributesValidationSchema = exports.generateAttributeValidationSchema = exports.generateValidationSchema = exports.editableSubgridFormValidator = exports.formValidator = exports.saveRecord = void 0;
27
27
  exports.getInitialValues = getInitialValues;
28
28
  const phone_1 = require("@headless-adminapp/app/utils/phone");
29
29
  const yup_1 = require("@hookform/resolvers/yup");
@@ -316,7 +316,7 @@ function extendAttributeStringValidationSchema({ attribute, validationSchema, la
316
316
  // extend the validation schema with the min length
317
317
  validationSchema = validationSchema.min(attribute.minLength, `${label}: ${strings.minLength}`);
318
318
  }
319
- if (attribute.pattern) {
319
+ if ('pattern' in attribute && attribute.pattern) {
320
320
  // extend the validation schema with the pattern
321
321
  validationSchema = validationSchema.matches(new RegExp(attribute.pattern), `${label}: ${strings.invalidFormat}`);
322
322
  }
@@ -388,3 +388,29 @@ exports.generateAttributeValidationSchema = (0, lodash_1.memoize)(function gener
388
388
  });
389
389
  return validationSchema;
390
390
  });
391
+ exports.generateAttributesValidationSchema = (0, lodash_1.memoize)(function generateAttributesValidationSchema({ attributes, language, strings, region, }) {
392
+ const columns = Object.keys(attributes);
393
+ return yup.object().shape({
394
+ ...columns.reduce((acc, column) => {
395
+ const attribute = attributes[column];
396
+ const validationSchema = (0, exports.generateAttributeValidationSchema)(attribute, language, strings, region);
397
+ return {
398
+ ...acc,
399
+ [column]: validationSchema,
400
+ };
401
+ }, {}),
402
+ });
403
+ }, (options) => JSON.stringify(options));
404
+ exports.attributesFormValidator = (0, lodash_1.memoize)(function formValidator({ attributes, language, strings, region, }) {
405
+ return async (values, context, options) => {
406
+ const validator = (0, exports.generateAttributesValidationSchema)({
407
+ attributes,
408
+ language,
409
+ strings,
410
+ region,
411
+ });
412
+ const resolver = (0, yup_1.yupResolver)(validator);
413
+ const result = await resolver(values, context, options);
414
+ return result;
415
+ };
416
+ }, (options) => JSON.stringify(options));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@headless-adminapp/app",
3
- "version": "1.4.22",
3
+ "version": "1.4.24",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -38,5 +38,5 @@
38
38
  "uuid": "11.0.3",
39
39
  "yup": "^1.4.0"
40
40
  },
41
- "gitHead": "8f687a2b8c3151c30c57f43105ac47c5d8c3ee79"
41
+ "gitHead": "3a4c06f1e18f8ac7861647b82d4a4f8cd8f0141c"
42
42
  }
@@ -1,6 +1,6 @@
1
1
  import { IsRouteActive, RouteResolver } from '@headless-adminapp/core/experience/route';
2
+ import { RouterInstance } from '@headless-adminapp/core/navigation';
2
3
  import { FC, PropsWithChildren } from 'react';
3
- import { RouterInstance } from './context';
4
4
  import { ReadonlyURLSearchParams } from './types';
5
5
  export interface RouteProviderProps {
6
6
  router: RouterInstance;
@@ -1,24 +1,8 @@
1
1
  import { NavPageItem } from '@headless-adminapp/core/experience/app';
2
+ import { RouterInstance } from '@headless-adminapp/core/navigation';
2
3
  import { ReadonlyURLSearchParams } from './types';
3
4
  export type InternalRouteResolver = (item: NavPageItem) => string;
4
5
  export type InternalIsRouteActive = (path: string, item: NavPageItem) => boolean;
5
- interface NavigateOptions {
6
- state?: any;
7
- }
8
- export type GuardFn = () => boolean | Promise<boolean>;
9
- export interface RouterInstance {
10
- back: () => Promise<void>;
11
- forward: () => Promise<void>;
12
- push(href: string, options?: NavigateOptions): Promise<void>;
13
- replace(href: string, options?: NavigateOptions): Promise<void>;
14
- prefetch(href: string): void;
15
- setState(state: any): void;
16
- setState(key: string, state: any): void;
17
- getState<T = any>(): T;
18
- getState<T = any>(key: string): T | undefined;
19
- registerGuard(fn: GuardFn): void;
20
- unregisterGuard(fn: GuardFn): void;
21
- }
22
6
  export declare const RouterContext: import("react").Context<RouterInstance>;
23
7
  export declare const RouterPathnameContext: import("react").Context<string>;
24
8
  export declare const RouterSearchParamsContext: import("react").Context<ReadonlyURLSearchParams>;
@@ -28,4 +12,3 @@ export interface RouteHelperContext {
28
12
  isRouteActive: InternalIsRouteActive;
29
13
  }
30
14
  export declare const RouteHelperContext: import("react").Context<RouteHelperContext>;
31
- export {};
@@ -1 +1 @@
1
- export declare function useRouter(): import("../context").RouterInstance;
1
+ export declare function useRouter(): import("@headless-adminapp/core/navigation").RouterInstance;