Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

[terra-table] Adding subsections to sections #2112

Merged
merged 54 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
e14fa46
initial changes for adding subsections to table
BenBoersma Mar 27, 2024
a6276c7
adding wdio tests and snapshot for default theme
BenBoersma Mar 27, 2024
ce6cc6b
added fusion-theme variables, added wdio tests, added jest tests, fix…
BenBoersma Mar 29, 2024
b3a7c15
Updating to fix linter errors
BenBoersma Mar 29, 2024
cc25304
updated wdio tests
sdadn Apr 1, 2024
7972bd5
Merge branch 'main' into adding-table-subsections
sdadn Apr 2, 2024
86bd928
removed linter comments
sdadn Apr 2, 2024
29bba90
added variables for subsection padding
sdadn Apr 3, 2024
6ee7c59
removed font family
sdadn Apr 3, 2024
586ed87
updated subsection logic
sdadn Apr 3, 2024
1124ed0
updated section logic
sdadn Apr 3, 2024
0318985
added row props const
sdadn Apr 4, 2024
7f12bcb
removed subsection subcomponent
sdadn Apr 4, 2024
86ed45e
added terra-section-header
sdadn Apr 4, 2024
cd98a09
added subsection ids
sdadn Apr 4, 2024
e273bee
updated section
sdadn Apr 4, 2024
6c7b129
updated theme files
sdadn Apr 4, 2024
2395c42
updated documentation
sdadn Apr 4, 2024
89e070a
Merge branch 'main' into adding-table-subsections
sdadn Apr 4, 2024
dfce99f
updated CHANGELOGs
sdadn Apr 4, 2024
6de3e9c
removed subsection tests
sdadn Apr 4, 2024
8eb7b7c
fixed WDIO tests
sdadn Apr 5, 2024
4fc5762
Merge branch 'main' into adding-table-subsections
sdadn Apr 5, 2024
9869403
reformatted tables
sdadn Apr 5, 2024
c254deb
Merge branch 'adding-table-subsections' of github.com:cerner/terra-fr…
sdadn Apr 5, 2024
b2e0aee
updated lowlight styles
sdadn Apr 8, 2024
040c0f2
Merge branch 'main' into adding-table-subsections
sdadn Apr 8, 2024
71869da
updated snapshots
sdadn Apr 8, 2024
628736e
updated scss
sdadn Apr 8, 2024
bc228de
updated styles
sdadn Apr 8, 2024
7fdc45b
updated snapshots
sdadn Apr 8, 2024
66c9105
updated tests
sdadn Apr 8, 2024
44a9dab
trigger build
sdadn Apr 8, 2024
e34bc71
Merge branch 'main' into adding-table-subsections
sdadn Apr 9, 2024
950b913
Update table-spec.js
sdadn Apr 9, 2024
2a80f7e
updated package-lock
sdadn Apr 9, 2024
baf2d69
removed extra snapshots
sdadn Apr 9, 2024
7e3d034
updated table snapshots
sdadn Apr 9, 2024
3fb73fe
remove old snapshots
sdadn Apr 9, 2024
95b2cf3
update lowlight theme
sdadn Apr 9, 2024
6f81725
updated fusion
sdadn Apr 9, 2024
331e757
updated css
sdadn Apr 9, 2024
796300f
updated css
sdadn Apr 9, 2024
b5ce5ae
updated snapshots
sdadn Apr 9, 2024
67b7f7d
linter fixes
sdadn Apr 9, 2024
9270557
linter fixes
sdadn Apr 9, 2024
a018196
added constant
sdadn Apr 9, 2024
a981a90
updated onCellSelect callback
sdadn Apr 9, 2024
e94e26b
updated subsection classame
sdadn Apr 9, 2024
d54279f
fix subsection sticky title
sdadn Apr 9, 2024
d1c988e
updated data attribute
sdadn Apr 9, 2024
0fc369b
removed redundant css
sdadn Apr 9, 2024
a357020
Revert padding
sdadn Apr 9, 2024
8061321
fixed wdio snapshots
sdadn Apr 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
209 changes: 64 additions & 145 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/terra-framework-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

* Added
* Added documentation for subsections in `terra-table`.
* Added examples and tests for `isAutoFocusEnabled` prop for `terra-data-grid`.

* Changed
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import React, { useState } from 'react';
import Table from 'terra-table';

const tableData = {
cols: [
{
id: 'Column-0', displayName: 'Patient', sortIndicator: 'ascending', isSelectable: true,
},
{
id: 'Column-1', displayName: 'Location', isSelectable: true,
},
{ id: 'Column-2', displayName: 'Illness Severity', isSelectable: true },
{ id: 'Column-3', displayName: 'Visit' },
{ id: 'Column-4', displayName: 'Allergy' },
{ id: 'Column-5', displayName: 'Primary Contact' },

],
sections: [{
id: 'section-0',
isCollapsible: true,
isCollapsed: true,
text: 'Test Section',
subsections: [
{
id: 'subsection-0',
text: 'Test SubSection',
rows: [
{
id: '1',
cells: [
{ content: 'Fleck, Arthur' },
{ content: '1007-MTN' },
{ content: 'Unstable' },
{ content: 'Inpatient, 2 months' },
{ content: '' },
{ content: 'Quinzell, Harleen' },
],
},
{
id: '2',
cells: [
{ content: 'Wayne, Bruce' },
{ content: '1007-MTN-DR' },
{ content: 'Stable' },
{ content: 'Outpatient, 2 days' },
{ content: 'Phytochemicals' },
{ content: 'Grayson, Richard' },
],
},
],
},
{
id: 'subsection-1',
text: 'Test SubSection #2',
rows: [
{
id: '3',
cells: [
{ content: 'Fleck, Arthur' },
{ content: '1007-MTN' },
{ content: 'Unstable' },
{ content: 'Inpatient, 2 months' },
{ content: '' },
{ content: 'Quinzell, Harleen' },
],
},
{
id: '4',
cells: [
{ content: 'Wayne, Bruce' },
{ content: '1007-MTN-DR' },
{ content: 'Stable' },
{ content: 'Outpatient, 2 days' },
{ content: 'Phytochemicals' },
{ content: 'Grayson, Richard' },
],
},
],
},
],
},
{
id: 'section-1',
isCollapsible: true,
isCollapsed: true,
text: 'Test Section #2',
subsections: [
{
id: 'subsection-2',
text: 'Test SubSection',
rows: [
{
id: '5',
cells: [
{ content: 'Parker, Peter' },
{ content: '1007-MTN' },
{ content: 'Unstable' },
{ content: 'Inpatient, 2 months' },
{ content: '' },
{ content: 'Octopus, Doctor' },
],
},
{
id: '6',
cells: [
{ content: 'Stark, Tony' },
{ content: '1007-MTN-DR' },
{ content: 'Stable' },
{ content: 'Outpatient, 2 days' },
{ content: 'Phytochemicals' },
{ content: 'America, Captain' },
],
},
],
},
{
id: 'subsection-3',
text: 'Test SubSection #2',
rows: [
{
id: '7',
cells: [
{ content: 'Parker, Peter' },
{ content: '1007-MTN' },
{ content: 'Unstable' },
{ content: 'Inpatient, 2 months' },
{ content: '' },
{ content: 'Octopus, Doctor' },
],
},
{
id: '8',
cells: [
{ content: 'Stark, Tony' },
{ content: '1007-MTN-DR' },
{ content: 'Stable' },
{ content: 'Outpatient, 2 days' },
{ content: 'Phytochemicals' },
{ content: 'America, Captain' },
],
},
],
},
],
}],
};

const TableWithCollapsibleSections = () => {
const [tableSections, setTableSections] = useState(tableData.sections);

const handleSectionSelect = (sectionId) => {
const newSections = [...tableSections];
const sectionIndex = newSections.findIndex(section => section.id === sectionId);

if (sectionIndex > -1) {
newSections[sectionIndex].isCollapsed = !newSections[sectionIndex].isCollapsed;
}

setTableSections(newSections);
};

return (
<Table
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add this example to user facing part of the documentation as well, so that users have access to the implementation code example.

id="table-with-sub-sections"
overflowColumns={tableData.cols}
sections={tableSections}
onSectionSelect={handleSectionSelect}
/>
);
};

export default TableWithCollapsibleSections;
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import React, { useState } from 'react';
import Table from 'terra-table';

const tableData = {
cols: [
{
id: 'Column-0', displayName: 'Patient', sortIndicator: 'ascending', isSelectable: true,
},
{
id: 'Column-1', displayName: 'Location', isSelectable: true,
},
{ id: 'Column-2', displayName: 'Illness Severity', isSelectable: true },
{ id: 'Column-3', displayName: 'Visit' },
{ id: 'Column-4', displayName: 'Allergy' },
{ id: 'Column-5', displayName: 'Primary Contact' },

],
sections: [{
id: 'section-0',
text: 'Test Section',
subsections: [
{
id: 'subsection-0',
text: 'Test SubSection',
rows: [
{
id: '1',
cells: [
{ content: 'Fleck, Arthur' },
{ content: '1007-MTN' },
{ content: 'Unstable' },
{ content: 'Inpatient, 2 months' },
{ content: '' },
{ content: 'Quinzell, Harleen' },
],
},
{
id: '2',
cells: [
{ content: 'Wayne, Bruce' },
{ content: '1007-MTN-DR' },
{ content: 'Stable' },
{ content: 'Outpatient, 2 days' },
{ content: 'Phytochemicals' },
{ content: 'Grayson, Richard' },
],
},
],
},
{
id: 'subsection-1',
text: 'Test SubSection #2',
rows: [
{
id: '3',
cells: [
{ content: 'Fleck, Arthur' },
{ content: '1007-MTN' },
{ content: 'Unstable' },
{ content: 'Inpatient, 2 months' },
{ content: '' },
{ content: 'Quinzell, Harleen' },
],
},
{
id: '4',
cells: [
{ content: 'Wayne, Bruce' },
{ content: '1007-MTN-DR' },
{ content: 'Stable' },
{ content: 'Outpatient, 2 days' },
{ content: 'Phytochemicals' },
{ content: 'Grayson, Richard' },
],
},
],
},
],
},
{
id: 'section-1',
text: 'Test Section #2',
rows: [
{
id: '5',
cells: [
{ content: 'Parker, Peter' },
{ content: '1007-MTN' },
{ content: 'Unstable' },
{ content: 'Inpatient, 2 months' },
{ content: '' },
{ content: 'Octopus, Doctor' },
],
},
{
id: '6',
cells: [
{ content: 'Stark, Tony' },
{ content: '1007-MTN-DR' },
{ content: 'Stable' },
{ content: 'Outpatient, 2 days' },
{ content: 'Phytochemicals' },
{ content: 'America, Captain' },
],
},
],
}],
};

const TableWithSections = () => {
const [tableSections, setTableSections] = useState(tableData.sections);

const handleSectionSelect = (sectionId) => {
const newSections = [...tableSections];
const sectionIndex = newSections.findIndex(section => section.id === sectionId);

if (sectionIndex > -1) {
newSections[sectionIndex].isCollapsed = !newSections[sectionIndex].isCollapsed;
}

setTableSections(newSections);
};

return (
<Table
id="table-with-sub-sections"
pinnedColumns={tableData.cols.slice(0, 2)}
overflowColumns={tableData.cols.slice(2)}
sections={tableSections}
onSectionSelect={handleSectionSelect}
/>
);
};

export default TableWithSections;
3 changes: 3 additions & 0 deletions packages/terra-table/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Added
* (flowsheet-data-grid only) Added support for subsections.

* Changed
* Updated the cell component auto focus logic to be configured by the grid context.

Expand Down
16 changes: 15 additions & 1 deletion packages/terra-table/src/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,18 @@ function Table(props) {
const headerRowCount = hasVisibleColumnHeaders ? (hasColumnHeaderActions ? 2 : 1) : 0;

// Calculate total table row count
const subSectionReducer = (rowCount, currentSubsection) => {
// eslint-disable-next-line no-param-reassign
currentSubsection.subSectionRowIndex = rowCount + 1;
return rowCount + currentSubsection.rows.length + 1;
};
const tableSectionReducer = (rowCount, currentSection) => {
if (currentSection.id !== defaultSectionRef.current) {
// eslint-disable-next-line no-param-reassign
currentSection.sectionRowIndex = rowCount + 1;
if (currentSection.subsections) {
return currentSection.subsections.reduce(subSectionReducer, rowCount + 1);
}
return rowCount + currentSection.rows.length + 1;
}
// eslint-disable-next-line no-param-reassign
Expand Down Expand Up @@ -373,7 +381,12 @@ function Table(props) {
// useEffect for row updates
useEffect(() => {
const previousSelectedRows = [...selectedRows.current];
const selectableRows = tableSections.flatMap(section => (section.rows.map(row => (row))));
const selectableRows = tableSections.flatMap(section => {
if (section.subsections) {
return section.subsections.flatMap(subsection => (subsection.rows.map(row => (row))));
}
return section.rows.map(row => (row));
});
selectedRows.current = selectableRows.filter((row) => row.isSelected).map(row => (row.id));

if (previousSelectedRows.length > 0 && selectedRows.current.length === 0) {
Expand Down Expand Up @@ -685,6 +698,7 @@ function Table(props) {
isTableStriped={isStriped}
text={section.text}
rows={section.rows}
subsections={section.subsections}
rowHeight={rowHeight}
rowSelectionMode={rowSelectionMode}
displayedColumns={displayedColumns}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
--terra-table-cell-border-left: 1px solid #181b1d;
--terra-table-cell-border-right: 1px solid #181b1d;
--terra-table-section-focus-outline: 3px dashed #fff;

--terra-table-subsection-border-bottom: #161616;
--terra-section-header-background: #161616;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.orion-fusion-theme {
--terra-table-cell-border-left: 1px solid #c8cacb;
--terra-table-cell-border-right: 1px solid #c8cacb;
--terra-section-header-font-size: 1rem;

/* stylelint-disable selector-max-compound-selectors */
&.header-row {
Expand All @@ -15,6 +16,5 @@
--terra-table-section-focus-outline: none;
}
}
/* stylelint-enable selector-max-compound-selectors */
}
}
Loading
Loading