@abgov/jsonforms-components 2.32.3 → 2.32.5

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.
Files changed (2) hide show
  1. package/index.esm.js +106 -90
  2. package/package.json +1 -1
package/index.esm.js CHANGED
@@ -7786,7 +7786,11 @@ const subErrorInParent = (error, paths) => {
7786
7786
  const getErrorsInScopes = (errors, scopes) => {
7787
7787
  return errors.filter(e => {
7788
7788
  // transfer scope #properties/value to data path /value
7789
- const dataPaths = scopes.map(s => '/' + toDataPath(s));
7789
+ const dataPaths = scopes.map(s => {
7790
+ const dot = toDataPath(s);
7791
+ const slash = '/' + dot.replace(/\./g, '/');
7792
+ return slash;
7793
+ });
7790
7794
  return dataPaths.includes(e.instancePath) || subErrorInParent(e, dataPaths);
7791
7795
  });
7792
7796
  };
@@ -7832,51 +7836,51 @@ const stepperReducer = (state, action) => {
7832
7836
  }
7833
7837
  case 'page/next':
7834
7838
  {
7835
- state.activeId += 1;
7836
- if (activeId === lastId) {
7837
- state.isOnReview = true;
7838
- state.hasNextButton = false;
7839
- state.hasPrevButton = false;
7840
- } else {
7841
- state.hasNextButton = true;
7842
- state.hasPrevButton = true;
7843
- state.isOnReview = false;
7844
- }
7845
- state.categories[activeId].isVisited = true;
7846
- return Object.assign({}, state);
7839
+ const newActive = activeId + 1;
7840
+ const newCategories = categories.map((c, idx) => idx === activeId ? Object.assign({}, c, {
7841
+ isVisited: true
7842
+ }) : c);
7843
+ const isOnReview = newActive === lastId + 1;
7844
+ return Object.assign({}, state, {
7845
+ activeId: newActive,
7846
+ categories: newCategories,
7847
+ isOnReview,
7848
+ hasNextButton: !isOnReview,
7849
+ hasPrevButton: newActive !== 0
7850
+ });
7847
7851
  }
7848
7852
  case 'page/prev':
7849
7853
  {
7850
- state.categories[activeId].isVisited = true;
7851
- if (activeId > 0) {
7852
- state.activeId -= 1;
7853
- state.hasPrevButton = state.activeId !== 0;
7854
- state.hasNextButton = true;
7855
- state.isOnReview = false;
7856
- }
7857
- return Object.assign({}, state);
7854
+ const newActive = Math.max(0, activeId - 1);
7855
+ const newCategories = categories.map((c, idx) => idx === activeId ? Object.assign({}, c, {
7856
+ isVisited: true
7857
+ }) : c);
7858
+ return Object.assign({}, state, {
7859
+ activeId: newActive,
7860
+ categories: newCategories,
7861
+ isOnReview: false,
7862
+ hasNextButton: true,
7863
+ hasPrevButton: newActive !== 0
7864
+ });
7858
7865
  }
7859
7866
  case 'page/to/index':
7860
7867
  {
7861
7868
  const {
7862
7869
  id
7863
7870
  } = action.payload;
7864
- state.activeId = id;
7865
- if (id === lastId + 1) {
7866
- state.isOnReview = true;
7867
- state.hasNextButton = false;
7868
- state.hasPrevButton = true;
7869
- return Object.assign({}, state);
7870
- } else {
7871
- if (state.categories[id]) {
7872
- state.categories[id].isVisited = true;
7873
- }
7874
- state.hasNextButton = id <= lastId;
7875
- state.hasPrevButton = id !== 0;
7876
- state.isOnReview = false;
7877
- state.maxReachedStep = Math.max(state.maxReachedStep, activeId);
7878
- return Object.assign({}, state);
7879
- }
7871
+ const newActive = id;
7872
+ const newCategories = categories.map((c, idx) => idx === id ? Object.assign({}, c, {
7873
+ isVisited: true
7874
+ }) : c);
7875
+ const isOnReview = newActive === lastId + 1;
7876
+ return Object.assign({}, state, {
7877
+ activeId: newActive,
7878
+ categories: newCategories,
7879
+ isOnReview,
7880
+ hasNextButton: !isOnReview,
7881
+ hasPrevButton: newActive !== 0,
7882
+ maxReachedStep: Math.max(state.maxReachedStep, activeId)
7883
+ });
7880
7884
  }
7881
7885
  case 'update/category':
7882
7886
  {
@@ -7887,40 +7891,43 @@ const stepperReducer = (state, action) => {
7887
7891
  schema,
7888
7892
  data
7889
7893
  } = action.payload;
7890
- if (id >= state.categories.length) {
7891
- return Object.assign({}, state);
7892
- }
7893
- if (schema && typeof schema === 'object') {
7894
- try {
7895
- ajv.validate(schema, data);
7896
- } catch (err) {
7897
- console.warn('AJV validation error:', err);
7898
- }
7899
- }
7900
- const incompletePaths = getIncompletePaths(ajv, schema, data, ((_a = state.categories[id]) === null || _a === void 0 ? void 0 : _a.scopes) || []);
7901
- const errorsInCategory = getErrorsInScopes(errors, ((_b = state.categories[id]) === null || _b === void 0 ? void 0 : _b.scopes) || []);
7902
- if (state.categories[id]) {
7903
- state.categories[id].isCompleted = (incompletePaths === null || incompletePaths === void 0 ? void 0 : incompletePaths.length) === 0;
7904
- state.categories[id].isValid = errorsInCategory.length === 0;
7905
- state.categories[id].isVisited = true;
7894
+ if (id >= categories.length) return state;
7895
+ try {
7896
+ ajv.validate(schema, data);
7897
+ } catch (err) {
7898
+ console.warn('AJV validation error:', err);
7906
7899
  }
7907
- return Object.assign({}, state);
7900
+ const incompletePaths = getIncompletePaths(ajv, schema, data, ((_a = categories[id]) === null || _a === void 0 ? void 0 : _a.scopes) || []);
7901
+ const errorsInCategory = getErrorsInScopes(errors, ((_b = categories[id]) === null || _b === void 0 ? void 0 : _b.scopes) || []);
7902
+ const newCategories = categories.map((cat, idx) => idx === id ? Object.assign({}, cat, {
7903
+ isCompleted: incompletePaths.length === 0,
7904
+ isValid: errorsInCategory.length === 0,
7905
+ isVisited: true
7906
+ }) : cat);
7907
+ return Object.assign({}, state, {
7908
+ categories: newCategories
7909
+ });
7908
7910
  }
7909
7911
  case 'validate/form':
7910
7912
  {
7911
7913
  const {
7912
7914
  errors = []
7913
7915
  } = action.payload;
7914
- state.isValid = errors.length === 0;
7915
- return Object.assign({}, state);
7916
+ return Object.assign({}, state, {
7917
+ isValid: errors.length === 0
7918
+ });
7916
7919
  }
7917
7920
  case 'toggle/category/review-link':
7918
7921
  {
7919
7922
  const {
7920
7923
  id
7921
7924
  } = action.payload;
7922
- state.categories[id].showReviewPageLink = !state.categories[id].showReviewPageLink;
7923
- return Object.assign({}, state);
7925
+ const newCategories = categories.map((cat, idx) => idx === id ? Object.assign({}, cat, {
7926
+ showReviewPageLink: !cat.showReviewPageLink
7927
+ }) : cat);
7928
+ return Object.assign({}, state, {
7929
+ categories: newCategories
7930
+ });
7924
7931
  }
7925
7932
  default:
7926
7933
  return state;
@@ -7982,7 +7989,7 @@ const JsonFormsStepperContextProvider = ({
7982
7989
  children,
7983
7990
  StepperProps
7984
7991
  }) => {
7985
- var _a, _b;
7992
+ var _a, _b, _c;
7986
7993
  const ctx = useJsonForms();
7987
7994
  /* istanbul ignore next */
7988
7995
  const {
@@ -7994,6 +8001,20 @@ const JsonFormsStepperContextProvider = ({
7994
8001
  const [stepperState, dispatch] = useReducer(stepperReducer, createStepperContextInitData(StepperProps));
7995
8002
  const stepperDispatch = (StepperProps === null || StepperProps === void 0 ? void 0 : StepperProps.customDispatch) || dispatch;
7996
8003
  const isCacheStatus = (_a = uischema.options) === null || _a === void 0 ? void 0 : _a.cacheStatus;
8004
+ //prevents infinite loop refresh
8005
+ const doValidatePage = useCallback(id => {
8006
+ var _a;
8007
+ stepperDispatch({
8008
+ type: 'update/category',
8009
+ payload: {
8010
+ errors: (_a = ctx === null || ctx === void 0 ? void 0 : ctx.core) === null || _a === void 0 ? void 0 : _a.errors,
8011
+ id,
8012
+ ajv,
8013
+ schema,
8014
+ data
8015
+ }
8016
+ });
8017
+ }, [stepperDispatch, (_b = ctx === null || ctx === void 0 ? void 0 : ctx.core) === null || _b === void 0 ? void 0 : _b.errors, ajv, schema, data]);
7997
8018
  const context = useMemo(() => {
7998
8019
  return {
7999
8020
  isProvided: true,
@@ -8037,35 +8058,22 @@ const JsonFormsStepperContextProvider = ({
8037
8058
  }
8038
8059
  });
8039
8060
  },
8040
- validatePage: id => {
8041
- var _a;
8042
- stepperDispatch({
8043
- type: 'update/category',
8044
- payload: {
8045
- errors: (_a = ctx === null || ctx === void 0 ? void 0 : ctx.core) === null || _a === void 0 ? void 0 : _a.errors,
8046
- id,
8047
- ajv,
8048
- schema,
8049
- data
8050
- }
8051
- });
8052
- },
8061
+ validatePage: doValidatePage,
8053
8062
  goToPage: id => {
8054
8063
  var _a, _b, _c;
8055
8064
  ajv.validate(schema, ((_a = ctx.core) === null || _a === void 0 ? void 0 : _a.data) || {});
8056
- if (stepperState.isOnReview !== true) {
8057
- for (let i = 0; i < id; i++) {
8058
- stepperDispatch({
8059
- type: 'update/category',
8060
- payload: {
8061
- errors: (_b = ctx === null || ctx === void 0 ? void 0 : ctx.core) === null || _b === void 0 ? void 0 : _b.errors,
8062
- id: i,
8063
- ajv,
8064
- schema,
8065
- data
8066
- }
8067
- });
8068
- }
8065
+ // Only update the current category
8066
+ if (!stepperState.isOnReview && id < stepperState.categories.length) {
8067
+ stepperDispatch({
8068
+ type: 'update/category',
8069
+ payload: {
8070
+ errors: (_b = ctx === null || ctx === void 0 ? void 0 : ctx.core) === null || _b === void 0 ? void 0 : _b.errors,
8071
+ id,
8072
+ ajv,
8073
+ schema,
8074
+ data
8075
+ }
8076
+ });
8069
8077
  }
8070
8078
  stepperDispatch({
8071
8079
  type: 'validate/form',
@@ -8089,7 +8097,7 @@ const JsonFormsStepperContextProvider = ({
8089
8097
  });
8090
8098
  }
8091
8099
  };
8092
- }, [stepperDispatch, stepperState, (_b = ctx.core) === null || _b === void 0 ? void 0 : _b.errors, ajv, schema, data]);
8100
+ }, [stepperDispatch, stepperState, (_c = ctx.core) === null || _c === void 0 ? void 0 : _c.errors, ajv, schema, data]);
8093
8101
  /* istanbul ignore next */
8094
8102
  useEffect(() => {
8095
8103
  const handleBeforeUnload = () => {
@@ -8130,6 +8138,7 @@ const summaryLabel = 'Summary';
8130
8138
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
8131
8139
  const FormStepper = props => {
8132
8140
  const formStepperCtx = useContext(JsonFormsStepperContext);
8141
+ const memoStepperProps = useMemo(() => Object.assign({}, props), [props]);
8133
8142
  /**
8134
8143
  * StepperCtx can only be provided once to prevent issues from categorization in categorization
8135
8144
  * */
@@ -8139,7 +8148,7 @@ const FormStepper = props => {
8139
8148
  return jsx(FormStepperView, Object.assign({}, props));
8140
8149
  }
8141
8150
  return jsx(JsonFormsStepperContextProvider, {
8142
- StepperProps: Object.assign({}, props),
8151
+ StepperProps: memoStepperProps,
8143
8152
  children: jsx(FormStepperView, Object.assign({}, props))
8144
8153
  });
8145
8154
  };
@@ -9026,9 +9035,14 @@ const BackButtonWrapper = styled.span(_t$5 || (_t$5 = _$5`
9026
9035
 
9027
9036
  .back-link {
9028
9037
  margin-top: var(--goa-space-m);
9038
+ color: var(--goa-color-interactive-default);
9039
+ text-decoration: underline;
9040
+ text-underline-offset: 2px;
9041
+ text-decoration-color: currentColor;
9042
+ display: inline-block;
9029
9043
  }
9030
9044
  display: inline-block;
9031
- color: #0070c4;
9045
+ color: var(--goa-color-interactive-default);
9032
9046
  cursor: pointer;
9033
9047
  margin-bottom: var(--goa-space-m);
9034
9048
 
@@ -9037,7 +9051,7 @@ const BackButtonWrapper = styled.span(_t$5 || (_t$5 = _$5`
9037
9051
  position: relative;
9038
9052
  top: 3px;
9039
9053
  right: 2px;
9040
- color: #0070c4;
9054
+ color: var(--goa-color-interactive-default);
9041
9055
  margin-left: 4px;
9042
9056
  }
9043
9057
  `));
@@ -9268,6 +9282,7 @@ function hasDataInScopes(data, scopes) {
9268
9282
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
9269
9283
  const FormPageStepper = props => {
9270
9284
  const formStepperCtx = useContext(JsonFormsStepperContext);
9285
+ const memoStepperProps = useMemo(() => Object.assign({}, props), [props]);
9271
9286
  /**
9272
9287
  * StepperCtx can only be provided once to prevent issues from categorization in categorization
9273
9288
  * */
@@ -9275,7 +9290,7 @@ const FormPageStepper = props => {
9275
9290
  return jsx(FormPagesView, Object.assign({}, props));
9276
9291
  }
9277
9292
  return jsx(JsonFormsStepperContextProvider, {
9278
- StepperProps: Object.assign({}, props),
9293
+ StepperProps: memoStepperProps,
9279
9294
  children: jsx(FormPagesView, Object.assign({}, props))
9280
9295
  });
9281
9296
  };
@@ -11886,6 +11901,7 @@ const AddressLookUpControl = props => {
11886
11901
  }));
11887
11902
  };
11888
11903
  useEffect(() => {
11904
+ if (!debouncedRenderAddress) return;
11889
11905
  handleInputChange('addressLine1', debouncedRenderAddress);
11890
11906
  }, [debouncedRenderAddress]); // eslint-disable-line react-hooks/exhaustive-deps
11891
11907
  useEffect(() => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "2.32.3",
3
+ "version": "2.32.5",
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",