-
Notifications
You must be signed in to change notification settings - Fork 841
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[EuiDataGrid] Various footer fixes (#5720)
* Fix focus fighting bug after moving a column and clicking its footer cell Using a cell `key` with a column ID causes the cell node reference to move, instead of the cell/node reference staying in place and cell props changing (which is how react-window behaves) * Footer docs example: remove expand button if footer cell is empty * Add Cypress tests * Add changelog entry * Address PR feedback * changelog * PR feedback: currency formatting
- Loading branch information
Constance
authored
Mar 18, 2022
1 parent
b564bf1
commit 3b8aa95
Showing
6 changed files
with
119 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/components/datagrid/body/data_grid_footer_row.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/// <reference types="../../../../cypress/support"/> | ||
|
||
import React, { useState, useEffect } from 'react'; | ||
import { EuiDataGrid } from '../'; | ||
|
||
describe('EuiDataGridFooterRow', () => { | ||
const mockData = [10, 15, 20]; | ||
|
||
const RenderCellValue = ({ rowIndex, columnId }) => | ||
columnId === 'b' ? mockData[rowIndex] : null; | ||
|
||
const RenderFooterCellValue = ({ columnId, setCellProps }) => { | ||
const value = columnId === 'b' ? mockData.reduce((a, b) => a + b, 0) : null; | ||
|
||
useEffect(() => { | ||
if (!value) setCellProps({ isExpandable: false }); | ||
}, [value, setCellProps]); | ||
|
||
return value; | ||
}; | ||
|
||
// We need to set up a test component here for column ordering to work | ||
const GridTest = () => { | ||
const [visibleColumns, setVisibleColumns] = useState(['a', 'b']); | ||
|
||
return ( | ||
<EuiDataGrid | ||
aria-label="Footer row tests" | ||
columns={[{ id: 'a' }, { id: 'b', display: 'Total' }]} | ||
columnVisibility={{ visibleColumns, setVisibleColumns }} | ||
rowCount={3} | ||
renderCellValue={RenderCellValue} | ||
renderFooterCellValue={RenderFooterCellValue} | ||
/> | ||
); | ||
}; | ||
GridTest.displayName = 'GridTest'; | ||
|
||
it('renders a footer of total values', () => { | ||
cy.mount(<GridTest />); | ||
|
||
cy.get( | ||
'[data-gridcell-column-index="1"][data-gridcell-row-index="3"]' | ||
).contains('45'); | ||
}); | ||
|
||
it('does not render an expansion button for the empty footer cell', () => { | ||
cy.mount(<GridTest />); | ||
|
||
cy.get( | ||
'[data-gridcell-column-index="0"][data-gridcell-row-index="3"]' | ||
).click(); | ||
cy.get('[data-test-subj="euiDataGridCellExpandButton"]').should( | ||
'not.exist' | ||
); | ||
}); | ||
|
||
// Regression test for #5720 | ||
it('does not bug focus when moving a column and then clicking its footer cell', () => { | ||
cy.mount(<GridTest />); | ||
|
||
cy.get( | ||
'[data-gridcell-column-index="1"][data-gridcell-row-index="-1"]' | ||
).click(); | ||
cy.contains('Move left').click(); | ||
|
||
cy.get('[data-gridcell-column-index="0"][data-gridcell-row-index="3"]') | ||
.click() | ||
.contains('45') | ||
.click(); | ||
|
||
// Note that the wait/timeout and multiple focused assertions are required for | ||
// for this specific bug which bounces focus rapidly between cells, as otherwise | ||
// Cypress re-tries until it happens to be on the cell with correct attributes | ||
cy.wait(50); | ||
const checkFocusedCell = () => { | ||
cy.wait(1); | ||
cy.focused({ timeout: 0 }) | ||
.should('have.attr', 'data-gridcell-column-index', '0') | ||
.should('not.have.attr', 'data-gridcell-column-index', '1'); | ||
}; | ||
checkFocusedCell(); | ||
checkFocusedCell(); | ||
checkFocusedCell(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
**Bug fixes** | ||
|
||
- Fixed `EuiDataGrid` footer cell focus bugging out after moving its column |