@abgov/jsonforms-components 1.55.0 → 1.55.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
@@ -6009,6 +6009,7 @@ const stepperReducer = (state, action) => {
6009
6009
  state.hasNextButton = id <= lastId;
6010
6010
  state.hasPrevButton = id !== 0;
6011
6011
  state.isOnReview = false;
6012
+ state.maxReachedStep = Math.max(state.maxReachedStep, activeId);
6012
6013
  return Object.assign({}, state);
6013
6014
  }
6014
6015
  }
@@ -6078,7 +6079,8 @@ const createStepperContextInitData = props => {
6078
6079
  hasPrevButton: activeId > 0 && activeId !== (categories === null || categories === void 0 ? void 0 : categories.length),
6079
6080
  path,
6080
6081
  isOnReview: activeId === (categories === null || categories === void 0 ? void 0 : categories.length),
6081
- isValid: valid === true
6082
+ isValid: valid === true,
6083
+ maxReachedStep: 0
6082
6084
  };
6083
6085
  };
6084
6086
  const JsonFormsStepperContext = /*#__PURE__*/createContext(undefined);
@@ -6115,6 +6117,17 @@ const JsonFormsStepperContextProvider = ({
6115
6117
  selectCategory: id => {
6116
6118
  return stepperState.categories[id];
6117
6119
  },
6120
+ validatePage: id => {
6121
+ var _a;
6122
+ stepperDispatch({
6123
+ type: 'update/category',
6124
+ payload: {
6125
+ errors: (_a = ctx === null || ctx === void 0 ? void 0 : ctx.core) === null || _a === void 0 ? void 0 : _a.errors,
6126
+ id,
6127
+ ajv
6128
+ }
6129
+ });
6130
+ },
6118
6131
  goToPage: (id, updateCategoryId) => {
6119
6132
  var _a, _b, _c;
6120
6133
  ajv.validate(schema, ((_a = ctx.core) === null || _a === void 0 ? void 0 : _a.data) || {});
@@ -6147,6 +6160,7 @@ const JsonFormsStepperContextProvider = ({
6147
6160
  }, [stepperDispatch, stepperState, (_a = ctx.core) === null || _a === void 0 ? void 0 : _a.errors]);
6148
6161
  useEffect(() => {
6149
6162
  if ((context === null || context === void 0 ? void 0 : context.isProvided) === true) {
6163
+ /* The block is used to cache the state for the tenant web app review editor */
6150
6164
  stepperDispatch({
6151
6165
  type: 'update/uischema',
6152
6166
  payload: {
@@ -6155,21 +6169,10 @@ const JsonFormsStepperContextProvider = ({
6155
6169
  }))
6156
6170
  }
6157
6171
  });
6172
+ context.goToPage(stepperState.maxReachedStep);
6173
+ context.goToPage(stepperState.activeId);
6158
6174
  }
6159
6175
  }, [JSON.stringify(StepperProps.uischema), JSON.stringify(StepperProps.schema)]);
6160
- useEffect(() => {
6161
- const newState = createStepperContextInitData(Object.assign(Object.assign({}, StepperProps), {
6162
- activeId: stepperState === null || stepperState === void 0 ? void 0 : stepperState.activeId
6163
- }));
6164
- if (JSON.stringify(newState) !== JSON.stringify(stepperState)) {
6165
- stepperDispatch({
6166
- type: 'update/uischema',
6167
- payload: {
6168
- state: newState
6169
- }
6170
- });
6171
- }
6172
- }, [StepperProps]);
6173
6176
  return jsx(JsonFormsStepperContext.Provider, {
6174
6177
  value: context,
6175
6178
  children: children
@@ -6429,17 +6432,19 @@ const FormPagesView = props => {
6429
6432
  } = props;
6430
6433
  const enumerators = useContext(JsonFormContext);
6431
6434
  const formStepperCtx = useContext(JsonFormsStepperContext);
6435
+ const {
6436
+ validatePage,
6437
+ goToPage
6438
+ } = formStepperCtx;
6432
6439
  const {
6433
6440
  categories,
6434
6441
  isOnReview,
6435
- isValid
6442
+ isValid,
6443
+ activeId
6436
6444
  } = formStepperCtx.selectStepperState();
6437
6445
  const submitFormFunction = enumerators === null || enumerators === void 0 ? void 0 : enumerators.submitFunction.get('submit-form');
6438
6446
  const submitForm = submitFormFunction && submitFormFunction();
6439
- uischema.options || {};
6440
6447
  const [isOpen, setIsOpen] = useState(false);
6441
- useState(false);
6442
- const [selectedPage, setSelectedPage] = useState(0);
6443
6448
  const handleSubmit = () => {
6444
6449
  if (submitForm) {
6445
6450
  submitForm(data);
@@ -6450,8 +6455,9 @@ const FormPagesView = props => {
6450
6455
  const onCloseModal = () => {
6451
6456
  setIsOpen(false);
6452
6457
  };
6453
- // eslint-disable-next-line
6454
- uischema.options;
6458
+ useEffect(() => {
6459
+ validatePage(activeId);
6460
+ }, [data]);
6455
6461
  return jsxs("div", {
6456
6462
  "data-testid": "form-stepper-test-wrapper",
6457
6463
  children: [jsx(Visible, {
@@ -6471,7 +6477,7 @@ const FormPagesView = props => {
6471
6477
  cells,
6472
6478
  data
6473
6479
  };
6474
- if (index === selectedPage && !isOnReview) {
6480
+ if (index === activeId && !isOnReview) {
6475
6481
  return jsxs("div", {
6476
6482
  "data-testid": `step_${index}-content-pages`,
6477
6483
  style: {
@@ -6479,7 +6485,7 @@ const FormPagesView = props => {
6479
6485
  },
6480
6486
  children: [index > 0 && jsx(BackButton, {
6481
6487
  testId: "back-button",
6482
- link: () => setSelectedPage(index - 1),
6488
+ link: () => goToPage(activeId - 1),
6483
6489
  text: "Back"
6484
6490
  }), jsxs(PageRenderPadding, {
6485
6491
  children: [jsxs("h3", {
@@ -6488,8 +6494,8 @@ const FormPagesView = props => {
6488
6494
  }), jsx(PageRenderPadding, {
6489
6495
  children: index !== categories.length - 1 ? jsx(GoAButton, {
6490
6496
  type: "submit",
6491
- onClick: () => setSelectedPage(index + 1),
6492
- disabled: !category.isValid,
6497
+ onClick: () => goToPage(activeId + 1),
6498
+ disabled: !(category.isValid && category.isCompleted),
6493
6499
  testId: "pages-save-continue-btn",
6494
6500
  children: "Save and continue"
6495
6501
  }) : jsx(GoAButton, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.55.0",
3
+ "version": "1.55.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",
@@ -18,6 +18,7 @@ export interface JsonFormsStepperContextProps {
18
18
  selectPath: () => string;
19
19
  selectCategory: (id: number) => CategoryState;
20
20
  goToPage: (id: number, updateCategoryId?: number) => void;
21
+ validatePage: (id: number) => void;
21
22
  isProvided?: boolean;
22
23
  }
23
24
  export declare const JsonFormsStepperContext: import("react").Context<JsonFormsStepperContextProps | undefined>;
@@ -23,5 +23,6 @@ export interface StepperContextDataType {
23
23
  path: string;
24
24
  isOnReview: boolean;
25
25
  isValid: boolean;
26
+ maxReachedStep: number;
26
27
  }
27
28
  export type CategorizationElement = Category | Categorization;