@abgov/jsonforms-components 2.41.0 → 2.41.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/index.esm.js CHANGED
@@ -5,7 +5,7 @@ import { GoAFormItem, GoAInput, GoATextArea, GoACallout, GoAInputDate, GoAInputD
5
5
  import styled from 'styled-components';
6
6
  import axios from 'axios';
7
7
  import get$1 from 'lodash/get';
8
- import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isControl, isEnumControl, isBooleanControl, schemaMatches, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, or, isObjectArrayControl, isPrimitiveArrayControl, Paths, toDataPath, hasType, isCategorization, isLayout } from '@jsonforms/core';
8
+ import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isControl as isControl$1, isEnumControl, isBooleanControl, schemaMatches, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, or, isObjectArrayControl, isPrimitiveArrayControl, Paths, toDataPath, Resolve, hasType, isCategorization, isLayout } from '@jsonforms/core';
9
9
  import { withJsonFormsControlProps, withJsonFormsEnumProps, withTranslateProps, JsonFormsDispatch, useJsonForms, withJsonFormsLayoutProps, withJsonFormsArrayLayoutProps, withJsonFormsAllOfProps, withJsonFormsCellProps } from '@jsonforms/react';
10
10
  import * as _$c from 'lodash';
11
11
  import ___default, { isEqual, isEmpty as isEmpty$1, isObject as isObject$f } from 'lodash';
@@ -6426,7 +6426,7 @@ const enumControl = props => {
6426
6426
  };
6427
6427
  const GoAEnumControlTester = rankWith(4, (uischema, schema, context) => {
6428
6428
  var _a;
6429
- return (schema === null || schema === void 0 ? void 0 : schema.type) === 'object' && isControl(uischema) && ((_a = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _a === void 0 ? void 0 : _a.format) === 'enum' || isEnumControl(uischema, schema, context);
6429
+ return (schema === null || schema === void 0 ? void 0 : schema.type) === 'object' && isControl$1(uischema) && ((_a = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _a === void 0 ? void 0 : _a.format) === 'enum' || isEnumControl(uischema, schema, context);
6430
6430
  });
6431
6431
  const GoAEnumControl = withJsonFormsEnumProps(withTranslateProps(enumControl), true);
6432
6432
 
@@ -7002,7 +7002,7 @@ const GoAEmailInput = props => {
7002
7002
  });
7003
7003
  };
7004
7004
  const GoAEmailControl = props => jsx(GoAEmailInput, Object.assign({}, props));
7005
- const GoAEmailControlTester = rankWith(4, and(isControl, schemaMatches(schema => schema.format === 'email')));
7005
+ const GoAEmailControlTester = rankWith(4, and(isControl$1, schemaMatches(schema => schema.format === 'email')));
7006
7006
  const GoAInputEmailControl = withJsonFormsControlProps(GoAEmailControl);
7007
7007
 
7008
7008
  let _$7 = t => t,
@@ -11094,6 +11094,25 @@ const getItemsTitle = schema => {
11094
11094
  }
11095
11095
  return undefined;
11096
11096
  };
11097
+ function isControl(uischema) {
11098
+ return uischema.type === 'Control';
11099
+ }
11100
+ function hasElements$1(uischema) {
11101
+ return Array.isArray(uischema.elements);
11102
+ }
11103
+ function hasDetail(uischema) {
11104
+ var _a;
11105
+ return uischema.type === 'ListWithDetail' && typeof ((_a = uischema.options) === null || _a === void 0 ? void 0 : _a.detail) === 'object';
11106
+ }
11107
+ function normalizeLabel(label) {
11108
+ if (typeof label === 'string') {
11109
+ return label;
11110
+ }
11111
+ if (typeof label === 'object' && label !== null) {
11112
+ return label.text;
11113
+ }
11114
+ return;
11115
+ }
11097
11116
  // eslint-disable-next-line
11098
11117
  const extractScopesFromUISchema = uischema => {
11099
11118
  var _a, _b, _c, _d, _e, _f;
@@ -11389,6 +11408,84 @@ function orderRowData(rowData, detailUiSchema) {
11389
11408
  }
11390
11409
  return ordered;
11391
11410
  }
11411
+ function getEffectiveInstancePath(error) {
11412
+ var _a;
11413
+ if (error.keyword === 'required' && ((_a = error.params) === null || _a === void 0 ? void 0 : _a.missingProperty)) {
11414
+ return `${error.instancePath}/${error.params.missingProperty}`;
11415
+ }
11416
+ return error.instancePath;
11417
+ }
11418
+ function prettify(prop) {
11419
+ return prop.replace(/([A-Z])/g, ' $1').replace(/[_-]/g, ' ').replace(/^./, c => c.toUpperCase());
11420
+ }
11421
+ function resolveLabel(instancePath, schema, uischema) {
11422
+ const prop = instancePath.split('/').filter(Boolean).pop();
11423
+ const scope = `#/properties/${prop}`;
11424
+ if (uischema) {
11425
+ const uiLabel = findControlLabel(uischema, scope);
11426
+ if (uiLabel) {
11427
+ return uiLabel;
11428
+ }
11429
+ }
11430
+ const schemaPath = ajvPathToSchemaPath(instancePath);
11431
+ const resolvedSchema = Resolve.schema(schema, schemaPath, schema);
11432
+ if (resolvedSchema === null || resolvedSchema === void 0 ? void 0 : resolvedSchema.title) {
11433
+ return resolvedSchema.title;
11434
+ }
11435
+ return prettify(prop || 'Unknown field');
11436
+ }
11437
+ function ajvPathToSchemaPath(instancePath) {
11438
+ const parts = instancePath.split('/').filter(Boolean);
11439
+ const result = [];
11440
+ for (const part of parts) {
11441
+ if (!isNaN(Number(part))) {
11442
+ // array index → items
11443
+ result.push('items');
11444
+ } else {
11445
+ result.push('properties', part);
11446
+ }
11447
+ }
11448
+ return result.join('.');
11449
+ }
11450
+ function findControlLabel(uischema, scope) {
11451
+ if (isControl(uischema) && uischema.scope === scope) {
11452
+ return normalizeLabel(uischema.label);
11453
+ }
11454
+ if (hasDetail(uischema)) {
11455
+ const found = findControlLabel(uischema.options.detail, scope);
11456
+ if (found) return found;
11457
+ }
11458
+ if (hasElements$1(uischema)) {
11459
+ for (const el of uischema.elements) {
11460
+ const found = findControlLabel(el, scope);
11461
+ if (found) return found;
11462
+ }
11463
+ }
11464
+ return;
11465
+ }
11466
+ function humanizeAjvError(error, schema, uischema) {
11467
+ var _a;
11468
+ const path = getEffectiveInstancePath(error);
11469
+ const label = resolveLabel(path, schema, uischema);
11470
+ switch (error.keyword) {
11471
+ case 'required':
11472
+ return `${label} is required`;
11473
+ case 'minLength':
11474
+ return `${label} must be at least ${error.params.limit} characters`;
11475
+ case 'maxLength':
11476
+ return `${label} must be at most ${error.params.limit} characters`;
11477
+ case 'format':
11478
+ return `${label} must be a valid ${error.params.format}`;
11479
+ case 'minimum':
11480
+ return `${label} must be ≥ ${error.params.limit}`;
11481
+ case 'maximum':
11482
+ return `${label} must be ≤ ${error.params.limit}`;
11483
+ case 'type':
11484
+ return `${label} must be a ${error.params.type}`;
11485
+ default:
11486
+ return `${label} ${(_a = error.message) !== null && _a !== void 0 ? _a : ''}`.trim();
11487
+ }
11488
+ }
11392
11489
  const MainTab = ({
11393
11490
  childPath,
11394
11491
  rowIndex,
@@ -11411,10 +11508,10 @@ const MainTab = ({
11411
11508
  const rowErrors = (_b = core === null || core === void 0 ? void 0 : core.errors) === null || _b === void 0 ? void 0 : _b.filter(e => {
11412
11509
  const base = `/${childPath.replace(/\./g, '/')}`;
11413
11510
  return e.instancePath === base || e.instancePath.startsWith(base + '/');
11414
- }).map(e => {
11415
- var _a, _b;
11416
- return ((_b = (_a = e === null || e === void 0 ? void 0 : e.message) === null || _a === void 0 ? void 0 : _a.trim) === null || _b === void 0 ? void 0 : _b.call(_a)) || '';
11417
- }).filter(msg => msg.length > 0).map((msg, index, arr) => `${msg}${index < arr.length - 1 ? ', ' : ''}`);
11511
+ }).filter(e => {
11512
+ var _a;
11513
+ return (((_a = e === null || e === void 0 ? void 0 : e.message) === null || _a === void 0 ? void 0 : _a.length) || 0) > 0;
11514
+ }).map(e => humanizeAjvError(e, core.schema, core.uischema)).map((msg, index, arr) => `${msg}${index < arr.length - 1 ? ', ' : ''}`);
11418
11515
  return jsx("div", {
11419
11516
  "data-testid": `object-array-main-item-${rowIndex}`,
11420
11517
  children: (rowErrors === null || rowErrors === void 0 ? void 0 : rowErrors.length) ? jsx(GoAFormItem, {
@@ -13928,11 +14025,11 @@ const getUISchemaErrors = (uiSchema, schema) => {
13928
14025
  if (isEmptyObject(uiSchema)) {
13929
14026
  return '';
13930
14027
  }
13931
- if (isControl(uiSchema) && (schema === null || schema === void 0 ? void 0 : schema.type) === 'object' && ((_a = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.options) === null || _a === void 0 ? void 0 : _a.format) === 'enum' && ((_b = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.options) === null || _b === void 0 ? void 0 : _b.register) === undefined) {
14028
+ if (isControl$1(uiSchema) && (schema === null || schema === void 0 ? void 0 : schema.type) === 'object' && ((_a = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.options) === null || _a === void 0 ? void 0 : _a.format) === 'enum' && ((_b = uiSchema === null || uiSchema === void 0 ? void 0 : uiSchema.options) === null || _b === void 0 ? void 0 : _b.register) === undefined) {
13932
14029
  return errMissingRegister;
13933
14030
  }
13934
14031
  // Check control elements
13935
- if (isControl(uiSchema) && hasType(uiSchema, 'Control')) {
14032
+ if (isControl$1(uiSchema) && hasType(uiSchema, 'Control')) {
13936
14033
  if (!isScopedPrefixed(uiSchema.scope)) {
13937
14034
  return errMalformedScope(uiSchema.scope);
13938
14035
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "2.41.0",
3
+ "version": "2.41.1",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Government of Alberta - React renderers for JSON Forms based on the design system.",
6
6
  "repository": "https://github.com/GovAlta/adsp-monorepo",
@@ -1,5 +1,6 @@
1
1
  import React from 'react';
2
- import { ArrayLayoutProps, ControlElement, JsonSchema, JsonFormsRendererRegistryEntry, JsonFormsCellRendererRegistryEntry, ArrayTranslations, Layout } from '@jsonforms/core';
2
+ import type { ErrorObject } from 'ajv';
3
+ import { ArrayLayoutProps, ControlElement, JsonSchema, JsonFormsRendererRegistryEntry, JsonFormsCellRendererRegistryEntry, ArrayTranslations, UISchemaElement, Layout } from '@jsonforms/core';
3
4
  import { WithDeleteDialogSupport } from './DeleteDialog';
4
5
  export type ObjectArrayControlProps = ArrayLayoutProps & WithDeleteDialogSupport;
5
6
  export declare const extractScopesFromUISchema: (uischema: any) => string[];
@@ -33,6 +34,8 @@ interface NonEmptyRowProps {
33
34
  uischema: ControlElement;
34
35
  listTitle?: string;
35
36
  }
37
+ export declare function findControlLabel(uischema: UISchemaElement, scope: string): string | undefined;
38
+ export declare function humanizeAjvError(error: ErrorObject, schema: JsonSchema, uischema?: UISchemaElement): string;
36
39
  export declare const NonEmptyList: React.MemoExoticComponent<({ childPath, schema, enabled, cells, uischema, }: NonEmptyRowProps & WithDeleteDialogSupport) => import("react/jsx-runtime").JSX.Element>;
37
40
  interface ListWithDetailControlProps extends ObjectArrayControlProps {
38
41
  currentTab: number;