Skip to content

Commit

Permalink
Add colIndex prop to cell actions
Browse files Browse the repository at this point in the history
- so that cell actions that trigger modals or flyouts can re-focus into the correct cell using the new ref API
  • Loading branch information
cee-chen committed Jan 5, 2022
1 parent 14401ef commit 1609e45
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/components/datagrid/body/data_grid_cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export class EuiDataGridCell extends Component<
rowManager,
...rest
} = this.props;
const { rowIndex } = rest;
const { rowIndex, colIndex } = rest;

const showCellButtons =
this.state.isFocused ||
Expand Down Expand Up @@ -546,6 +546,7 @@ export class EuiDataGridCell extends Component<
</div>
<EuiDataGridCellButtons
rowIndex={rowIndex}
colIndex={colIndex}
column={column}
popoverIsOpen={this.state.popoverIsOpen}
closePopover={this.closePopover}
Expand Down Expand Up @@ -588,6 +589,7 @@ export class EuiDataGridCell extends Component<
panelRefFn={(ref) => (this.popoverPanelRef.current = ref)}
popoverIsOpen={this.state.popoverIsOpen}
rowIndex={rowIndex}
colIndex={colIndex}
renderCellValue={rest.renderCellValue}
popoverContent={PopoverContent}
/>
Expand Down
2 changes: 2 additions & 0 deletions src/components/datagrid/body/data_grid_cell_buttons.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('EuiDataGridCellButtons', () => {
closePopover: jest.fn(),
onExpandClick: jest.fn(),
rowIndex: 0,
colIndex: 0,
};

it('renders an expand button', () => {
Expand Down Expand Up @@ -66,6 +67,7 @@ describe('EuiDataGridCellButtons', () => {
<Component
Component={[Function]}
closePopover={[MockFunction]}
colIndex={0}
columnId="someId"
isExpanded={false}
key="0"
Expand Down
5 changes: 4 additions & 1 deletion src/components/datagrid/body/data_grid_cell_buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ export const EuiDataGridCellButtons = ({
onExpandClick,
column,
rowIndex,
colIndex,
}: {
popoverIsOpen: boolean;
closePopover: () => void;
onExpandClick: () => void;
column?: EuiDataGridColumn;
rowIndex: number;
colIndex: number;
}) => {
const buttonIconClasses = classNames('euiDataGridRowCell__expandButtonIcon', {
'euiDataGridRowCell__expandButtonIcon-isActive': popoverIsOpen,
Expand Down Expand Up @@ -74,6 +76,7 @@ export const EuiDataGridCellButtons = ({
<CellButtonElement
key={idx}
rowIndex={rowIndex}
colIndex={colIndex}
columnId={column.id}
Component={ButtonComponent}
isExpanded={false}
Expand All @@ -83,7 +86,7 @@ export const EuiDataGridCellButtons = ({
}
)
: [];
}, [column, rowIndex, closePopover]);
}, [column, colIndex, rowIndex, closePopover]);

return (
<div className={buttonClasses}>{[...additionalButtons, expandButton]}</div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/datagrid/body/data_grid_cell_popover.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import { EuiDataGridCellPopover } from './data_grid_cell_popover';

describe('EuiDataGridCellPopover', () => {
const requiredProps = {
// column,
rowIndex: 0,
colIndex: 0,
cellContentProps: {
rowIndex: 0,
columnId: 'someId',
Expand Down Expand Up @@ -123,6 +123,7 @@ describe('EuiDataGridCellPopover', () => {
<Component
Component={[Function]}
closePopover={[MockFunction]}
colIndex={0}
columnId="someId"
isExpanded={true}
rowIndex={0}
Expand Down
2 changes: 2 additions & 0 deletions src/components/datagrid/body/data_grid_cell_popover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function EuiDataGridCellPopover({
popoverIsOpen,
renderCellValue,
rowIndex,
colIndex,
}: EuiDataGridCellPopoverProps) {
const CellElement = renderCellValue as JSXElementConstructor<
EuiDataGridCellValueElementProps
Expand Down Expand Up @@ -71,6 +72,7 @@ export function EuiDataGridCellPopover({
<EuiFlexItem key={idx}>
<CellButtonElement
rowIndex={rowIndex}
colIndex={colIndex}
columnId={column.id}
Component={(props: EuiButtonEmptyProps) => (
<EuiButtonEmpty {...props} size="s" />
Expand Down
1 change: 1 addition & 0 deletions src/components/datagrid/data_grid_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ export interface EuiDataGridCellPopoverProps {
| JSXElementConstructor<EuiDataGridCellValueElementProps>
| ((props: EuiDataGridCellValueElementProps) => ReactNode);
rowIndex: number;
colIndex: number;
}
export interface EuiDataGridColumnSortingDraggableProps {
id: string;
Expand Down

0 comments on commit 1609e45

Please sign in to comment.