Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

feat: change page size in tables directly (#5243)

Shahmir Varqha351fe490c346
diff --git a/frontend/src/components/data-table/column-explorer-panel/column-explorer.tsx b/frontend/src/components/data-table/column-explorer-panel/column-explorer.tsx
index ca7d4249a3..f9e59d9ce7 100644
--- a/frontend/src/components/data-table/column-explorer-panel/column-explorer.tsx
+++ b/frontend/src/components/data-table/column-explorer-panel/column-explorer.tsx
@@ -112,27 +112,27 @@ const ColumnItem = ({
return (
<>
- <CommandItem key={columnName} onSelect={() => setIsExpanded(!isExpanded)}>
- <div className="flex flex-row items-center gap-1.5 group w-full">
- <ColumnName columnName={columnText} dataType={dataType} />
- <div className="ml-auto">
- <Tooltip content="Copy column name" delayDuration={400}>
- <Button
- variant="text"
- size="icon"
- className="group-hover:opacity-100 opacity-0 hover:bg-muted text-muted-foreground hover:text-foreground"
- >
- <CopyClipboardIcon
- tooltip={false}
- value={columnName}
- className="h-3 w-3"
- />
- </Button>
- </Tooltip>
- <span className="text-xs text-muted-foreground">
- {externalType}
- </span>
- </div>
+ <CommandItem
+ key={columnName}
+ onSelect={() => setIsExpanded(!isExpanded)}
+ className="flex flex-row items-center gap-1.5 group w-full cursor-pointer"
+ >
+ <ColumnName columnName={columnText} dataType={dataType} />
+ <div className="ml-auto">
+ <Tooltip content="Copy column name" delayDuration={400}>
+ <Button
+ variant="text"
+ size="icon"
+ className="group-hover:opacity-100 opacity-0 hover:bg-muted text-muted-foreground hover:text-foreground"
+ >
+ <CopyClipboardIcon
+ tooltip={false}
+ value={columnName}
+ className="h-3 w-3"
+ />
+ </Button>
+ </Tooltip>
+ <span className="text-xs text-muted-foreground">{externalType}</span>
</div>
</CommandItem>
{isExpanded && (
diff --git a/frontend/src/components/data-table/pagination.tsx b/frontend/src/components/data-table/pagination.tsx
index 92a9ea37ff..adb6ae2a79 100644
--- a/frontend/src/components/data-table/pagination.tsx
+++ b/frontend/src/components/data-table/pagination.tsx
@@ -13,6 +13,15 @@ import { Button } from "@/components/ui/button";
import { PluralWord } from "@/utils/pluralize";
import { range } from "lodash-es";
import type { DataTableSelection } from "./types";
+import {
+ Select,
+ SelectContent,
+ SelectGroup,
+ SelectItem,
+ SelectLabel,
+ SelectTrigger,
+ SelectValue,
+} from "../ui/select";
interface DataTablePaginationProps<TData> {
table: Table<TData>;
@@ -101,9 +110,42 @@ export const DataTablePagination = <TData,>({
);
const totalPages = table.getPageCount();
+ const pageSize = table.getState().pagination.pageSize;
+
+ // Ensure unique page sizes
+ const pageSizeSet = new Set([5, 10, 25, 50, 100, pageSize]);
+ const pageSizes = [...pageSizeSet].sort((a, b) => a - b);
+
return (
<div className="flex flex-1 items-center justify-between px-2">
- <div className="text-sm text-muted-foreground">{renderTotal()}</div>
+ <div className="flex items-center gap-2">
+ <div className="text-sm text-muted-foreground">{renderTotal()}</div>
+ <div className="flex items-center gap-1 text-xs">
+ <Select
+ value={pageSize.toString()}
+ onValueChange={(value) => table.setPageSize(Number(value))}
+ >
+ <SelectTrigger className="w-12 h-[18px] !shadow-none !hover:shadow-none !ring-0">
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent>
+ <SelectGroup>
+ <SelectLabel>Rows per page</SelectLabel>
+ {[...pageSizes].map((size) => {
+ const sizeStr = size.toString();
+ return (
+ <SelectItem key={size} value={sizeStr}>
+ {sizeStr}
+ </SelectItem>
+ );
+ })}
+ </SelectGroup>
+ </SelectContent>
+ </Select>
+ <span>/ page</span>
+ </div>
+ </div>
+
<div className="flex items-end space-x-2">
<Button
size="xs"
diff --git a/frontend/src/components/ui/number-field.tsx b/frontend/src/components/ui/number-field.tsx
index f5090ba8d6..2e75b10bb9 100644
--- a/frontend/src/components/ui/number-field.tsx
+++ b/frontend/src/components/ui/number-field.tsx
@@ -12,10 +12,11 @@ import { cn } from "@/utils/cn";
export interface NumberFieldProps extends AriaNumberFieldProps {
placeholder?: string;
+ variant?: "default" | "xs";
}
export const NumberField = React.forwardRef<HTMLInputElement, NumberFieldProps>(
- ({ placeholder, ...props }, ref) => {
+ ({ placeholder, variant = "default", ...props }, ref) => {
return (
<AriaNumberField
{...props}
@@ -27,9 +28,11 @@ export const NumberField = React.forwardRef<HTMLInputElement, NumberFieldProps>(
<div
className={cn(
"shadow-xsSolid hover:shadow-smSolid hover:focus-within:shadow-mdSolid",
- "flex h-6 w-full mb-1 overflow-hidden rounded-sm border border-input bg-background text-sm font-code ring-offset-background",
+ "flex overflow-hidden rounded-sm border border-input bg-background text-sm font-code ring-offset-background",
"disabled:cursor-not-allowed disabled:opacity-50 disabled:shadow-xsSolid",
"focus-within:shadow-mdSolid focus-within:outline-none focus-within:ring-1 focus-within:ring-ring focus-within:border-primary",
+ variant === "default" ? "h-6 w-full mb-1" : "h-4 w-full mb-0.5",
+ variant === "xs" && "text-xs",
props.className,
)}
>
@@ -48,16 +51,36 @@ export const NumberField = React.forwardRef<HTMLInputElement, NumberFieldProps>(
"placeholder:text-muted-foreground",
"outline-none",
"disabled:cursor-not-allowed disabled:opacity-50",
- "px-1.5",
+ variant === "default" ? "px-1.5" : "px-1",
)}
/>
<div className={"flex flex-col border-s-2"}>
- <StepperButton slot="increment" isDisabled={props.isDisabled}>
- <ChevronUp aria-hidden={true} className="w-3 h-3 -mb-[1px]" />
+ <StepperButton
+ slot="increment"
+ isDisabled={props.isDisabled}
+ variant={variant}
+ >
+ <ChevronUp
+ aria-hidden={true}
+ className={cn(
+ "w-3 h-3 -mb-[1px]",
+ variant === "xs" && "w-2 h-2",
+ )}
+ />
</StepperButton>
<div className={"h-[1px] flex-shrink-0 divider bg-border z-10"} />
- <StepperButton slot="decrement" isDisabled={props.isDisabled}>
- <ChevronDown aria-hidden={true} className="w-3 h-3 -mt-[1px]" />
+ <StepperButton
+ slot="decrement"
+ isDisabled={props.isDisabled}
+ variant={variant}
+ >
+ <ChevronDown
+ aria-hidden={true}
+ className={cn(
+ "w-3 h-3 -mt-[1px]",
+ variant === "xs" && "w-2 h-2",
+ )}
+ />
</StepperButton>
</div>
</div>
@@ -67,14 +90,15 @@ export const NumberField = React.forwardRef<HTMLInputElement, NumberFieldProps>(
);
NumberField.displayName = "NumberField";
-const StepperButton = (props: ButtonProps) => {
+const StepperButton = (props: ButtonProps & { variant?: "default" | "xs" }) => {
return (
<Button
{...props}
className={cn(
- "px-0.5 cursor-default text-muted-foreground pressed:bg-muted-foreground group-disabled:text-disabled-foreground outline-none focus-visible:text-primary",
+ "cursor-default text-muted-foreground pressed:bg-muted-foreground group-disabled:text-disabled-foreground outline-none focus-visible:text-primary",
"disabled:cursor-not-allowed disabled:opacity-50",
!props.isDisabled && "hover:text-primary hover:bg-muted",
+ props.variant === "default" ? "px-0.5" : "px-0.25",
)}
/>
);
diff --git a/frontend/src/plugins/impl/DataTablePlugin.tsx b/frontend/src/plugins/impl/DataTablePlugin.tsx
index 9b3c7378b5..0869f2a3dd 100644
--- a/frontend/src/plugins/impl/DataTablePlugin.tsx
+++ b/frontend/src/plugins/impl/DataTablePlugin.tsx
@@ -409,13 +409,8 @@ export const LoadingDataTableComponent = memo(
// If pageSize changes, reset pagination state
useEffect(() => {
- if (paginationState.pageSize !== props.pageSize) {
- setPaginationState({
- pageIndex: 0,
- pageSize: props.pageSize,
- });
- }
- }, [props.pageSize, paginationState.pageSize]);
+ setPaginationState({ pageIndex: 0, pageSize: props.pageSize });
+ }, [props.pageSize]);
// Data loading
const { data, loading, error } = useAsyncData<{
@@ -433,6 +428,8 @@ export const LoadingDataTableComponent = memo(
let totalRows = props.totalRows;
let cellStyles = props.cellStyles;
+ const pageSizeChanged = paginationState.pageSize !== props.pageSize;
+
// If it is just the first page and no search query,
// we can show the initial page.
const canShowInitialPage =
@@ -440,7 +437,8 @@ export const LoadingDataTableComponent = memo(
paginationState.pageIndex === 0 &&
filters.length === 0 &&
sorting.length === 0 &&
- !props.lazy;
+ !props.lazy &&
+ !pageSizeChanged;
if (sorting.length > 1) {
Logger.warn("Multiple sort columns are not supported");
diff --git a/frontend/src/plugins/impl/data-frames/forms/__tests__/__snapshots__/form.test.tsx.snap b/frontend/src/plugins/impl/data-frames/forms/__tests__/__snapshots__/form.test.tsx.snap
index d8eda1057b..4c05818fee 100644
--- a/frontend/src/plugins/impl/data-frames/forms/__tests__/__snapshots__/form.test.tsx.snap
+++ b/frontend/src/plugins/impl/data-frames/forms/__tests__/__snapshots__/form.test.tsx.snap
@@ -799,7 +799,7 @@ exports[`renderZodSchema > should render a form sample_rows 1`] = `
data-rac=""
>
<div
- class="shadow-xsSolid hover:shadow-smSolid hover:focus-within:shadow-mdSolid flex h-6 w-full overflow-hidden rounded-sm border border-input bg-background text-sm font-code ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 disabled:shadow-xsSolid focus-within:shadow-mdSolid focus-within:outline-none focus-within:ring-1 focus-within:ring-ring focus-within:border-primary my-0"
+ class="shadow-xsSolid hover:shadow-smSolid hover:focus-within:shadow-mdSolid flex overflow-hidden rounded-sm border border-input bg-background text-sm font-code ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 disabled:shadow-xsSolid focus-within:shadow-mdSolid focus-within:outline-none focus-within:ring-1 focus-within:ring-ring focus-within:border-primary h-6 w-full my-0"
>
<input
aria-describedby=":r2a:-form-item-description"
@@ -822,7 +822,7 @@ exports[`renderZodSchema > should render a form sample_rows 1`] = `
<button
aria-controls=":r2a:-form-item"
aria-label="Increase"
- class="px-0.5 cursor-default text-muted-foreground pressed:bg-muted-foreground group-disabled:text-disabled-foreground outline-none focus-visible:text-primary disabled:cursor-not-allowed disabled:opacity-50 hover:text-primary hover:bg-muted"
+ class="cursor-default text-muted-foreground pressed:bg-muted-foreground group-disabled:text-disabled-foreground outline-none focus-visible:text-primary disabled:cursor-not-allowed disabled:opacity-50 hover:text-primary hover:bg-muted px-0.5"
data-rac=""
id="react-aria-:r2h:"
slot="increment"
@@ -853,7 +853,7 @@ exports[`renderZodSchema > should render a form sample_rows 1`] = `
<button
aria-controls=":r2a:-form-item"
aria-label="Decrease"
- class="px-0.5 cursor-default text-muted-foreground pressed:bg-muted-foreground group-disabled:text-disabled-foreground outline-none focus-visible:text-primary disabled:cursor-not-allowed disabled:opacity-50 hover:text-primary hover:bg-muted"
+ class="cursor-default text-muted-foreground pressed:bg-muted-foreground group-disabled:text-disabled-foreground outline-none focus-visible:text-primary disabled:cursor-not-allowed disabled:opacity-50 hover:text-primary hover:bg-muted px-0.5"
data-rac=""
id="react-aria-:r2i:"
slot="decrement"