Skip to content

Commit 4caf36a

Browse files
committed
Rename Table to DataGrid
1 parent 08ce42b commit 4caf36a

File tree

9 files changed

+52
-46
lines changed

9 files changed

+52
-46
lines changed

chartlets.js/CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
- `Switch`
4444
- `Tabs`
4545
- `Slider`
46-
- `Table`
46+
- `DataGrid`
4747

4848
* Supporting `tooltip` property for interactive MUI components.
4949

chartlets.js/packages/lib/src/plugins/mui/Table.test.tsx renamed to chartlets.js/packages/lib/src/plugins/mui/DataGrid.test.tsx

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import { describe, expect, it } from "vitest";
22
import { fireEvent, render, screen } from "@testing-library/react";
3-
import { Table } from "./Table";
3+
import { DataGrid } from "./DataGrid";
44
import { createChangeHandler } from "@/plugins/mui/common.test";
55

6-
describe("Table", () => {
6+
describe("DataGrid", () => {
77
const mockColumns = [
88
{ field: "id", headerName: "ID" },
99
{ field: "name", headerName: "Name" },
1010
];
1111
const mockRows = [{ id: 1, name: "MockRow" }];
1212
const paginationModel = { page: 1, pageSize: 10 };
1313

14-
it("should render the Table component", () => {
14+
it("should render the DataGrid component", () => {
1515
render(
16-
<Table
16+
<DataGrid
1717
columns={mockColumns}
1818
rows={mockRows}
19-
type="Table"
20-
id="tableId"
21-
ariaLabel="Test Table"
19+
type="DataGrid"
20+
id="datagridId"
21+
ariaLabel="Test DataGrid"
2222
onChange={() => {}}
2323
paginationModel={paginationModel}
2424
pageSizeOptions={[10, 25, 50]}
@@ -28,17 +28,17 @@ describe("Table", () => {
2828
expect(screen.getByText("MockRow")).toBeInTheDocument();
2929

3030
const grid = screen.getByTestId("data-grid-test-id");
31-
expect(grid).toHaveAttribute("aria-label", "Test Table");
31+
expect(grid).toHaveAttribute("aria-label", "Test DataGrid");
3232
});
3333

3434
it("should handle row click", () => {
3535
const { recordedEvents, onChange } = createChangeHandler();
3636
render(
37-
<Table
37+
<DataGrid
3838
columns={mockColumns}
3939
rows={mockRows}
40-
type="Table"
41-
id="tableId"
40+
type="DataGrid"
41+
id="datagridId"
4242
onChange={onChange}
4343
/>,
4444
);
@@ -47,21 +47,21 @@ describe("Table", () => {
4747
fireEvent.click(row);
4848

4949
expect(recordedEvents.length).toBe(1);
50-
expect(recordedEvents[0].componentType).toBe("Table");
51-
expect(recordedEvents[0].id).toBe("tableId");
50+
expect(recordedEvents[0].componentType).toBe("DataGrid");
51+
expect(recordedEvents[0].id).toBe("datagridId");
5252
expect(recordedEvents[0].property).toBe("value");
5353
expect(recordedEvents[0].value).toEqual(mockRows[0]);
5454
});
5555

5656
it("should render with other props correctly", () => {
5757
render(
58-
<Table
58+
<DataGrid
5959
columns={mockColumns}
6060
rows={mockRows}
61-
type="Table"
62-
id="tableId"
61+
type="DataGrid"
62+
id="datagridId"
6363
onChange={() => {}}
64-
ariaLabel="Test Table"
64+
ariaLabel="Test DataGrid"
6565
autoPageSize={true}
6666
checkboxSelection={true}
6767
density="compact"
@@ -86,7 +86,12 @@ describe("Table", () => {
8686

8787
it("should not render if no columns are provided", () => {
8888
render(
89-
<Table rows={mockRows} type="Table" id="tableId" onChange={() => {}} />,
89+
<DataGrid
90+
rows={mockRows}
91+
type="DataGrid"
92+
id="datagridId"
93+
onChange={() => {}}
94+
/>,
9095
);
9196
expect(screen.queryByRole("grid")).not.toBeInTheDocument();
9297
});

chartlets.js/packages/lib/src/plugins/mui/Table.tsx renamed to chartlets.js/packages/lib/src/plugins/mui/DataGrid.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "@mui/x-data-grid";
1010
import type { ComponentProps, ComponentState } from "@/index";
1111

12-
interface TableState extends ComponentState {
12+
interface DataGridState extends ComponentState {
1313
rows?: GridRowModel[];
1414
columns?: GridColDef[];
1515
ariaLabel?: string;
@@ -41,9 +41,9 @@ interface TableState extends ComponentState {
4141
rowSelection?: boolean;
4242
}
4343

44-
interface TableProps extends ComponentProps, TableState {}
44+
interface DataGridProps extends ComponentProps, DataGridState {}
4545

46-
export const Table = ({
46+
export const DataGrid = ({
4747
type,
4848
id,
4949
style,
@@ -73,7 +73,7 @@ export const Table = ({
7373
paginationModel,
7474
pageSizeOptions,
7575
onChange,
76-
}: TableProps) => {
76+
}: DataGridProps) => {
7777
if (!columns) {
7878
return;
7979
}

chartlets.js/packages/lib/src/plugins/mui/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Switch } from "./Switch";
1111
import { Tabs } from "./Tabs";
1212
import { Typography } from "./Typography";
1313
import { Slider } from "./Slider";
14-
import { Table } from "@/plugins/mui/Table";
14+
import { DataGrid } from "@/plugins/mui/DataGrid";
1515

1616
export default function mui(): Plugin {
1717
return {
@@ -26,7 +26,7 @@ export default function mui(): Plugin {
2626
["Select", Select],
2727
["Slider", Slider],
2828
["Switch", Switch],
29-
["Table", Table],
29+
["DataGrid", DataGrid],
3030
["Tabs", Tabs],
3131
["Typography", Typography],
3232
],

chartlets.py/CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
- `RadioGroup` and `Radio`
2424
- `Tabs`
2525
- `Slider`
26-
- `Table`
26+
- `DataGrid`
2727

2828
## Version 0.0.29 (from 2024/11/26)
2929

chartlets.py/chartlets/components/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from .select import Select
1313
from .slider import Slider
1414
from .switch import Switch
15-
from .table import Table
15+
from .datagrid import DataGrid
1616
from .tabs import Tab
1717
from .tabs import Tabs
1818
from .typography import Typography

chartlets.py/chartlets/components/table.py renamed to chartlets.py/chartlets/components/datagrid.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ class InitialState(TypedDict):
2323

2424

2525
@dataclass(frozen=True)
26-
class Table(Component):
27-
"""The Data Grid presents information in a structured format of rows and
26+
class DataGrid(Component):
27+
"""The DataGrid presents information in a structured format of rows and
2828
columns.
29-
30-
The data is displayed in a user-friendly interface for efficient editing,
31-
reviewing, and analysis.
3229
"""
3330

3431
rows: List[dict[str, Any]] = field(default_factory=list)

chartlets.py/demo/my_extension/my_panel_4.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from chartlets import Component, Input, Output
2-
from chartlets.components import Box, Slider, Typography, Table
2+
from chartlets.components import Box, Slider, Typography, DataGrid
33

44
from server.context import Context
55
from server.panel import Panel
@@ -49,10 +49,12 @@ def render_panel(
4949
{"id": 3, "firstName": "Peter", "lastName": "Jones", "age": 40},
5050
]
5151

52-
table = Table(id="table", rows=rows, columns=columns, checkboxSelection=True)
52+
datagrid = DataGrid(
53+
id="datagrid", rows=rows, columns=columns, checkboxSelection=True
54+
)
5355

54-
table_text = Typography(
55-
id="table_text", children=["Click on any row in " "the table."]
56+
datagrid_text = Typography(
57+
id="datagrid_text", children=["Click on any row in the datagrid."]
5658
)
5759

5860
return Box(
@@ -63,17 +65,17 @@ def render_panel(
6365
"height": "100%",
6466
"gap": "6px",
6567
},
66-
children=[slider, info_text, table, table_text],
68+
children=[slider, info_text, datagrid, datagrid_text],
6769
)
6870

6971

7072
# noinspection PyUnusedLocal
7173
@panel.callback(
7274
Input("slider"),
73-
Input("table"),
75+
Input("datagrid"),
7476
Output("info_text", "children"),
75-
Output("table_text", "children"),
77+
Output("datagrid_text", "children"),
7678
)
77-
def update_info_text(ctx: Context, slider: int, table) -> tuple[str, str]:
79+
def update_info_text(ctx: Context, slider: int, datagrid) -> tuple[str, str]:
7880
slider = slider or 0
79-
return f"The value is {slider}.", f"The selected row is {table}."
81+
return f"The value is {slider}.", f"The selected row is {datagrid}."

chartlets.py/tests/components/table_test.py renamed to chartlets.py/tests/components/datagrid_test.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
from chartlets.components import Table
1+
from chartlets.components import DataGrid
22
from tests.component_test import make_base
33

44

5-
class TableTest(make_base(Table)):
5+
class DataGridTest(make_base(DataGrid)):
66
def test_is_json_serializable(self):
77
columns = [
88
{"field": "id", "headerName": "ID"},
@@ -15,10 +15,12 @@ def test_is_json_serializable(self):
1515
{"id": 2, "firstName": "Jane", "lastName": "Smith", "age": 25},
1616
]
1717
self.assert_is_json_serializable(
18-
self.cls(rows=rows, columns=columns, id="my-table", checkboxSelection=True),
18+
self.cls(
19+
rows=rows, columns=columns, id="my-datagrid", checkboxSelection=True
20+
),
1921
{
20-
"type": "Table",
21-
"id": "my-table",
22+
"type": "DataGrid",
23+
"id": "my-datagrid",
2224
"rows": rows,
2325
"columns": columns,
2426
"checkboxSelection": True,

0 commit comments

Comments
 (0)