This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
[terra-table] Add row selection to table component #1857
Merged
Merged
Changes from 5 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
764f174
[terra-table] Add row selection to Terra Table.
cm9361 ad46889
WDIO updates
cm9361 b3eaac0
Update CHANGELOGs
cm9361 867e0b3
Fix lint errors.
cm9361 2853b67
Allow space to work properly for editable fields.
cm9361 32a6210
Resolved review comments
cm9361 0544515
Updated row selection example.
cm9361 7b5db46
Merge remote-tracking branch 'origin' into table-row-selection
cm9361 0de3d7c
Merge remote-tracking branch 'origin' into table-row-selection
cm9361 8d78bba
Update JEST snapshots.
cm9361 bc16517
Merge remote-tracking branch 'origin' into table-row-selection
cm9361 d5ff4b0
Merge remote-tracking branch 'origin' into table-row-selection
cm9361 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
3 changes: 3 additions & 0 deletions
3
...-framework-docs/src/terra-dev-site/doc/table/Examples/TableRowSelection.doc.mdx
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 @@ | ||
import TableRowSelection from './TableRowSelection?dev-site-example'; | ||
|
||
<TableRowSelection title='Table With Row Selection' /> |
234 changes: 234 additions & 0 deletions
234
packages/terra-framework-docs/src/terra-dev-site/doc/table/Examples/TableRowSelection.jsx
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,234 @@ | ||
import React, { useState, useRef, useCallback } from 'react'; | ||
import Table from 'terra-table'; | ||
|
||
const tableDataJSON = { | ||
cols: [ | ||
{ id: 'Column-0', displayName: 'Patient' }, | ||
{ id: 'Column-1', displayName: 'Location' }, | ||
{ id: 'Column-2', displayName: 'Illness Severity' }, | ||
{ id: 'Column-3', displayName: 'Visit' }, | ||
{ id: 'Column-4', displayName: 'Allergy' }, | ||
{ id: 'Column-5', displayName: 'Primary Contact' }, | ||
{ id: 'Column-6', displayName: 'Generic Order Counts' }, | ||
], | ||
rows: [ | ||
{ | ||
id: '1', | ||
cells: [ | ||
{ content: 'Fleck, Arthur' }, | ||
{ content: '1007-MTN' }, | ||
{ content: 'Unstable' }, | ||
{ content: 'Inpatient, 2 months' }, | ||
{ content: '' }, | ||
{ content: 'Quinzell, Harleen' }, | ||
{ content: '', isMasked: true }, | ||
], | ||
}, | ||
{ | ||
id: '2', | ||
cells: [ | ||
{ content: 'Wayne, Bruce' }, | ||
{ content: '1107-MTN-DR' }, | ||
{ content: 'Stable' }, | ||
{ content: 'Outpatient, 2 days' }, | ||
{ content: 'Phytochemicals' }, | ||
{ content: 'Grayson, Richard' }, | ||
{ content: '' }, | ||
|
||
], | ||
}, | ||
{ | ||
id: '3', | ||
cells: [ | ||
{ content: 'Carr, Alicia' }, | ||
{ content: '1007-MTN' }, | ||
{ content: 'Unstable' }, | ||
{ content: 'Inpatient, 3 months' }, | ||
{ content: '' }, | ||
{ content: 'Quinzell, Harleen' }, | ||
{ content: '' }, | ||
|
||
], | ||
}, | ||
{ | ||
id: '4', | ||
cells: [ | ||
{ content: 'McMurphy, Donald' }, | ||
{ content: '1024-MTN', isMasked: true }, | ||
{ content: 'Stable' }, | ||
{ content: 'Inpatient, 5 months' }, | ||
{ content: '' }, | ||
{ content: 'Quinzell, Harleen' }, | ||
{ content: '' }, | ||
], | ||
}, | ||
{ | ||
id: '5', | ||
cells: [ | ||
{ content: 'Peters, Timothy' }, | ||
{ content: '1207-MTN' }, | ||
{ content: 'Unstable', isMasked: true }, | ||
{ content: 'Outpatient, 15 days' }, | ||
{ content: '' }, | ||
{ content: 'Quinzell, Harleen' }, | ||
{ content: '' }, | ||
], | ||
}, | ||
{ | ||
id: '6', | ||
cells: [ | ||
{ content: 'Jones, Becky' }, | ||
{ content: '1007-MTN' }, | ||
{ content: 'Unstable' }, | ||
{ content: 'Inpatient, 2 months' }, | ||
{ content: '' }, | ||
{ content: 'Quinzell, Harleen' }, | ||
{ content: '' }, | ||
], | ||
}, | ||
{ | ||
id: '7', | ||
cells: [ | ||
{ content: 'Williams, Peter' }, | ||
{ content: '1002-KTN' }, | ||
{ content: 'Unstable' }, | ||
{ content: 'Outpatient, 9 days' }, | ||
{ content: '' }, | ||
{ content: 'Quinzell, Harleen' }, | ||
{ content: '' }, | ||
], | ||
}, | ||
{ | ||
id: '8', | ||
cells: [ | ||
{ content: 'Pratt, Michaela' }, | ||
{ content: '2108-NTN' }, | ||
{ content: 'Stable' }, | ||
{ content: 'Outpatient, 45 days' }, | ||
{ content: '' }, | ||
{ content: 'Quinzell, Harleen' }, | ||
{ content: '' }, | ||
], | ||
}, | ||
{ | ||
id: '9', | ||
cells: [ | ||
{ content: 'Styris, Scott' }, | ||
{ content: '1007-MTN', isMasked: true }, | ||
{ content: 'Unstable' }, | ||
{ content: 'Inpatient, 2 months' }, | ||
{ content: '' }, | ||
{ content: 'Quinzell, Harleen' }, | ||
{ content: '' }, | ||
], | ||
}, | ||
{ | ||
id: '10', | ||
cells: [ | ||
{ content: 'Cook, Allan' }, | ||
{ content: '1700-SKB' }, | ||
{ content: 'Stable' }, | ||
{ content: 'Inpatient, 4 months' }, | ||
{ content: '' }, | ||
{ content: 'Quinzell, Harleen' }, | ||
{ content: '' }, | ||
], | ||
}, | ||
{ | ||
id: '11', | ||
cells: [ | ||
{ content: 'Lahey, Nathaniel' }, | ||
{ content: '1348-DRS' }, | ||
{ content: 'Unstable' }, | ||
{ content: 'Inpatient, 1 months' }, | ||
{ content: '' }, | ||
{ content: 'Quinzell, Harleen' }, | ||
{ content: '' }, | ||
], | ||
}, | ||
{ | ||
id: '12', | ||
cells: [ | ||
{ content: 'Harris, Isabella' }, | ||
{ content: '1809-MTN' }, | ||
{ content: 'Stable' }, | ||
{ content: 'Inpatient, 6 months' }, | ||
{ content: '' }, | ||
{ content: 'Quinzell, Harleen' }, | ||
{ content: '' }, | ||
], | ||
}, | ||
{ | ||
id: '13', | ||
cells: [ | ||
{ content: 'Millstone, Asher' }, | ||
{ content: '4133-MZN' }, | ||
{ content: 'Unstable' }, | ||
{ content: 'Inpatient, 9 months' }, | ||
{ content: '' }, | ||
{ content: 'Quinzell, Harleen' }, | ||
{ content: '' }, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
const RowSelection = () => { | ||
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. I would have expected a test page similar to this one and some accompanying WDIO tests for row selection. 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. I agree with you. I covered in jest, but should also have added the appropriate WDIO tests. Thank you for catching this. |
||
const rowSelectionModeRef = useRef(); | ||
const rowHeaderIndex = 0; | ||
const { cols, rows } = tableDataJSON; | ||
const [rowData, setRowData] = useState(rows); | ||
const [hasSelectableRows, setHasSelectableRows] = useState(false); | ||
|
||
const clearRowSelection = useCallback(() => { | ||
const newRowData = [...rowData]; | ||
// eslint-disable-next-line no-return-assign, no-param-reassign | ||
newRowData.forEach(row => (row.isSelected = false)); | ||
setRowData(newRowData); | ||
}, [rowData]); | ||
|
||
const onRowSelectionModeChange = useCallback((event) => { | ||
if (!event.target.checked) { | ||
clearRowSelection(); | ||
} | ||
setHasSelectableRows(event.target.checked); | ||
}, [clearRowSelection]); | ||
|
||
const onRowSelect = useCallback((rowId) => { | ||
// Remove current selections | ||
const newRowData = [...rowData]; | ||
|
||
const dataRowToUpdate = newRowData.find(row => row.id === rowId); | ||
if (dataRowToUpdate) { | ||
dataRowToUpdate.isSelected = !dataRowToUpdate.isSelected; | ||
} | ||
|
||
setRowData(newRowData); | ||
}, [rowData]); | ||
|
||
return ( | ||
<React.Fragment> | ||
<div> | ||
<label htmlFor="rowSelectionMode"><b>Row Selection Mode</b></label> | ||
<input | ||
id="rowSelectionMode" | ||
type="checkbox" | ||
ref={rowSelectionModeRef} | ||
onChange={onRowSelectionModeChange} | ||
/> | ||
</div> | ||
<Table | ||
id="table-with-row-selections" | ||
overflowColumns={cols} | ||
rows={rowData} | ||
rowHeaderIndex={rowHeaderIndex} | ||
columnWidth="180px" | ||
ariaLabel="Table with Row Selections" | ||
hasSelectableRows={hasSelectableRows} // Prop to turn row selection mode on/off | ||
onRowSelect={onRowSelect} // For row selection, consumer must provide a callback that the Worklist Data Grid will call when the user selects one or more rows. | ||
/> | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
export default RowSelection; |
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 |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
* Added | ||
* Added the ability to toggle zebra striping for table rows. | ||
* Added row selection mode to the table component. | ||
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. This might have been due to a merge/rebase, but this should go under the Unreleased section |
||
|
||
* Changed | ||
* Updated the table component so that the cell dive-in logic would not execute when not in the grid context. | ||
|
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.
Can you move this to the released section?
Also looks like these entries for
packages/terra-framework-docs/CHANGELOG.md
also got merged in the wrong section:#1858