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.

chore: remove ag-grid, dead code (#5663)

Myles Scolnick3ad107a1a00a
diff --git a/frontend/package.json b/frontend/package.json
index 35da91265d..2323ba4a97 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -94,8 +94,6 @@
"@xterm/addon-attach": "^0.11.0",
"@xterm/addon-fit": "^0.10.0",
"@xterm/xterm": "^5.5.0",
- "ag-grid-community": "^32.3.8",
- "ag-grid-react": "^32.3.8",
"ai": "^4.3.16",
"ansi_up": "^6.0.6",
"class-variance-authority": "^0.7.1",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index 2170ebee8b..1e89686a20 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -258,12 +258,6 @@ importers:
'@xterm/xterm':
specifier: ^5.5.0
version: 5.5.0
- ag-grid-community:
- specifier: ^32.3.8
- version: 32.3.8
- ag-grid-react:
- specifier: ^32.3.8
ai:
specifier: ^4.3.16
@@ -3956,18 +3950,6 @@ packages:
engines: {node: '>=0.4.0'}
hasBin: true
- resolution: {integrity: sha512-zlvnvtpJDRACXtMjrq09K//eXZEdybeAQmQ94TEOCcNkinrMGMuM0WJXS2pJ64f7ic5fGqT3EQliWXwoRNF7cg==}
-
- resolution: {integrity: sha512-+ffiqyXQllUT1Gvb6VJ7Y2LDDqnl9ni62ne0yLoL20mNEBlivvYuHQ9Y9oMqE/8+AmAeIX+7r+W5IkktrwY5Rg==}
-
- resolution: {integrity: sha512-OWV6ow76RZCjHKmcmS2S0vLupPxqjH/+SEBdSjUmBpS5yHs4aXsoighoyhRsOKOK3IMGPm2rG5A4iGlNPVkjrw==}
- peerDependencies:
- react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
- react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0
-
resolution: {integrity: sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg==}
engines: {node: '>= 14'}
@@ -13362,19 +13344,6 @@ snapshots:
-
- dependencies:
- ag-charts-types: 10.3.8
-
- dependencies:
- ag-grid-community: 32.3.8
- prop-types: 15.8.1
- react: 19.1.0
- react-dom: 19.1.0([email protected])
-
dependencies:
debug: 4.4.1
diff --git a/frontend/src/plugins/impl/data-editor/data-editor.tsx b/frontend/src/plugins/impl/data-editor/data-editor.tsx
deleted file mode 100644
index 175797bd28..0000000000
--- a/frontend/src/plugins/impl/data-editor/data-editor.tsx
+++ /dev/null
@@ -1,241 +0,0 @@
-/* Copyright 2024 Marimo. All rights reserved. */
-
-import type {
- CellEditingStoppedEvent,
- ColDef,
- GridReadyEvent,
- RowDataTransaction,
-} from "ag-grid-community";
-import { AgGridReact } from "ag-grid-react";
-import { PlusIcon } from "lucide-react";
-import React, { useCallback, useEffect, useMemo, useRef } from "react";
-import type { FieldTypesWithExternalType } from "@/components/data-table/types";
-import { Button } from "@/components/ui/button";
-import { useTheme } from "@/theme/useTheme";
-import { cn } from "@/utils/cn";
-import type { DataType } from "../vega/vega-loader";
-
-export interface DataEditorProps<T> {
- data: T[];
- pagination: boolean;
- pageSize: number;
- fieldTypes: FieldTypesWithExternalType | null | undefined;
- edits: Array<{
- rowIdx: number;
- columnId: string;
- value: unknown;
- }>;
- onAddEdits: (
- edits: Array<{
- rowIdx: number;
- columnId: string;
- value: unknown;
- }>,
- ) => void;
- onAddRows: (newRows: object[]) => void;
- columnSizingMode: "fit" | "auto";
-}
-
-function cellEditorForDataType(dataType: DataType) {
- switch (dataType) {
- case "string":
- return "agTextCellEditor";
- case "number":
- return "agNumberCellEditor";
- case "boolean":
- return "agCheckboxCellEditor";
- // TODO: not working properly
- // case "date":
- // case "datetime":
- // case "time":
- // return 'agDateCellEditor';
- default:
- return "agTextCellEditor";
- }
-}
-
-function getHeaderKeys(data: object[]) {
- if (data.length === 0) {
- return [];
- }
- return Object.keys(data[0]);
-}
-
-const DataEditor: React.FC<DataEditorProps<object>> = ({
- data,
- edits,
- pagination,
- pageSize,
- fieldTypes,
- onAddEdits,
- onAddRows,
- columnSizingMode,
-}) => {
- const { theme } = useTheme();
- const gridRef = useRef<AgGridReact>(null);
- const headerKeys = useMemo(() => {
- if (fieldTypes) {
- return fieldTypes.map(([columnName]) => columnName);
- }
- return getHeaderKeys(data);
- }, [data, fieldTypes]);
-
- const finalRowData = useMemo(() => {
- for (const edit of edits) {
- if (edit.rowIdx >= data.length) {
- // Add a new row if rowIndex is out of bounds
- const newRow = { [edit.columnId]: edit.value };
- data.push(newRow);
- } else {
- const row = data[edit.rowIdx];
- (row as Record<string, unknown>)[edit.columnId] = edit.value;
- }
- }
- return data;
- }, [data, edits]);
-
- const columnDefs = useMemo(() => {
- const defs: ColDef[] = [];
- for (const header of headerKeys) {
- defs.push({
- field: header,
- editable: true,
- sortable: false,
- filter: false,
- cellEditorSelector: (params) => {
- const colId = params.column.getColId();
- const dataType: DataType =
- fieldTypes?.find(
- ([columnName]) => columnName === colId,
- )?.[1]?.[0] || "string";
- if (dataType) {
- if (typeof params.value === "string" && params.value.length > 60) {
- return { component: "agLargeTextCellEditor", popup: true };
- }
- return { component: cellEditorForDataType(dataType) };
- }
- return;
- },
- });
- }
- return defs;
- }, [headerKeys, fieldTypes]);
-
- const defaultColDef = useMemo<ColDef>(() => {
- return {
- sortable: true,
- filter: true,
- minWidth: 100, // Add minimum width to ensure columns are readable
- };
- }, []);
-
- const sizeColumns = useCallback(() => {
- // Size the columns to either fit the grid or auto-size based on content
- const api = gridRef.current?.api;
- if (!api) {
- return;
- }
-
- if (columnSizingMode === "fit") {
- api.sizeColumnsToFit();
- } else if (columnSizingMode === "auto") {
- api.autoSizeAllColumns();
- }
- }, [columnSizingMode]);
-
- const onGridReady = useCallback(
- (params: GridReadyEvent) => {
- sizeColumns();
- },
- [sizeColumns],
- );
-
- useEffect(() => {
- // Update grid layout when column sizing prop changes
- sizeColumns();
- }, [columnSizingMode, sizeColumns]);
-
- const onCellEditingStopped = useCallback(
- (event: CellEditingStoppedEvent) => {
- if (!event.valueChanged || event.rowIndex === null) {
- return;
- }
- const edit = {
- rowIdx: event.rowIndex,
- columnId: event.column.getColId(),
- value: event.newValue,
- };
- onAddEdits([edit]);
- },
- [onAddEdits],
- );
-
- const totalRows = data.length;
- const needsPagination = pagination && totalRows > pageSize;
-
- const handleAddRow = useCallback(() => {
- const newRow = Object.fromEntries(
- headerKeys.map((key) => {
- const dataType: DataType =
- fieldTypes?.find(([columnName]) => columnName === key)?.[1]?.[0] ||
- "string";
- switch (dataType) {
- case "boolean":
- return [key, false];
- case "integer":
- case "number":
- return [key, 0];
- case "date":
- return [key, new Date()];
- default:
- return [key, ""];
- }
- }),
- );
- onAddRows([newRow]);
-
- // Update the grid with the new row
- const transaction: RowDataTransaction = {
- add: [newRow],
- addIndex: finalRowData.length,
- };
- gridRef.current?.api.applyTransaction(transaction);
- }, [fieldTypes, onAddRows, headerKeys, finalRowData]);
-
- return (
- <div
- className={cn(
- theme === "dark" ? "ag-theme-quartz-dark" : "ag-theme-quartz",
- "ag-theme-marimo flex h-[400px] flex-col",
- "relative",
- )}
- >
- <AgGridReact
- ref={gridRef}
- rowData={finalRowData}
- columnDefs={columnDefs}
- defaultColDef={defaultColDef}
- cellSelection={true}
- pagination={needsPagination}
- paginationPageSize={pageSize}
- onGridReady={onGridReady}
- undoRedoCellEditing={true}
- stopEditingWhenCellsLoseFocus={true}
- onCellEditingStopped={onCellEditingStopped}
- animateRows={false}
- singleClickEdit={true}
- suppressFieldDotNotation={true}
- headerHeight={40}
- rowHeight={35}
- />
- <div className="p-2 border-t flex justify-end">
- <Button variant="text" size="xs" onClick={handleAddRow}>
- <PlusIcon className="w-3 h-3 mr-1" />
- Add Row
- </Button>
- </div>
- </div>
- );
-};
-
-export default DataEditor;