@abgov/jsonforms-components 1.40.1 → 1.40.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
@@ -6,7 +6,7 @@ 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, isControl, isScoped, hasType, isCategorization, isLayout } from '@jsonforms/core';
8
8
  import { withJsonFormsControlProps, withJsonFormsRendererProps, withJsonFormsEnumProps, withTranslateProps, useJsonForms, JsonFormsDispatch, withJsonFormsLayoutProps, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
9
- import { isEqual, isObject as isObject$e } from 'lodash';
9
+ import { isEqual, isEmpty as isEmpty$2, isObject as isObject$e } from 'lodash';
10
10
  import merge from 'lodash/merge';
11
11
  import isEmpty$1 from 'lodash/isEmpty';
12
12
  import range from 'lodash/range';
@@ -2465,12 +2465,19 @@ const StepperContext = /*#__PURE__*/createContext({
2465
2465
  const isEmpty = value => {
2466
2466
  return value === undefined || value === null || typeof value === 'string' && value.length < 1;
2467
2467
  };
2468
- const getCompletionStatus = (table, step) => {
2468
+ const getCompletionStatus = (table, step, isFormChanged = false) => {
2469
2469
  const nonEmptyCount = getNonEmptyCount(table, step);
2470
+ const requiredCount = getRequiredCount(table, step);
2470
2471
  if (nonEmptyCount === 0) {
2471
- return undefined;
2472
+ if (!isFormChanged) {
2473
+ return undefined;
2474
+ }
2475
+ if (requiredCount === 0) {
2476
+ return 'complete';
2477
+ } else {
2478
+ return 'incomplete';
2479
+ }
2472
2480
  }
2473
- const requiredCount = getRequiredCount(table, step);
2474
2481
  const requiredNonEmptyCount = getNonEmptyRequiredCount(table, step);
2475
2482
  if (requiredNonEmptyCount === requiredCount) {
2476
2483
  return 'complete';
@@ -2478,7 +2485,9 @@ const getCompletionStatus = (table, step) => {
2478
2485
  return 'incomplete';
2479
2486
  };
2480
2487
  const getNonEmptyCount = (table, step) => {
2481
- const nonEmptyStatuses = Object.keys(table).filter(k => table[k].step === step && !isEmpty(table[k].value));
2488
+ const nonEmptyStatuses = Object.keys(table).filter(k => {
2489
+ return table[k].step === step && !isEmpty(table[k].value);
2490
+ });
2482
2491
  return nonEmptyStatuses.length;
2483
2492
  };
2484
2493
  const getRequiredCount = (table, step) => {
@@ -5593,7 +5602,7 @@ const FormStepper = props => {
5593
5602
  useEffect(() => {
5594
5603
  const statuses = Array(categories.length);
5595
5604
  categories.forEach((_, i) => {
5596
- statuses[i] = getCompletionStatus(inputStatuses, i + 1);
5605
+ statuses[i] = isEmpty$2(stepStatuses[i]) ? getCompletionStatus(inputStatuses, i + 1) : stepStatuses[i];
5597
5606
  });
5598
5607
  setStepStatuses(statuses);
5599
5608
  }, [inputStatuses, categories]);
@@ -5613,7 +5622,7 @@ const FormStepper = props => {
5613
5622
  return jsx(Fragment, {});
5614
5623
  }
5615
5624
  function nextPage(page, disabled) {
5616
- const pageStatus = getCompletionStatus(inputStatuses, page);
5625
+ const pageStatus = getCompletionStatus(inputStatuses, page, true);
5617
5626
  const statuses = [...stepStatuses];
5618
5627
  statuses[page - 1] = pageStatus ? pageStatus : 'incomplete';
5619
5628
  setStepStatuses(statuses);
@@ -5625,6 +5634,10 @@ const FormStepper = props => {
5625
5634
  setPage(page);
5626
5635
  }
5627
5636
  function prevPage(page, disabled) {
5637
+ const pageStatus = getCompletionStatus(inputStatuses, page, true);
5638
+ const statuses = [...stepStatuses];
5639
+ statuses[page - 1] = pageStatus ? pageStatus : 'incomplete';
5640
+ setStepStatuses(statuses);
5628
5641
  page--;
5629
5642
  while (page >= 0 && disabled[page - 1]) {
5630
5643
  /* istanbul ignore next */
@@ -8266,7 +8279,7 @@ const NameInputs = ({
8266
8279
  testId: "wrapper",
8267
8280
  children: [jsx(GoAFormItem, {
8268
8281
  testId: "formitem-first-name",
8269
- label: "First Name",
8282
+ label: "First name",
8270
8283
  requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('firstName')) ? 'required' : undefined,
8271
8284
  error: (_a = errors === null || errors === void 0 ? void 0 : errors['firstName']) !== null && _a !== void 0 ? _a : '',
8272
8285
  children: jsx(GoAInput, {
@@ -8284,7 +8297,7 @@ const NameInputs = ({
8284
8297
  })
8285
8298
  }), jsx(GoAFormItem, {
8286
8299
  testId: "formitem-middle-name",
8287
- label: "Middle Name",
8300
+ label: "Middle name",
8288
8301
  requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('middleName')) ? 'required' : undefined,
8289
8302
  children: jsx(GoAInput, {
8290
8303
  type: "text",
@@ -8297,7 +8310,7 @@ const NameInputs = ({
8297
8310
  })
8298
8311
  }), jsx(GoAFormItem, {
8299
8312
  testId: "formitem-last-name",
8300
- label: "Last Name",
8313
+ label: "Last name",
8301
8314
  requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('lastName')) ? 'required' : undefined,
8302
8315
  error: (_b = errors === null || errors === void 0 ? void 0 : errors['lastName']) !== null && _b !== void 0 ? _b : '',
8303
8316
  children: jsx(GoAInput, {
@@ -8465,7 +8478,7 @@ const FullNameDobControl = props => {
8465
8478
  minChildWidth: "0ch",
8466
8479
  gap: "s",
8467
8480
  children: [jsx(GoAFormItem, {
8468
- label: "First Name",
8481
+ label: "First name",
8469
8482
  requirement: ((_a = schema === null || schema === void 0 ? void 0 : schema.required) === null || _a === void 0 ? void 0 : _a.includes('firstName')) ? 'required' : undefined,
8470
8483
  error: (_b = errors === null || errors === void 0 ? void 0 : errors['firstName']) !== null && _b !== void 0 ? _b : '',
8471
8484
  children: jsx(GoAInput, {
@@ -8485,7 +8498,7 @@ const FullNameDobControl = props => {
8485
8498
  width: "100%"
8486
8499
  })
8487
8500
  }), jsx(GoAFormItem, {
8488
- label: "Middle Name",
8501
+ label: "Middle name",
8489
8502
  requirement: ((_c = schema === null || schema === void 0 ? void 0 : schema.required) === null || _c === void 0 ? void 0 : _c.includes('middleName')) ? 'required' : undefined,
8490
8503
  children: jsx(GoAInput, {
8491
8504
  type: "text",
@@ -8497,7 +8510,7 @@ const FullNameDobControl = props => {
8497
8510
  width: "100%"
8498
8511
  })
8499
8512
  }), jsx(GoAFormItem, {
8500
- label: "Last Name",
8513
+ label: "Last name",
8501
8514
  requirement: ((_d = schema === null || schema === void 0 ? void 0 : schema.required) === null || _d === void 0 ? void 0 : _d.includes('lastName')) ? 'required' : undefined,
8502
8515
  error: (_e = errors === null || errors === void 0 ? void 0 : errors['lastName']) !== null && _e !== void 0 ? _e : '',
8503
8516
  children: jsx(GoAInput, {
@@ -8518,7 +8531,7 @@ const FullNameDobControl = props => {
8518
8531
  minChildWidth: "0ch",
8519
8532
  gap: "s",
8520
8533
  children: jsx(GoAFormItem, {
8521
- label: "Date of Birth",
8534
+ label: "Date of birth",
8522
8535
  error: (_f = errors === null || errors === void 0 ? void 0 : errors['dateOfBirth']) !== null && _f !== void 0 ? _f : '',
8523
8536
  requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('dateOfBirth')) ? 'required' : undefined,
8524
8537
  children: jsx(GoAInput, {
@@ -8550,20 +8563,20 @@ const FullNameDobReviewControl = props => {
8550
8563
  minChildWidth: "0ch",
8551
8564
  gap: "s",
8552
8565
  children: [jsx(GoAFormItem, {
8553
- label: "First Name",
8566
+ label: "First name",
8554
8567
  requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('firstName')) ? 'required' : undefined,
8555
8568
  children: jsx("div", {
8556
8569
  "data-testid": `firstName-control-${props.id}`,
8557
8570
  children: (_a = props.data) === null || _a === void 0 ? void 0 : _a.firstName
8558
8571
  })
8559
8572
  }), jsx(GoAFormItem, {
8560
- label: "Middle Name",
8573
+ label: "Middle name",
8561
8574
  children: jsx("div", {
8562
8575
  "data-testid": `middleName-control-${props.id}`,
8563
8576
  children: (_b = props.data) === null || _b === void 0 ? void 0 : _b.middleName
8564
8577
  })
8565
8578
  }), jsx(GoAFormItem, {
8566
- label: "Last Name",
8579
+ label: "Last name",
8567
8580
  requirement: (requiredFields === null || requiredFields === void 0 ? void 0 : requiredFields.includes('lastName')) ? 'required' : undefined,
8568
8581
  children: jsx("div", {
8569
8582
  "data-testid": `lastName-control-${props.id}`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.40.1",
3
+ "version": "1.40.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",
@@ -15,5 +15,5 @@ export declare const StepperContext: import("react").Context<{
15
15
  isInitialized: (_: string) => boolean;
16
16
  stepId: number;
17
17
  }>;
18
- export declare const getCompletionStatus: (table: StatusTable, step: number) => GoAFormStepStatusType | undefined;
18
+ export declare const getCompletionStatus: (table: StatusTable, step: number, isFormChanged?: boolean) => GoAFormStepStatusType | undefined;
19
19
  export declare const logRequiredFields: (table: StatusTable, step: number) => void;