@abgov/jsonforms-components 1.50.4 → 1.50.6

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
@@ -5914,13 +5914,15 @@ const stepperReducer = (state, action) => {
5914
5914
  {
5915
5915
  const {
5916
5916
  id,
5917
+ ajv,
5917
5918
  errors
5918
5919
  } = action.payload;
5919
- if (state.isOnReview) {
5920
- return Object.assign({}, state);
5921
- }
5920
+ /*
5921
+ ctx.core.errors only includes required errors when the fields are touched. In this case, we still ajv to figure out the required errors at the very beginning.
5922
+ */
5923
+ const incompletePaths = getIncompletePaths(ajv, state.categories[id].scopes);
5922
5924
  const errorsInCategory = errors.filter(e => categories[id].scopes.map(s => '/' + toDataPath(s)).includes(e.instancePath));
5923
- state.categories[id].isCompleted = errorsInCategory.filter(e => e.keyword === 'required').length === 0;
5925
+ state.categories[id].isCompleted = (incompletePaths === null || incompletePaths === void 0 ? void 0 : incompletePaths.length) === 0;
5924
5926
  state.categories[id].isValid = errorsInCategory.length === 0;
5925
5927
  return Object.assign({}, state);
5926
5928
  }
@@ -6000,7 +6002,12 @@ const JsonFormsStepperContextProvider = ({
6000
6002
  children,
6001
6003
  StepperProps
6002
6004
  }) => {
6005
+ var _a;
6003
6006
  const ctx = useJsonForms();
6007
+ const {
6008
+ schema,
6009
+ ajv
6010
+ } = StepperProps;
6004
6011
  const [stepperState, dispatch] = useReducer(stepperReducer, createStepperContextInitData(StepperProps));
6005
6012
  const stepperDispatch = (StepperProps === null || StepperProps === void 0 ? void 0 : StepperProps.customDispatch) || dispatch;
6006
6013
  const context = useMemo(() => {
@@ -6024,13 +6031,15 @@ const JsonFormsStepperContextProvider = ({
6024
6031
  return stepperState.categories[id];
6025
6032
  },
6026
6033
  goToPage: (id, updateCategoryId) => {
6027
- var _a, _b, _c;
6034
+ var _a, _b, _c, _d;
6035
+ ajv.validate(schema, ((_a = ctx.core) === null || _a === void 0 ? void 0 : _a.data) || {});
6028
6036
  if (updateCategoryId !== undefined) {
6029
6037
  stepperDispatch({
6030
6038
  type: 'update/category',
6031
6039
  payload: {
6032
- errors: ((_a = ctx.core) === null || _a === void 0 ? void 0 : _a.errors) || [],
6033
- id: updateCategoryId
6040
+ errors: (_b = ctx === null || ctx === void 0 ? void 0 : ctx.core) === null || _b === void 0 ? void 0 : _b.errors,
6041
+ id: updateCategoryId,
6042
+ ajv
6034
6043
  }
6035
6044
  });
6036
6045
  }
@@ -6038,15 +6047,16 @@ const JsonFormsStepperContextProvider = ({
6038
6047
  stepperDispatch({
6039
6048
  type: 'update/category',
6040
6049
  payload: {
6041
- errors: ((_b = ctx.core) === null || _b === void 0 ? void 0 : _b.errors) || [],
6042
- id: stepperState.activeId
6050
+ errors: (_c = ctx === null || ctx === void 0 ? void 0 : ctx.core) === null || _c === void 0 ? void 0 : _c.errors,
6051
+ id: stepperState.activeId,
6052
+ ajv
6043
6053
  }
6044
6054
  });
6045
6055
  }
6046
6056
  stepperDispatch({
6047
6057
  type: 'validate/form',
6048
6058
  payload: {
6049
- errors: (_c = ctx.core) === null || _c === void 0 ? void 0 : _c.errors
6059
+ errors: (_d = ctx === null || ctx === void 0 ? void 0 : ctx.core) === null || _d === void 0 ? void 0 : _d.errors
6050
6060
  }
6051
6061
  });
6052
6062
  stepperDispatch({
@@ -6057,7 +6067,7 @@ const JsonFormsStepperContextProvider = ({
6057
6067
  });
6058
6068
  }
6059
6069
  };
6060
- }, [ctx === null || ctx === void 0 ? void 0 : ctx.core, stepperDispatch, stepperState]);
6070
+ }, [stepperDispatch, stepperState, (_a = ctx.core) === null || _a === void 0 ? void 0 : _a.errors]);
6061
6071
  useEffect(() => {
6062
6072
  if ((context === null || context === void 0 ? void 0 : context.isProvided) === true) {
6063
6073
  stepperDispatch({
@@ -6067,7 +6077,7 @@ const JsonFormsStepperContextProvider = ({
6067
6077
  }
6068
6078
  });
6069
6079
  }
6070
- }, [JSON.stringify(StepperProps.uischema)]);
6080
+ }, [JSON.stringify(StepperProps.uischema), JSON.stringify(StepperProps.schema)]);
6071
6081
  return jsx(JsonFormsStepperContext.Provider, {
6072
6082
  value: context,
6073
6083
  children: children
@@ -6090,7 +6100,7 @@ const FormStepper = props => {
6090
6100
  });
6091
6101
  };
6092
6102
  const FormStepperView = props => {
6093
- var _a, _b, _c;
6103
+ var _a;
6094
6104
  const {
6095
6105
  uischema,
6096
6106
  data,
@@ -6129,17 +6139,15 @@ const FormStepperView = props => {
6129
6139
  const onCloseModal = () => {
6130
6140
  setIsOpen(false);
6131
6141
  };
6132
- return jsxs("div", {
6142
+ return jsx("div", {
6133
6143
  "data-testid": "form-stepper-test-wrapper",
6134
- children: [jsx("div", {
6135
- children: ((_a = categories[activeId]) === null || _a === void 0 ? void 0 : _a.isCompleted) && ((_b = categories[activeId]) === null || _b === void 0 ? void 0 : _b.isVisited)
6136
- }), jsx(Visible, {
6144
+ children: jsx(Visible, {
6137
6145
  visible: visible,
6138
6146
  children: jsxs("div", {
6139
6147
  id: `${path || `goa`}-form-stepper`,
6140
6148
  className: "formStepper",
6141
6149
  children: [jsxs(GoAFormStepper, {
6142
- testId: `form-stepper-headers-${(_c = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _c === void 0 ? void 0 : _c.testId}` || 'form-stepper-test',
6150
+ testId: `form-stepper-headers-${(_a = uischema === null || uischema === void 0 ? void 0 : uischema.options) === null || _a === void 0 ? void 0 : _a.testId}` || 'form-stepper-test',
6143
6151
  onChange: step => {
6144
6152
  goToPage(step - 1);
6145
6153
  },
@@ -6147,7 +6155,7 @@ const FormStepperView = props => {
6147
6155
  return jsx(GoAFormStep, {
6148
6156
  "data-testid": `stepper-tab-${index}`,
6149
6157
  text: `${c.label}`,
6150
- status: c.isValid ? 'complete' : 'incomplete'
6158
+ status: c.isCompleted && c.isValid ? 'complete' : 'incomplete'
6151
6159
  }, `stepper-tab-${index}`);
6152
6160
  }), jsx(GoAFormStep, {
6153
6161
  text: "Review"
@@ -6242,7 +6250,7 @@ const FormStepperView = props => {
6242
6250
  }), "(i.e. no actual form is being submitted)"]
6243
6251
  })]
6244
6252
  })
6245
- })]
6253
+ })
6246
6254
  });
6247
6255
  };
6248
6256
  const FormStepperControl = withAjvProps(withTranslateProps(withJsonFormsLayoutProps(FormStepper)));
@@ -6408,15 +6416,16 @@ const FileUploader = _a => {
6408
6416
  if (!enumerators) {
6409
6417
  return jsx(Fragment, {});
6410
6418
  }
6419
+ const sentenceCaseLabel = convertToSentenceCase(label);
6411
6420
  return jsxs(FileUploaderStyle, {
6412
6421
  id: "file-upload",
6413
6422
  className: "FileUploader",
6414
6423
  children: [required ? jsx(GoAFormItem, {
6415
- label: label,
6424
+ label: sentenceCaseLabel,
6416
6425
  requirement: "required"
6417
6426
  }) : jsx("div", {
6418
6427
  className: "label",
6419
- children: props.label
6428
+ children: sentenceCaseLabel
6420
6429
  }), !readOnly && jsx("div", {
6421
6430
  className: "file-upload",
6422
6431
  children: jsx(GoAFileUploadInput, {
@@ -8436,6 +8445,7 @@ const AddressLookUpControl = props => {
8436
8445
  };
8437
8446
  const [address, setAddress] = useState(data || defaultAddress);
8438
8447
  const [searchTerm, setSearchTerm] = useState('');
8448
+ const [saveSearchTerm, setSaveSearchTerm] = useState(false);
8439
8449
  const [suggestions, setSuggestions] = useState([]);
8440
8450
  const [loading, setLoading] = useState(false);
8441
8451
  const [errors, setErrors] = useState({});
@@ -8476,6 +8486,12 @@ const AddressLookUpControl = props => {
8476
8486
  showLabel: false
8477
8487
  }));
8478
8488
  };
8489
+ useEffect(() => {
8490
+ if (saveSearchTerm) {
8491
+ handleInputChange('addressLine1', searchTerm);
8492
+ setSaveSearchTerm(false);
8493
+ }
8494
+ }, [saveSearchTerm]); // eslint-disable-line react-hooks/exhaustive-deps
8479
8495
  useEffect(() => {
8480
8496
  const fetchSuggestions = () => __awaiter(void 0, void 0, void 0, function* () {
8481
8497
  if (searchTerm.length > 2 && dropdownSelected === false) {
@@ -8496,10 +8512,10 @@ const AddressLookUpControl = props => {
8496
8512
  }
8497
8513
  });
8498
8514
  fetchSuggestions();
8499
- }, [searchTerm, dropdownSelected]); // eslint-disable-line react-hooks/exhaustive-deps
8515
+ }, [searchTerm]); // eslint-disable-line react-hooks/exhaustive-deps
8500
8516
  const handleDropdownChange = value => {
8501
8517
  setSearchTerm(value);
8502
- handleInputChange('addressLine1', value);
8518
+ setSaveSearchTerm(true);
8503
8519
  };
8504
8520
  const handleSuggestionClick = suggestion => {
8505
8521
  const suggestAddress = mapSuggestionToAddress(suggestion);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.50.4",
3
+ "version": "1.50.6",
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",
@@ -1,6 +1,7 @@
1
1
  import { StepperContextDataType } from './types';
2
2
  import { ErrorObject } from 'ajv';
3
3
  import { Dispatch } from 'react';
4
+ import Ajv from 'ajv';
4
5
  export type JsonFormStepperDispatch = Dispatch<StepperAction>;
5
6
  export type StepperAction = {
6
7
  type: 'page/next';
@@ -14,8 +15,9 @@ export type StepperAction = {
14
15
  } | {
15
16
  type: 'update/category';
16
17
  payload: {
17
- errors: ErrorObject[];
18
+ errors?: ErrorObject[];
18
19
  id: number;
20
+ ajv: Ajv;
19
21
  };
20
22
  } | {
21
23
  type: 'validate/form';