@abgov/jsonforms-components 1.2.4 → 1.3.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
@@ -3,8 +3,8 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import { GoAFormItem, GoACallout, GoAInputDate, GoAInput, GoATextArea, GoAInputDateTime, GoAInputTime, GoADropdown, GoADropdownItem, GoARadioGroup, GoARadioItem, GoACheckbox, GoAFormStepper, GoAFormStep, GoAPages, GoAButton, GoAIconButton, GoAFileUploadInput, GoAModal, GoACircularProgress, GoAGrid, GoAContainer, GoAButtonGroup, GoADetails } from '@abgov/react-components';
4
4
  import { Hidden, Typography, FormHelperText } from '@mui/material';
5
5
  import styled from 'styled-components';
6
- import { rankWith, isDateControl, isStringControl, and, optionIs, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, isDescriptionHidden, isVisible, isEnabled, deriveLabelForUISchemaElement, uiTypeIs, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, withIncreasedRank, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
7
- import { withJsonFormsControlProps, withJsonFormsEnumProps, withTranslateProps, withJsonFormsLayoutProps, JsonFormsDispatch, useJsonForms, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
6
+ import { rankWith, uiTypeIs, isDateControl, isStringControl, and, optionIs, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, isDescriptionHidden, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, withIncreasedRank, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
7
+ import { withJsonFormsRendererProps, withJsonFormsControlProps, withJsonFormsEnumProps, withTranslateProps, withJsonFormsLayoutProps, JsonFormsDispatch, useJsonForms, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
8
8
  import React, { createContext, useEffect, useState, useMemo, useContext, useCallback } from 'react';
9
9
  import merge from 'lodash/merge';
10
10
  import axios from 'axios';
@@ -2407,24 +2407,23 @@ const GoAInputBaseControl = props => {
2407
2407
  });
2408
2408
  };
2409
2409
 
2410
- /**
2411
- * Used internally by registered Controls, the MessageControl
2412
- * is used to display an error message if a component cannot be rendered
2413
- * due to input errors - typically from options.componentProps.
2414
- *
2415
- * NOTE: The component itself is not, and should not, be registered.
2416
- *
2417
- * @param message the message to be displayed
2418
- *
2419
- * @returns component for displaying the message in the correct style
2420
- */
2421
- // TODO: Add styling
2422
- const MessageControl = message => {
2423
- return jsx(GoACallout, {
2424
- type: "emergency",
2425
- children: message
2426
- });
2410
+ // Used locally for callout presentation
2411
+ const callout = props => {
2412
+ const componentProps = Object.assign({
2413
+ size: 'medium',
2414
+ type: 'emergency',
2415
+ message: 'unknown'
2416
+ }, props);
2417
+ return jsx(GoACallout, Object.assign({}, componentProps, {
2418
+ children: componentProps.message
2419
+ }));
2420
+ };
2421
+ const CalloutControl = props => {
2422
+ var _a, _b;
2423
+ return callout(((_b = (_a = props === null || props === void 0 ? void 0 : props.uischema) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.componentProps) || {});
2427
2424
  };
2425
+ const GoACalloutControlTester = rankWith(1, uiTypeIs('Callout'));
2426
+ var GoACalloutControl = withJsonFormsRendererProps(CalloutControl);
2428
2427
 
2429
2428
  const errMalformedDate = (scope, type) => {
2430
2429
  return `${type}-date for variable '${scope}' has an incorrect format.`;
@@ -2442,7 +2441,9 @@ const isValidDateFormat = date => {
2442
2441
  return standardized !== undefined;
2443
2442
  };
2444
2443
  const invalidDateFormat = (scope, type) => {
2445
- return MessageControl(errMalformedDate(scope, type));
2444
+ return callout({
2445
+ message: errMalformedDate(scope, type)
2446
+ });
2446
2447
  };
2447
2448
  const reformatDateProps = props => {
2448
2449
  if (props) {
@@ -3702,7 +3703,7 @@ let _$4 = t => t,
3702
3703
  _t$4,
3703
3704
  _t2$2,
3704
3705
  _t3$1,
3705
- _t4,
3706
+ _t4$1,
3706
3707
  _t5,
3707
3708
  _t6,
3708
3709
  _t7;
@@ -3727,7 +3728,7 @@ const ReviewItemHeader = styled.div(_t3$1 || (_t3$1 = _$4`
3727
3728
  justify-content: space-between;
3728
3729
  margin-bottom: 2rem;
3729
3730
  `));
3730
- const ReviewItemTitle = styled.div(_t4 || (_t4 = _$4`
3731
+ const ReviewItemTitle = styled.div(_t4$1 || (_t4$1 = _$4`
3731
3732
  font-size: var(--fs-xl);
3732
3733
  line-height: var(--lh-lg);
3733
3734
  font-weight: var(--fw-light);
@@ -4212,7 +4213,8 @@ const ObjectArrayToolBar = /*#__PURE__*/React.memo(function TableToolbar({
4212
4213
  let _$1 = t => t,
4213
4214
  _t$1,
4214
4215
  _t2,
4215
- _t3;
4216
+ _t3,
4217
+ _t4;
4216
4218
  const DeleteDialogContent = styled.div(_t$1 || (_t$1 = _$1`
4217
4219
  margin-bottom: var(--goa-space-m);
4218
4220
  `));
@@ -4222,6 +4224,9 @@ const ToolBarHeader = styled.div(_t2 || (_t2 = _$1`
4222
4224
  const ObjectArrayTitle = styled.h2(_t3 || (_t3 = _$1`
4223
4225
  margin-bottom: var(--goa-space-l);
4224
4226
  `));
4227
+ const DisplayWrapper = styled.div(_t4 || (_t4 = _$1`
4228
+ display: ${0};
4229
+ `), p => p.visible ? 'initial' : 'none');
4225
4230
 
4226
4231
  // eslint-disable-next-line
4227
4232
  const extractScopesFromUISchema = uischema => {
@@ -4301,17 +4306,18 @@ const ctxToNonEmptyCellProps = (ctx, ownProps) => {
4301
4306
  renderers: ownProps.renderers || ctx.renderers
4302
4307
  };
4303
4308
  };
4304
- const NonEmptyCellComponent = /*#__PURE__*/React.memo(function NonEmptyCellComponent({
4305
- schema,
4306
- errors,
4307
- enabled,
4308
- renderers,
4309
- cells,
4310
- rowPath,
4311
- isValid,
4312
- uischema
4313
- }) {
4314
- var _a, _b;
4309
+ const NonEmptyCellComponent = /*#__PURE__*/React.memo(function NonEmptyCellComponent(props) {
4310
+ var _a, _b, _c;
4311
+ const {
4312
+ schema,
4313
+ errors,
4314
+ enabled,
4315
+ renderers,
4316
+ cells,
4317
+ rowPath,
4318
+ isValid,
4319
+ uischema
4320
+ } = props;
4315
4321
  const propNames = getValidColumnProps(schema);
4316
4322
  const propScopes = (uischema === null || uischema === void 0 ? void 0 : uischema.scope) ? propNames.map(name => {
4317
4323
  return `#/properties/${name}`;
@@ -4337,6 +4343,7 @@ const NonEmptyCellComponent = /*#__PURE__*/React.memo(function NonEmptyCellCompo
4337
4343
  // eslint-disable-next-line
4338
4344
  (_b = uischema === null || uischema === void 0 ? void 0 : uischema.elements) === null || _b === void 0 ? void 0 : _b.map(element => {
4339
4345
  return jsx(JsonFormsDispatch, {
4346
+ "data-testid": `jsonforms-object-list-defined-elements-dispatch`,
4340
4347
  schema: schema,
4341
4348
  uischema: element,
4342
4349
  path: rowPath,
@@ -4344,7 +4351,7 @@ const NonEmptyCellComponent = /*#__PURE__*/React.memo(function NonEmptyCellCompo
4344
4351
  renderers: renderers,
4345
4352
  cells: cells
4346
4353
  }, rowPath);
4347
- }), jsx(JsonFormsDispatch, {
4354
+ }), ((_c = uiSchemaElementsForNotDefined === null || uiSchemaElementsForNotDefined === void 0 ? void 0 : uiSchemaElementsForNotDefined.elements) === null || _c === void 0 ? void 0 : _c.length) > 0 && jsx(JsonFormsDispatch, {
4348
4355
  schema: schema,
4349
4356
  uischema: uiSchemaElementsForNotDefined,
4350
4357
  path: rowPath,
@@ -4456,38 +4463,37 @@ class ObjectArrayControl extends React.Component {
4456
4463
  const controlElement = uischema;
4457
4464
  // eslint-disable-next-line
4458
4465
  const listTitle = label || ((_a = uischema.options) === null || _a === void 0 ? void 0 : _a.title);
4459
- return jsx(Hidden, {
4460
- xsUp: !visible,
4461
- children: jsxs("div", {
4462
- children: [jsxs(ToolBarHeader, {
4463
- children: [listTitle && jsx(ObjectArrayTitle, {
4464
- children: listTitle
4465
- }), jsx(ObjectArrayToolBar, {
4466
- errors: errors,
4467
- label: label,
4468
- addItem: this.addItem,
4469
- numColumns: 0,
4470
- path: path,
4471
- uischema: controlElement,
4472
- schema: schema,
4473
- rootSchema: rootSchema,
4474
- enabled: enabled,
4475
- translations: translations
4476
- })]
4477
- }), jsx("div", {
4478
- children: jsx(ObjectArrayList, Object.assign({
4479
- path: path,
4480
- schema: schema,
4481
- uischema: uischema,
4482
- enabled: enabled,
4483
- openDeleteDialog: openDeleteDialog,
4484
- translations: translations,
4485
- data: data,
4486
- cells: cells,
4487
- config: config
4488
- }, additionalProps))
4466
+ return jsxs(DisplayWrapper, {
4467
+ visible: visible,
4468
+ "data-testid": "jsonforms-object-list-wrapper",
4469
+ children: [jsxs(ToolBarHeader, {
4470
+ children: [listTitle && jsx(ObjectArrayTitle, {
4471
+ children: listTitle
4472
+ }), jsx(ObjectArrayToolBar, {
4473
+ errors: errors,
4474
+ label: label,
4475
+ addItem: this.addItem,
4476
+ numColumns: 0,
4477
+ path: path,
4478
+ uischema: controlElement,
4479
+ schema: schema,
4480
+ rootSchema: rootSchema,
4481
+ enabled: enabled,
4482
+ translations: translations
4489
4483
  })]
4490
- })
4484
+ }), jsx("div", {
4485
+ children: jsx(ObjectArrayList, Object.assign({
4486
+ path: path,
4487
+ schema: schema,
4488
+ uischema: uischema,
4489
+ enabled: enabled,
4490
+ openDeleteDialog: openDeleteDialog,
4491
+ translations: translations,
4492
+ data: data,
4493
+ cells: cells,
4494
+ config: config
4495
+ }, additionalProps))
4496
+ })]
4491
4497
  });
4492
4498
  }
4493
4499
  }
@@ -4849,7 +4855,7 @@ const isLayoutType = schema => {
4849
4855
  return hasType(schema, 'VerticalLayout') || hasType(schema, 'HorizontalLayout') || hasType(schema, 'Categorization') || hasType(schema, 'Group');
4850
4856
  };
4851
4857
  const isKnownType = schema => {
4852
- return hasType(schema, 'Control') || isLayoutType(schema) || hasType(schema, 'HelpContent') || isListWithDetail(schema);
4858
+ return hasType(schema, 'Control') || isLayoutType(schema) || hasType(schema, 'HelpContent') || isListWithDetail(schema) || hasType(schema, 'Callout');
4853
4859
  };
4854
4860
  const isListWithDetail = schema => {
4855
4861
  return hasType(schema, 'ListWithDetail');
@@ -4873,9 +4879,6 @@ const isEmptyElements = schema => {
4873
4879
  const hasVariant = schema => {
4874
4880
  return 'options' in schema && schema.options !== undefined && schema.options !== null && 'variant' in schema.options;
4875
4881
  };
4876
- const isValidJsonObject = schema => {
4877
- return typeof schema === 'object' && Object.keys(schema).length === 0 || 'properties' in schema && ('type' in schema && schema.type === 'object' || !('type' in schema));
4878
- };
4879
4882
 
4880
4883
  const errCategorizationHasNonCategories = "Each element of 'Categorizations' must be of type 'Category'";
4881
4884
  const errCategorizationHasNoElements = 'A Categorization must contain Categories.';
@@ -4967,15 +4970,6 @@ const getUISchemaErrors = (uiSchema, schema) => {
4967
4970
  return null;
4968
4971
  };
4969
4972
 
4970
- const isValidJsonSchema = schema => {
4971
- if (isNullSchema(schema)) {
4972
- return '';
4973
- }
4974
- if (!isValidJsonObject(schema)) {
4975
- return 'Unable to render: json schema is not valid.';
4976
- }
4977
- return null;
4978
- };
4979
4973
  // Some 'errors' need not be reported, but we want to handle them
4980
4974
  // here. e.g. A layout with empty elements should be quietly ignored.
4981
4975
  // this is handled by the errors !== '' check.
@@ -4984,17 +4978,11 @@ const ErrorControl = props => {
4984
4978
  schema,
4985
4979
  uischema
4986
4980
  } = props;
4987
- // Report data schema errors over ui schema ones, as errors in the former
4988
- // can cause cascading errors in the latter.
4989
- const dataSchemaErrors = isValidJsonSchema(schema);
4990
- if (dataSchemaErrors && dataSchemaErrors !== '') {
4991
- return jsx("p", {
4992
- children: dataSchemaErrors
4993
- });
4994
- }
4995
4981
  const uiSchemaErrors = getUISchemaErrors(uischema, schema);
4996
4982
  if (uiSchemaErrors && uiSchemaErrors !== '') {
4997
- return MessageControl(uiSchemaErrors);
4983
+ return callout({
4984
+ message: uiSchemaErrors
4985
+ });
4998
4986
  }
4999
4987
  return jsx("span", {});
5000
4988
  };
@@ -5003,9 +4991,8 @@ const ErrorControl = props => {
5003
4991
  * one that must get used if there are any errors whatsoever.
5004
4992
  */
5005
4993
  const GoAErrorControlTester = rankWith(1000, (uischema, schema, context) => {
5006
- const validJsonSchema = isValidJsonSchema(schema);
5007
4994
  const validUiSchema = getUISchemaErrors(uischema, schema);
5008
- return validUiSchema != null || validJsonSchema != null;
4995
+ return validUiSchema != null;
5009
4996
  });
5010
4997
  var GoAErrorControl = withJsonFormsControlProps(ErrorControl);
5011
4998
 
@@ -5037,6 +5024,9 @@ const GoABaseRenderers = [
5037
5024
  }, {
5038
5025
  tester: GoATimeControlTester,
5039
5026
  renderer: GoAInputTimeControl
5027
+ }, {
5028
+ tester: GoACalloutControlTester,
5029
+ renderer: GoACalloutControl
5040
5030
  }, {
5041
5031
  tester: materialSliderControlTester,
5042
5032
  renderer: MaterialSliderControl
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.2.4",
3
+ "version": "1.3.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",
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ import { RankedTester } from '@jsonforms/core';
3
+ import { GoACalloutSize, GoACalloutType } from '@abgov/react-components-new';
4
+ export interface CalloutProps {
5
+ size?: GoACalloutSize;
6
+ type?: GoACalloutType;
7
+ message?: string;
8
+ }
9
+ export declare const callout: (props: CalloutProps) => JSX.Element;
10
+ export declare const GoACalloutControlTester: RankedTester;
11
+ declare const _default: React.ComponentType<import("@jsonforms/core").OwnPropsOfJsonFormsRenderer>;
12
+ export default _default;
@@ -1,10 +1,24 @@
1
1
  import React from 'react';
2
- import { ArrayLayoutProps, ControlElement, JsonSchema, JsonFormsCellRendererRegistryEntry, ArrayTranslations } from '@jsonforms/core';
2
+ import { ArrayLayoutProps, ControlElement, JsonSchema, JsonFormsRendererRegistryEntry, JsonFormsCellRendererRegistryEntry, ArrayTranslations, Layout } from '@jsonforms/core';
3
3
  import { WithDeleteDialogSupport } from './DeleteDialog';
4
+ export type ObjectArrayControlProps = ArrayLayoutProps & WithDeleteDialogSupport;
4
5
  export interface EmptyListProps {
5
6
  numColumns: number;
6
7
  translations: ArrayTranslations;
7
8
  }
9
+ interface NonEmptyRowComponentProps {
10
+ propName?: string;
11
+ schema: JsonSchema;
12
+ rootSchema?: JsonSchema;
13
+ rowPath: string;
14
+ errors: string;
15
+ enabled: boolean;
16
+ renderers?: JsonFormsRendererRegistryEntry[];
17
+ cells?: JsonFormsCellRendererRegistryEntry[];
18
+ isValid: boolean;
19
+ uischema?: ControlElement | Layout;
20
+ }
21
+ export declare const NonEmptyCellComponent: React.NamedExoticComponent<NonEmptyRowComponentProps>;
8
22
  interface NonEmptyRowProps {
9
23
  childPath: string;
10
24
  schema: JsonSchema;
@@ -17,7 +31,7 @@ interface NonEmptyRowProps {
17
31
  uischema: ControlElement;
18
32
  }
19
33
  export declare const NonEmptyList: React.MemoExoticComponent<({ childPath, schema, rowIndex, openDeleteDialog, enabled, cells, path, translations, uischema, }: NonEmptyRowProps & WithDeleteDialogSupport) => import("react/jsx-runtime").JSX.Element>;
20
- export declare class ObjectArrayControl extends React.Component<ArrayLayoutProps & WithDeleteDialogSupport, any> {
34
+ export declare class ObjectArrayControl extends React.Component<ObjectArrayControlProps, any> {
21
35
  addItem: (path: string, value: any) => () => void;
22
36
  render(): import("react/jsx-runtime").JSX.Element;
23
37
  }
@@ -1,3 +1,6 @@
1
1
  export declare const DeleteDialogContent: import("styled-components").StyledComponent<"div", any, {}, never>;
2
2
  export declare const ToolBarHeader: import("styled-components").StyledComponent<"div", any, {}, never>;
3
3
  export declare const ObjectArrayTitle: import("styled-components").StyledComponent<"h2", any, {}, never>;
4
+ export declare const DisplayWrapper: import("styled-components").StyledComponent<"div", any, {
5
+ visible: boolean;
6
+ }, never>;
@@ -11,4 +11,3 @@ export declare const isCategorization: (uiSchema: UISchemaElement) => boolean;
11
11
  export declare const hasElements: (schema: object) => boolean;
12
12
  export declare const isEmptyElements: (schema: object) => boolean;
13
13
  export declare const hasVariant: (schema: UISchemaElement) => boolean;
14
- export declare const isValidJsonObject: (schema: JsonSchema) => boolean;
@@ -1,12 +0,0 @@
1
- /**
2
- * Used internally by registered Controls, the MessageControl
3
- * is used to display an error message if a component cannot be rendered
4
- * due to input errors - typically from options.componentProps.
5
- *
6
- * NOTE: The component itself is not, and should not, be registered.
7
- *
8
- * @param message the message to be displayed
9
- *
10
- * @returns component for displaying the message in the correct style
11
- */
12
- export declare const MessageControl: (message: string) => JSX.Element;