@abgov/jsonforms-components 2.33.0 → 2.34.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
@@ -8924,9 +8924,10 @@ const SummaryRow = ({
8924
8924
  };
8925
8925
 
8926
8926
  function mergeOrphanSections(sections) {
8927
+ var _a;
8927
8928
  const result = [];
8928
8929
  for (const section of sections) {
8929
- const hasValidTitle = section.sectionTitle && section.sectionTitle.trim() !== '';
8930
+ const hasValidTitle = ((_a = section.sectionTitle) === null || _a === void 0 ? void 0 : _a.trim()) !== '';
8930
8931
  if (hasValidTitle) {
8931
8932
  result.push(Object.assign({}, section, {
8932
8933
  categories: [...section.categories]
@@ -8945,73 +8946,57 @@ function mergeOrphanSections(sections) {
8945
8946
  return result;
8946
8947
  }
8947
8948
  function expandSections(inputArray) {
8948
- if (!inputArray || inputArray.length === 0) return [];
8949
- const originalSection = inputArray[0];
8950
- const categories = originalSection.categories || [];
8951
- return categories.map((category, index) => ({
8952
- sectionTitle: `${category.label} Section`,
8953
- categories: [category]
8949
+ if (!(inputArray === null || inputArray === void 0 ? void 0 : inputArray.length)) return [];
8950
+ const original = inputArray[0];
8951
+ const categories = original.categories || [];
8952
+ return categories.map(cat => ({
8953
+ sectionTitle: `${cat.label} Section`,
8954
+ categories: [cat]
8954
8955
  }));
8955
8956
  }
8956
- /* eslint-disable jsx-a11y/anchor-is-valid */
8957
+ const shouldShow = cat => {
8958
+ var _a, _b;
8959
+ return ((_b = (_a = cat === null || cat === void 0 ? void 0 : cat.uischema) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.showInTaskList) !== false;
8960
+ };
8961
+ function updateCompletion(group, index) {
8962
+ const category = group[index];
8963
+ if (!shouldShow(category)) return category;
8964
+ let endIndex = index;
8965
+ while (endIndex + 1 < group.length && !shouldShow(group[endIndex + 1])) {
8966
+ endIndex++;
8967
+ }
8968
+ const relevant = group.slice(index, endIndex + 1); // current + subsequent hidden
8969
+ const newIsCompleted = relevant.every(cat => cat.isCompleted);
8970
+ if (category.isCompleted === newIsCompleted) return category;
8971
+ return Object.assign({}, category, {
8972
+ isCompleted: newIsCompleted
8973
+ });
8974
+ }
8957
8975
  const TaskList = ({
8958
8976
  categories,
8959
8977
  onClick,
8960
8978
  title,
8961
8979
  subtitle,
8962
- isValid
8980
+ isValid,
8981
+ hideSummary
8963
8982
  }) => {
8964
8983
  const testid = 'table-of-contents';
8965
- const sectioned = getCategorySections(categories);
8966
- const [completedGroups, setCompletedGroups] = useState(0);
8967
- const [total, setTotal] = useState(sectioned.filter(s => s.categories && s.sectionTitle).length);
8968
- const shouldShow = cat => {
8969
- var _a, _b;
8970
- return ((_b = (_a = cat === null || cat === void 0 ? void 0 : cat.uischema) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.showInTaskList) !== false;
8971
- };
8972
- const updateCompletion = (group, category, groupIndex) => {
8973
- let leftIndex = groupIndex;
8974
- while (leftIndex > 0 && !shouldShow(group[leftIndex - 1])) {
8975
- leftIndex--;
8976
- }
8977
- let rightIndex = groupIndex;
8978
- while (rightIndex < group.length - 1 && !shouldShow(group[rightIndex + 1])) {
8979
- rightIndex++;
8980
- }
8981
- const currentLocalGroup = group.slice(leftIndex, rightIndex + 1);
8982
- const modifyCategory = JSON.parse(JSON.stringify(category));
8983
- modifyCategory.isCompleted = currentLocalGroup.length === currentLocalGroup.filter(cat => cat.isCompleted).length;
8984
- return modifyCategory;
8985
- };
8986
- const showInTaskListList = categories.map(cat => {
8987
- var _a, _b, _c, _d;
8988
- return ((_b = (_a = cat === null || cat === void 0 ? void 0 : cat.uischema) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.showInTaskList) || ((_d = (_c = cat === null || cat === void 0 ? void 0 : cat.uischema) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.showInTaskList) === undefined;
8989
- });
8984
+ // Merge and expand sections
8985
+ const mergedSections = useMemo(() => {
8986
+ let sections = mergeOrphanSections(getCategorySections(categories));
8987
+ if (sections.length === 1) {
8988
+ sections = expandSections(sections);
8989
+ }
8990
+ return sections;
8991
+ }, [categories]);
8992
+ // Derived values
8993
+ const totalGroups = useMemo(() => mergedSections.filter(section => section.categories.some(shouldShow)).length, [mergedSections]);
8994
+ const completedGroups = useMemo(() => mergedSections.filter(section => {
8995
+ const visibleCats = section.categories.filter(shouldShow);
8996
+ return visibleCats.length > 0 && visibleCats.every(cat => cat.isCompleted);
8997
+ }).length, [mergedSections]);
8990
8998
  let globalIndex = 0;
8991
8999
  let sectionIndex = 1;
8992
- useEffect(() => {
8993
- let count = 0;
8994
- let mergedSections = mergeOrphanSections(sectioned);
8995
- if (mergedSections.length === 1) {
8996
- mergedSections = expandSections(mergedSections);
8997
- setTotal(mergedSections.length);
8998
- }
8999
- mergedSections.forEach(({
9000
- categories: group
9001
- }) => {
9002
- let countInGroup = 0;
9003
- group.forEach((category, groupIndex) => {
9004
- const modifyCategory = updateCompletion(group, category, groupIndex);
9005
- if (getCategoryStatus(modifyCategory) === 'Completed') {
9006
- countInGroup++;
9007
- }
9008
- });
9009
- if (countInGroup === group.length) {
9010
- count++;
9011
- }
9012
- });
9013
- setCompletedGroups(count);
9014
- }, [categories, sectioned]); // re-run whenever categories change
9015
9000
  return jsx(PageBorder, {
9016
9001
  children: jsxs("div", {
9017
9002
  "data-testid": testid,
@@ -9028,40 +9013,32 @@ const TaskList = ({
9028
9013
  children: subtitle
9029
9014
  }), jsx(ApplicationStatus, {
9030
9015
  completedGroups: completedGroups,
9031
- totalGroups: total
9016
+ totalGroups: totalGroups
9032
9017
  }), jsx(GoATable, {
9033
9018
  width: "100%",
9034
9019
  children: jsxs("tbody", {
9035
- children: [sectioned.map(({
9020
+ children: [mergedSections.map(({
9036
9021
  sectionTitle,
9037
9022
  categories: group
9038
9023
  }, index) => jsxs(React.Fragment, {
9039
- children: [sectionTitle && showInTaskListList[globalIndex] && jsx(SectionHeaderRow, {
9024
+ children: [sectionTitle && group.some(shouldShow) && jsx(SectionHeaderRow, {
9040
9025
  title: sectionTitle,
9041
9026
  index: sectionIndex++
9042
9027
  }, `section-${sectionTitle}`), group.map((category, groupIndex) => {
9043
- const showCurrent = showInTaskListList[globalIndex];
9044
- const idx = globalIndex++; // renamed from `index` to avoid shadowing
9045
- let currentCategory = category;
9046
- const modifyCategory = updateCompletion(group, category, groupIndex);
9047
- const showGroupTaskListList = categories.map(cat => shouldShow(cat));
9048
- if (showGroupTaskListList.length > showGroupTaskListList.filter(item => item === true).length) {
9049
- currentCategory = modifyCategory;
9050
- }
9051
- if (showCurrent) {
9052
- return jsx(CategoryRow, {
9053
- category: currentCategory,
9054
- index: idx,
9055
- onClick: onClick
9056
- }, `cat-${category.label}-${idx}`);
9057
- }
9058
- return null;
9028
+ const showCurrent = shouldShow(category);
9029
+ const idx = globalIndex++;
9030
+ const currentCategory = showCurrent ? updateCompletion(group, groupIndex) : category;
9031
+ return showCurrent ? jsx(CategoryRow, {
9032
+ category: currentCategory,
9033
+ index: idx,
9034
+ onClick: onClick
9035
+ }, `cat-${category.label}-${idx}`) : null;
9059
9036
  })]
9060
- }, index)), jsx(SummaryRow, {
9037
+ }, index)), !hideSummary ? jsx(SummaryRow, {
9061
9038
  index: globalIndex,
9062
9039
  isValid: isValid,
9063
9040
  onClick: onClick
9064
- }, "task-list-table-summary")]
9041
+ }, "task-list-table-summary") : null]
9065
9042
  })
9066
9043
  })]
9067
9044
  })
@@ -9214,7 +9191,7 @@ const BackButton = ({
9214
9191
  };
9215
9192
 
9216
9193
  const RenderPages = props => {
9217
- var _a, _b, _c, _d;
9194
+ var _a, _b, _c, _d, _e, _f, _g;
9218
9195
  const {
9219
9196
  data,
9220
9197
  schema,
@@ -9240,6 +9217,8 @@ const RenderPages = props => {
9240
9217
  } = formStepperCtx.selectStepperState();
9241
9218
  const hideSubmit = (_b = (_a = props.categoryProps.uischema.options) === null || _a === void 0 ? void 0 : _a.hideSubmit) !== null && _b !== void 0 ? _b : false;
9242
9219
  const toAppOverviewLabel = (_d = (_c = props.categoryProps.uischema.options) === null || _c === void 0 ? void 0 : _c.toAppOverviewLabel) !== null && _d !== void 0 ? _d : 'Back to application overview';
9220
+ const submissionLabel = (_f = (_e = props.categoryProps.uischema.options) === null || _e === void 0 ? void 0 : _e.submissionLabel) !== null && _f !== void 0 ? _f : 'Next';
9221
+ const hideSummary = (_g = props.categoryProps.uischema.options) === null || _g === void 0 ? void 0 : _g.hideSummary;
9243
9222
  const submitFormFunction = enumerators === null || enumerators === void 0 ? void 0 : enumerators.submitFunction.get('submit-form');
9244
9223
  const submitForm = submitFormFunction && submitFormFunction();
9245
9224
  const saveFormFunction = enumerators === null || enumerators === void 0 ? void 0 : enumerators.saveFunction.get('save-form');
@@ -9287,6 +9266,8 @@ const RenderPages = props => {
9287
9266
  data
9288
9267
  };
9289
9268
  if (index === activeId && !isOnReview) {
9269
+ const currentStep = index + 1 - categories.filter(c => !c.visible && c.id < index).length;
9270
+ const totalSteps = categories.filter(c => c.visible).length;
9290
9271
  return jsxs("div", {
9291
9272
  "data-testid": `step_${index}-content-pages`,
9292
9273
  style: {
@@ -9294,7 +9275,7 @@ const RenderPages = props => {
9294
9275
  },
9295
9276
  children: [jsxs(PageRenderPadding, {
9296
9277
  children: [jsxs("h3", {
9297
- children: ["Step ", index + 1 - categories.filter(c => !c.visible && c.id < index).length, " of", ' ', categories.filter(c => c.visible).length]
9278
+ children: ["Step ", currentStep, " of ", totalSteps]
9298
9279
  }), jsx(RenderStepElements, Object.assign({}, categoryProps))]
9299
9280
  }), jsx(PageRenderPadding, {
9300
9281
  children: jsxs(GoAGrid, {
@@ -9327,11 +9308,13 @@ const RenderPages = props => {
9327
9308
  while (nextId < categories.length && categories[nextId].visible === false) {
9328
9309
  nextId = nextId + 1;
9329
9310
  }
9330
- goToPage(nextId);
9311
+ if (!(currentStep === totalSteps && hideSummary)) {
9312
+ goToPage(nextId);
9313
+ }
9331
9314
  },
9332
9315
  disabled: !enabled,
9333
9316
  testId: "pages-save-continue-btn",
9334
- children: "Next"
9317
+ children: currentStep === totalSteps ? submissionLabel : "Next"
9335
9318
  })
9336
9319
  })]
9337
9320
  })
@@ -9438,7 +9421,7 @@ const FormPageStepper = props => {
9438
9421
  });
9439
9422
  };
9440
9423
  const FormPagesView = props => {
9441
- var _a, _b, _c, _d;
9424
+ var _a, _b, _c, _d, _e, _f;
9442
9425
  const data = props.data;
9443
9426
  const formStepperCtx = useContext(JsonFormsStepperContext);
9444
9427
  const {
@@ -9472,7 +9455,8 @@ const FormPagesView = props => {
9472
9455
  onClick: handleGoToPage,
9473
9456
  title: (_b = (_a = props.uischema) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.title,
9474
9457
  subtitle: (_d = (_c = props.uischema) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.subtitle,
9475
- isValid: completedCount === visibleCats.length
9458
+ isValid: completedCount === visibleCats.length,
9459
+ hideSummary: (_f = (_e = props.uischema) === null || _e === void 0 ? void 0 : _e.options) === null || _f === void 0 ? void 0 : _f.hideSummary
9476
9460
  };
9477
9461
  return jsx(TaskList, Object.assign({}, tocProps));
9478
9462
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "2.33.0",
3
+ "version": "2.34.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,3 +1,4 @@
1
+ import React from 'react';
1
2
  import { RankedTester } from '@jsonforms/core';
2
3
  import { CategoriesState } from '../context';
3
4
  export interface TocProps {
@@ -6,6 +7,7 @@ export interface TocProps {
6
7
  title?: string;
7
8
  subtitle?: string;
8
9
  isValid: boolean;
10
+ hideSummary: boolean;
9
11
  }
10
- export declare const TaskList: ({ categories, onClick, title, subtitle, isValid }: TocProps) => JSX.Element;
12
+ export declare const TaskList: React.FC<TocProps>;
11
13
  export declare const TableOfContentsTester: RankedTester;