Skip to content

Commit d9a9974

Browse files
committed
[EuiDataGrid] Make various component callback types more consistent
- prefer using `ComponentType` over `JSXElementConstructor` and over functions
1 parent 64b47f4 commit d9a9974

4 files changed

Lines changed: 14 additions & 35 deletions

File tree

src/components/datagrid/body/data_grid_cell.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import React, {
1313
createRef,
1414
FocusEvent,
1515
FunctionComponent,
16-
JSXElementConstructor,
1716
KeyboardEvent,
1817
memo,
1918
MutableRefObject,
@@ -33,7 +32,6 @@ import {
3332
EuiDataGridSetCellProps,
3433
EuiDataGridCellValueElementProps,
3534
EuiDataGridCellValueProps,
36-
EuiDataGridCellPopoverElementProps,
3735
} from '../data_grid_types';
3836
import {
3937
EuiDataGridCellActions,
@@ -66,8 +64,7 @@ const EuiDataGridCellContent: FunctionComponent<
6664
...rest
6765
}) => {
6866
// React is more permissible than the TS types indicate
69-
const CellElement =
70-
renderCellValue as JSXElementConstructor<EuiDataGridCellValueElementProps>;
67+
const CellElement = renderCellValue;
7168

7269
return (
7370
<>
@@ -501,10 +498,8 @@ export class EuiDataGridCell extends Component<
501498
columnId,
502499
columnType,
503500
} = this.props;
504-
const PopoverElement = (renderCellPopover ||
505-
DefaultCellPopover) as JSXElementConstructor<EuiDataGridCellPopoverElementProps>;
506-
const CellElement =
507-
renderCellValue as JSXElementConstructor<EuiDataGridCellValueElementProps>;
501+
const PopoverElement = renderCellPopover || DefaultCellPopover;
502+
const CellElement = renderCellValue;
508503
const sharedProps = {
509504
rowIndex,
510505
colIndex,

src/components/datagrid/body/data_grid_cell_actions.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
* Side Public License, v 1.
77
*/
88

9-
import React, { JSXElementConstructor, useMemo, useCallback } from 'react';
9+
import React, { useMemo, useCallback } from 'react';
1010
import {
1111
EuiDataGridColumn,
1212
EuiDataGridColumnCellAction,
13-
EuiDataGridColumnCellActionProps,
1413
} from '../data_grid_types';
1514

1615
import { EuiI18n } from '../../i18n';
@@ -74,11 +73,8 @@ export const EuiDataGridCellActions = ({
7473
);
7574
return visibleCellActions.map(
7675
(Action: EuiDataGridColumnCellAction, idx: number) => {
77-
// React is more permissible than the TS types indicate
78-
const ActionButtonElement =
79-
Action as JSXElementConstructor<EuiDataGridColumnCellActionProps>;
8076
return (
81-
<ActionButtonElement
77+
<Action
8278
key={idx}
8379
rowIndex={rowIndex}
8480
colIndex={colIndex}
@@ -114,12 +110,10 @@ export const EuiDataGridCellPopoverActions = ({
114110

115111
const renderActions = useCallback(
116112
(Action: EuiDataGridColumnCellAction, idx: number) => {
117-
const ActionButtonElement =
118-
Action as JSXElementConstructor<EuiDataGridColumnCellActionProps>;
119113
return (
120114
<EuiFlexItem key={idx}>
121115
<div>
122-
<ActionButtonElement
116+
<Action
123117
rowIndex={rowIndex}
124118
colIndex={colIndex}
125119
columnId={column!.id}

src/components/datagrid/data_grid_types.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import {
1010
ComponentType,
11-
JSXElementConstructor,
1211
ReactNode,
1312
HTMLAttributes,
1413
CSSProperties,
@@ -18,7 +17,6 @@ import {
1817
Ref,
1918
Component,
2019
PropsWithChildren,
21-
ComponentClass,
2220
} from 'react';
2321
import {
2422
VariableSizeGridProps,
@@ -279,7 +277,7 @@ export type CommonGridProps = CommonProps &
279277
* allowing hooks, context, and other React concepts to be used.
280278
* It receives #EuiDataGridCustomBodyProps as its only argument.
281279
*/
282-
renderCustomGridBody?: (args: EuiDataGridCustomBodyProps) => ReactNode;
280+
renderCustomGridBody?: ComponentType<EuiDataGridCustomBodyProps>;
283281
/**
284282
* Defines the initial style of the grid. Accepts a partial #EuiDataGridStyle object.
285283
* Settings provided may be overwritten or merged with user defined preferences if `toolbarVisibility.showDisplaySelector.allowDensity = true` (which is the default).
@@ -454,7 +452,7 @@ export interface EuiDataGridCustomBodyProps {
454452
* You may also pass in any other optional cell prop overrides
455453
* that `EuiDataGridCell` accepts, such as `isExpandable` or `renderCellValue`.
456454
*/
457-
Cell: JSXElementConstructor<
455+
Cell: ComponentType<
458456
{
459457
colIndex: number;
460458
visibleRowIndex: number;
@@ -560,7 +558,7 @@ export interface EuiDataGridCellPopoverElementProps
560558
* For certain columns or schemas, you may want to fall back to the standard EuiDataGrid popover display.
561559
* If so, that component is provided here as a passed React function component for your usage.
562560
*/
563-
DefaultCellPopover: JSXElementConstructor<EuiDataGridCellPopoverElementProps>;
561+
DefaultCellPopover: ComponentType<EuiDataGridCellPopoverElementProps>;
564562
/**
565563
* Allows passing props to the wrapping cell expansion popover and panel.
566564
* Accepts any props that `EuiPopover` accepts, except for `button` and `closePopover`.
@@ -582,12 +580,8 @@ export interface EuiDataGridCellProps {
582580
isExpandable: boolean;
583581
className?: string;
584582
popoverContext: DataGridCellPopoverContextShape;
585-
renderCellValue:
586-
| ((props: EuiDataGridCellValueElementProps) => ReactNode)
587-
| ComponentClass<EuiDataGridCellValueElementProps>;
588-
renderCellPopover?:
589-
| JSXElementConstructor<EuiDataGridCellPopoverElementProps>
590-
| ((props: EuiDataGridCellPopoverElementProps) => ReactNode);
583+
renderCellValue: ComponentType<EuiDataGridCellValueElementProps>;
584+
renderCellPopover?: ComponentType<EuiDataGridCellPopoverElementProps>;
591585
setRowHeight?: (height: number) => void;
592586
getRowHeight?: (rowIndex: number) => number;
593587
style?: React.CSSProperties;
@@ -706,9 +700,8 @@ export interface EuiDataGridColumn {
706700
visibleCellActions?: number;
707701
}
708702

709-
export type EuiDataGridColumnCellAction = (
710-
props: EuiDataGridColumnCellActionProps
711-
) => ReactNode;
703+
export type EuiDataGridColumnCellAction =
704+
ComponentType<EuiDataGridColumnCellActionProps>;
712705

713706
export interface EuiDataGridColumnActions {
714707
/**

src/components/datagrid/utils/in_memory.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
import React, {
1010
FunctionComponent,
11-
JSXElementConstructor,
1211
useCallback,
1312
useEffect,
1413
useMemo,
@@ -22,7 +21,6 @@ import {
2221
EuiDataGridInMemory,
2322
EuiDataGridInMemoryValues,
2423
EuiDataGridInMemoryRendererProps,
25-
EuiDataGridCellValueElementProps,
2624
} from '../data_grid_types';
2725

2826
/**
@@ -91,8 +89,7 @@ export const EuiDataGridInMemoryRenderer: FunctionComponent<
9189
const [documentFragment] = useState(() => document.createDocumentFragment());
9290

9391
const cells = useMemo(() => {
94-
const CellElement =
95-
renderCellValue as JSXElementConstructor<EuiDataGridCellValueElementProps>;
92+
const CellElement = renderCellValue;
9693

9794
const cells = [];
9895

0 commit comments

Comments
 (0)