Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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,87 @@
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 handleKeyDown = useCallback((e: React.KeyboardEvent<HTMLDivElement>) => {
if (null === containerRef.current) {
return;
}

const scrollNode = containerRef.current.querySelector<HTMLElement>(
VIRTUAL_TABLE_HOLDER_SELECTOR
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can we cache this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done


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

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

CSS selector dependency introduces maintenance risk.

The code relies on antd's internal CSS class which could change in future versions. Consider adding error handling or documentation about this dependency.

 const scrollNode = containerRef.current.querySelector<HTMLElement>(
     VIRTUAL_TABLE_HOLDER_SELECTOR
 );

 if (null === scrollNode) {
+    console.warn("VirtualTable: Virtual table holder not found. Ensure antd table has virtual=true");
     return;
 }
📝 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
const scrollNode = containerRef.current.querySelector<HTMLElement>(
VIRTUAL_TABLE_HOLDER_SELECTOR
);
if (null === scrollNode) {
return;
}
const scrollNode = containerRef.current.querySelector<HTMLElement>(
VIRTUAL_TABLE_HOLDER_SELECTOR
);
if (null === scrollNode) {
console.warn(
"VirtualTable: Virtual table holder not found. Ensure antd table has virtual=true"
);
return;
}
🤖 Prompt for AI Agents
In components/log-viewer-webui/client/src/components/VirtualTable/index.tsx
around lines 32 to 38, the code depends on an internal antd CSS selector which
may change and break functionality. To fix this, add error handling to
gracefully handle cases where the selector is not found, and include a comment
documenting this dependency and the potential risk for future maintainers.


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,17 @@
import type {TableProps} from "antd";


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

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 scroll increment configurable.

The fixed 32-pixel increment works well for most cases, but consider making this configurable through props for different use cases or accessibility needs.

🤖 Prompt for AI Agents
In components/log-viewer-webui/client/src/components/VirtualTable/typings.tsx at
line 7, the scroll increment is currently a fixed constant set to 32 pixels. To
make it configurable, refactor the code to accept the scroll increment value as
a prop in the relevant component(s). Replace the fixed SCROLL_INCREMENT usage
with this prop, providing a default value of 32 if no prop is supplied, allowing
different scroll increments for various use cases or accessibility requirements.


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

/**
* Antd Table props with virtual omitted since set by VirtualTable.
*/
export type VirtualTableProps<RecordType> = Omit<TableProps<RecordType>, "virtual">;
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 {
SearchResult,
searchResultsTableColumns,
Expand All @@ -24,8 +23,6 @@ const SearchResultsTable = () => {
const [tableHeight, setTableHeight] = useState<number>(0);
const containerRef = useRef<HTMLDivElement>(null);

// Antd table requires a fixed height for virtual scrolling. The effect sets a fixed height
// based on the window height, container top, and fixed padding.
useEffect(() => {
const updateHeight = () => {
if (containerRef.current) {
Expand All @@ -44,16 +41,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