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.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: table checkbox width and pinning styles (#2345)
Myles Scolnickfcabffdc73fb
diff --git a/frontend/package.json b/frontend/package.jsonindex 122c92f43b..f111608acc 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -178,6 +178,7 @@"@storybook/testing-library": "^0.2.2","@swc-jotai/react-refresh": "^0.1.1","@testing-library/react": "^16.0.0",+ "@testing-library/react-hooks": "^8.0.1","@types/emscripten": "^1.39.13","@types/katex": "^0.16.7","@types/lodash-es": "^4.17.12",diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yamlindex f7f28977af..2ca3fc7c6a 100644--- a/frontend/pnpm-lock.yaml+++ b/frontend/pnpm-lock.yaml@@ -421,6 +421,9 @@ devDependencies:'@testing-library/react':specifier: ^16.0.0version: 16.0.0(@testing-library/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])+ '@testing-library/react-hooks':+ specifier: ^8.0.1'@types/emscripten':specifier: ^1.39.13version: 1.39.13@@ -7710,6 +7713,30 @@ packages:dev: true+ /@testing-library/[email protected](@types/[email protected])([email protected])([email protected])([email protected]):+ resolution: {integrity: sha512-Aqhl2IVmLt8IovEVarNDFuJDVWVvhnr9/GCU6UUnrYXwgDFF9h2L2o2P9KBni1AST5sT6riAyoukFLyjQUgD/g==}+ engines: {node: '>=12'}+ peerDependencies:+ '@types/react': ^16.9.0 || ^17.0.0+ react: ^16.9.0 || ^17.0.0+ react-dom: ^16.9.0 || ^17.0.0+ react-test-renderer: ^16.9.0 || ^17.0.0+ peerDependenciesMeta:+ '@types/react':+ optional: true+ react-dom:+ optional: true+ react-test-renderer:+ optional: true+ dependencies:+ '@babel/runtime': 7.25.6+ '@types/react': 18.3.7+ react: 18.3.1+ react-dom: 18.3.1([email protected])+ react-error-boundary: 3.1.4([email protected])+ react-test-renderer: 18.3.1([email protected])+ dev: true+/@testing-library/[email protected](@testing-library/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected]):resolution: {integrity: sha512-guuxUKRWQ+FgNX0h0NS0FIq3Q3uLtWVpBzcLOggmfMoUpgBnzBzvLLd4fbm6yS8ydJd94cIfY4yP9qUQjM2KwQ==}engines: {node: '>=18'}@@ -15754,6 +15781,16 @@ packages:react-is: 18.1.0dev: true+ resolution: {integrity: sha512-uM9uPzZJTF6wRQORmSrvOIgt4lJ9MC1sNgEOj2XGsDTRE4kmpWxg7ENK9EWNKJRMAOY9z0MuF4yIfl6gp4sotA==}+ engines: {node: '>=10', npm: '>=6'}+ peerDependencies:+ react: '>=16.13.1'+ dependencies:+ '@babel/runtime': 7.25.6+ react: 18.3.1+ dev: true+resolution: {integrity: sha512-b6PwbdSv8XeOSYvjt8LpgpKrZ0yGdtZokYwkwV2wlcZbxgopHX/hgPl5VgpnoVOWd868n1hktM8Qm4b+02MiLQ==}peerDependencies:diff --git a/frontend/src/components/data-table/__test__/useColumnPinning.test.ts b/frontend/src/components/data-table/__test__/useColumnPinning.test.tsnew file mode 100644index 0000000000..efd79edb7a--- /dev/null+++ b/frontend/src/components/data-table/__test__/useColumnPinning.test.ts@@ -0,0 +1,75 @@+/* Copyright 2024 Marimo. All rights reserved. */+import { SELECT_COLUMN_ID } from "../types";+import { renderHook, act } from "@testing-library/react-hooks";+import { describe, it, expect } from "vitest";+import { useColumnPinning } from "../hooks/useColumnPinning";++describe("useColumnPinning", () => {+ it("should initialize with correct default values", () => {+ const { result } = renderHook(() => useColumnPinning());+ expect(result.current.columnPinning).toEqual({+ left: [],+ right: undefined,+ });+ });++ it("should add SELECT_COLUMN_ID to left when freezeColumnsLeft is provided", () => {+ const { result } = renderHook(() =>+ useColumnPinning(["column1", "column2"]),+ );+ expect(result.current.columnPinning.left).toEqual([+ SELECT_COLUMN_ID,+ "column1",+ "column2",+ ]);+ });++ it("should not add SELECT_COLUMN_ID if it's already present", () => {+ const { result } = renderHook(() =>+ useColumnPinning([SELECT_COLUMN_ID, "column1"]),+ );+ expect(result.current.columnPinning.left).toEqual([+ SELECT_COLUMN_ID,+ "column1",+ ]);+ });++ it("should set right columns correctly", () => {+ const { result } = renderHook(() =>+ useColumnPinning(undefined, ["column3", "column4"]),+ );+ expect(result.current.columnPinning.right).toEqual(["column3", "column4"]);+ });++ it("should update column pinning state correctly", () => {+ const { result } = renderHook(() => useColumnPinning());++ act(() => {+ result.current.setColumnPinning({+ left: ["column1"],+ right: ["column2"],+ });+ });++ expect(result.current.columnPinning).toEqual({+ left: [SELECT_COLUMN_ID, "column1"],+ right: ["column2"],+ });+ });++ it("should handle function updates to column pinning state", () => {+ const { result } = renderHook(() => useColumnPinning(["initialLeft"]));++ act(() => {+ result.current.setColumnPinning((prev: object) => ({+ ...prev,+ right: ["newRight"],+ }));+ });++ expect(result.current.columnPinning).toEqual({+ left: [SELECT_COLUMN_ID, "initialLeft"],+ right: ["newRight"],+ });+ });+});diff --git a/frontend/src/components/data-table/columns.tsx b/frontend/src/components/data-table/columns.tsxindex a207718536..b3c6c9b235 100644--- a/frontend/src/components/data-table/columns.tsx+++ b/frontend/src/components/data-table/columns.tsx@@ -169,6 +169,7 @@ export function generateColumns<T>({if (selection === "single" || selection === "multi") {columns.unshift({id: "__select__",+ maxSize: 40,header: ({ table }) =>selection === "multi" ? (<Checkboxdiff --git a/frontend/src/components/data-table/hooks/useColumnPinning.ts b/frontend/src/components/data-table/hooks/useColumnPinning.tsindex d7056e7f97..de516ba66b 100644--- a/frontend/src/components/data-table/hooks/useColumnPinning.ts+++ b/frontend/src/components/data-table/hooks/useColumnPinning.ts@@ -13,29 +13,31 @@ export function useColumnPinning(freezeColumnsRight?: string[],): UseColumnPinningResult {const [columnPinning, setColumnPinning] = React.useState<ColumnPinningState>({- left: freezeColumnsLeft- ? [SELECT_COLUMN_ID, ...freezeColumnsLeft]- : [SELECT_COLUMN_ID],+ left: maybeAddSelectColumnId(freezeColumnsLeft),right: freezeColumnsRight,});- const setColumnPinningWithFreeze = React.useCallback(- (newState: React.SetStateAction<ColumnPinningState>) => {- setColumnPinning((prevState) => {- const updatedState =- typeof newState === "function" ? newState(prevState) : newState;- return {- left:- !freezeColumnsLeft || freezeColumnsLeft?.includes(SELECT_COLUMN_ID)- ? freezeColumnsLeft- : [SELECT_COLUMN_ID, ...(freezeColumnsLeft || [])],- right: freezeColumnsRight,- ...updatedState,- };- });- },- [freezeColumnsLeft, freezeColumnsRight],- );+ const setColumnPinningWithFreeze = (+ newState: React.SetStateAction<ColumnPinningState>,+ ) => {+ setColumnPinning((prevState) => {+ const updatedState =+ typeof newState === "function" ? newState(prevState) : newState;+ return {+ left: maybeAddSelectColumnId(updatedState.left),+ right: updatedState.right,+ };+ });+ };return { columnPinning, setColumnPinning: setColumnPinningWithFreeze };}++function maybeAddSelectColumnId(freezeColumns: string[] | undefined): string[] {+ if (!freezeColumns || freezeColumns.length === 0) {+ return [];+ }+ return freezeColumns.includes(SELECT_COLUMN_ID)+ ? freezeColumns+ : [SELECT_COLUMN_ID, ...freezeColumns];+}diff --git a/frontend/src/components/data-table/renderers.tsx b/frontend/src/components/data-table/renderers.tsxindex c889b3efff..c1178d6866 100644--- a/frontend/src/components/data-table/renderers.tsx+++ b/frontend/src/components/data-table/renderers.tsx@@ -122,7 +122,7 @@ function getPinningStyles<TData>(isPinned === "right" && column.getIsFirstColumn("right");return {- className: cn(isPinned && "bg-background", "shadow-r z-10"),+ className: cn(isPinned && "bg-inherit", "shadow-r z-10"),style: {boxShadow:isLastLeftPinnedColumn && column.id !== "__select__"diff --git a/frontend/src/components/ui/table.tsx b/frontend/src/components/ui/table.tsxindex 67996af051..65fd5c7b55 100644--- a/frontend/src/components/ui/table.tsx+++ b/frontend/src/components/ui/table.tsx@@ -21,7 +21,11 @@ const TableHeader = React.forwardRef<HTMLTableSectionElement,React.HTMLAttributes<HTMLTableSectionElement>>(({ className, ...props }, ref) => (- <thead ref={ref} className={cn("[&_tr]:border-b", className)} {...props} />+ <thead+ ref={ref}+ className={cn("[&_tr]:border-b bg-background", className)}+ {...props}+ />));TableHeader.displayName = "TableHeader";@@ -56,7 +60,7 @@ const TableRow = React.forwardRef<<trref={ref}className={cn(- "border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",+ "border-b transition-colors bg-background hover:bg-[var(--slate-2)] data-[state=selected]:bg-[var(--slate-3)]",className,)}{...props}diff --git a/marimo/_smoke_tests/tables/ibis_example.py b/marimo/_smoke_tests/tables/ibis_example.pyindex b8d84cb27a..7d6fef992b 100644--- a/marimo/_smoke_tests/tables/ibis_example.py+++ b/marimo/_smoke_tests/tables/ibis_example.py@@ -14,10 +14,38 @@ def __():def __(mo):import ibis- table = ibis.memtable({"a": [1, 2, 3] * 1000, "b": [4, 5, 6] * 1000})+ # hover:bg-muted/50 data-[state=selected]:bg-muted+ memtable = ibis.memtable(+ {+ "rowid": range(3000),+ "a": [1, 2, 3] * 1000,+ "b": [4, 5, 6] * 1000,+ "c": [4, 5, 6] * 1000,+ "d": [4, 5, 6] * 1000,+ "e": [4, 5, 6] * 1000,+ }+ )++ table = mo.ui.table(memtable, page_size=5)+ return ibis, memtable, table- mo.ui.table(table)- return ibis, table++def __(table):+ table+ return+++def __(mo, table):+ mo.ui.table(table.value)+ return+++def __(table):+ table.value+ returnif __name__ == "__main__":