Skip to content

Commit 649acaf

Browse files
committed
check for bounds
1 parent 2e34246 commit 649acaf

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

frontend/src/components/data-table/__tests__/utils.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ describe("getPageIndexForRow", () => {
5858

5959
// Last row of current page
6060
expect(getPageIndexForRow(19, 1, 10)).toBeNull();
61+
62+
// Last row of last page
63+
expect(getPageIndexForRow(99, 9, 10)).toBeNull();
6164
});
6265

6366
it("should handle edge case of row 0", () => {

frontend/src/components/data-table/row-viewer-panel/row-viewer.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,11 @@ export const RowViewerPanel: React.FC<RowViewerPanelProps> = ({
145145
}
146146

147147
if (rows.length !== 1) {
148+
const message = tooManyRows
149+
? "LazyFrame, no data available."
150+
: `Expected 1 row, got ${rows.length} rows. Please report the issue.`;
148151
return (
149-
<SimpleBanner
150-
kind="warn"
151-
Icon={AlertTriangle}
152-
message={`Expected 1 row, got ${rows.length} rows. Please report the issue.`}
153-
/>
152+
<SimpleBanner kind="warn" Icon={AlertTriangle} message={message} />
154153
);
155154
}
156155

frontend/src/plugins/impl/DataTablePlugin.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,15 @@ const DataTableComponent = ({
852852

853853
const setViewedRow = useEvent((rowIdx: number) => {
854854
setViewedRowIdx(rowIdx);
855+
856+
const outOfBounds =
857+
rowIdx < 0 ||
858+
(typeof totalRows === "number" && rowIdx >= totalRows) ||
859+
totalRows === TOO_MANY_ROWS;
860+
if (outOfBounds) {
861+
return;
862+
}
863+
855864
// If the rowIdx moves to the next / previous page, update the pagination state
856865
const newPageIndex = getPageIndexForRow(
857866
rowIdx,

0 commit comments

Comments
 (0)