Skip to content

Commit a3f666d

Browse files
committed
refactor: rename Cell to DataCell
1 parent 3150f3a commit a3f666d

File tree

5 files changed

+25
-77
lines changed

5 files changed

+25
-77
lines changed

packages/pluggableWidgets/datagrid-web/src/components/Cell.tsx renamed to packages/pluggableWidgets/datagrid-web/src/components/DataCell.tsx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
import { useFocusTargetProps } from "@mendix/widget-plugin-grid/keyboard-navigation/useFocusTargetProps";
2+
import { ObjectItem } from "mendix";
23
import { computed } from "mobx";
34
import { observer } from "mobx-react-lite";
4-
import { ReactElement, useMemo } from "react";
5-
import { CellComponentProps } from "../typings/CellComponent";
5+
import { ReactElement, ReactNode, useMemo } from "react";
6+
import { EventsController } from "../typings/CellComponent";
67
import { GridColumn } from "../typings/GridColumn";
78
import { CellElement } from "./CellElement";
89

9-
const component = observer(function Cell(props: CellComponentProps<GridColumn>): ReactElement {
10+
interface DataCellProps {
11+
children?: ReactNode;
12+
className?: string;
13+
column: GridColumn;
14+
item: ObjectItem;
15+
key?: string | number;
16+
rowIndex: number;
17+
columnIndex?: number;
18+
clickable?: boolean;
19+
preview?: boolean;
20+
eventsController: EventsController;
21+
}
22+
23+
export const DataCell = observer(function DataCell(props: DataCellProps): ReactElement {
1024
const keyNavProps = useFocusTargetProps<HTMLDivElement>({
1125
columnIndex: props.columnIndex ?? -1,
1226
rowIndex: props.rowIndex
@@ -36,6 +50,3 @@ const component = observer(function Cell(props: CellComponentProps<GridColumn>):
3650
</CellElement>
3751
);
3852
});
39-
40-
// Override NamedExoticComponent type
41-
export const Cell = component as (props: CellComponentProps<GridColumn>) => ReactElement;

packages/pluggableWidgets/datagrid-web/src/components/Row.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import { ReactElement } from "react";
44
import { SelectActionHelper } from "../helpers/SelectActionHelper";
55
import { EventsController } from "../typings/CellComponent";
66
import { GridColumn } from "../typings/GridColumn";
7-
import { Cell } from "./Cell";
87
import { CheckboxCell } from "./CheckboxCell";
8+
import { DataCell } from "./DataCell";
99
import { SelectorCell } from "./SelectorCell";
1010

1111
export interface RowProps {
@@ -18,6 +18,7 @@ export interface RowProps {
1818
totalRows: number;
1919
clickable: boolean;
2020
eventsController: EventsController;
21+
checkboxColumnEnabled: boolean;
2122
}
2223

2324
export function Row(props: RowProps): ReactElement {
@@ -32,7 +33,7 @@ export function Row(props: RowProps): ReactElement {
3233
role="row"
3334
aria-selected={ariaSelected}
3435
>
35-
{selectActionHelper.showCheckboxColumn && (
36+
{props.checkboxColumnEnabled && (
3637
<CheckboxCell
3738
item={props.item}
3839
key="checkbox_cell"
@@ -42,20 +43,18 @@ export function Row(props: RowProps): ReactElement {
4243
/>
4344
)}
4445
{props.columns.map((column, baseIndex) => {
45-
const cell = (
46-
<Cell
46+
return (
47+
<DataCell
4748
key={`row_${props.item.id}_col_${column.columnId}`}
4849
column={column}
4950
rowIndex={props.index}
50-
columnIndex={selectActionHelper.showCheckboxColumn ? baseIndex + 1 : baseIndex}
51+
columnIndex={props.checkboxColumnEnabled ? baseIndex + 1 : baseIndex}
5152
item={props.item}
5253
clickable={props.clickable}
5354
preview={false}
5455
eventsController={eventsController}
5556
/>
5657
);
57-
58-
return cell;
5958
})}
6059
{props.showSelectorCell && (
6160
<SelectorCell

packages/pluggableWidgets/datagrid-web/src/components/RowsRenderer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const RowsRenderer = observer(function RowsRenderer(): ReactElement {
2626
item={item}
2727
key={`row_${item.id}`}
2828
showSelectorCell={config.columnsHidable}
29+
checkboxColumnEnabled={config.checkboxColumnEnabled}
2930
/>
3031
);
3132
})}
Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,6 @@
1-
import { ObjectItem } from "mendix";
2-
import { ReactElement, ReactNode } from "react";
3-
import { GridColumn } from "./GridColumn";
41
import { ElementProps } from "@mendix/widget-plugin-grid/event-switch/base";
2+
import { ObjectItem } from "mendix";
53

64
export interface EventsController {
75
getProps(item: ObjectItem): ElementProps<HTMLDivElement>;
86
}
9-
10-
export interface CellComponentProps<C extends GridColumn> {
11-
children?: ReactNode;
12-
className?: string;
13-
column: C;
14-
item: ObjectItem;
15-
key?: string | number;
16-
rowIndex: number;
17-
columnIndex?: number;
18-
clickable?: boolean;
19-
preview?: boolean;
20-
eventsController: EventsController;
21-
}
22-
23-
export type CellComponent<C extends GridColumn> = (props: CellComponentProps<C>) => ReactElement;

packages/pluggableWidgets/datagrid-web/src/utils/test-utils.tsx

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
import { FocusTargetController } from "@mendix/widget-plugin-grid/keyboard-navigation/FocusTargetController";
2-
import { PositionController } from "@mendix/widget-plugin-grid/keyboard-navigation/PositionController";
3-
import { VirtualGridLayout } from "@mendix/widget-plugin-grid/keyboard-navigation/VirtualGridLayout";
41
import { dynamic, list, listAttr, listExp } from "@mendix/widget-plugin-test-utils";
5-
import { GUID, ObjectItem } from "mendix";
62
import { ColumnsType, DatagridContainerProps } from "../../typings/DatagridProps";
7-
import { Cell } from "../components/Cell";
8-
import { WidgetProps } from "../components/Widget";
93
import { SelectActionHelper } from "../helpers/SelectActionHelper";
104
import { ColumnStore } from "../helpers/state/column/ColumnStore";
115
import { IColumnParentStore } from "../helpers/state/ColumnGroupStore";
@@ -68,46 +62,6 @@ export function mockGridColumn(c: ColumnsType, index: number): GridColumn {
6862
return new ColumnStore(index, c, parentStore);
6963
}
7064

71-
export function mockWidgetProps(): WidgetProps<GridColumn, ObjectItem> {
72-
const id = "dg1";
73-
const columnsProp = [column("Test")];
74-
const columns = columnsProp.map((col, index) => mockGridColumn(col, index));
75-
76-
return {
77-
CellComponent: Cell,
78-
className: "test",
79-
columnsDraggable: false,
80-
columnsFilterable: false,
81-
columnsHidable: false,
82-
columnsResizable: false,
83-
columnsSortable: false,
84-
data: [{ id: "123456" as GUID }],
85-
exporting: false,
86-
filterRenderer: () => <input type="text" defaultValue="dummy" />,
87-
headerWrapperRenderer: (_index, header) => header,
88-
id,
89-
onExportCancel: jest.fn(),
90-
paginationType: "buttons",
91-
visibleColumns: columns,
92-
availableColumns: columns,
93-
columnsSwap: jest.fn(),
94-
setIsResizing: jest.fn(),
95-
processedRows: 0,
96-
selectActionHelper: mockSelectionProps(),
97-
cellEventsController: { getProps: () => Object.create({}) },
98-
checkboxEventsController: { getProps: () => Object.create({}) },
99-
isFirstLoad: false,
100-
isFetchingNextBatch: false,
101-
loadingType: "spinner",
102-
columnsLoading: false,
103-
showRefreshIndicator: false,
104-
focusController: new FocusTargetController(
105-
new PositionController(),
106-
new VirtualGridLayout(1, columns.length, 10)
107-
)
108-
};
109-
}
110-
11165
export function mockContainerProps(overrides?: Partial<DatagridContainerProps>): DatagridContainerProps {
11266
return {
11367
class: "dg-one",

0 commit comments

Comments
 (0)