@abgov/jsonforms-components 1.52.0 → 1.53.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
@@ -5,7 +5,7 @@ import styled from 'styled-components';
5
5
  import React, { createContext, useContext, useReducer, useMemo, useEffect, useState, useRef, useCallback } from 'react';
6
6
  import axios from 'axios';
7
7
  import get$1 from 'lodash/get';
8
- import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, toDataPath, getControlPath, deriveLabelForUISchemaElement, isEnabled, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, schemaMatches, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
8
+ import { rankWith, isStringControl, and, optionIs, uiTypeIs, isDateControl, isNumberControl, isIntegerControl, isDateTimeControl, isTimeControl, isEnumControl, isBooleanControl, getAjv, isVisible, getControlPath, toDataPath, deriveLabelForUISchemaElement, isEnabled, schemaTypeIs, formatIs, createDefaultValue, Paths, or, isObjectArrayControl, isPrimitiveArrayControl, schemaMatches, hasType, isControl, isCategorization, isLayout } from '@jsonforms/core';
9
9
  import { withJsonFormsControlProps, withJsonFormsRendererProps, withJsonFormsEnumProps, withTranslateProps, useJsonForms, JsonFormsDispatch, withJsonFormsLayoutProps, withJsonFormsArrayLayoutProps, withJsonFormsCellProps } from '@jsonforms/react';
10
10
  import * as _$b from 'lodash';
11
11
  import { isEqual, isObject as isObject$f } from 'lodash';
@@ -5854,6 +5854,48 @@ const FormStepperReviewer = props => {
5854
5854
  };
5855
5855
  const FormStepperReviewControl = withAjvProps(withTranslateProps(withJsonFormsLayoutProps(FormStepperReviewer)));
5856
5856
 
5857
+ const isErrorPathIncluded = (errorPaths, path) => {
5858
+ return errorPaths.some(ePath => {
5859
+ /**
5860
+ * case A: errorPaths: [name] path: [name]
5861
+ *
5862
+ * case B: errorPath: [name] path: [name.firstName]
5863
+ * */
5864
+ return ePath === path || path.startsWith(ePath + '.');
5865
+ });
5866
+ };
5867
+ function isNumber(value) {
5868
+ return value != null && value !== '' && !isNaN(Number(value.toString()));
5869
+ }
5870
+ const getIncompletePaths = (ajv, scopes) => {
5871
+ var _a;
5872
+ const requiredErrorPaths = (_a = ajv === null || ajv === void 0 ? void 0 : ajv.errors) === null || _a === void 0 ? void 0 : _a.filter(e => e.keyword === 'required').map(e => {
5873
+ return getControlPath(e);
5874
+ });
5875
+ const _scopes = scopes.map(scope => toDataPath(scope)).filter(path => requiredErrorPaths && isErrorPathIncluded(requiredErrorPaths, path));
5876
+ return _scopes;
5877
+ };
5878
+ const subErrorInParent = (error, paths) => {
5879
+ /*
5880
+ Detect is there sub error in an object array.
5881
+ For example: error with instance path /roadmap/0/when belongs to /roadmap
5882
+ */
5883
+ const errorPaths = error.instancePath.split('/');
5884
+ if (errorPaths.length < 3) return false;
5885
+ if (isNumber(errorPaths[errorPaths.length - 2])) {
5886
+ const parentPath = errorPaths.slice(0, errorPaths.length - 2).join('/');
5887
+ return paths.includes(parentPath);
5888
+ }
5889
+ return false;
5890
+ };
5891
+ const getErrorsInScopes = (errors, scopes) => {
5892
+ return errors.filter(e => {
5893
+ // transfer scope #properties/value to data path /value
5894
+ const dataPaths = scopes.map(s => '/' + toDataPath(s));
5895
+ return dataPaths.includes(e.instancePath) || subErrorInParent(e, dataPaths);
5896
+ });
5897
+ };
5898
+
5857
5899
  const stepperReducer = (state, action) => {
5858
5900
  const {
5859
5901
  activeId,
@@ -5921,7 +5963,7 @@ const stepperReducer = (state, action) => {
5921
5963
  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
5964
  */
5923
5965
  const incompletePaths = getIncompletePaths(ajv, state.categories[id].scopes);
5924
- const errorsInCategory = errors.filter(e => categories[id].scopes.map(s => '/' + toDataPath(s)).includes(e.instancePath));
5966
+ const errorsInCategory = getErrorsInScopes(errors, state.categories[id].scopes || []);
5925
5967
  state.categories[id].isCompleted = (incompletePaths === null || incompletePaths === void 0 ? void 0 : incompletePaths.length) === 0;
5926
5968
  state.categories[id].isValid = errorsInCategory.length === 0;
5927
5969
  return Object.assign({}, state);
@@ -5939,24 +5981,6 @@ const stepperReducer = (state, action) => {
5939
5981
  }
5940
5982
  };
5941
5983
 
5942
- const isErrorPathIncluded = (errorPaths, path) => {
5943
- return errorPaths.some(ePath => {
5944
- /**
5945
- * case A: errorPaths: [name] path: [name]
5946
- *
5947
- * case B: errorPath: [name] path: [name.firstName]
5948
- * */
5949
- return ePath === path || path.startsWith(ePath + '.');
5950
- });
5951
- };
5952
- const getIncompletePaths = (ajv, scopes) => {
5953
- var _a;
5954
- const requiredErrorPaths = (_a = ajv === null || ajv === void 0 ? void 0 : ajv.errors) === null || _a === void 0 ? void 0 : _a.filter(e => e.keyword === 'required').map(e => {
5955
- return getControlPath(e);
5956
- });
5957
- const _scopes = scopes.map(scope => toDataPath(scope)).filter(path => requiredErrorPaths && isErrorPathIncluded(requiredErrorPaths, path));
5958
- return _scopes;
5959
- };
5960
5984
  const createStepperContextInitData = props => {
5961
5985
  var _a;
5962
5986
  const {
@@ -6156,7 +6180,7 @@ const FormStepperView = props => {
6156
6180
  return jsx(GoAFormStep, {
6157
6181
  "data-testid": `stepper-tab-${index}`,
6158
6182
  text: `${c.label}`,
6159
- status: c.isCompleted && c.isValid ? 'complete' : 'incomplete'
6183
+ status: c.isVisited ? c.isCompleted && c.isValid ? 'complete' : 'incomplete' : undefined
6160
6184
  }, `stepper-tab-${index}`);
6161
6185
  }), jsx(GoAFormStep, {
6162
6186
  text: "Review"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.52.0",
3
+ "version": "1.53.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",
@@ -1,7 +1,6 @@
1
1
  import { ReactNode, Dispatch } from 'react';
2
2
  import { CategorizationStepperLayoutRendererProps } from '../types';
3
3
  import { StepperContextDataType, CategoryState } from './types';
4
- import Ajv from 'ajv';
5
4
  import { JsonFormStepperDispatch } from './reducer';
6
5
  export interface JsonFormsStepperContextProviderProps {
7
6
  children: ReactNode;
@@ -21,7 +20,5 @@ export interface JsonFormsStepperContextProps {
21
20
  goToPage: (id: number, updateCategoryId?: number) => void;
22
21
  isProvided?: boolean;
23
22
  }
24
- export declare const isErrorPathIncluded: (errorPaths: string[], path: string) => boolean;
25
- export declare const getIncompletePaths: (ajv: Ajv, scopes: string[]) => string[];
26
23
  export declare const JsonFormsStepperContext: import("react").Context<JsonFormsStepperContextProps | undefined>;
27
24
  export declare const JsonFormsStepperContextProvider: ({ children, StepperProps, }: JsonFormsStepperContextProviderProps) => JSX.Element;
@@ -1,3 +1,4 @@
1
1
  export * from './StepperContext';
2
2
  export * from './types';
3
3
  export * from './reducer';
4
+ export * from './util';
@@ -0,0 +1,4 @@
1
+ import Ajv, { ErrorObject } from 'ajv';
2
+ export declare const isErrorPathIncluded: (errorPaths: string[], path: string) => boolean;
3
+ export declare const getIncompletePaths: (ajv: Ajv, scopes: string[]) => string[];
4
+ export declare const getErrorsInScopes: (errors: ErrorObject[], scopes: string[]) => ErrorObject[];