Skip to content

Commit

Permalink
Simplify and fix failing RenderCellValue types
Browse files Browse the repository at this point in the history
remove `|` and bake `Record<string, any>` into the props
  • Loading branch information
cee-chen committed Mar 7, 2024
1 parent e74d022 commit 3fd6bc6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
8 changes: 3 additions & 5 deletions src/components/datagrid/data_grid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -988,9 +988,7 @@ describe('EuiDataGrid', () => {
rowCount: 1,
};

const RenderCellValueWithContext: RenderCellValueWithContext = ({
someContext,
}) => (
const RenderCellValueWithContext: RenderCellValue = ({ someContext }) => (
<div data-test-subj="renderedCell">
{someContext ? 'hello' : 'world'}
</div>
Expand Down
19 changes: 8 additions & 11 deletions src/components/datagrid/data_grid_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -604,18 +604,15 @@ export interface EuiDataGridCellPopoverElementProps
) => void;
}

type CellContext = Record<string, any>;

export type EuiDataGridCellValueElementPropsWithContext =
EuiDataGridCellValueElementProps & CellContext;
type CellContext = Omit<
Record<string, any>,
keyof EuiDataGridCellValueElementProps
>;
type CellPropsWithContext = CellContext & EuiDataGridCellValueElementProps;

export type RenderCellValue =
| ((props: EuiDataGridCellValueElementProps) => ReactNode)
| ComponentClass<EuiDataGridCellValueElementProps>;

export type RenderCellValueWithContext =
| ((props: EuiDataGridCellValueElementPropsWithContext) => ReactNode)
| ComponentClass<EuiDataGridCellValueElementPropsWithContext>;
| ((props: CellPropsWithContext) => ReactNode)
| ComponentClass<CellPropsWithContext>;

export interface EuiDataGridCellProps {
rowIndex: number;
Expand All @@ -629,7 +626,7 @@ export interface EuiDataGridCellProps {
isExpandable: boolean;
className?: string;
popoverContext: DataGridCellPopoverContextShape;
renderCellValue: RenderCellValue | RenderCellValueWithContext;
renderCellValue: RenderCellValue;
cellContext?: CellContext;
renderCellPopover?:
| JSXElementConstructor<EuiDataGridCellPopoverElementProps>
Expand Down

0 comments on commit 3fd6bc6

Please sign in to comment.