@abgov/jsonforms-components 1.32.0 → 1.32.2

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
@@ -1,11 +1,12 @@
1
1
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
2
2
  import React, { createContext, useContext, useReducer, useMemo, useEffect, useState, useCallback, useRef } from 'react';
3
- import { GoAFormItem, GoAInput, GoATextArea, GoACallout, GoAInputDate, GoAInputDateTime, GoAInputTime, GoADropdown, GoADropdownItem, GoARadioGroup, GoARadioItem, GoACheckbox, GoAGrid, GoAFormStepper, GoAFormStep, GoAPages, GoAButton, GoAModal, GoAButtonGroup, GoAIconButton, GoAFileUploadInput, GoACircularProgress, GoAContainer, GoADetails } from '@abgov/react-components';
3
+ import { GoAFormItem, GoAInput, GoATextArea, GoACallout, GoAInputDate, GoAInputDateTime, GoAInputTime, GoARadioGroup, GoARadioItem, GoACheckbox, GoAGrid, GoAFormStepper, GoAFormStep, GoAPages, GoAButton, GoAModal, GoAButtonGroup, GoAIconButton, GoAFileUploadInput, GoACircularProgress, GoAContainer, GoADetails } from '@abgov/react-components';
4
4
  import styled from 'styled-components';
5
5
  import axios from 'axios';
6
6
  import get$1 from 'lodash/get';
7
7
  import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, isEnabled, deriveLabelForUISchemaElement, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
8
8
  import { withJsonFormsControlProps, withJsonFormsRendererProps, withJsonFormsEnumProps, withTranslateProps, useJsonForms, JsonFormsDispatch, withJsonFormsLayoutProps, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
9
+ import { isEqual } from 'lodash';
9
10
  import merge from 'lodash/merge';
10
11
  import isEmpty$1 from 'lodash/isEmpty';
11
12
  import range from 'lodash/range';
@@ -1627,9 +1628,9 @@ $$h({ target: 'Object', stat: true, arity: 2, forced: Object.assign !== assign }
1627
1628
  assign: assign
1628
1629
  });
1629
1630
 
1630
- let _$7 = t => t,
1631
- _t$7;
1632
- const FormFieldWrapper = styled.div(_t$7 || (_t$7 = _$7`
1631
+ let _$8 = t => t,
1632
+ _t$8;
1633
+ const FormFieldWrapper = styled.div(_t$8 || (_t$8 = _$8`
1633
1634
  margin-bottom: var(--goa-space-l);
1634
1635
  `));
1635
1636
 
@@ -2717,16 +2718,16 @@ const onChangeForNumericControl = props => {
2717
2718
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2718
2719
  const onChangeForCheckboxData = (data, name, value) => data ? !value ? data === null || data === void 0 ? void 0 : data.filter(item => item !== name) : [...data, name] : [name];
2719
2720
 
2720
- let _$6 = t => t,
2721
- _t$6,
2722
- _t2$3;
2723
- styled.div(_t$6 || (_t$6 = _$6`
2721
+ let _$7 = t => t,
2722
+ _t$7,
2723
+ _t2$4;
2724
+ styled.div(_t$7 || (_t$7 = _$7`
2724
2725
  height: 70vh;
2725
2726
  overflow-y: auto;
2726
2727
  padding-left: var(--goa-space-2xs);
2727
2728
  padding-right: var(--goa-space-2xs);
2728
2729
  `));
2729
- const Visible = styled.div(_t2$3 || (_t2$3 = _$6`
2730
+ const Visible = styled.div(_t2$4 || (_t2$4 = _$7`
2730
2731
  display: ${0};
2731
2732
  `), p => p.visible ? 'initial' : 'none');
2732
2733
 
@@ -3469,7 +3470,7 @@ const JsonFormRegisterProvider = ({
3469
3470
  return [];
3470
3471
  },
3471
3472
  fetchErrors: criteria => {
3472
- var _a;
3473
+ var _a, _b;
3473
3474
  if (criteria === null || criteria === void 0 ? void 0 : criteria.url) {
3474
3475
  const matchFound = registers === null || registers === void 0 ? void 0 : registers.registerData.some(listItem => {
3475
3476
  var _a;
@@ -3480,7 +3481,7 @@ const JsonFormRegisterProvider = ({
3480
3481
  });
3481
3482
  return matchFound ? '' : `${((_a = registers.errors[criteria === null || criteria === void 0 ? void 0 : criteria.url]) === null || _a === void 0 ? void 0 : _a.message) || ''}`;
3482
3483
  } else if (criteria === null || criteria === void 0 ? void 0 : criteria.urn) {
3483
- if (registers === null || registers === void 0 ? void 0 : registers.nonExistent) {
3484
+ if (((_b = registers === null || registers === void 0 ? void 0 : registers.nonExistent) === null || _b === void 0 ? void 0 : _b.length) > 0) {
3484
3485
  const matchFound = registers === null || registers === void 0 ? void 0 : registers.nonExistent.some(listItem => {
3485
3486
  var _a;
3486
3487
  if ((_a = criteria === null || criteria === void 0 ? void 0 : criteria.urn) === null || _a === void 0 ? void 0 : _a.toString().includes(listItem)) {
@@ -4211,13 +4212,127 @@ const GoATimeControl = props => jsx(GoAInputBaseControl, Object.assign({}, props
4211
4212
  const GoATimeControlTester = rankWith(4, isTimeControl);
4212
4213
  const GoAInputTimeControl = withJsonFormsControlProps(GoATimeControl);
4213
4214
 
4215
+ let _$6 = t => t,
4216
+ _t$6,
4217
+ _t2$3,
4218
+ _t3$3,
4219
+ _t4$2;
4220
+ styled.div(_t$6 || (_t$6 = _$6`
4221
+ text-overflow: ellipsis;
4222
+ overflow: hidden;
4223
+ min-height: 43px;
4224
+ box-sizing: border-box;
4225
+ width: 100%;
4226
+ padding: 8px;
4227
+ padding-right: 8px;
4228
+ border-radius: 4px;
4229
+ border: 1px solid #666;
4230
+ font-size: 18px;
4231
+ font-weight: 400;
4232
+ -webkit-appearance: none;
4233
+ -moz-appearance: none;
4234
+ appearance: none;
4235
+ box-shadow: ${0};
4236
+ `), p => p.isOpen ? `0 0 0 3px #feba35` : '');
4237
+ const GoADropdownListContainerWrapper = styled.div(_t2$3 || (_t2$3 = _$6`
4238
+ position: relative;
4239
+ display: ${0};
4240
+ `), p => !(p === null || p === void 0 ? void 0 : p.isOpen) && 'none');
4241
+ const GoADropdownListContainer = styled.div(_t3$3 || (_t3$3 = _$6`
4242
+ border: solid 1px #dcdcdc;
4243
+ border-radius: 4px;
4244
+ background: #fff;
4245
+ padding: 0;
4246
+ margin-top: 3px;
4247
+ width: 100%;
4248
+ overflow-y: auto;
4249
+ z-index: 1000;
4250
+ position: absolute;
4251
+ line-height: 2rem;
4252
+ max-height: ${0};
4253
+ `), p => p.optionListMaxHeight || '272px');
4254
+ const GoADropdownListOption = styled.div(_t4$2 || (_t4$2 = _$6`
4255
+ padding: 4px 12px;
4256
+ text-overflow: ellipsis;
4257
+ color: ${0} !important;
4258
+ border: 1px solid #f1f1f1;
4259
+ z-index: 1001;
4260
+ background: ${0};
4261
+ &:hover {
4262
+ background-color: ${0};
4263
+ color: ${0} !important;
4264
+ }
4265
+ `), p => p.isSelected ? 'white' : 'var(--goa-color-greyscale-black)', p => p.isSelected ? 'var(--goa-color-interactive-default)' : '#fff', p => p.isSelected ? 'var(--goa-color-interactive-default)' : '#f1f1f1', p => p.isSelected ? 'white' : '#333');
4266
+ const Dropdown = props => {
4267
+ const {
4268
+ label,
4269
+ selected,
4270
+ onChange,
4271
+ optionListMaxHeight,
4272
+ isAutocompletion,
4273
+ id
4274
+ } = props;
4275
+ const [isOpen, setIsOpen] = useState(false);
4276
+ const [selectedOption, setSelectedOption] = useState(selected);
4277
+ const trailingIcon = isOpen ? 'chevron-up' : 'chevron-down';
4278
+ const [items, setItems] = useState(props.items);
4279
+ const [inputText, setInputText] = useState(selected);
4280
+ useEffect(() => {
4281
+ setItems(props.items);
4282
+ }, [isEqual(props.items, items)]);
4283
+ return jsxs("div", {
4284
+ "data-testid": id,
4285
+ children: [jsx(GoAInput, {
4286
+ name: `dropdown-${label}`,
4287
+ width: "100%",
4288
+ value: inputText,
4289
+ testId: `${id}-input`,
4290
+ id: `${id}-input`,
4291
+ readonly: !isAutocompletion,
4292
+ onChange: (name, value) => {
4293
+ if (isAutocompletion) {
4294
+ setIsOpen(true);
4295
+ const selectedItems = props.items.filter(item => {
4296
+ return item.label.includes(value);
4297
+ });
4298
+ setItems(selectedItems);
4299
+ }
4300
+ },
4301
+ trailingIcon: trailingIcon,
4302
+ onFocus: () => {
4303
+ setIsOpen(!isOpen);
4304
+ }
4305
+ }), jsx(GoADropdownListContainerWrapper, {
4306
+ isOpen: isOpen,
4307
+ children: jsx(GoADropdownListContainer, {
4308
+ optionListMaxHeight: optionListMaxHeight,
4309
+ children: items.map(item => {
4310
+ return jsx(GoADropdownListOption, {
4311
+ isSelected: item.value === selected,
4312
+ children: jsx("div", {
4313
+ "data-testid": `${id}-${item.label}-option`,
4314
+ onClick: () => {
4315
+ onChange(item.value);
4316
+ setSelectedOption(item.value);
4317
+ setInputText(item.value);
4318
+ setIsOpen(false);
4319
+ },
4320
+ children: item.label
4321
+ }, `jsonforms-dropdown-${label}-${item.value}`)
4322
+ });
4323
+ })
4324
+ })
4325
+ })]
4326
+ });
4327
+ };
4328
+
4214
4329
  function fetchRegisterConfigFromOptions(options) {
4215
4330
  if (!(options === null || options === void 0 ? void 0 : options.url) && !(options === null || options === void 0 ? void 0 : options.urn)) return undefined;
4216
4331
  const config = Object.assign({}, options);
4217
4332
  return config;
4218
4333
  }
4219
4334
  const EnumSelect = props => {
4220
- var _a, _b, _c, _d, _e;
4335
+ var _a, _b, _c, _d;
4221
4336
  const {
4222
4337
  data,
4223
4338
  id,
@@ -4242,9 +4357,8 @@ const EnumSelect = props => {
4242
4357
  error = (registerCtx === null || registerCtx === void 0 ? void 0 : registerCtx.fetchErrors(registerConfig)) || '';
4243
4358
  }
4244
4359
  const autocompletion = ((_d = (_c = props.uischema) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.autocomplete) === true;
4245
- const appliedUiSchemaOptions = merge({}, config, props.uischema.options);
4246
4360
  const mergedOptions = useMemo(() => {
4247
- const newOptions = [...(options || []), ...registerData.map(d => {
4361
+ const newOptions = [...(options || []), ...((registerData === null || registerData === void 0 ? void 0 : registerData.map(d => {
4248
4362
  if (typeof d === 'string') {
4249
4363
  return {
4250
4364
  value: d,
@@ -4253,7 +4367,7 @@ const EnumSelect = props => {
4253
4367
  } else {
4254
4368
  return Object.assign({}, d);
4255
4369
  }
4256
- })];
4370
+ })) || [])];
4257
4371
  const hasNonEmptyOptions = newOptions.some(option => option.value !== '');
4258
4372
  if (!hasNonEmptyOptions && newOptions.length === 1 && newOptions[0].value === '') {
4259
4373
  return newOptions;
@@ -4266,6 +4380,7 @@ const EnumSelect = props => {
4266
4380
  }
4267
4381
  return newOptions.filter(option => option.value !== '');
4268
4382
  }, [registerData, options]);
4383
+ console.log(mergedOptions);
4269
4384
  useEffect(() => {
4270
4385
  if (registerConfig) {
4271
4386
  registerCtx === null || registerCtx === void 0 ? void 0 : registerCtx.fetchRegisterByUrl(registerConfig);
@@ -4274,25 +4389,16 @@ const EnumSelect = props => {
4274
4389
  return jsx("div", {
4275
4390
  children: error.length > 0 ? callout({
4276
4391
  message: error
4277
- }) : jsx(GoADropdown, Object.assign({
4278
- name: `${label}`,
4279
- value: data,
4280
- disabled: !enabled,
4281
- relative: true,
4282
- filterable: autocompletion,
4283
- testId: `${id || label}-jsonform`
4284
- }, appliedUiSchemaOptions, {
4285
- onChange: (name, value) => {
4392
+ }) : jsx(Dropdown, {
4393
+ items: mergedOptions,
4394
+ selected: data,
4395
+ id: `jsonforms-${label}-dropdown`,
4396
+ label: label,
4397
+ isAutocompletion: autocompletion,
4398
+ onChange: value => {
4286
4399
  handleChange(path, value);
4287
4400
  }
4288
- }, (_e = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _e === void 0 ? void 0 : _e.componentProps, {
4289
- children: mergedOptions === null || mergedOptions === void 0 ? void 0 : mergedOptions.map(item => {
4290
- return jsx(GoADropdownItem, {
4291
- value: `${item.value}`,
4292
- label: `${item.label}`
4293
- }, `json-form-dropdown-${item.value}`);
4294
- })
4295
- }), `${id}-jsonform-key`)
4401
+ })
4296
4402
  });
4297
4403
  };
4298
4404
  const enumControl = props => {
@@ -4869,7 +4975,7 @@ class ContextProviderClass {
4869
4975
  this.enumValues.set(key, () => data);
4870
4976
  };
4871
4977
  this.setup = props => {
4872
- var _a, _b, _c;
4978
+ var _a, _b;
4873
4979
  this.selfProps = props;
4874
4980
  if (props.fileManagement) {
4875
4981
  const {
@@ -4892,17 +4998,17 @@ class ContextProviderClass {
4892
4998
  }
4893
4999
  if (props.data) {
4894
5000
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4895
- (_a = props.data) === null || _a === void 0 ? void 0 : _a.forEach(item => {
4896
- this.enumValues.set(Object.keys(item)[0], () => item);
5001
+ Object.keys(props.data).forEach(item => {
5002
+ this.enumValues.set(item, () => props.data[item]);
4897
5003
  });
4898
5004
  }
4899
5005
  if (!props.children) {
4900
5006
  return null;
4901
5007
  }
4902
- this.baseEnumerator.isFormSubmitted = (_b = props.isFormSubmitted) !== null && _b !== void 0 ? _b : false;
5008
+ this.baseEnumerator.isFormSubmitted = (_a = props.isFormSubmitted) !== null && _a !== void 0 ? _a : false;
4903
5009
  return jsx(JsonFormContext.Provider, {
4904
5010
  value: this.baseEnumerator,
4905
- children: (_c = this.selfProps) === null || _c === void 0 ? void 0 : _c.children
5011
+ children: (_b = this.selfProps) === null || _b === void 0 ? void 0 : _b.children
4906
5012
  });
4907
5013
  };
4908
5014
  this.getContextProvider = () => {
@@ -4925,8 +5031,6 @@ class ContextProviderClass {
4925
5031
  * Grabs data stored under a given key
4926
5032
  *
4927
5033
  */
4928
- // FIXME give some clue as to what data is being fetched.
4929
- // e.g.is it getFormContextData?
4930
5034
  this.getFormContextData = key => {
4931
5035
  const dataFunction = this.baseEnumerator.data.get(key);
4932
5036
  return dataFunction && dataFunction();
@@ -5412,6 +5516,7 @@ const FileUploader = _a => {
5412
5516
  const fileListValue = enumerators.data.get('file-list');
5413
5517
  const countries = ['Argentina', 'Brazil', 'Canada', 'Denmark', 'Egypt', 'France', 'Greece', 'India', 'Japan', 'Kenya'];
5414
5518
  enumerators.addFormContextData('countries', countries);
5519
+ const user = enumerators === null || enumerators === void 0 ? void 0 : enumerators.getFormContextData('user');
5415
5520
  // eslint-disable-next-line
5416
5521
  const fileList = fileListValue && fileListValue();
5417
5522
  const {
@@ -5460,7 +5565,7 @@ const FileUploader = _a => {
5460
5565
  const timeoutId = setTimeout(delayedFunction, 1);
5461
5566
  return () => clearTimeout(timeoutId);
5462
5567
  }, [handleChange, fileList, propertyId]);
5463
- const readOnly = ((_d = (_c = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _c === void 0 ? void 0 : _c.componentProps) === null || _d === void 0 ? void 0 : _d.readOnly) === true || (props === null || props === void 0 ? void 0 : props.isStepperReview) === true;
5568
+ const readOnly = ((_d = (_c = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _c === void 0 ? void 0 : _c.componentProps) === null || _d === void 0 ? void 0 : _d.readOnly) === true || (props === null || props === void 0 ? void 0 : props.isStepperReview) === true || user === null;
5464
5569
  const maxFileSize = (_g = (_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.maxFileSize) !== null && _g !== void 0 ? _g : '';
5465
5570
  const accept = (_k = (_j = (_h = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _h === void 0 ? void 0 : _h.componentProps) === null || _j === void 0 ? void 0 : _j.accept) !== null && _k !== void 0 ? _k : '';
5466
5571
  return jsxs(FileUploaderStyle, {
@@ -6603,7 +6708,8 @@ const GoAGroupControlComponent = props => {
6603
6708
  enabled,
6604
6709
  renderers,
6605
6710
  cells,
6606
- visible
6711
+ visible,
6712
+ isStepperReview
6607
6713
  } = props;
6608
6714
  const group = uischema;
6609
6715
  return jsxs(Visible, {
@@ -6627,7 +6733,9 @@ const GoAGroupControlComponent = props => {
6627
6733
  }), !((_o = group.options) === null || _o === void 0 ? void 0 : _o.componentProps) && jsxs("div", {
6628
6734
  children: [group.label && jsx("h3", {
6629
6735
  children: group.label
6630
- }), jsx(GoAContainer, {
6736
+ }), isStepperReview && jsx(Fragment, {
6737
+ children: renderLayoutElements(group.elements, schema, path, enabled, renderers, cells)
6738
+ }), !isStepperReview && jsx(GoAContainer, {
6631
6739
  children: renderLayoutElements(group.elements, schema, path, enabled, renderers, cells)
6632
6740
  })]
6633
6741
  })]
@@ -6984,6 +7092,14 @@ const GoAErrorControlTester = rankWith(1000, (uischema, schema, context) => {
6984
7092
  });
6985
7093
  var GoAErrorControl = withJsonFormsControlProps(ErrorControl);
6986
7094
 
7095
+ const GoAGroupReviewControlComponent = props => {
7096
+ return jsx(GoAGroupControlComponent, Object.assign({}, props, {
7097
+ isStepperReview: true
7098
+ }));
7099
+ };
7100
+ const GoAGroupReviewLayoutTester = rankWith(1, uiTypeIs('Group'));
7101
+ const GoAGroupReviewControl = withJsonFormsLayoutProps(GoAGroupReviewControlComponent, true);
7102
+
6987
7103
  const createDefaultAjv = (...schemas) => {
6988
7104
  const ajv = new Ajv({
6989
7105
  allErrors: true,
@@ -8312,8 +8428,8 @@ const GoABaseReviewRenderers = [
8312
8428
  tester: GoAlVerticalLayoutTester,
8313
8429
  renderer: GoAVerticalLayout
8314
8430
  }, {
8315
- tester: GoAGroupLayoutTester,
8316
- renderer: GoAGroupControl
8431
+ tester: GoAGroupReviewLayoutTester,
8432
+ renderer: GoAGroupReviewControl
8317
8433
  }, {
8318
8434
  tester: HelpContentTester,
8319
8435
  renderer: HelpReviewContent
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.32.0",
3
+ "version": "1.32.2",
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,15 @@
1
+ export interface Item {
2
+ label: string;
3
+ value: string;
4
+ }
5
+ interface DropdownProps {
6
+ items: Array<Item>;
7
+ label: string;
8
+ selected: string;
9
+ optionListMaxHeight?: string;
10
+ onChange: (value: string) => void;
11
+ isAutocompletion?: boolean;
12
+ id?: string;
13
+ }
14
+ export declare const Dropdown: (props: DropdownProps) => JSX.Element;
15
+ export {};
@@ -1,5 +1,8 @@
1
1
  import React from 'react';
2
2
  import { LayoutProps, RankedTester } from '@jsonforms/core';
3
- export declare const GoAGroupControlComponent: (props: LayoutProps) => JSX.Element;
3
+ export interface withIsStepper {
4
+ isStepperReview: boolean;
5
+ }
6
+ export declare const GoAGroupControlComponent: (props: LayoutProps & withIsStepper) => JSX.Element;
4
7
  export declare const GoAGroupLayoutTester: RankedTester;
5
- export declare const GoAGroupControl: React.ComponentType<LayoutProps & import("@jsonforms/core").OwnPropsOfLayout>;
8
+ export declare const GoAGroupControl: React.ComponentType<LayoutProps & withIsStepper & import("@jsonforms/core").OwnPropsOfLayout>;
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ import { LayoutProps, RankedTester } from '@jsonforms/core';
3
+ export declare const GoAGroupReviewControlComponent: (props: LayoutProps) => JSX.Element;
4
+ export declare const GoAGroupReviewLayoutTester: RankedTester;
5
+ export declare const GoAGroupReviewControl: React.ComponentType<LayoutProps & import("@jsonforms/core").OwnPropsOfLayout>;