@abgov/jsonforms-components 2.40.0 → 2.41.0

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.
Files changed (2) hide show
  1. package/index.esm.js +35 -8
  2. package/package.json +2 -2
package/index.esm.js CHANGED
@@ -14,7 +14,7 @@ import isEmpty from 'lodash/isEmpty';
14
14
  import range from 'lodash/range';
15
15
  import pluralize from 'pluralize';
16
16
  import { evaluateSync, compileSync } from '@mdx-js/mdx';
17
- import { Parser } from 'expr-eval';
17
+ import { Parser } from 'expr-eval-fork';
18
18
  import Ajv from 'ajv';
19
19
  import addErrors from 'ajv-errors';
20
20
  import addFormats from 'ajv-formats';
@@ -6601,8 +6601,32 @@ const CheckBoxGroupDiv = styled.div(_t$8 || (_t$8 = _$8`
6601
6601
  }
6602
6602
  `));
6603
6603
 
6604
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
6605
+ const getEnumOptions = schema => {
6606
+ var _a, _b;
6607
+ if (((_a = schema === null || schema === void 0 ? void 0 : schema.items) === null || _a === void 0 ? void 0 : _a.oneOf) && Array.isArray(schema.items.oneOf)) {
6608
+ return schema.items.oneOf;
6609
+ }
6610
+ if ((schema === null || schema === void 0 ? void 0 : schema.oneOf) && Array.isArray(schema.oneOf)) {
6611
+ return schema.oneOf;
6612
+ }
6613
+ const newSchema = schema;
6614
+ return (schema === null || schema === void 0 ? void 0 : schema.enum) || ((_b = newSchema === null || newSchema === void 0 ? void 0 : newSchema.items) === null || _b === void 0 ? void 0 : _b.enum) || [];
6615
+ };
6616
+ const getOptionValue = option => {
6617
+ return typeof option === 'string' ? option : option.const;
6618
+ };
6619
+ const getOptionLabel = option => {
6620
+ if (typeof option === 'string') {
6621
+ return option;
6622
+ }
6623
+ return option.title || option.const;
6624
+ };
6625
+ const getOptionDescription = option => {
6626
+ return typeof option === 'string' ? undefined : option.description;
6627
+ };
6604
6628
  const CheckboxGroup = props => {
6605
- var _a, _b, _c;
6629
+ var _a, _b;
6606
6630
  const {
6607
6631
  data,
6608
6632
  id,
@@ -6615,20 +6639,23 @@ const CheckboxGroup = props => {
6615
6639
  label,
6616
6640
  enabled
6617
6641
  } = props;
6618
- const newSchema = schema;
6619
- const enumData = (schema === null || schema === void 0 ? void 0 : schema.enum) || ((_a = newSchema === null || newSchema === void 0 ? void 0 : newSchema.items) === null || _a === void 0 ? void 0 : _a.enum) || [];
6642
+ const enumOptions = getEnumOptions(schema);
6620
6643
  const appliedUiSchemaOptions = merge({}, config, props.uischema.options, options);
6621
6644
  return jsx(Checkboxes, {
6622
- orientation: ((_b = uischema.options) === null || _b === void 0 ? void 0 : _b.orientation) ? (_c = uischema.options) === null || _c === void 0 ? void 0 : _c.orientation : 'vertical',
6645
+ orientation: ((_a = uischema.options) === null || _a === void 0 ? void 0 : _a.orientation) ? (_b = uischema.options) === null || _b === void 0 ? void 0 : _b.orientation : 'vertical',
6623
6646
  testId: `${label || id}-jsonforms-checkboxes`,
6624
- children: enumData.map(enumValue => {
6647
+ children: enumOptions.map(enumOption => {
6648
+ const enumValue = getOptionValue(enumOption);
6649
+ const enumLabel = getOptionLabel(enumOption);
6650
+ const enumDescription = getOptionDescription(enumOption);
6625
6651
  return jsx(GoACheckbox, Object.assign({
6626
6652
  name: enumValue,
6627
6653
  disabled: !enabled,
6628
6654
  checked: data ? data.includes(enumValue) : false,
6629
6655
  value: `${enumValue}`
6630
6656
  }, appliedUiSchemaOptions, {
6631
- text: enumValue,
6657
+ text: enumLabel,
6658
+ description: enumDescription,
6632
6659
  testId: `${enumValue}-checkbox`,
6633
6660
  onChange: (name, value) => {
6634
6661
  let newData = Array.isArray(data) ? [...data] : [];
@@ -6639,7 +6666,7 @@ const CheckboxGroup = props => {
6639
6666
  }
6640
6667
  handleChange(path, newData.length === 0 ? undefined : newData);
6641
6668
  }
6642
- }));
6669
+ }), enumValue);
6643
6670
  })
6644
6671
  });
6645
6672
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "2.40.0",
3
+ "version": "2.41.0",
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",
@@ -13,7 +13,7 @@
13
13
  "ajv-errors": "^3.0.0",
14
14
  "ajv-formats": "^3.0.1",
15
15
  "@mdx-js/mdx": "^3.1.0",
16
- "expr-eval": "^2.0.2",
16
+ "expr-eval-fork": "^3.0.1",
17
17
  "pluralize": "^8.0.0"
18
18
  },
19
19
  "dependencies": {