Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import React, {
useCallback,
useRef,
} from "react";

import {Table} from "antd";

import {
SCROLL_INCREMENT,
VIRTUAL_TABLE_HOLDER_SELECTOR,
type VirtualTableProps,
} from "./typings";


/**
* Virtual table that supports keyboard navigation.
*
* @param props
* @param props.tableProps
* @return
*/
const VirtualTable = <RecordType extends object = Record<string, unknown>>({
...tableProps
}: VirtualTableProps<RecordType>) => {
const containerRef = useRef<HTMLDivElement>(null);
const scrollNodeRef = useRef<HTMLElement>(null);

const handleKeyDown = useCallback((e: React.KeyboardEvent<HTMLDivElement>) => {
if (null === containerRef.current) {
return;
}

const scrollNode = scrollNodeRef.current;
if (null === scrollNode) {
scrollNodeRef.current = containerRef.current.querySelector<HTMLElement>(
VIRTUAL_TABLE_HOLDER_SELECTOR
);
}

if (null === scrollNode) {
return;
}

const visibleTableHeight = scrollNode.clientHeight;
let {scrollTop} = scrollNode;

switch (e.key) {
case "ArrowDown":
scrollTop += SCROLL_INCREMENT;
break;
case "ArrowUp":
// Prevent scrolling past the top.
scrollTop = Math.max(scrollTop - SCROLL_INCREMENT, 0);
break;
case "PageDown":
scrollTop += visibleTableHeight;
break;
case "PageUp":
// Prevent scrolling past the top.
scrollTop = Math.max(scrollTop - visibleTableHeight, 0);
break;
case "Home":
scrollTop = 0;
break;
case "End":
// Scroll to the bottom of the table.
scrollTop = Number.MAX_SAFE_INTEGER;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use scrollHeight instead of MAX_SAFE_INTEGER for "End" key.

Setting scrollTop to MAX_SAFE_INTEGER may not reliably scroll to the bottom. Use the element's scrollHeight for more predictable behaviour.

 case "End":
     // Scroll to the bottom of the table.
-    scrollTop = Number.MAX_SAFE_INTEGER;
+    scrollTop = scrollNode.scrollHeight - scrollNode.clientHeight;
     break;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
scrollTop = Number.MAX_SAFE_INTEGER;
case "End":
// Scroll to the bottom of the table.
scrollTop = scrollNode.scrollHeight - scrollNode.clientHeight;
break;
🤖 Prompt for AI Agents
In components/log-viewer-webui/client/src/components/VirtualTable/index.tsx at
line 63, replace the assignment of scrollTop from Number.MAX_SAFE_INTEGER to the
element's scrollHeight property. This change ensures that pressing the "End" key
scrolls reliably to the bottom by using the actual scrollable height of the
element instead of an arbitrary large number.

break;
default:
return;
}

scrollNode.scrollTop = scrollTop;
e.preventDefault();
}, []);

return (
<div
ref={containerRef}
style={{outline: "none"}}
tabIndex={0}
onKeyDown={handleKeyDown}
>
<Table<RecordType>
virtual={true}
{...tableProps}/>
</div>
);
};

export default VirtualTable;
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type {TableProps} from "antd";


/**
* Number of pixels to scroll vertically when using keyboard arrow navigation.
*/
const SCROLL_INCREMENT = 32;

/**
* CSS selector for the virtual table body element.
*/
const VIRTUAL_TABLE_HOLDER_SELECTOR = ".ant-table-tbody-virtual-holder";

/**
* Antd Table props with virtual omitted since set by VirtualTable.
*/
type VirtualTableProps<RecordType> = Omit<TableProps<RecordType>, "virtual">;

export {
SCROLL_INCREMENT,
VIRTUAL_TABLE_HOLDER_SELECTOR,
};
export type {VirtualTableProps};
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
useState,
} from "react";

import {Table} from "antd";
import dayjs from "dayjs";

import {DashboardCard} from "../../../components/DashboardCard";
import VirtualTable from "../../../components/VirtualTable";
import useIngestStatsStore from "../ingestStatsStore";
import {querySql} from "../sqlConfig";
import styles from "./index.module.css";
Expand Down Expand Up @@ -85,11 +85,12 @@ const Jobs = ({className}: JobsProps) => {
return (
<div className={className}>
<DashboardCard title={"Ingestion Jobs"}>
<Table<JobData>
<VirtualTable<JobData>
className={styles["jobs"] || ""}
columns={jobColumns}
dataSource={jobs}
pagination={false}/>
pagination={false}
scroll={{y: 400}}/>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Consider making the fixed scroll height responsive.

The 400px fixed height might not work well on smaller screens or different viewport sizes. Consider calculating height dynamically like in SearchResultsTable.

-                    scroll={{y: 400}}/>
+                    scroll={{y: Math.min(400, window.innerHeight * 0.6)}}/>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
scroll={{y: 400}}/>
scroll={{y: Math.min(400, window.innerHeight * 0.6)}}/>
🤖 Prompt for AI Agents
In components/log-viewer-webui/client/src/pages/IngestPage/Jobs/index.tsx at
line 93, the scroll height is currently fixed at 400px, which may not be
responsive on different screen sizes. Modify the scroll height to be dynamically
calculated based on the viewport or container size, similar to the approach used
in SearchResultsTable, to ensure better responsiveness across devices.

</DashboardCard>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
useState,
} from "react";

import {Table} from "antd";

import VirtualTable from "../../../../components/VirtualTable";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Deep relative import path – consider aliasing.

The import for VirtualTable uses a lengthy relative path (../../../../components/VirtualTable), which can be brittle. Define a path alias (e.g. @components/VirtualTable) in your TS config to improve maintainability and readability.

🤖 Prompt for AI Agents
In
components/log-viewer-webui/client/src/pages/SearchPage/SearchResults/SearchResultsTable/index.tsx
at line 7, the import of VirtualTable uses a deep relative path which is hard to
maintain. To fix this, define a path alias like '@components' in the TypeScript
configuration (tsconfig.json) pointing to the components directory, then update
the import statement to use this alias instead of the relative path.

import useSearchStore from "../../SearchState/index";
import {
SearchResult,
Expand Down Expand Up @@ -57,16 +56,16 @@ const SearchResultsTable = () => {
}, []);

return (
<div ref={containerRef}>
<Table<SearchResult>
<div
ref={containerRef}
style={{outline: "none"}}
>
<VirtualTable<SearchResult>
columns={searchResultsTableColumns}
dataSource={searchResults || []}
pagination={false}
rowKey={(record) => record._id.toString()}
scroll={{y: tableHeight}}
virtual={true}
dataSource={searchResults ?
searchResults :
[]}/>
scroll={{y: tableHeight}}/>
</div>
);
};
Expand Down