@agilant/toga-blox 1.0.195 → 1.0.196
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/dist/components/TableCell/TableCell.d.ts +2 -1
- package/dist/components/TableCell/TableCell.js +3 -3
- package/dist/components/TableCell/TableCell.stories.js +1 -0
- package/dist/components/TableRow/TableRow.d.ts +2 -1
- package/dist/components/TableRow/TableRow.js +2 -2
- package/dist/components/TableRow/TableRow.stories.js +2 -2
- package/dist/components/TableRow/TableRow.test.js +5 -5
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ export interface TableCellProps<T extends DataWithUUID> {
|
|
|
8
8
|
onToggle: () => void;
|
|
9
9
|
linkText?: string;
|
|
10
10
|
cellExpandable?: boolean;
|
|
11
|
+
maxCharacters?: number;
|
|
11
12
|
}
|
|
12
|
-
declare const TableCell: <T extends DataWithUUID>({ cell, isLastCell, hasInfiniteScroll, expanded, onToggle, linkText, cellExpandable, }: TableCellProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
declare const TableCell: <T extends DataWithUUID>({ cell, isLastCell, hasInfiniteScroll, expanded, onToggle, linkText, cellExpandable, maxCharacters, }: TableCellProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
13
14
|
export default TableCell;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
const MAX_CHARS = 30;
|
|
3
|
-
const TableCell = ({ cell, isLastCell, hasInfiniteScroll, expanded, onToggle, linkText = "text-purple-500 ml-1 underline", cellExpandable = false, }) => {
|
|
3
|
+
const TableCell = ({ cell, isLastCell, hasInfiniteScroll, expanded, onToggle, linkText = "text-purple-500 ml-1 underline", cellExpandable = false, maxCharacters, }) => {
|
|
4
4
|
/* decide if this cell even needs a toggle */
|
|
5
5
|
const isString = typeof cell.value === "string";
|
|
6
6
|
const fullText = isString ? cell.value : "";
|
|
7
|
-
const isLong = isString && fullText.length >
|
|
7
|
+
const isLong = isString && fullText.length > maxCharacters;
|
|
8
8
|
const hasToggle = cellExpandable && isLong;
|
|
9
|
-
const truncated = fullText.slice(0,
|
|
9
|
+
const truncated = fullText.slice(0, maxCharacters);
|
|
10
10
|
/* stop row click when toggling */
|
|
11
11
|
const handleToggle = (e) => {
|
|
12
12
|
e.stopPropagation(); // ← prevents bubbling to the <tr>
|
|
@@ -20,8 +20,9 @@ export interface TableRowProps<T extends DataWithUUID> {
|
|
|
20
20
|
expandedContent?: ReactNode;
|
|
21
21
|
linkText?: string;
|
|
22
22
|
rowClassNames?: string;
|
|
23
|
+
maxCharacters: number;
|
|
23
24
|
expandedRowUuid?: string | null;
|
|
24
25
|
onToggleRow?: (uuid: string) => void;
|
|
25
26
|
}
|
|
26
|
-
declare const TableRow: <T extends DataWithUUID>({ row, prepareRow, activeIndex, activeRowColor, rowHoverClasses, rowClassNames, hasInfiniteScroll, rowUuid, onRowClick, expandedCells, toggleCell, hasDropDown, onFetchRowData, loadingIndicator, errorIndicator, expandedContent, linkText, expandedRowUuid, cellExpandable, onToggleRow, }: TableRowProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
declare const TableRow: <T extends DataWithUUID>({ row, prepareRow, activeIndex, activeRowColor, rowHoverClasses, rowClassNames, hasInfiniteScroll, rowUuid, onRowClick, expandedCells, toggleCell, hasDropDown, onFetchRowData, loadingIndicator, errorIndicator, expandedContent, linkText, expandedRowUuid, cellExpandable, onToggleRow, maxCharacters, }: TableRowProps<T>) => import("react/jsx-runtime").JSX.Element;
|
|
27
28
|
export default TableRow;
|
|
@@ -3,7 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import { Fragment, useState } from "react";
|
|
4
4
|
import { motion, AnimatePresence } from "framer-motion";
|
|
5
5
|
import TableCell from "../TableCell";
|
|
6
|
-
const TableRow = ({ row, prepareRow, activeIndex, activeRowColor = "bg-pink-100", rowHoverClasses = "hover:bg-navy-100 hover:cursor-pointer", rowClassNames = "", hasInfiniteScroll, rowUuid, onRowClick, expandedCells, toggleCell, hasDropDown = false, onFetchRowData, loadingIndicator, errorIndicator, expandedContent, linkText = "text-blue-500", expandedRowUuid = null, cellExpandable = false, onToggleRow, }) => {
|
|
6
|
+
const TableRow = ({ row, prepareRow, activeIndex, activeRowColor = "bg-pink-100", rowHoverClasses = "hover:bg-navy-100 hover:cursor-pointer", rowClassNames = "", hasInfiniteScroll, rowUuid, onRowClick, expandedCells, toggleCell, hasDropDown = false, onFetchRowData, loadingIndicator, errorIndicator, expandedContent, linkText = "text-blue-500", expandedRowUuid = null, cellExpandable = false, onToggleRow, maxCharacters = 30, }) => {
|
|
7
7
|
prepareRow(row);
|
|
8
8
|
const rowClasses = `border-primary${activeIndex === row.index ? ` activeRow ${activeRowColor}` : ""}`;
|
|
9
9
|
/* keep fetch/loading local */
|
|
@@ -41,7 +41,7 @@ const TableRow = ({ row, prepareRow, activeIndex, activeRowColor = "bg-pink-100"
|
|
|
41
41
|
: {};
|
|
42
42
|
return (_jsxs(Fragment, { children: [_jsx("tr", { "data-testid": "table-row", className: `border-b border-b-navy-200 ${rowHoverClasses} ${rowClasses} ${rowClassNames}`, onClick: handleRowClick, ...safeRowProps, children: row.cells.map((cell, idx) => {
|
|
43
43
|
const cellKey = `${rowUuid ?? "no-uuid"}-${cell.column.id}`;
|
|
44
|
-
return (_jsx(TableCell, { cell: cell, isLastCell: idx === row.cells.length - 1, hasInfiniteScroll: hasInfiniteScroll, cellExpandable: cellExpandable, rowUuid: rowUuid, expanded: expandedCells[cellKey] ?? false, onToggle: () => toggleCell(cellKey), linkText: linkText }, cellKey));
|
|
44
|
+
return (_jsx(TableCell, { cell: cell, isLastCell: idx === row.cells.length - 1, hasInfiniteScroll: hasInfiniteScroll, cellExpandable: cellExpandable, rowUuid: rowUuid, expanded: expandedCells[cellKey] ?? false, onToggle: () => toggleCell(cellKey), linkText: linkText, maxCharacters: maxCharacters }, cellKey));
|
|
45
45
|
}) }, rowUuid), hasDropDown && (_jsx(AnimatePresence, { children: isExpanded && (_jsx("tr", { "data-testid": "expanded-row", children: _jsx("td", { colSpan: row.cells.length, className: "p-0", children: _jsx(motion.div, { initial: { height: 0, opacity: 0 }, animate: { height: "auto", opacity: 1 }, exit: { height: 0, opacity: 0 }, transition: { duration: 0.3 }, className: "overflow-hidden w-full", children: isLoading ? (loadingIndicator ?? (_jsx("span", { children: "Loading..." }))) : error ? (errorIndicator ? (errorIndicator(error)) : (_jsxs("span", { className: "text-red-700", children: ["Error: ", error.message] }))) : (expandedContent ?? (_jsxs("span", { children: ["drop down \u2013 ", rowUuid] }))) }, "expanded-dropdown-content") }) })) }))] }));
|
|
46
46
|
};
|
|
47
47
|
export default TableRow;
|
|
@@ -98,7 +98,7 @@ const Template = (args) => {
|
|
|
98
98
|
const onToggleRow = React.useCallback((uuid) => setExpandedRowUuid((prev) => (prev === uuid ? null : uuid)), []);
|
|
99
99
|
return (_jsx("table", { className: "min-w-[700px]", children: _jsx("tbody", { children: _jsx(TableRow, { row: undefined, prepareRow: function (row) {
|
|
100
100
|
throw new Error("Function not implemented.");
|
|
101
|
-
}, ...args, expandedCells: expandedCells, toggleCell: toggleCell, hasInfiniteScroll: args.hasInfiniteScroll ?? true, onRowClick: args.onRowClick ?? (() => alert("from row")), expandedRowUuid: expandedRowUuid, onToggleRow: onToggleRow }) }) }));
|
|
101
|
+
}, ...args, expandedCells: expandedCells, toggleCell: toggleCell, hasInfiniteScroll: args.hasInfiniteScroll ?? true, onRowClick: args.onRowClick ?? (() => alert("from row")), expandedRowUuid: expandedRowUuid, onToggleRow: onToggleRow, maxCharacters: 30 }) }) }));
|
|
102
102
|
};
|
|
103
103
|
/* ------------------------------------------------------------------ */
|
|
104
104
|
/* STORIES */
|
|
@@ -124,5 +124,5 @@ export const MultipleRows = () => {
|
|
|
124
124
|
const toggleCell = React.useCallback((key) => setExpandedCells((s) => ({ ...s, [key]: !s[key] })), []);
|
|
125
125
|
const [expandedRowUuid, setExpandedRowUuid] = React.useState(null);
|
|
126
126
|
const onToggleRow = React.useCallback((uuid) => setExpandedRowUuid((prev) => (prev === uuid ? null : uuid)), []);
|
|
127
|
-
return (_jsx("table", { className: "min-w-[700px]", children: _jsxs("tbody", { children: [_jsx(TableRow, { row: mockRow, prepareRow: prepareRow, hasInfiniteScroll: true, onRowClick: () => alert("from row"), hasDropDown: true, rowUuid: "1", expandedContent: sampleData.expandedContent, expandedCells: expandedCells, toggleCell: toggleCell, expandedRowUuid: expandedRowUuid, onToggleRow: onToggleRow }), _jsx(TableRow, { row: mockRow2, prepareRow: prepareRow, hasInfiniteScroll: true, onRowClick: () => alert("from row"), hasDropDown: false, rowUuid: "2", expandedContent: sampleData.expandedContent, expandedCells: expandedCells, toggleCell: toggleCell, expandedRowUuid: expandedRowUuid, onToggleRow: onToggleRow, cellExpandable: true })] }) }));
|
|
127
|
+
return (_jsx("table", { className: "min-w-[700px]", children: _jsxs("tbody", { children: [_jsx(TableRow, { row: mockRow, prepareRow: prepareRow, hasInfiniteScroll: true, onRowClick: () => alert("from row"), hasDropDown: true, rowUuid: "1", expandedContent: sampleData.expandedContent, expandedCells: expandedCells, toggleCell: toggleCell, expandedRowUuid: expandedRowUuid, onToggleRow: onToggleRow, maxCharacters: 30 }), _jsx(TableRow, { row: mockRow2, prepareRow: prepareRow, hasInfiniteScroll: true, onRowClick: () => alert("from row"), hasDropDown: false, rowUuid: "2", expandedContent: sampleData.expandedContent, expandedCells: expandedCells, toggleCell: toggleCell, expandedRowUuid: expandedRowUuid, onToggleRow: onToggleRow, cellExpandable: true, maxCharacters: 30 })] }) }));
|
|
128
128
|
};
|
|
@@ -25,7 +25,7 @@ describe("TableRow - Branch Coverage Tests", () => {
|
|
|
25
25
|
throw new Error("Function not implemented.");
|
|
26
26
|
}, expandedCells: undefined, toggleCell: function (key) {
|
|
27
27
|
throw new Error("Function not implemented.");
|
|
28
|
-
} }) }) }));
|
|
28
|
+
}, maxCharacters: 0 }) }) }));
|
|
29
29
|
expect(screen.getByTestId("table-row")).toHaveClass("activeRow");
|
|
30
30
|
});
|
|
31
31
|
it("covers isActive = false (row is NOT active)", () => {
|
|
@@ -33,14 +33,14 @@ describe("TableRow - Branch Coverage Tests", () => {
|
|
|
33
33
|
throw new Error("Function not implemented.");
|
|
34
34
|
}, expandedCells: undefined, toggleCell: function (key) {
|
|
35
35
|
throw new Error("Function not implemented.");
|
|
36
|
-
} }) }) }));
|
|
36
|
+
}, maxCharacters: 0 }) }) }));
|
|
37
37
|
expect(screen.getByTestId("table-row")).not.toHaveClass("activeRow");
|
|
38
38
|
});
|
|
39
39
|
it("covers onRowClick = defined + rowUuid = provided", () => {
|
|
40
40
|
const mockOnRowClick = vi.fn();
|
|
41
41
|
render(_jsx("table", { children: _jsx("tbody", { children: _jsx(TableRow, { row: baseMockRow, prepareRow: mockPrepareRow, onRowClick: mockOnRowClick, rowUuid: "some-uuid", hasInfiniteScroll: false, expandedCells: undefined, toggleCell: function (key) {
|
|
42
42
|
throw new Error("Function not implemented.");
|
|
43
|
-
} }) }) }));
|
|
43
|
+
}, maxCharacters: 0 }) }) }));
|
|
44
44
|
fireEvent.click(screen.getByTestId("table-row"));
|
|
45
45
|
expect(mockOnRowClick).toHaveBeenCalledWith(baseMockRow.index, // 0
|
|
46
46
|
"some-uuid", expect.anything() // Synthetic event
|
|
@@ -50,7 +50,7 @@ describe("TableRow - Branch Coverage Tests", () => {
|
|
|
50
50
|
const mockOnRowClick = vi.fn();
|
|
51
51
|
render(_jsx("table", { children: _jsx("tbody", { children: _jsx(TableRow, { row: baseMockRow, prepareRow: mockPrepareRow, onRowClick: mockOnRowClick, hasInfiniteScroll: false, expandedCells: undefined, toggleCell: function (key) {
|
|
52
52
|
throw new Error("Function not implemented.");
|
|
53
|
-
} }) }) }));
|
|
53
|
+
}, maxCharacters: 0 }) }) }));
|
|
54
54
|
fireEvent.click(screen.getByTestId("table-row"));
|
|
55
55
|
expect(mockOnRowClick).toHaveBeenCalledWith(baseMockRow.index, // 0
|
|
56
56
|
"", expect.anything());
|
|
@@ -60,7 +60,7 @@ describe("TableRow - Branch Coverage Tests", () => {
|
|
|
60
60
|
throw new Error("Function not implemented.");
|
|
61
61
|
}, expandedCells: undefined, toggleCell: function (key) {
|
|
62
62
|
throw new Error("Function not implemented.");
|
|
63
|
-
} }) }) }));
|
|
63
|
+
}, maxCharacters: 0 }) }) }));
|
|
64
64
|
// onRowClick not provided; just ensure no crash
|
|
65
65
|
fireEvent.click(screen.getByTestId("table-row"));
|
|
66
66
|
});
|