From ad95e8587a4347a3e9a0e3c7c96205b1ee206d4c Mon Sep 17 00:00:00 2001 From: Cee Chen Date: Wed, 6 Mar 2024 20:59:10 -0800 Subject: [PATCH] Simplify and fix failing `RenderCellValue` types remove `|` and bake `Record` into the props --- src/components/datagrid/data_grid.test.tsx | 8 +++----- src/components/datagrid/data_grid_types.ts | 19 ++++++++----------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/src/components/datagrid/data_grid.test.tsx b/src/components/datagrid/data_grid.test.tsx index 302e0e84c46..367a157a13a 100644 --- a/src/components/datagrid/data_grid.test.tsx +++ b/src/components/datagrid/data_grid.test.tsx @@ -8,8 +8,8 @@ import React, { useEffect, useState } from 'react'; import { mount, ReactWrapper } from 'enzyme'; -import { EuiDataGrid, RenderCellValue, RenderCellValueWithContext } from './'; -import { EuiDataGridProps } from './data_grid_types'; +import { EuiDataGrid } from './'; +import type { EuiDataGridProps, RenderCellValue } from './data_grid_types'; import { findTestSubject, requiredProps } from '../../test'; import { render } from '../../test/rtl'; import { EuiDataGridColumnResizer } from './body/header/data_grid_column_resizer'; @@ -988,9 +988,7 @@ describe('EuiDataGrid', () => { rowCount: 1, }; - const RenderCellValueWithContext: RenderCellValueWithContext = ({ - someContext, - }) => ( + const RenderCellValueWithContext: RenderCellValue = ({ someContext }) => (
{someContext ? 'hello' : 'world'}
diff --git a/src/components/datagrid/data_grid_types.ts b/src/components/datagrid/data_grid_types.ts index 4ce7375c79f..8608552e6c0 100644 --- a/src/components/datagrid/data_grid_types.ts +++ b/src/components/datagrid/data_grid_types.ts @@ -604,18 +604,15 @@ export interface EuiDataGridCellPopoverElementProps ) => void; } -type CellContext = Record; - -export type EuiDataGridCellValueElementPropsWithContext = - EuiDataGridCellValueElementProps & CellContext; +type CellContext = Omit< + Record, + keyof EuiDataGridCellValueElementProps +>; +type CellPropsWithContext = CellContext & EuiDataGridCellValueElementProps; export type RenderCellValue = - | ((props: EuiDataGridCellValueElementProps) => ReactNode) - | ComponentClass; - -export type RenderCellValueWithContext = - | ((props: EuiDataGridCellValueElementPropsWithContext) => ReactNode) - | ComponentClass; + | ((props: CellPropsWithContext) => ReactNode) + | ComponentClass; export interface EuiDataGridCellProps { rowIndex: number; @@ -629,7 +626,7 @@ export interface EuiDataGridCellProps { isExpandable: boolean; className?: string; popoverContext: DataGridCellPopoverContextShape; - renderCellValue: RenderCellValue | RenderCellValueWithContext; + renderCellValue: RenderCellValue; cellContext?: CellContext; renderCellPopover?: | JSXElementConstructor