@abgov/jsonforms-components 1.9.0 → 1.10.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
@@ -4,11 +4,9 @@ import { GoACallout, GoAInputDate, GoAFormItem, GoAInput, GoATextArea, GoAInputD
4
4
  import styled from 'styled-components';
5
5
  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';
6
6
  import { withJsonFormsRendererProps, withJsonFormsControlProps, withJsonFormsEnumProps, withTranslateProps, withJsonFormsLayoutProps, JsonFormsDispatch, useJsonForms, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
7
- import React, { createContext, useEffect, useState, useMemo, useContext, useCallback } from 'react';
7
+ import React, { createContext, useEffect, useContext, useState, useMemo, useCallback } from 'react';
8
8
  import merge from 'lodash/merge';
9
9
  import axios from 'axios';
10
- import TextField from '@mui/material/TextField';
11
- import Autocomplete from '@mui/material/Autocomplete';
12
10
  import isEmpty from 'lodash/isEmpty';
13
11
  import range from 'lodash/range';
14
12
  import Ajv from 'ajv';
@@ -3279,14 +3277,16 @@ function addDataByOptions(key, url, location, type, values) {
3279
3277
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3280
3278
  const enumValues = new Map();
3281
3279
  const enumFunctions = new Map();
3280
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3281
+ const enumSubmitFunctions = new Map();
3282
3282
  const baseEnumerator = {
3283
3283
  data: enumValues,
3284
- functions: enumFunctions
3284
+ functions: enumFunctions,
3285
+ submitFunction: enumSubmitFunctions
3285
3286
  };
3286
3287
  const JsonFormContext = /*#__PURE__*/createContext(baseEnumerator);
3287
3288
  function ContextProvider(props) {
3288
3289
  var _a;
3289
- React.useContext(JsonFormContext);
3290
3290
  if (props.fileManagement) {
3291
3291
  const {
3292
3292
  fileList,
@@ -3303,6 +3303,13 @@ function ContextProvider(props) {
3303
3303
  enumFunctions.set('download-file', () => downloadFileFunction);
3304
3304
  enumFunctions.set('delete-file', () => deleteFileFunction);
3305
3305
  }
3306
+ if (props.submit) {
3307
+ const {
3308
+ submitForm
3309
+ } = props.submit;
3310
+ const submitFunction = submitForm ? submitForm : () => {};
3311
+ enumSubmitFunctions.set('submit-form', () => submitFunction);
3312
+ }
3306
3313
  if (props.data) {
3307
3314
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
3308
3315
  (_a = props.data) === null || _a === void 0 ? void 0 : _a.forEach(item => {
@@ -3409,13 +3416,14 @@ const GoAEnumControlTester = rankWith(2, isEnumControl);
3409
3416
  const GoAEnumControl = withJsonFormsEnumProps(withTranslateProps(numControl), true);
3410
3417
 
3411
3418
  const EnumSelectAutoComplete = props => {
3412
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
3419
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
3413
3420
  const {
3414
3421
  data,
3415
3422
  schema,
3416
3423
  path,
3417
3424
  handleChange,
3418
- uischema
3425
+ uischema,
3426
+ label
3419
3427
  } = props;
3420
3428
  let enumData = (schema === null || schema === void 0 ? void 0 : schema.enum) || [];
3421
3429
  const dataKey = (_b = (_a = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _a === void 0 ? void 0 : _a.enumContext) === null || _b === void 0 ? void 0 : _b.key;
@@ -3423,11 +3431,6 @@ const EnumSelectAutoComplete = props => {
3423
3431
  const location = (_f = (_e = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _e === void 0 ? void 0 : _e.enumContext) === null || _f === void 0 ? void 0 : _f.location;
3424
3432
  const type = (_h = (_g = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _g === void 0 ? void 0 : _g.enumContext) === null || _h === void 0 ? void 0 : _h.type;
3425
3433
  const values = (_k = (_j = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _j === void 0 ? void 0 : _j.enumContext) === null || _k === void 0 ? void 0 : _k.values;
3426
- const defaultProps = {
3427
- options: enumData,
3428
- getOptionLabel: option => option
3429
- };
3430
- const [inputValue, setInputValue] = React.useState('');
3431
3434
  useEffect(() => {
3432
3435
  if (dataKey && url) {
3433
3436
  addDataByOptions(dataKey, url, location, type, values);
@@ -3437,25 +3440,34 @@ const EnumSelectAutoComplete = props => {
3437
3440
  const newData = getData(dataKey);
3438
3441
  // eslint-disable-next-line
3439
3442
  enumData = newData;
3440
- defaultProps.options = enumData;
3441
3443
  }
3442
- return jsx(Autocomplete, Object.assign({}, defaultProps, {
3443
- id: "autocomplete",
3444
- getOptionLabel: option => option,
3445
- isOptionEqualToValue: (option, value) => option.id === value.id,
3446
- value: data || null,
3447
- onChange: (name, value) => {
3448
- handleChange(path, value);
3449
- setInputValue(value);
3450
- },
3451
- renderInput: params => {
3452
- return jsx(TextField, Object.assign({}, params, {
3453
- variant: "outlined",
3454
- size: "small",
3455
- placeholder: schema === null || schema === void 0 ? void 0 : schema.description
3456
- }));
3457
- }
3458
- }));
3444
+ const readOnly = (_o = (_m = (_l = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _l === void 0 ? void 0 : _l.componentProps) === null || _m === void 0 ? void 0 : _m.readOnly) !== null && _o !== void 0 ? _o : false;
3445
+ return jsx("div", {
3446
+ children: readOnly ? jsx("div", {
3447
+ children: jsx(GoADropdown, {
3448
+ disabled: true,
3449
+ placeholder: data,
3450
+ onChange: () => {}
3451
+ })
3452
+ }) : jsx(GoADropdown, {
3453
+ value: data,
3454
+ onChange: (name, value) => {
3455
+ handleChange(path, value);
3456
+ },
3457
+ testId: `autocomplete-dropdown-${label}`,
3458
+ id: `autocomplete-dropdown-${label}`,
3459
+ width: "100%",
3460
+ filterable: true,
3461
+ relative: true,
3462
+ ariaLabel: label,
3463
+ children: enumData === null || enumData === void 0 ? void 0 : enumData.map(item => {
3464
+ return jsx(GoADropdownItem, {
3465
+ value: item,
3466
+ label: item
3467
+ }, `autocomplete-${item}`);
3468
+ })
3469
+ })
3470
+ });
3459
3471
  };
3460
3472
  const numControlAutoComplete = props => {
3461
3473
  return jsx(GoAInputBaseControl, Object.assign({}, props, {
@@ -3622,6 +3634,38 @@ const BooleanRadioControl = props => jsx(GoAInputBaseControl, Object.assign({},
3622
3634
  const GoABooleanRadioControlTester = rankWith(3, and(isBooleanControl, optionIs('radio', true)));
3623
3635
  const GoABooleanRadioControl = withJsonFormsControlProps(BooleanRadioControl);
3624
3636
 
3637
+ /******************************************************************************
3638
+ Copyright (c) Microsoft Corporation.
3639
+
3640
+ Permission to use, copy, modify, and/or distribute this software for any
3641
+ purpose with or without fee is hereby granted.
3642
+
3643
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
3644
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
3645
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
3646
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
3647
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
3648
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
3649
+ PERFORMANCE OF THIS SOFTWARE.
3650
+ ***************************************************************************** */
3651
+
3652
+ function __rest(s, e) {
3653
+ var t = {};
3654
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
3655
+ t[p] = s[p];
3656
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
3657
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
3658
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
3659
+ t[p[i]] = s[p[i]];
3660
+ }
3661
+ return t;
3662
+ }
3663
+
3664
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
3665
+ var e = new Error(message);
3666
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
3667
+ };
3668
+
3625
3669
  let _$5 = t => t,
3626
3670
  _t$5,
3627
3671
  _t2$3;
@@ -3676,7 +3720,7 @@ const GridItem = styled.div(_t2$3 || (_t2$3 = _$5`
3676
3720
  let _$4 = t => t,
3677
3721
  _t$4,
3678
3722
  _t2$2,
3679
- _t3$1,
3723
+ _t3$2,
3680
3724
  _t4$1,
3681
3725
  _t5,
3682
3726
  _t6,
@@ -3699,7 +3743,7 @@ const ReviewItemSection = styled.div(_t2$2 || (_t2$2 = _$4`
3699
3743
  border: 1px solid #dcdcdc;
3700
3744
  border-radius: 5px;
3701
3745
  `));
3702
- const ReviewItemHeader = styled.div(_t3$1 || (_t3$1 = _$4`
3746
+ const ReviewItemHeader = styled.div(_t3$2 || (_t3$2 = _$4`
3703
3747
  display: flex;
3704
3748
  align-items: center;
3705
3749
  justify-content: space-between;
@@ -3865,20 +3909,26 @@ requiredFields) => elements.map((element, index) => {
3865
3909
  return null;
3866
3910
  });
3867
3911
 
3868
- const FormStepper = ({
3869
- uischema,
3870
- data,
3871
- schema,
3872
- // eslint-disable-next-line
3873
- ajv,
3874
- path,
3875
- cells,
3876
- renderers,
3877
- config,
3878
- visible,
3879
- enabled,
3880
- t
3881
- }) => {
3912
+ const FormStepper = _a => {
3913
+ var _b, _c, _d;
3914
+ var {
3915
+ uischema,
3916
+ data,
3917
+ schema,
3918
+ // eslint-disable-next-line
3919
+ ajv,
3920
+ path,
3921
+ cells,
3922
+ renderers,
3923
+ config,
3924
+ visible,
3925
+ enabled,
3926
+ t
3927
+ } = _a;
3928
+ __rest(_a, ["uischema", "data", "schema", "ajv", "path", "cells", "renderers", "config", "visible", "enabled", "t"]);
3929
+ const enumerators = useContext(JsonFormContext);
3930
+ const submitFormFunction = enumerators.submitFunction.get('submit-form');
3931
+ const submitForm = submitFormFunction && submitFormFunction();
3882
3932
  const categorization = uischema;
3883
3933
  const rawCategories = JSON.parse(JSON.stringify(categorization));
3884
3934
  const [step, setStep] = useState(1);
@@ -3892,8 +3942,11 @@ const FormStepper = ({
3892
3942
  }, [categorization, data, ajv]);
3893
3943
  const disabledCategoryMap = categories.map(c => !isEnabled(c, data, '', ajv));
3894
3944
  const handleSubmit = () => {
3895
- setIsOpen(true);
3896
- console.log('submitted', data);
3945
+ if (submitForm) {
3946
+ submitForm(data);
3947
+ } else {
3948
+ setIsOpen(true);
3949
+ }
3897
3950
  };
3898
3951
  const onSubmit = () => {
3899
3952
  setIsOpen(false);
@@ -3904,14 +3957,23 @@ const FormStepper = ({
3904
3957
  }, [categories, t]);
3905
3958
  useEffect(() => {}, [categories.length]);
3906
3959
  // eslint-disable-next-line react-hooks/exhaustive-deps
3907
- const vslidateFormData = formData => {
3908
- const validate = ajv.compile(schema);
3960
+ const validateFormData = formData => {
3961
+ const newSchema = JSON.parse(JSON.stringify(schema));
3962
+ Object.keys(newSchema.properties || {}).forEach(propertyName => {
3963
+ var _a;
3964
+ const property = newSchema.properties || {};
3965
+ property[propertyName].enum = getData(propertyName);
3966
+ if (((_a = property[propertyName]) === null || _a === void 0 ? void 0 : _a.format) === 'file-urn') {
3967
+ delete property[propertyName].format;
3968
+ }
3969
+ });
3970
+ const validate = ajv.compile(newSchema);
3909
3971
  return validate(formData);
3910
3972
  };
3911
3973
  useEffect(() => {
3912
- const valid = vslidateFormData(data);
3974
+ const valid = validateFormData(data);
3913
3975
  setIsFormValid(valid);
3914
- }, [data, vslidateFormData]);
3976
+ }, [data, validateFormData]);
3915
3977
  if ((categories === null || categories === void 0 ? void 0 : categories.length) < 1) {
3916
3978
  // eslint-disable-next-line
3917
3979
  return jsx(Fragment, {});
@@ -3987,102 +4049,114 @@ const FormStepper = ({
3987
4049
  })
3988
4050
  );
3989
4051
  };
3990
- const handleEdit = index => {
4052
+ const changePage = index => {
3991
4053
  setPage(index + 1);
3992
4054
  };
3993
- return jsx(Visible, {
3994
- visible: visible,
3995
- children: jsxs("div", {
3996
- id: `${path || `goa`}-form-stepper`,
3997
- className: "formStepper",
3998
- children: [jsxs(GoAFormStepper, {
3999
- testId: "form-stepper-test",
4000
- step: step,
4001
- onChange: step => {
4002
- setTab(step);
4003
- },
4004
- children: [categories === null || categories === void 0 ? void 0 : categories.map((category, index) => {
4005
- return jsx(GoAFormStep, {
4006
- text: `${CategoryLabels[index]}`,
4007
- status: 'incomplete'
4008
- }, `${CategoryLabels[index]}-tab`);
4009
- }), jsx(GoAFormStep, {
4010
- text: "Review",
4011
- status: "incomplete"
4012
- })]
4013
- }), jsxs(GoAPages, {
4014
- current: step,
4015
- mb: "xl",
4016
- children: [categories === null || categories === void 0 ? void 0 : categories.map((category, index) => {
4017
- return jsx("div", {
4018
- "data-testid": `step_${index}-content`,
4019
- children: renderStepElements(category, index)
4020
- }, `${CategoryLabels[index]}`);
4021
- }), jsxs("div", {
4022
- children: [jsx("h3", {
4023
- style: {
4024
- flex: 1
4025
- },
4026
- children: "Summary"
4027
- }), jsx(ReviewItem, {
4028
- children: categories === null || categories === void 0 ? void 0 : categories.map((category, index) => {
4029
- const categoryLabel = category.label || category.i18n || 'Unknown Category';
4030
- const requiredFields = getAllRequiredFields(schema);
4031
- return jsxs(ReviewItemSection, {
4032
- children: [jsxs(ReviewItemHeader, {
4033
- children: [jsx(ReviewItemTitle, {
4034
- children: categoryLabel
4035
- }), jsx(Anchor, {
4036
- onClick: () => handleEdit(index),
4037
- children: "Edit"
4055
+ const readOnly = (_d = (_c = (_b = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _b === void 0 ? void 0 : _b.componentProps) === null || _c === void 0 ? void 0 : _c.readOnly) !== null && _d !== void 0 ? _d : false;
4056
+ return jsx("div", {
4057
+ "data-testid": "form-stepper-test-wrapper",
4058
+ children: jsx(Visible, {
4059
+ visible: visible,
4060
+ children: jsxs("div", {
4061
+ id: `${path || `goa`}-form-stepper`,
4062
+ className: "formStepper",
4063
+ children: [jsxs(GoAFormStepper, {
4064
+ testId: "form-stepper-test",
4065
+ step: step,
4066
+ onChange: step => {
4067
+ setTab(step);
4068
+ },
4069
+ children: [categories === null || categories === void 0 ? void 0 : categories.map((category, index) => {
4070
+ return jsx(GoAFormStep, {
4071
+ text: `${CategoryLabels[index]}`,
4072
+ status: 'incomplete'
4073
+ }, `${CategoryLabels[index]}-tab`);
4074
+ }), jsx(GoAFormStep, {
4075
+ text: "Review",
4076
+ status: "incomplete"
4077
+ })]
4078
+ }), jsxs(GoAPages, {
4079
+ current: step,
4080
+ mb: "xl",
4081
+ children: [categories === null || categories === void 0 ? void 0 : categories.map((category, index) => {
4082
+ return jsx("div", {
4083
+ "data-testid": `step_${index}-content`,
4084
+ style: {
4085
+ marginTop: '1.5rem'
4086
+ },
4087
+ children: renderStepElements(category, index)
4088
+ }, `${CategoryLabels[index]}`);
4089
+ }), jsxs("div", {
4090
+ children: [jsx("h3", {
4091
+ style: {
4092
+ flex: 1,
4093
+ marginBottom: '1rem'
4094
+ },
4095
+ children: "Summary"
4096
+ }), jsx(ReviewItem, {
4097
+ children: categories.map((category, index) => {
4098
+ const categoryLabel = category.label || category.i18n || 'Unknown Category';
4099
+ const requiredFields = getAllRequiredFields(schema);
4100
+ return jsxs(ReviewItemSection, {
4101
+ children: [jsxs(ReviewItemHeader, {
4102
+ children: [jsx(ReviewItemTitle, {
4103
+ children: categoryLabel
4104
+ }), jsx(Anchor, {
4105
+ onClick: () => changePage(index),
4106
+ children: readOnly ? 'View' : 'Edit'
4107
+ })]
4108
+ }), jsx(Grid, {
4109
+ children: renderFormFields(category.elements, data, requiredFields)
4038
4110
  })]
4039
- }), jsx(Grid, {
4040
- children: renderFormFields(category.elements, data, requiredFields)
4041
- })]
4042
- }, index);
4043
- })
4111
+ }, index);
4112
+ })
4113
+ })]
4044
4114
  })]
4045
- })]
4046
- }), step && step !== 0 && jsxs(GoAGrid, {
4047
- minChildWidth: "100px",
4048
- children: [jsx("div", {
4049
- children: step !== 1 && jsx(GoAButton, {
4050
- type: "secondary",
4051
- disabled: disabledCategoryMap[step - 1] || !enabled,
4052
- onClick: () => prevPage(step, disabledCategoryMap),
4053
- children: "Previous"
4054
- })
4055
- }), jsxs(RightAlignmentDiv, {
4056
- children: [step !== null && showNextBtn && jsx(GoAButton, {
4057
- type: "primary",
4058
- disabled: disabledCategoryMap[step - 1] || !enabled,
4059
- onClick: () => nextPage(step, disabledCategoryMap),
4060
- children: "Next"
4061
- }), !showNextBtn && jsx(GoAButton, {
4062
- type: "primary",
4063
- onClick: handleSubmit,
4064
- disabled: !isFormValid || !enabled,
4065
- children: "Submit"
4115
+ }), step && step !== 0 && jsxs(GoAGrid, {
4116
+ minChildWidth: "100px",
4117
+ children: [jsx("div", {
4118
+ children: step !== 1 ? jsx(GoAButton, {
4119
+ type: "secondary",
4120
+ disabled: disabledCategoryMap[step - 1] || !enabled,
4121
+ onClick: () => prevPage(step, disabledCategoryMap),
4122
+ children: "Previous"
4123
+ }) : jsx("div", {})
4124
+ }), jsxs(RightAlignmentDiv, {
4125
+ children: [step !== null && showNextBtn && jsx(GoAButton, {
4126
+ type: "primary",
4127
+ disabled: disabledCategoryMap[step - 1] || !enabled,
4128
+ onClick: () => nextPage(step, disabledCategoryMap),
4129
+ children: "Next"
4130
+ }), !showNextBtn && jsx("div", {
4131
+ children: jsx(GoAButton, {
4132
+ type: "primary",
4133
+ onClick: handleSubmit,
4134
+ disabled: !isFormValid || !enabled,
4135
+ children: "Submit"
4136
+ })
4137
+ })]
4066
4138
  })]
4067
- })]
4068
- }), jsxs(GoAModal, {
4069
- testId: "submit-confirmation",
4070
- open: isOpen,
4071
- heading: 'Form Submitted',
4072
- width: "640px",
4073
- actions: jsx(GoAButtonGroup, {
4074
- alignment: "end",
4075
- children: jsx(GoAButton, {
4076
- type: "primary",
4077
- testId: "submit-form",
4078
- onClick: onSubmit,
4079
- children: "Close"
4139
+ }), jsx(GoAModal, {
4140
+ testId: "submit-confirmation",
4141
+ open: isOpen,
4142
+ heading: 'Form Submitted',
4143
+ width: "640px",
4144
+ actions: jsxs(GoAButtonGroup, {
4145
+ alignment: "end",
4146
+ children: [jsx(GoAButton, {
4147
+ type: "primary",
4148
+ testId: "submit-form",
4149
+ onClick: onSubmit,
4150
+ children: "Close"
4151
+ }), !showNextBtn && jsx(GoAButton, {
4152
+ type: "primary",
4153
+ onClick: handleSubmit,
4154
+ disabled: !isFormValid || !enabled,
4155
+ children: "Submit"
4156
+ })]
4080
4157
  })
4081
- }),
4082
- children: [jsx("b", {
4083
- children: "Submit is a test for preview purposes "
4084
- }), "(i.e. no actual form is being submitted)"]
4085
- })]
4158
+ })]
4159
+ })
4086
4160
  })
4087
4161
  });
4088
4162
  };
@@ -4105,38 +4179,6 @@ const categoriesAreValid = uischema => {
4105
4179
  };
4106
4180
  const CategorizationRendererTester = rankWith(2, and(uiTypeIs('Categorization'), categoriesAreValid, optionIs('variant', 'stepper')));
4107
4181
 
4108
- /******************************************************************************
4109
- Copyright (c) Microsoft Corporation.
4110
-
4111
- Permission to use, copy, modify, and/or distribute this software for any
4112
- purpose with or without fee is hereby granted.
4113
-
4114
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
4115
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
4116
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
4117
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
4118
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
4119
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
4120
- PERFORMANCE OF THIS SOFTWARE.
4121
- ***************************************************************************** */
4122
-
4123
- function __rest(s, e) {
4124
- var t = {};
4125
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4126
- t[p] = s[p];
4127
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
4128
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
4129
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
4130
- t[p[i]] = s[p[i]];
4131
- }
4132
- return t;
4133
- }
4134
-
4135
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
4136
- var e = new Error(message);
4137
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
4138
- };
4139
-
4140
4182
  let _$3 = t => t,
4141
4183
  _t$3;
4142
4184
  const GoAContextMenuIcon = props => {
@@ -4198,11 +4240,12 @@ const DeleteFileModal = ({
4198
4240
 
4199
4241
  let _$2 = t => t,
4200
4242
  _t$2,
4201
- _t2$1;
4243
+ _t2$1,
4244
+ _t3$1;
4202
4245
  const DELAY_UPLOAD_TIMEOUT_MS = 200;
4203
4246
  const DELAY_DELETE_TIMEOUT_MS = 80;
4204
4247
  const FileUploader = _a => {
4205
- var _b;
4248
+ var _b, _c, _d, _e;
4206
4249
  var {
4207
4250
  data,
4208
4251
  path,
@@ -4266,6 +4309,7 @@ const FileUploader = _a => {
4266
4309
  const timeoutId = setTimeout(delayedFunction, 1);
4267
4310
  return () => clearTimeout(timeoutId);
4268
4311
  }, [handleChange, fileList, propertyId]);
4312
+ const readOnly = (_e = (_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) !== null && _e !== void 0 ? _e : false;
4269
4313
  return jsxs(FileUploaderStyle, {
4270
4314
  id: "file-upload",
4271
4315
  className: "FileUploader",
@@ -4275,7 +4319,7 @@ const FileUploader = _a => {
4275
4319
  }) : jsx("div", {
4276
4320
  className: "label",
4277
4321
  children: props.label
4278
- }), jsx("div", {
4322
+ }), !readOnly && jsx("div", {
4279
4323
  className: "file-upload",
4280
4324
  children: jsx(GoAFileUploadInput, {
4281
4325
  variant: variant,
@@ -4293,43 +4337,61 @@ const FileUploader = _a => {
4293
4337
  })
4294
4338
  })
4295
4339
  }) : jsx("div", {
4296
- children: fileList && getFile() && jsxs(AttachmentBorder, {
4297
- children: [jsx("div", {
4298
- children: getFileName()
4299
- }), jsxs(GoAContextMenu, {
4300
- children: [jsx(GoAContextMenuIcon, {
4340
+ children: fileList && getFile() && jsx("div", {
4341
+ children: readOnly ? jsxs(AttachmentBorderDisabled, {
4342
+ children: [getFileName(), ' ', jsx(GoAContextMenuIcon, {
4301
4343
  testId: "download-icon",
4302
4344
  title: "Download",
4303
4345
  type: "download",
4304
4346
  onClick: () => downloadFile(getFile())
4305
- }), jsx(GoAContextMenuIcon, {
4306
- "data-testid": "delete-icon",
4307
- title: "Delete",
4308
- type: "trash",
4309
- onClick: () => {
4310
- setShowFileDeleteConfirmation(true);
4347
+ })]
4348
+ }) : jsxs(AttachmentBorder, {
4349
+ children: [jsx("div", {
4350
+ children: getFileName()
4351
+ }), jsxs(GoAContextMenu, {
4352
+ children: [jsx(GoAContextMenuIcon, {
4353
+ testId: "download-icon",
4354
+ title: "Download",
4355
+ type: "download",
4356
+ onClick: () => downloadFile(getFile())
4357
+ }), jsx(GoAContextMenuIcon, {
4358
+ "data-testid": "delete-icon",
4359
+ title: "Delete",
4360
+ type: "trash",
4361
+ onClick: () => {
4362
+ setShowFileDeleteConfirmation(true);
4363
+ }
4364
+ })]
4365
+ }), jsx(DeleteFileModal, {
4366
+ isOpen: showFileDeleteConfirmation,
4367
+ title: "Delete file",
4368
+ content: `Delete file ${getFile().filename} ?`,
4369
+ onCancel: () => setShowFileDeleteConfirmation(false),
4370
+ onDelete: () => {
4371
+ setShowFileDeleteConfirmation(false);
4372
+ deleteFile(getFile());
4373
+ const handleFunction = () => {
4374
+ handleChange(propertyId, '');
4375
+ };
4376
+ setTimeout(handleFunction, DELAY_DELETE_TIMEOUT_MS);
4311
4377
  }
4312
4378
  })]
4313
- }), jsx(DeleteFileModal, {
4314
- isOpen: showFileDeleteConfirmation,
4315
- title: "Delete file",
4316
- content: `Delete file ${getFile().filename} ?`,
4317
- onCancel: () => setShowFileDeleteConfirmation(false),
4318
- onDelete: () => {
4319
- setShowFileDeleteConfirmation(false);
4320
- deleteFile(getFile());
4321
- const handleFunction = () => {
4322
- handleChange(propertyId, '');
4323
- };
4324
- setTimeout(handleFunction, DELAY_DELETE_TIMEOUT_MS);
4325
- }
4326
- })]
4379
+ })
4327
4380
  })
4328
4381
  })
4329
4382
  })]
4330
4383
  });
4331
4384
  };
4332
- const AttachmentBorder = styled.div(_t$2 || (_t$2 = _$2`
4385
+ const AttachmentBorderDisabled = styled.div(_t$2 || (_t$2 = _$2`
4386
+ display: flex;
4387
+ flex-direction: row;
4388
+ border: var(--goa-border-width-s) solid #dcdcdc;
4389
+ border-radius: var(--goa-border-radius-m);
4390
+ padding: var(--goa-space-xs);
4391
+ width: fit-content;
4392
+ background-color: #f1f1f1;
4393
+ `));
4394
+ const AttachmentBorder = styled.div(_t2$1 || (_t2$1 = _$2`
4333
4395
  display: flex;
4334
4396
  flex-direction: row;
4335
4397
  border: var(--goa-border-width-s) solid #dcdcdc;
@@ -4338,7 +4400,7 @@ const AttachmentBorder = styled.div(_t$2 || (_t$2 = _$2`
4338
4400
  width: fit-content;
4339
4401
  margin-top: var(--goa-space-2xs);
4340
4402
  `));
4341
- const FileUploaderStyle = styled.div(_t2$1 || (_t2$1 = _$2`
4403
+ const FileUploaderStyle = styled.div(_t3$1 || (_t3$1 = _$2`
4342
4404
  .label {
4343
4405
  display: block;
4344
4406
  font-weight: var(--goa-font-weight-bold);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.9.0",
3
+ "version": "1.10.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",
@@ -10,14 +10,19 @@ interface FileManagement {
10
10
  downloadFile?: (file: File) => void;
11
11
  deleteFile?: (file: File) => void;
12
12
  }
13
+ interface SubmitManagement {
14
+ submitForm?: (any: any) => void;
15
+ }
13
16
  type Props = {
14
17
  children?: React.ReactNode;
15
18
  fileManagement?: FileManagement;
19
+ submit?: SubmitManagement;
16
20
  data?: any;
17
21
  };
18
22
  export declare const JsonFormContext: React.Context<{
19
23
  data: Map<string, () => Record<string, any> | string[]>;
20
24
  functions: Map<string, () => (file: File, propertyId: string) => void>;
25
+ submitFunction: Map<string, () => (data: any) => void>;
21
26
  }>;
22
27
  export declare function ContextProvider(props: Props): JSX.Element | null;
23
28
  /**
@@ -5,7 +5,7 @@ import { AjvProps } from '@jsonforms/material-renderers';
5
5
  export interface CategorizationStepperLayoutRendererProps extends StatePropsOfLayout, AjvProps, TranslateProps {
6
6
  data: any;
7
7
  }
8
- export declare const FormStepper: ({ uischema, data, schema, ajv, path, cells, renderers, config, visible, enabled, t, }: CategorizationStepperLayoutRendererProps) => import("react/jsx-runtime").JSX.Element;
8
+ export declare const FormStepper: ({ uischema, data, schema, ajv, path, cells, renderers, config, visible, enabled, t, ...props }: CategorizationStepperLayoutRendererProps) => import("react/jsx-runtime").JSX.Element;
9
9
  export declare const flattenObject: (obj: Record<string, string>) => Record<string, string>;
10
10
  export declare const FormStepperControl: (props: CategorizationStepperLayoutRendererProps & import("@jsonforms/core").OwnPropsOfLayout) => React.JSX.Element;
11
11
  export default FormStepper;