@abgov/jsonforms-components 2.28.1 → 2.29.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 +47 -24
  2. package/package.json +1 -1
package/index.esm.js CHANGED
@@ -5,10 +5,10 @@ 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, isEnumControl, isBooleanControl, isControl, schemaMatches, getAjv, isVisible, toDataPath, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, or, isObjectArrayControl, isPrimitiveArrayControl, Paths, hasType, isCategorization, isLayout } from '@jsonforms/core';
8
+ import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isControl, isEnumControl, isBooleanControl, schemaMatches, getAjv, isVisible, toDataPath, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, or, isObjectArrayControl, isPrimitiveArrayControl, Paths, 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
- import { isEqual, isEmpty as isEmpty$1, isObject as isObject$f } from 'lodash';
11
+ import ___default, { isEqual, isEmpty as isEmpty$1, isObject as isObject$f } from 'lodash';
12
12
  import merge from 'lodash/merge';
13
13
  import isEmpty from 'lodash/isEmpty';
14
14
  import range from 'lodash/range';
@@ -6367,7 +6367,7 @@ function fetchRegisterConfigFromOptions(options) {
6367
6367
  return config;
6368
6368
  }
6369
6369
  const EnumSelect = props => {
6370
- var _a, _b, _c, _d, _e, _f;
6370
+ var _a, _b, _c, _d, _e, _f, _g, _h;
6371
6371
  const {
6372
6372
  data,
6373
6373
  enabled,
@@ -6378,18 +6378,20 @@ const EnumSelect = props => {
6378
6378
  uischema,
6379
6379
  required,
6380
6380
  setIsVisited,
6381
- isVisited
6381
+ isVisited,
6382
+ schema
6382
6383
  } = props;
6383
6384
  const registerCtx = useContext(JsonFormsRegisterContext);
6384
6385
  const registerConfig = fetchRegisterConfigFromOptions((_b = (_a = props.uischema) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.register);
6385
- // eslint-disable-next-line react-hooks/exhaustive-deps
6386
+ const labelPath = ((_c = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _c === void 0 ? void 0 : _c.label) || 'label';
6387
+ const valuePath = ((_d = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _d === void 0 ? void 0 : _d.value) || 'value';
6386
6388
  let registerData = [];
6387
6389
  let error = '';
6388
6390
  if (registerConfig) {
6389
6391
  registerData = registerCtx === null || registerCtx === void 0 ? void 0 : registerCtx.selectRegisterData(registerConfig);
6390
6392
  error = (registerCtx === null || registerCtx === void 0 ? void 0 : registerCtx.fetchErrors(registerConfig)) || '';
6391
6393
  }
6392
- const autoCompletion = ((_d = (_c = props.uischema) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.autoComplete) === true;
6394
+ const autoCompletion = ((_f = (_e = props.uischema) === null || _e === void 0 ? void 0 : _e.options) === null || _f === void 0 ? void 0 : _f.autoComplete) === true;
6393
6395
  const mergedOptions = useMemo(() => {
6394
6396
  const newOptions = [...(options || []), ...((registerData === null || registerData === void 0 ? void 0 : registerData.map(d => {
6395
6397
  if (typeof d === 'string') {
@@ -6397,9 +6399,16 @@ const EnumSelect = props => {
6397
6399
  value: d,
6398
6400
  label: d
6399
6401
  };
6400
- } else {
6401
- return Object.assign({}, d);
6402
+ } else if (typeof d === 'object' && d !== null) {
6403
+ return {
6404
+ value: ___default.get(d, valuePath) || '',
6405
+ label: ___default.get(d, labelPath) || ''
6406
+ };
6402
6407
  }
6408
+ return {
6409
+ label: '',
6410
+ value: ''
6411
+ };
6403
6412
  })) || [])];
6404
6413
  const hasNonEmptyOptions = newOptions.some(option => option.value !== '');
6405
6414
  if (!hasNonEmptyOptions && newOptions.length === 1 && newOptions[0].value === '') {
@@ -6413,7 +6422,7 @@ const EnumSelect = props => {
6413
6422
  }
6414
6423
  return newOptions.filter(option => option.value !== '');
6415
6424
  }, [registerData, options]);
6416
- const width = ((_f = (_e = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _e === void 0 ? void 0 : _e.componentProps) === null || _f === void 0 ? void 0 : _f.width) || '100%';
6425
+ const width = ((_h = (_g = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _g === void 0 ? void 0 : _g.componentProps) === null || _h === void 0 ? void 0 : _h.width) || '100%';
6417
6426
  useEffect(() => {
6418
6427
  if (registerConfig) {
6419
6428
  registerCtx === null || registerCtx === void 0 ? void 0 : registerCtx.fetchRegisterByUrl(registerConfig);
@@ -6425,13 +6434,19 @@ const EnumSelect = props => {
6425
6434
  }) : jsx(Dropdown, {
6426
6435
  items: mergedOptions,
6427
6436
  enabled: enabled,
6428
- selected: data,
6437
+ selected: typeof data === 'object' ? ___default.get(data, valuePath) : data,
6429
6438
  width: width,
6430
6439
  id: `jsonforms-${label}-dropdown`,
6431
6440
  label: label,
6432
6441
  isAutoCompletion: autoCompletion,
6433
6442
  onChange: value => {
6434
- handleChange(path, value);
6443
+ if (schema.type === 'object') {
6444
+ handleChange(path, registerData.find(o => {
6445
+ return ___default.get(o, valuePath) === value;
6446
+ }));
6447
+ } else {
6448
+ handleChange(path, value);
6449
+ }
6435
6450
  }
6436
6451
  }, `jsonforms-${label}-dropdown`)
6437
6452
  });
@@ -6441,8 +6456,10 @@ const enumControl = props => {
6441
6456
  input: EnumSelect
6442
6457
  }));
6443
6458
  };
6444
- const GoAEnumControlTester = rankWith(2, isEnumControl);
6445
- // HOC order can be reversed with https://github.com/eclipsesource/jsonforms/issues/1987
6459
+ const GoAEnumControlTester = rankWith(4, (uischema, schema, context) => {
6460
+ var _a;
6461
+ 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);
6462
+ });
6446
6463
  const GoAEnumControl = withJsonFormsEnumProps(withTranslateProps(enumControl), true);
6447
6464
 
6448
6465
  const RadioGroup = props => {
@@ -8450,15 +8467,26 @@ const TaskList = ({
8450
8467
  children: [sectionTitle && showInTaskListList[globalIndex] && jsx(SectionHeaderRow, {
8451
8468
  title: sectionTitle,
8452
8469
  index: sectionIndex++
8453
- }, `section-${sectionTitle}`), group.map(category => {
8454
- const showGroupTaskListList = categories.map(cat => {
8455
- var _a, _b, _c, _d;
8456
- return ((_b = (_a = cat === null || cat === void 0 ? void 0 : cat.uischema) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.showInTaskList) || ((_d = (_c = cat === null || cat === void 0 ? void 0 : cat.uischema) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.showInTaskList) === undefined;
8457
- });
8470
+ }, `section-${sectionTitle}`), group.map((category, groupIndex) => {
8471
+ //eslint-disable-next-line
8472
+ const shouldShow = cat => {
8473
+ var _a, _b;
8474
+ return ((_b = (_a = cat === null || cat === void 0 ? void 0 : cat.uischema) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.showInTaskList) !== false;
8475
+ };
8476
+ let leftIndex = groupIndex;
8477
+ while (leftIndex > 0 && !shouldShow(group[leftIndex - 1])) {
8478
+ leftIndex--;
8479
+ }
8480
+ let rightIndex = groupIndex;
8481
+ while (rightIndex < group.length - 1 && !shouldShow(group[rightIndex + 1])) {
8482
+ rightIndex++;
8483
+ }
8484
+ const currentLocalGroup = group.slice(leftIndex, rightIndex + 1);
8485
+ const showGroupTaskListList = categories.map(cat => shouldShow(cat));
8458
8486
  const showCurrent = showInTaskListList[globalIndex];
8459
8487
  const index = globalIndex++;
8460
8488
  const modifyCategory = JSON.parse(JSON.stringify(category));
8461
- modifyCategory.isCompleted = group.length === group.filter(category => category.isCompleted).length;
8489
+ modifyCategory.isCompleted = currentLocalGroup.length === currentLocalGroup.filter(category => category.isCompleted).length;
8462
8490
  let currentCategory = category;
8463
8491
  if (showGroupTaskListList.length > showGroupTaskListList.filter(item => item === true).length) {
8464
8492
  currentCategory = modifyCategory;
@@ -8592,11 +8620,6 @@ const BackButtonWrapper = styled.span(_t$5 || (_t$5 = _$5`
8592
8620
 
8593
8621
  .back-link {
8594
8622
  margin-top: var(--goa-space-m);
8595
- color: #0070c4;
8596
- text-decoration: underline;
8597
- text-underline-offset: 2px;
8598
- text-decoration-color: currentColor;
8599
- display: inline-block;
8600
8623
  }
8601
8624
  display: inline-block;
8602
8625
  color: #0070c4;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "2.28.1",
3
+ "version": "2.29.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",