-
Notifications
You must be signed in to change notification settings - Fork 839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[EuiDataGrid] Add new cellContext
prop/API
#7374
Merged
cee-chen
merged 23 commits into
elastic:main
from
kqualters-elastic:row-cell-context-proposal
Mar 7, 2024
Merged
Changes from 10 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
fc625d0
Add rowCellContext POC
kqualters-elastic 3248acc
Fix types in docs/tests
kqualters-elastic 3261a14
Fix unneeded re-renders
kqualters-elastic b7eb3a7
Cleanup types
kqualters-elastic d15c935
Fix skeleton text performance
kqualters-elastic 150662e
Delete React version specific snapshot test
kqualters-elastic 2d17b85
Merge branch 'main' into row-cell-context-proposal
kqualters-elastic b20463d
Merge upstream WIP
kqualters-elastic 509412f
Merge remote-tracking branch 'upstream/main' into row-cell-context-pr…
kqualters-elastic 9ed36d9
Fix upstream merge, tests, and types
kqualters-elastic 46a5975
Merge remote-tracking branch 'upstream/main' into row-cell-context-pr…
kqualters-elastic 03f545e
Merge branch 'main' into row-cell-context-proposal
kqualters-elastic 0ef0d42
Add display name
kqualters-elastic c83ce72
Merge branch 'row-cell-context-proposal' of github.com:kqualters-elas…
kqualters-elastic 2a2b2d2
Remove non-datagrid related change
kqualters-elastic 341595a
Added changelog
kqualters-elastic beda44c
Merge branch 'main' into row-cell-context-proposal
kqualters-elastic 57f9673
[PR feedback] Rename `renderCellContext` to `cellContext` and switch …
cee-chen c56a4a5
Write unit test for new API
cee-chen e8ce9c2
Update changelog
cee-chen 5b7805e
Revert changes unrelated to `cellContext`
cee-chen ad95e85
Simplify and fix failing `RenderCellValue` types
cee-chen 4cab7dc
Add docs example + copy
cee-chen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import { | |
EuiDataGridPaginationProps, | ||
EuiDataGridSorting, | ||
EuiDataGridColumnSortingConfig, | ||
RenderCellValue, | ||
} from '../../../../../src'; | ||
|
||
const raw_data: Array<{ [key: string]: string }> = []; | ||
|
@@ -67,6 +68,14 @@ const columns = [ | |
}, | ||
]; | ||
|
||
const checkboxRowCellRender: RenderCellValue = ({ rowIndex }) => ( | ||
<EuiCheckbox | ||
id={`select-row-${rowIndex}`} | ||
aria-label="Select row" | ||
onChange={() => {}} | ||
/> | ||
); | ||
|
||
const leadingControlColumns: EuiDataGridProps['leadingControlColumns'] = [ | ||
{ | ||
id: 'selection', | ||
|
@@ -78,13 +87,7 @@ const leadingControlColumns: EuiDataGridProps['leadingControlColumns'] = [ | |
onChange={() => {}} | ||
/> | ||
), | ||
rowCellRender: ({ rowIndex }) => ( | ||
<EuiCheckbox | ||
id={`select-row-${rowIndex}`} | ||
aria-label="Select row" | ||
onChange={() => {}} | ||
/> | ||
), | ||
rowCellRender: checkboxRowCellRender, | ||
}, | ||
]; | ||
|
||
|
@@ -103,6 +106,22 @@ const trailingControlColumns: EuiDataGridProps['trailingControlColumns'] = [ | |
}, | ||
]; | ||
|
||
const RowCellRender: RenderCellValue = ({ setCellProps, rowIndex }) => { | ||
setCellProps({ style: { width: '100%', height: 'auto' } }); | ||
|
||
const firstName = raw_data[rowIndex].name.split(', ')[1]; | ||
const isGood = faker.datatype.boolean(); | ||
return ( | ||
<> | ||
{firstName}'s account has {isGood ? 'no' : ''} outstanding fees.{' '} | ||
<EuiIcon | ||
type={isGood ? 'checkInCircleFilled' : 'error'} | ||
color={isGood ? 'success' : 'danger'} | ||
/> | ||
</> | ||
); | ||
}; | ||
|
||
// The custom row details is actually a trailing control column cell with | ||
// a hidden header. This is important for accessibility and markup reasons | ||
// @see https://fuschia-stretch.glitch.me/ for more | ||
|
@@ -120,21 +139,7 @@ const rowDetails: EuiDataGridProps['trailingControlColumns'] = [ | |
|
||
// When rendering this custom cell, we'll want to override | ||
// the automatic width/heights calculated by EuiDataGrid | ||
rowCellRender: ({ setCellProps, rowIndex }) => { | ||
setCellProps({ style: { width: '100%', height: 'auto' } }); | ||
|
||
const firstName = raw_data[rowIndex].name.split(', ')[1]; | ||
const isGood = faker.datatype.boolean(); | ||
return ( | ||
<> | ||
{firstName}'s account has {isGood ? 'no' : ''} outstanding fees.{' '} | ||
<EuiIcon | ||
type={isGood ? 'checkInCircleFilled' : 'error'} | ||
color={isGood ? 'success' : 'danger'} | ||
/> | ||
</> | ||
); | ||
}, | ||
rowCellRender: RowCellRender, | ||
}, | ||
]; | ||
|
||
|
@@ -144,10 +149,10 @@ const footerCellValues: { [key: string]: string } = { | |
.toLocaleString('en-US', { style: 'currency', currency: 'USD' })}`, | ||
}; | ||
|
||
const RenderFooterCellValue: EuiDataGridProps['renderFooterCellValue'] = ({ | ||
columnId, | ||
setCellProps, | ||
}) => { | ||
const renderCellValue: RenderCellValue = ({ rowIndex, columnId }) => | ||
raw_data[rowIndex][columnId]; | ||
|
||
const RenderFooterCellValue: RenderCellValue = ({ columnId, setCellProps }) => { | ||
const value = footerCellValues[columnId]; | ||
|
||
useEffect(() => { | ||
|
@@ -298,9 +303,7 @@ export default () => { | |
onChangeItemsPerPage: onChangePageSize, | ||
}} | ||
rowCount={raw_data.length} | ||
renderCellValue={({ rowIndex, columnId }) => | ||
raw_data[rowIndex][columnId] | ||
} | ||
renderCellValue={renderCellValue} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏾 |
||
renderFooterCellValue={RenderFooterCellValue} | ||
renderCustomGridBody={RenderCustomGridBody} | ||
height={autoHeight ? undefined : 400} | ||
|
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the anonymous function get re-created on re-renders? Technically this array should be stable since it's outside the render, but not sure if it's worth passing
const noOp = () => {}
to this and the headerCellRender below?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore, I see this is docs