@agilant/toga-blox 1.0.40 → 1.0.41

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.
@@ -1,15 +1,36 @@
1
+ import React from "react";
2
+ import { Row } from "react-table";
1
3
  import { DataWithUUID } from "../TableCell";
2
- import TableRowProps from ".";
3
- interface TableRowProps {
4
- row: any;
5
- prepareRow: (row: any) => void;
4
+ /**
5
+ * The props for your reusable TableRow component.
6
+ *
7
+ * @template T - extends DataWithUUID
8
+ */
9
+ export interface TableRowProps<T extends DataWithUUID> {
10
+ /** The row object from react-table */
11
+ row: Row<T>;
12
+ /** Function from react-table to prepare the row. */
13
+ prepareRow: (row: Row<T>) => void;
14
+ /** Optionally mark this row as active, comparing row.index to activeIndex. */
6
15
  activeIndex?: number;
16
+ /** Class to apply if the row is active. */
7
17
  activeRowColor?: string;
18
+ /** Globally enable/disable "trim" on cells. */
8
19
  globalTrimActive?: boolean;
20
+ /** A UUID for this row. */
9
21
  rowUuid?: string;
22
+ /** Column "inputs" or config array, if relevant to your TableCell. */
10
23
  columnInputs?: string[];
24
+ /** Classes for row hover styling. Defaults to "hover:bg-red-100 hover:cursor-pointer" */
11
25
  rowHoverClasses?: string;
12
- onRowClick?: (index: number, rowUuid: string, event: React.MouseEvent) => void;
26
+ /**
27
+ * Called when the row is clicked.
28
+ *
29
+ * @param index - the row.index from react-table
30
+ * @param rowUuid - the row's UUID
31
+ * @param event - the click event on the <tr>
32
+ */
33
+ onRowClick?: (index: number, rowUuid: string, event: React.MouseEvent<HTMLTableRowElement, MouseEvent>) => void;
13
34
  }
14
- declare const TableRow: <T extends DataWithUUID>({ row, prepareRow, activeIndex, globalTrimActive, rowUuid, columnInputs, activeRowColor, rowHoverClasses, onRowClick, }: TableRowProps) => import("react/jsx-runtime").JSX.Element;
35
+ declare const TableRow: <T extends DataWithUUID>({ row, prepareRow, activeIndex, globalTrimActive, rowUuid, columnInputs, activeRowColor, rowHoverClasses, onRowClick, }: TableRowProps<T>) => import("react/jsx-runtime").JSX.Element;
15
36
  export default TableRow;
@@ -9,9 +9,7 @@ const TableRow = ({ row, prepareRow, activeIndex, globalTrimActive, rowUuid, col
9
9
  rowClasses += ` activeRow ${activeRowColor}`;
10
10
  }
11
11
  return (_jsx("tr", { "data-testid": "table-row", className: `border-b border-b-navy-200 ${rowHoverClasses} ${rowClasses}`, ...(row.getRowProps ? row.getRowProps() : {}), onClick: (event) => {
12
- if (onRowClick) {
13
- onRowClick(row.index, rowUuid || "", event);
14
- }
12
+ onRowClick?.(row.index, rowUuid || "", event);
15
13
  }, children: row.cells.map((cell, index) => {
16
14
  const isLastCell = index === row.cells.length - 1;
17
15
  const cellProps = cell.getCellProps();
@@ -4,16 +4,21 @@ import { render, screen, fireEvent } from "@testing-library/react";
4
4
  import TableRow from "./TableRow";
5
5
  describe("TableRow - Branch Coverage Tests", () => {
6
6
  const mockPrepareRow = vi.fn();
7
- // Basic row object
8
7
  const baseMockRow = {
8
+ // REQUIRED BY Row<T>:
9
+ id: "mock-row-id",
9
10
  index: 0,
10
- getRowProps: vi.fn(() => ({})),
11
+ original: { uuid: "mock-uuid" },
12
+ subRows: [],
11
13
  cells: [
12
14
  {
13
15
  getCellProps: vi.fn(() => ({ key: "cell-0" })),
14
16
  render: vi.fn(() => "Cell 0"),
15
17
  },
16
18
  ],
19
+ allCells: [],
20
+ values: {},
21
+ getRowProps: vi.fn(() => ({ key: "row-props-0" })),
17
22
  };
18
23
  it("covers isActive = true (row is active)", () => {
19
24
  render(_jsx("table", { children: _jsx("tbody", { children: _jsx(TableRow, { row: { ...baseMockRow, index: 5 }, prepareRow: mockPrepareRow, activeIndex: 5 }) }) }));
@@ -27,18 +32,20 @@ describe("TableRow - Branch Coverage Tests", () => {
27
32
  const mockOnRowClick = vi.fn();
28
33
  render(_jsx("table", { children: _jsx("tbody", { children: _jsx(TableRow, { row: baseMockRow, prepareRow: mockPrepareRow, onRowClick: mockOnRowClick, rowUuid: "some-uuid" }) }) }));
29
34
  fireEvent.click(screen.getByTestId("table-row"));
30
- // Because rowUuid is defined, we expect 'some-uuid'
31
- expect(mockOnRowClick).toHaveBeenCalledWith(baseMockRow.index, "some-uuid", expect.anything() // Synthetic event
35
+ expect(mockOnRowClick).toHaveBeenCalledWith(baseMockRow.index, // 0
36
+ "some-uuid", expect.anything() // Synthetic event
32
37
  );
33
38
  });
34
39
  it("covers onRowClick = defined + rowUuid = undefined (so calls empty string)", () => {
35
40
  const mockOnRowClick = vi.fn();
36
41
  render(_jsx("table", { children: _jsx("tbody", { children: _jsx(TableRow, { row: baseMockRow, prepareRow: mockPrepareRow, onRowClick: mockOnRowClick }) }) }));
37
42
  fireEvent.click(screen.getByTestId("table-row"));
38
- expect(mockOnRowClick).toHaveBeenCalledWith(baseMockRow.index, "", expect.anything());
43
+ expect(mockOnRowClick).toHaveBeenCalledWith(baseMockRow.index, // 0
44
+ "", expect.anything());
39
45
  });
40
46
  it("covers onRowClick = NOT defined", () => {
41
47
  render(_jsx("table", { children: _jsx("tbody", { children: _jsx(TableRow, { row: baseMockRow, prepareRow: mockPrepareRow }) }) }));
48
+ // onRowClick not provided; just ensure no crash
42
49
  fireEvent.click(screen.getByTestId("table-row"));
43
50
  });
44
51
  });
@@ -8,4 +8,5 @@ export interface TableRowProps<T extends object> {
8
8
  columnInputs?: string[];
9
9
  rowHoverClasses?: string;
10
10
  addRowToClickedRows?: (rowUuid: string) => void;
11
+ onRowClick?: (index: number, rowUuid: string, event: React.MouseEvent<HTMLTableRowElement, MouseEvent>) => void;
11
12
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@agilant/toga-blox",
3
3
  "private": false,
4
- "version": "1.0.40",
4
+ "version": "1.0.41",
5
5
  "description": "",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",