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

Commit

Permalink
[terra-data-grid] Add section support to Flowsheet (#1896)
Browse files Browse the repository at this point in the history
  • Loading branch information
cm9361 authored Nov 17, 2023
1 parent 7c8a802 commit aa35e5b
Show file tree
Hide file tree
Showing 28 changed files with 334 additions and 156 deletions.
1 change: 1 addition & 0 deletions packages/terra-data-grid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

* Added
* Added `hasVisibleColumnHeaders` prop for FlowsheetDataGrid to toggle visibility of column headers.
* Added section support to FlowsheetDataGrid.

Changed
* Updated all columns and cells to be selectable in FlowsheetDataGrid, as `isSelectable` prop is not supported for columns or cells.
Expand Down
21 changes: 17 additions & 4 deletions packages/terra-data-grid/src/DataGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import PropTypes from 'prop-types';
import { injectIntl } from 'react-intl';
import classNames from 'classnames/bind';
import * as KeyCode from 'keycode-js';
import Table, { GridConstants, GridContext } from 'terra-table';
import Table, {
GridConstants, GridContext, sectionShape, rowShape, columnShape, validateRowHeaderIndex,
} from 'terra-table';
import VisuallyHiddenText from 'terra-visually-hidden-text';
import rowShape from './proptypes/rowShape';
import { columnShape } from './proptypes/columnShape';
import WorklistDataGridUtils from './utils/WorklistDataGridUtils';
import validateRowHeaderIndex from './proptypes/validators';
import styles from './DataGrid.module.scss';
import './_elementPolyfill';

Expand Down Expand Up @@ -38,6 +37,11 @@ const propTypes = {
*/
rows: PropTypes.arrayOf(rowShape),

/**
* Data for content in the body of the table. Sections will be rendered in the order given.
*/
sections: PropTypes.arrayOf(sectionShape),

/**
* Data for pinned columns. Pinned columns are the stickied leftmost columns of the grid.
* Columns will be presented in the order given.
Expand Down Expand Up @@ -89,6 +93,11 @@ const propTypes = {
*/
onCellSelect: PropTypes.func,

/**
* Function that is called when a collapsible section is selected. Parameters: `onSectionSelect(sectionId)`
*/
onSectionSelect: PropTypes.func,

/**
* Callback function that is called when a selectable column is selected. Parameters:
* @param {string} columnId columnId
Expand Down Expand Up @@ -161,11 +170,13 @@ const DataGrid = injectIntl((props) => {
onColumnSelect,
onRangeSelection,
onRowSelectionHeaderSelect,
onSectionSelect,
overflowColumns,
pinnedColumns,
rowHeaderIndex,
rowHeight,
rows,
sections,
} = props;

const displayedColumns = (hasSelectableRows ? [WorklistDataGridUtils.ROW_SELECTION_COLUMN] : []).concat(pinnedColumns).concat(overflowColumns);
Expand Down Expand Up @@ -518,6 +529,7 @@ const DataGrid = injectIntl((props) => {
<Table
id={`${id}-table`}
rows={dataGridRows}
sections={sections}
ariaLabelledBy={ariaLabelledBy}
ariaLabel={ariaLabel}
activeColumnIndex={(gridHasFocus && focusedRow === 0) ? focusedCol : undefined}
Expand All @@ -531,6 +543,7 @@ const DataGrid = injectIntl((props) => {
rowHeaderIndex={rowHeaderIndex}
onColumnResize={onColumnResize}
onColumnSelect={handleColumnSelect}
onSectionSelect={onSectionSelect}
onCellSelect={handleCellSelection}
onRowSelectionHeaderSelect={handleRowSelectionHeaderSelect}
hasSelectableRows={hasSelectableRows}
Expand Down
59 changes: 49 additions & 10 deletions packages/terra-data-grid/src/FlowsheetDataGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import classNames from 'classnames/bind';
import * as KeyCode from 'keycode-js';

import VisuallyHiddenText from 'terra-visually-hidden-text';

import { sectionShape, rowShape, columnShape } from 'terra-table';
import DataGrid from './DataGrid';
import rowShape from './proptypes/rowShape';
import { columnShape } from './proptypes/columnShape';
import styles from './FlowsheetDataGrid.module.scss';

const cx = classNames.bind(styles);
Expand All @@ -37,6 +35,11 @@ const propTypes = {
*/
rows: PropTypes.arrayOf(rowShape),

/**
* Data for content in the body of the table. Sections will be rendered in the order given.
*/
sections: PropTypes.arrayOf(sectionShape),

/**
* Data for columns. Columns will be presented in the order given.
* The first column, pinned to the leftmost side of the grid, will contain row headers.
Expand Down Expand Up @@ -66,6 +69,11 @@ const propTypes = {
*/
onCellSelect: PropTypes.func,

/**
* Function that is called when a collapsible section is selected. Parameters: `onSectionSelect(sectionId)`
*/
onSectionSelect: PropTypes.func,

/**
* Callback function that is called when all selected cells need to be unselected. Parameters: none.
*/
Expand Down Expand Up @@ -104,11 +112,13 @@ function FlowsheetDataGrid(props) {
ariaLabelledBy,
ariaLabel,
rows,
sections,
columns,
defaultColumnWidth,
columnHeaderHeight,
rowHeight,
onCellSelect,
onSectionSelect,
onClearSelectedCells,
onCellRangeSelect,
intl,
Expand Down Expand Up @@ -156,6 +166,39 @@ function FlowsheetDataGrid(props) {
return newRows;
}, [intl, rows]);

const flowsheetSections = useMemo(() => {
if (!sections) {
return null;
}

const noResultCellContent = (
<>
<span aria-hidden>{intl.formatMessage({ id: 'Terra.flowsheetDataGrid.no-result-display' })}</span>
<VisuallyHiddenText text={intl.formatMessage({ id: 'Terra.flowsheetDataGrid.no-result' })} />
</>
);

const newSections = [...sections];
newSections.forEach((section, sectionIndex) => {
const newRows = [...section.rows];
newRows.forEach((row, rowIndex) => {
const newCells = [...row.cells];
newCells.forEach((cell, cellIndex) => {
newCells[cellIndex].isSelectable = cell.isSelectable !== false;
// Cell content has no result and is not a row header (first column), set content to "No result".
if (contentHasNoResult(cell.content) && cellIndex !== 0) {
newCells[cellIndex].content = noResultCellContent;
}
});

newRows[rowIndex].cells = newCells;
});
newSections[sectionIndex].rows = newRows;
});

return newSections;
}, [intl, sections]);

useEffect(() => {
const previousSelectedCells = [...selectedCells.current];
const newSelectedCells = [];
Expand All @@ -179,12 +222,6 @@ function FlowsheetDataGrid(props) {
}
}, [intl, rows, columns, setCellSelectionAriaLiveMessage]);

const handleClearSelectedCells = useCallback(() => {
if (onClearSelectedCells) {
onClearSelectedCells();
}
}, [onClearSelectedCells]);

const selectCellRange = useCallback((rowIndex, columnIndex) => {
const anchorRowIndex = rows.findIndex(row => row.id === anchorCell.current.rowId);
const anchorColumnIndex = columns.findIndex(col => col.id === anchorCell.current.columnId);
Expand Down Expand Up @@ -294,14 +331,16 @@ function FlowsheetDataGrid(props) {
ariaLabel={ariaLabel}
ariaLabelledBy={ariaLabelledBy}
rows={flowsheetRows}
sections={flowsheetSections}
rowHeight={rowHeight}
rowHeaderIndex={0}
pinnedColumns={pinnedColumns}
overflowColumns={overflowColumns}
defaultColumnWidth={defaultColumnWidth}
columnHeaderHeight={columnHeaderHeight}
onCellSelect={handleCellSelection}
onClearSelection={handleClearSelectedCells}
onSectionSelect={onSectionSelect}
onClearSelection={onClearSelectedCells}
onCellRangeSelect={handleCellRangeSelection}
hasVisibleColumnHeaders={hasVisibleColumnHeaders}
/>
Expand Down
4 changes: 1 addition & 3 deletions packages/terra-data-grid/src/WorklistDataGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import { injectIntl } from 'react-intl';
import classNames from 'classnames/bind';
import * as KeyCode from 'keycode-js';
import VisuallyHiddenText from 'terra-visually-hidden-text';
import rowShape from './proptypes/rowShape';
import { columnShape } from './proptypes/columnShape';
import validateRowHeaderIndex from './proptypes/validators';
import { rowShape, columnShape, validateRowHeaderIndex } from 'terra-table';
import styles from './WorklistDataGrid.module.scss';
import DataGrid from './DataGrid';
import WorklistDataGridUtils from './utils/WorklistDataGridUtils';
Expand Down
22 changes: 0 additions & 22 deletions packages/terra-data-grid/src/proptypes/cellShape.js

This file was deleted.

47 changes: 0 additions & 47 deletions packages/terra-data-grid/src/proptypes/columnShape.js

This file was deleted.

24 changes: 0 additions & 24 deletions packages/terra-data-grid/src/proptypes/rowShape.js

This file was deleted.

18 changes: 0 additions & 18 deletions packages/terra-data-grid/src/proptypes/validators.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ exports[`FlowsheetDataGrid renders the row header column as pinned and remaining
id="test-terra-flowsheet-data-grid"
onCellRangeSelect={[Function]}
onCellSelect={[Function]}
onClearSelection={[Function]}
overflowColumns={
Array [
Object {
Expand Down Expand Up @@ -114,6 +113,7 @@ exports[`FlowsheetDataGrid renders the row header column as pinned and remaining
},
]
}
sections={null}
/>
<VisuallyHiddenText
aria-live="polite"
Expand All @@ -135,7 +135,6 @@ exports[`FlowsheetDataGrid replaces non-header empty, null, or "--" cell content
id="test-terra-flowsheet-data-grid"
onCellRangeSelect={[Function]}
onCellSelect={[Function]}
onClearSelection={[Function]}
overflowColumns={
Array [
Object {
Expand Down Expand Up @@ -281,6 +280,7 @@ exports[`FlowsheetDataGrid replaces non-header empty, null, or "--" cell content
},
]
}
sections={null}
/>
<VisuallyHiddenText
aria-live="polite"
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions packages/terra-data-grid/tests/wdio/flowsheet-data-grid-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,15 @@ Terra.describeViewports('FlowsheetDataGrid', ['medium', 'large'], () => {
Terra.validates.element('cell-3-1-focused', { selector: defaultSelector });
});
});

describe('Sections', () => {
const sectionSelector = '#flowsheet-with-sections';
beforeEach(() => {
browser.url('raw/tests/cerner-terra-framework-docs/data-grid/flowsheet-data-grid/flowsheet-with-sections');
});

it('validate Flowsheet section UI', () => {
Terra.validates.element('flowsheet-with-sections', { selector: sectionSelector });
});
});
});
1 change: 1 addition & 0 deletions packages/terra-framework-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Added
* Added new test for Terra Slider component for long field labels.
* Added `hasVisibleColumnHeaders` example for FlowsheetDataGrid.
* Added examples and tests to `terra-data-grid` for sections in FlowsheetDataGrid.

* Updated
* Updated About page of `terra-table` to provide accessibility documentation for Home and End keys.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import FlowsheetWithSections from "./FlowsheetWithSections?dev-site-example";

<FlowsheetWithSections />
Loading

0 comments on commit aa35e5b

Please sign in to comment.