@abgov/jsonforms-components 1.14.2 → 1.14.4

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
@@ -4092,6 +4092,30 @@ const validateData = (jsonSchema, data, ajv) => {
4092
4092
  }
4093
4093
  };
4094
4094
 
4095
+ /**
4096
+ * Steps can be hidden:
4097
+ * When the user clicks on a step in the stepper function, it returns
4098
+ * a step number relative to all steps. Map to the step number relative
4099
+ * to the visible steps.
4100
+ */
4101
+ const mapToVisibleStep = (step, allSteps, visibleSteps) => {
4102
+ if (visibleSteps.length < 1) return 0;
4103
+ if (step < 1) return 1;
4104
+ if (allSteps.length !== visibleSteps.length) {
4105
+ const stepIndex = step - 1;
4106
+ if (step > 1 && step <= allSteps.length) {
4107
+ // Check to see if the the step is visible
4108
+ const selectedLabel = allSteps[stepIndex];
4109
+ const selectedIndex = visibleSteps.indexOf(selectedLabel);
4110
+ step = selectedIndex !== -1 ? selectedIndex + 1 : 1;
4111
+ }
4112
+ if (step > allSteps.length) {
4113
+ step = visibleSteps.length;
4114
+ }
4115
+ }
4116
+ return step;
4117
+ };
4118
+
4095
4119
  const FormStepper = props => {
4096
4120
  var _a, _b, _c, _d;
4097
4121
  const {
@@ -4173,35 +4197,16 @@ const FormStepper = props => {
4173
4197
  }
4174
4198
  setPage(page);
4175
4199
  }
4176
- const getNextStep = step => {
4177
- const rawCategoryLabels = rawCategories.elements.map(category => category.label);
4178
- if (rawCategoryLabels.length !== CategoryLabels.length) {
4179
- if (step > 1 && step <= rawCategoryLabels.length) {
4180
- const selectedTabLabel = rawCategoryLabels[step - 1];
4181
- const selectedTab = CategoryLabels.indexOf(selectedTabLabel);
4182
- const newStep = selectedTab !== -1 ? selectedTab + 1 : step;
4183
- return newStep;
4184
- }
4185
- if (step > rawCategoryLabels.length) {
4186
- return step - 1;
4187
- }
4188
- }
4189
- return step;
4190
- };
4191
4200
  function setTab(page) {
4192
- page = getNextStep(page);
4193
- setStep(page);
4194
- if (page < 1 || page > categories.length + 1) return;
4195
- setShowNextBtn(categories.length + 1 !== page);
4201
+ const rawCategoryLabels = rawCategories.elements.map(category => category.label);
4202
+ page = mapToVisibleStep(page, rawCategoryLabels, CategoryLabels);
4203
+ setPage(page);
4196
4204
  }
4197
4205
  function setPage(page) {
4198
4206
  setStep(page);
4199
4207
  if (page < 1 || page > categories.length + 1) return;
4200
4208
  setShowNextBtn(categories.length + 1 !== page);
4201
4209
  }
4202
- const changePage = index => {
4203
- setPage(index + 1);
4204
- };
4205
4210
  const updateInputStatus = inputStatus => {
4206
4211
  inputStatuses[inputStatus.id] = inputStatus;
4207
4212
  setInputStatuses(Object.assign({}, inputStatuses));
@@ -4273,12 +4278,14 @@ const FormStepper = props => {
4273
4278
  children: categories.map((category, index) => {
4274
4279
  const categoryLabel = category.label || category.i18n || 'Unknown Category';
4275
4280
  const requiredFields = getAllRequiredFields(schema);
4281
+ const testId = `${categoryLabel}-review-link`;
4276
4282
  return jsxs(ReviewItemSection, {
4277
4283
  children: [jsxs(ReviewItemHeader, {
4278
4284
  children: [jsx(ReviewItemTitle, {
4279
4285
  children: categoryLabel
4280
4286
  }), jsx(Anchor, {
4281
- onClick: () => changePage(index),
4287
+ onClick: () => setPage(index + 1),
4288
+ "data-testid": testId,
4282
4289
  children: readOnly ? 'View' : 'Edit'
4283
4290
  })]
4284
4291
  }), jsx(Grid, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "1.14.2",
3
+ "version": "1.14.4",
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",
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Steps can be hidden:
3
+ * When the user clicks on a step in the stepper function, it returns
4
+ * a step number relative to all steps. Map to the step number relative
5
+ * to the visible steps.
6
+ */
7
+ export declare const mapToVisibleStep: (step: number, allSteps: string[], visibleSteps: (string | undefined)[]) => number;