Skip to content
Draft
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
39 changes: 38 additions & 1 deletion packages/backend.ai-ui/src/components/Table/BAITable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ import { AnyObject, GetProps } from 'antd/es/_util/type';
import { ColumnType, ColumnsType } from 'antd/es/table';
import classNames from 'classnames';
import _ from 'lodash';
import { ReactNode, useEffect, useMemo, useRef, useState } from 'react';
import {
ReactNode,
useEffect,
useEffectEvent,
useMemo,
useRef,
useState,
} from 'react';
import { Resizable, ResizeCallbackData } from 'react-resizable';

/**
Expand All @@ -28,6 +35,7 @@ interface BAITablePaginationConfig
extends Omit<TablePaginationConfig, 'position'> {
/** Additional content to display in the pagination area */
extraContent?: ReactNode;
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The new autoAdjustCurrentPage property is missing JSDoc documentation. Please add a comment describing what this option does, its default value, and when it should be disabled.

Suggested documentation:

/** Whether to automatically adjust the current page when it exceeds the maximum available page (defaults to true) */
autoAdjustCurrentPage?: boolean;
Suggested change
extraContent?: ReactNode;
extraContent?: ReactNode;
/**
* Whether to automatically adjust the current page when it exceeds the maximum available page (defaults to true)
*/

Copilot uses AI. Check for mistakes.
autoAdjustCurrentPage?: boolean;
}

/**
Expand Down Expand Up @@ -214,6 +222,7 @@ const BAITable = <RecordType extends object = any>({
...tableProps
}: BAITableProps<RecordType>): React.ReactElement => {
const { styles } = useStyles();
const { autoAdjustCurrentPage = true } = tableProps.pagination || {};
const [resizedColumnWidths, setResizedColumnWidths] = useState<
Record<string, number>
>(generateResizedColumnWidths(columns));
Expand Down Expand Up @@ -316,6 +325,34 @@ const BAITable = <RecordType extends object = any>({
columnOverrides,
]);

const adjustCurrentPage = useEffectEvent(() => {
if (!tableProps.pagination) return;
// if current page exceeds max page, adjust it
const current = currentPage || 1;
const pageSize = currentPageSize || 10;
const total =
tableProps.pagination?.total || tableProps.dataSource?.length || 0;
const maxPage = Math.max(1, Math.ceil(total / pageSize));

if (current > maxPage) {
setCurrentPage(maxPage);
tableProps.pagination?.onChange?.(maxPage, pageSize);
return;
}
});

useEffect(() => {
if (tableProps.pagination && autoAdjustCurrentPage) {
adjustCurrentPage();
}
}, [
tableProps.dataSource,
tableProps.pagination,
autoAdjustCurrentPage,
currentPage,
currentPageSize,
]);
Comment on lines +348 to +354
Copy link

Copilot AI Nov 13, 2025

Choose a reason for hiding this comment

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

The useEffect dependency array includes adjustCurrentPage, but since adjustCurrentPage is created by useEffectEvent (which should have stable identity), it shouldn't be included in the dependency array. However, since useEffectEvent is not a real React API (see other comment), this needs to be fixed.

When you switch to useEventNotStable (as recommended), remove adjustCurrentPage from the dependency array since that hook returns a stable function reference:

useEffect(() => {
  if (tableProps.pagination && autoAdjustCurrentPage) {
    adjustCurrentPage();
  }
}, [
  tableProps.dataSource,
  tableProps.pagination,
  autoAdjustCurrentPage,
  currentPage,
  currentPageSize,
  // adjustCurrentPage should be removed as useEventNotStable returns a stable reference
]);

Copilot uses AI. Check for mistakes.

return (
<BAIFlex direction="column" align="stretch" gap={'sm'}>
<Table
Expand Down
Loading