@abgov/jsonforms-components 1.53.8 → 1.53.9

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
@@ -2635,7 +2635,7 @@ const invalidSin = 'Social insurance number is invalid';
2635
2635
  * @param words
2636
2636
  * @returns sentence word string.
2637
2637
  */
2638
- const capitalizeFirstLetter = words => {
2638
+ const capitalizeFirstLetter$1 = words => {
2639
2639
  const value = words.charAt(0).toUpperCase() + words.slice(1).toLowerCase();
2640
2640
  return value;
2641
2641
  };
@@ -2661,7 +2661,7 @@ const controlScopeMatchesLabel = (scope, label) => {
2661
2661
  const getLabelText = (scope, label) => {
2662
2662
  let labelToUpdate = '';
2663
2663
  if (controlScopeMatchesLabel(scope, label || '') && !areAllUppercase(label)) {
2664
- labelToUpdate = capitalizeFirstLetter(label || '');
2664
+ labelToUpdate = capitalizeFirstLetter$1(label || '');
2665
2665
  } else {
2666
2666
  labelToUpdate = label || '';
2667
2667
  }
@@ -2709,7 +2709,7 @@ const checkFieldValidity = props => {
2709
2709
  uischema,
2710
2710
  schema
2711
2711
  } = props;
2712
- const labelToUpdate = getLabelText(uischema.scope, label);
2712
+ const labelToUpdate = (uischema === null || uischema === void 0 ? void 0 : uischema.scope) ? getLabelText(uischema === null || uischema === void 0 ? void 0 : uischema.scope, label) : label;
2713
2713
  const extraSchema = schema;
2714
2714
  if (extraSchema && data && (extraSchema === null || extraSchema === void 0 ? void 0 : extraSchema.title) === sinTitle) {
2715
2715
  if (data.length === 11 && !validateSinWithLuhn(data)) {
@@ -2991,7 +2991,7 @@ const onChangeForInputControl = props => {
2991
2991
  handleChange,
2992
2992
  path
2993
2993
  } = controlProps;
2994
- handleChange(path, value);
2994
+ handleChange(path, value === '' ? undefined : value);
2995
2995
  };
2996
2996
  /**
2997
2997
  * Helper function to process onChange event for Date controls.
@@ -4470,9 +4470,6 @@ const GoAInputText = props => {
4470
4470
  // maxLength={appliedUiSchemaOptions?.maxLength}
4471
4471
  name: (appliedUiSchemaOptions === null || appliedUiSchemaOptions === void 0 ? void 0 : appliedUiSchemaOptions.name) || `${id || label}-input`,
4472
4472
  testId: (appliedUiSchemaOptions === null || appliedUiSchemaOptions === void 0 ? void 0 : appliedUiSchemaOptions.testId) || `${id}-input`,
4473
- // Don't use handleChange in the onChange event, use the keyPress or onBlur.
4474
- // If you use it onChange along with keyPress event it will cause a
4475
- // side effect that causes the validation to render when it shouldn't.
4476
4473
  onChange: (name, value) => {
4477
4474
  let formattedValue = value;
4478
4475
  if (schema && schema.title === sinTitle && value !== '') {
@@ -6793,7 +6790,8 @@ let _$2 = t => t,
6793
6790
  _t11,
6794
6791
  _t12,
6795
6792
  _t13,
6796
- _t14;
6793
+ _t14,
6794
+ _t15;
6797
6795
  const DeleteDialogContent = styled.div(_t$2 || (_t$2 = _$2`
6798
6796
  margin-bottom: var(--goa-space-m);
6799
6797
  `));
@@ -6813,47 +6811,52 @@ const ObjectArrayTitle = styled.h3(_t4$1 || (_t4$1 = _$2`
6813
6811
  font-size: var(--goa-font-size-2);
6814
6812
  }
6815
6813
  `));
6816
- const TextCenter = styled.div(_t5$1 || (_t5$1 = _$2`
6814
+ const RequiredSpan = styled.span(_t5$1 || (_t5$1 = _$2`
6815
+ color: #666666;
6816
+ font-weight: var(--goa-font-weight-regular);
6817
+ font-size: var(--goa-font-size-2);
6818
+ `));
6819
+ const TextCenter = styled.div(_t6$1 || (_t6$1 = _$2`
6817
6820
  text-align: center;
6818
6821
  `));
6819
- const SideMenuItem = styled.div(_t6$1 || (_t6$1 = _$2`
6822
+ const SideMenuItem = styled.div(_t7 || (_t7 = _$2`
6820
6823
  &:hover {
6821
6824
  background: #f1f1f1;
6822
6825
  }
6823
6826
  `));
6824
- const RowFlex = styled.div(_t7 || (_t7 = _$2`
6827
+ const RowFlex = styled.div(_t8 || (_t8 = _$2`
6825
6828
  display: flex;
6826
6829
  align-items: stretch;
6827
6830
  `));
6828
- const RowFlexMenu = styled.div(_t8 || (_t8 = _$2`
6831
+ const RowFlexMenu = styled.div(_t9 || (_t9 = _$2`
6829
6832
  display: flex;
6830
6833
  flex-direction: row;
6831
6834
  border-bottom: 1px solid #dcdcdc;
6832
6835
  `));
6833
- const FlexTabs = styled.div(_t9 || (_t9 = _$2`
6836
+ const FlexTabs = styled.div(_t10 || (_t10 = _$2`
6834
6837
  flex-direction: column;
6835
6838
  flex: 1;
6836
6839
  overflow-y: auto !important;
6837
6840
  margin-right: 1.5rem;
6838
6841
  `));
6839
- const FlexForm = styled.div(_t10 || (_t10 = _$2`
6842
+ const FlexForm = styled.div(_t11 || (_t11 = _$2`
6840
6843
  flex-direction: column;
6841
6844
  margin: 1.5rem 0;
6842
6845
  flex: 3;
6843
6846
  `));
6844
- const TabName = styled.div(_t11 || (_t11 = _$2`
6847
+ const TabName = styled.div(_t12 || (_t12 = _$2`
6845
6848
  margin: 1rem 0 1rem 1rem;
6846
6849
  font-weight: 700;
6847
6850
  `));
6848
- const Trash = styled.div(_t12 || (_t12 = _$2`
6851
+ const Trash = styled.div(_t13 || (_t13 = _$2`
6849
6852
  margin: 0.75rem 1.25rem 0.75rem 0.75rem;
6850
6853
  margin-left: auto;
6851
6854
  `));
6852
- const ListContainer = styled.div(_t13 || (_t13 = _$2`
6855
+ const ListContainer = styled.div(_t14 || (_t14 = _$2`
6853
6856
  padding: 0 1.5rem 0 0;
6854
6857
  border: 1px solid #dcdcdc;
6855
6858
  `));
6856
- const TableTHHeader = styled.th(_t14 || (_t14 = _$2`
6859
+ const TableTHHeader = styled.th(_t15 || (_t15 = _$2`
6857
6860
  background-color: var(--goa-color-greyscale-100) !important;
6858
6861
  `));
6859
6862
 
@@ -6928,7 +6931,7 @@ const ObjectArrayToolBar = /*#__PURE__*/React.memo(function TableToolbar({
6928
6931
  "aria-label": translations.addAriaLabel,
6929
6932
  onClick: addItem(path, createDefaultValue(schema, rootSchema)),
6930
6933
  type: (_c = (_b = uischema.options) === null || _b === void 0 ? void 0 : _b.addButtonType) !== null && _c !== void 0 ? _c : 'primary',
6931
- children: ((_d = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _d === void 0 ? void 0 : _d.addButtonText) || capitalizeFirstLetter(`Add ${arrayLabel}`)
6934
+ children: ((_d = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _d === void 0 ? void 0 : _d.addButtonText) || capitalizeFirstLetter$1(`Add ${arrayLabel}`)
6932
6935
  })
6933
6936
  })
6934
6937
  });
@@ -6955,7 +6958,13 @@ function objectListReducer(state, action) {
6955
6958
  category
6956
6959
  } = action.payload;
6957
6960
  const newCategories = Object.assign({}, categories);
6958
- newCategories[name].data = category;
6961
+ if (!newCategories[name]) {
6962
+ newCategories[name] = {
6963
+ data: category
6964
+ };
6965
+ } else {
6966
+ newCategories[name].data = category;
6967
+ }
6959
6968
  return Object.assign(Object.assign({}, state), {
6960
6969
  categories: newCategories
6961
6970
  });
@@ -7090,8 +7099,12 @@ const ctxToNonEmptyCellProps$1 = (ctx, ownProps) => {
7090
7099
  handleChange: ownProps.handleChange
7091
7100
  };
7092
7101
  };
7102
+ function capitalizeFirstLetter(str) {
7103
+ if (!str) return ''; // Handle empty strings
7104
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
7105
+ }
7093
7106
  const NonEmptyCellComponent$1 = /*#__PURE__*/React.memo(function NonEmptyCellComponent(props) {
7094
- var _a;
7107
+ var _a, _b;
7095
7108
  const {
7096
7109
  schema,
7097
7110
  enabled,
@@ -7107,10 +7120,11 @@ const NonEmptyCellComponent$1 = /*#__PURE__*/React.memo(function NonEmptyCellCom
7107
7120
  errors
7108
7121
  } = props;
7109
7122
  const properties = (schema === null || schema === void 0 ? void 0 : schema.items) && 'properties' in schema.items && schema.items.properties || {};
7123
+ const required = (_a = schema.items) === null || _a === void 0 ? void 0 : _a.required;
7110
7124
  return jsxs(NonEmptyCellStyle, {
7111
7125
  children: [
7112
7126
  // eslint-disable-next-line
7113
- (_a = uischema === null || uischema === void 0 ? void 0 : uischema.elements) === null || _a === void 0 ? void 0 : _a.map(element => {
7127
+ (_b = uischema === null || uischema === void 0 ? void 0 : uischema.elements) === null || _b === void 0 ? void 0 : _b.map(element => {
7114
7128
  return jsx(JsonFormsDispatch, {
7115
7129
  "data-testid": `jsonforms-object-list-defined-elements-dispatch`,
7116
7130
  schema: schema,
@@ -7127,8 +7141,10 @@ const NonEmptyCellComponent$1 = /*#__PURE__*/React.memo(function NonEmptyCellCom
7127
7141
  children: [Object.keys(properties).map((key, index) => {
7128
7142
  if (!isInReview) {
7129
7143
  return jsx("th", {
7130
- children: jsx("p", {
7131
- children: convertToSentenceCase(key)
7144
+ children: jsxs("p", {
7145
+ children: [convertToSentenceCase(key), (required === null || required === void 0 ? void 0 : required.includes(key)) && jsx(RequiredSpan, {
7146
+ children: "(required)"
7147
+ })]
7132
7148
  })
7133
7149
  }, index);
7134
7150
  }
@@ -7152,21 +7168,26 @@ const NonEmptyCellComponent$1 = /*#__PURE__*/React.memo(function NonEmptyCellCom
7152
7168
  var _a;
7153
7169
  const dataObject = properties[element];
7154
7170
  const schemaName = element;
7171
+ const currentData = data && data[num] ? data[num][element] : '';
7155
7172
  const error = errors === null || errors === void 0 ? void 0 : errors.find(
7156
7173
  // eslint-disable-next-line
7157
7174
  e => e.instancePath === `/${props.rowPath.replace(/\./g, '/')}/${i}/${element}`);
7175
+ if ((error === null || error === void 0 ? void 0 : error.message.includes('must NOT have fewer')) && required.find(r => r === schemaName) && (isEmptyBoolean(schema, currentData) || isEmptyNumber(schema, currentData))) {
7176
+ error.message = `${capitalizeFirstLetter(schemaName)} is required`;
7177
+ }
7158
7178
  return jsx("td", {
7159
7179
  children: isInReview ? jsx("div", {
7160
7180
  "data-testid": `#/properties/${schemaName}-input-${i}-review`,
7161
- children: data && data[num] ? data[num][element] : ''
7181
+ children: currentData
7162
7182
  }) : jsx(GoAFormItem, {
7163
7183
  error: (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : '',
7164
7184
  mb: errorRow && !error && '2xl' || 'xs',
7165
7185
  children: dataObject.type === 'number' || dataObject.type === 'string' && !dataObject.enum ? jsx(GoAInput, {
7186
+ error: (error === null || error === void 0 ? void 0 : error.message.length) > 0,
7166
7187
  type: dataObject.type === 'number' ? 'number' : 'text',
7167
7188
  id: schemaName,
7168
7189
  name: schemaName,
7169
- value: data && data[num] ? data[num][element] : '',
7190
+ value: currentData,
7170
7191
  testId: `#/properties/${schemaName}-input-${i}`,
7171
7192
  onChange: (name, value) => {
7172
7193
  handleChange(rowPath, {
@@ -7338,7 +7359,7 @@ const ObjectArrayControl = props => {
7338
7359
  });
7339
7360
  currentCategory.data = newCategoryData;
7340
7361
  }
7341
- if ((currentCategory === null || currentCategory === void 0 ? void 0 : currentCategory.count) > 0) currentCategory.count--;
7362
+ if ((currentCategory === null || currentCategory === void 0 ? void 0 : currentCategory.count) && (currentCategory === null || currentCategory === void 0 ? void 0 : currentCategory.count) > 0) currentCategory.count--;
7342
7363
  let handleChangeData = Object.keys(newCategoryData).map(key => {
7343
7364
  return newCategoryData[key];
7344
7365
  });
@@ -7354,12 +7375,14 @@ const ObjectArrayControl = props => {
7354
7375
  }
7355
7376
  });
7356
7377
  };
7378
+ //eslint-disable-next-line
7357
7379
  const handleChangeWithData = (path, value) => {
7380
+ var _a;
7358
7381
  if (path) {
7359
7382
  const categories = registers.categories;
7360
- const currentCategory = categories[path].data;
7383
+ const currentCategory = ((_a = categories[path]) === null || _a === void 0 ? void 0 : _a.data) || {};
7361
7384
  const newData = {};
7362
- const allKeys = Object.keys(value).concat(Object.keys(currentCategory));
7385
+ const allKeys = Object.keys(value).concat(Object.keys(currentCategory || []));
7363
7386
  const allKeysUnique = allKeys.filter((a, b) => allKeys.indexOf(a) === b);
7364
7387
  Object.keys(allKeysUnique).forEach(num => {
7365
7388
  if (!newData[num]) {
@@ -7369,7 +7392,7 @@ const ObjectArrayControl = props => {
7369
7392
  newData[num][path] = currentCategory[num][path];
7370
7393
  });
7371
7394
  value[num] && Object.keys(value[num]).forEach(path => {
7372
- newData[num][path] = value[num][path] || currentCategory[num] && currentCategory[num][path];
7395
+ newData[num][path] = value[num][path] !== undefined ? value[num][path] : currentCategory[num] && currentCategory[num][path];
7373
7396
  });
7374
7397
  });
7375
7398
  const handleChangeData = Object.keys(newData).map(key => {
@@ -7410,8 +7433,10 @@ const ObjectArrayControl = props => {
7410
7433
  visible: visible,
7411
7434
  "data-testid": "jsonforms-object-list-wrapper",
7412
7435
  children: [jsxs(ToolBarHeader, {
7413
- children: [isInReview && listTitle && jsx("b", {
7414
- children: listTitle
7436
+ children: [isInReview && listTitle && jsxs("b", {
7437
+ children: [listTitle, " ", jsx("span", {
7438
+ children: additionalProps.required && '(required)'
7439
+ })]
7415
7440
  }), !isInReview && listTitle && jsxs(ObjectArrayTitle, {
7416
7441
  children: [listTitle, " ", jsx("span", {
7417
7442
  children: additionalProps.required && '(required)'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.53.8",
3
+ "version": "1.53.9",
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",
@@ -7,7 +7,7 @@ export interface Categories {
7
7
  [category: string]: Category;
8
8
  }
9
9
  interface Category {
10
- count: number;
10
+ count?: number;
11
11
  data: StateData;
12
12
  }
13
13
  interface Value {
@@ -3,6 +3,7 @@ export declare const DeleteDialogContent: import("styled-components/dist/types")
3
3
  export declare const NonEmptyCellStyle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
4
4
  export declare const ToolBarHeader: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
5
5
  export declare const ObjectArrayTitle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLHeadingElement>, HTMLHeadingElement>, never>> & string;
6
+ export declare const RequiredSpan: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, never>> & string;
6
7
  export declare const TextCenter: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
7
8
  export declare const SideMenuItem: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;
8
9
  export declare const RowFlex: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, never>> & string;