@abgov/jsonforms-components 2.34.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,15 +8946,32 @@ 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,
@@ -8963,56 +8981,22 @@ const TaskList = ({
8963
8981
  hideSummary
8964
8982
  }) => {
8965
8983
  const testid = 'table-of-contents';
8966
- const sectioned = getCategorySections(categories);
8967
- const [completedGroups, setCompletedGroups] = useState(0);
8968
- const [total, setTotal] = useState(sectioned.filter(s => s.categories && s.sectionTitle).length);
8969
- const shouldShow = cat => {
8970
- var _a, _b;
8971
- 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;
8972
- };
8973
- const updateCompletion = (group, category, groupIndex) => {
8974
- let leftIndex = groupIndex;
8975
- while (leftIndex > 0 && !shouldShow(group[leftIndex - 1])) {
8976
- leftIndex--;
8977
- }
8978
- let rightIndex = groupIndex;
8979
- while (rightIndex < group.length - 1 && !shouldShow(group[rightIndex + 1])) {
8980
- rightIndex++;
8981
- }
8982
- const currentLocalGroup = group.slice(leftIndex, rightIndex + 1);
8983
- const modifyCategory = JSON.parse(JSON.stringify(category));
8984
- modifyCategory.isCompleted = currentLocalGroup.length === currentLocalGroup.filter(cat => cat.isCompleted).length;
8985
- return modifyCategory;
8986
- };
8987
- const showInTaskListList = categories.map(cat => {
8988
- var _a, _b, _c, _d;
8989
- 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;
8990
- });
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]);
8991
8998
  let globalIndex = 0;
8992
8999
  let sectionIndex = 1;
8993
- useEffect(() => {
8994
- let count = 0;
8995
- let mergedSections = mergeOrphanSections(sectioned);
8996
- if (mergedSections.length === 1) {
8997
- mergedSections = expandSections(mergedSections);
8998
- setTotal(mergedSections.length);
8999
- }
9000
- mergedSections.forEach(({
9001
- categories: group
9002
- }) => {
9003
- let countInGroup = 0;
9004
- group.forEach((category, groupIndex) => {
9005
- const modifyCategory = updateCompletion(group, category, groupIndex);
9006
- if (getCategoryStatus(modifyCategory) === 'Completed') {
9007
- countInGroup++;
9008
- }
9009
- });
9010
- if (countInGroup === group.length) {
9011
- count++;
9012
- }
9013
- });
9014
- setCompletedGroups(count);
9015
- }, [categories, sectioned]); // re-run whenever categories change
9016
9000
  return jsx(PageBorder, {
9017
9001
  children: jsxs("div", {
9018
9002
  "data-testid": testid,
@@ -9029,34 +9013,26 @@ const TaskList = ({
9029
9013
  children: subtitle
9030
9014
  }), jsx(ApplicationStatus, {
9031
9015
  completedGroups: completedGroups,
9032
- totalGroups: total
9016
+ totalGroups: totalGroups
9033
9017
  }), jsx(GoATable, {
9034
9018
  width: "100%",
9035
9019
  children: jsxs("tbody", {
9036
- children: [sectioned.map(({
9020
+ children: [mergedSections.map(({
9037
9021
  sectionTitle,
9038
9022
  categories: group
9039
9023
  }, index) => jsxs(React.Fragment, {
9040
- children: [sectionTitle && showInTaskListList[globalIndex] && jsx(SectionHeaderRow, {
9024
+ children: [sectionTitle && group.some(shouldShow) && jsx(SectionHeaderRow, {
9041
9025
  title: sectionTitle,
9042
9026
  index: sectionIndex++
9043
9027
  }, `section-${sectionTitle}`), group.map((category, groupIndex) => {
9044
- const showCurrent = showInTaskListList[globalIndex];
9045
- const idx = globalIndex++; // renamed from `index` to avoid shadowing
9046
- let currentCategory = category;
9047
- const modifyCategory = updateCompletion(group, category, groupIndex);
9048
- const showGroupTaskListList = categories.map(cat => shouldShow(cat));
9049
- if (showGroupTaskListList.length > showGroupTaskListList.filter(item => item === true).length) {
9050
- currentCategory = modifyCategory;
9051
- }
9052
- if (showCurrent) {
9053
- return jsx(CategoryRow, {
9054
- category: currentCategory,
9055
- index: idx,
9056
- onClick: onClick
9057
- }, `cat-${category.label}-${idx}`);
9058
- }
9059
- 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;
9060
9036
  })]
9061
9037
  }, index)), !hideSummary ? jsx(SummaryRow, {
9062
9038
  index: globalIndex,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abgov/jsonforms-components",
3
- "version": "2.34.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 {
@@ -8,5 +9,5 @@ export interface TocProps {
8
9
  isValid: boolean;
9
10
  hideSummary: boolean;
10
11
  }
11
- export declare const TaskList: ({ categories, onClick, title, subtitle, isValid, hideSummary, }: TocProps) => JSX.Element;
12
+ export declare const TaskList: React.FC<TocProps>;
12
13
  export declare const TableOfContentsTester: RankedTester;