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

Commit

Permalink
Merge remote-tracking branch 'origin' into table-row-selection-callback
Browse files Browse the repository at this point in the history
  • Loading branch information
cm9361 committed Dec 4, 2023
2 parents dc7ea69 + 1b5e5b9 commit f0bc90e
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 65 deletions.
3 changes: 3 additions & 0 deletions packages/terra-data-grid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Changed
* Removed console warning message when no pinned columns exist.

## 1.5.0 - (December 1, 2023)

* Changed
Expand Down
7 changes: 0 additions & 7 deletions packages/terra-data-grid/src/utils/constants.js

This file was deleted.

44 changes: 1 addition & 43 deletions packages/terra-data-grid/tests/jest/DataGrid.test.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from 'react';
/* eslint-disable-next-line import/no-extraneous-dependencies */
import { mountWithIntl, shallowWithIntl } from 'terra-enzyme-intl';
import { mountWithIntl } from 'terra-enzyme-intl';
import { v4 as uuidv4 } from 'uuid';
import DataGrid from '../../src/DataGrid';
import ERRORS from '../../src/utils/constants';

// Source data for tests
const dataFile = {
Expand Down Expand Up @@ -244,46 +243,5 @@ describe('with pinned columns', () => {
const pinnedColumnHeaderCells = wrapper.find('.pinned');

expect(pinnedColumnHeaderCells).toHaveLength(1 * (dataFile.rows.length + 1));
expect(console.warn).toHaveBeenCalledWith(expect.stringContaining(ERRORS.PINNED_COLUMNS_UNDEFINED)); // eslint-disable-line no-console
});
});

describe('Error handling - prop types', () => {
it('throws an error if rowHeaderIndex is not an integer', () => {
shallowWithIntl(
<DataGrid
id="test-terra-data-grid"
rows={dataFile.rows}
rowHeaderIndex="2"
/>,
);

expect(console.error).toHaveBeenCalledWith(expect.stringContaining(ERRORS.ROW_HEADER_INDEX_NOT_AN_INTEGER)); // eslint-disable-line no-console
});

it('throws an error if rowHeaderIndex is not a positive integer', () => {
shallowWithIntl(
<DataGrid
id="test-terra-data-grid"
rows={dataFile.rows}
rowHeaderIndex={-1}
/>,
);

expect(console.error).toHaveBeenCalledWith(expect.stringContaining(ERRORS.ROW_HEADER_INDEX_LESS_THAN_ZERO)); // eslint-disable-line no-console
});

it('throws an error if rowHeaderIndex is greater than the length of pinned columns', () => {
shallowWithIntl(
<DataGrid
id="test-terra-data-grid"
pinnedColumns={dataFile.cols.slice(0, 2)}
overflowColumns={dataFile.cols.slice(2)}
rowHeaderIndex={2}
rows={dataFile.rows}
/>,
);

expect(console.error).toHaveBeenCalledWith(expect.stringContaining(ERRORS.ROW_HEADER_INDEX_EXCEEDS_PINNED)); // eslint-disable-line no-console
});
});
3 changes: 3 additions & 0 deletions packages/terra-framework-docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

* Added
* Added documentation for exported constants of `terra-table` in the About page.

* Changed
* Updated examples and tests for `terra-table` to consume updated onRowSelect callback.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ import Table from "terra-table";

<TablePropsTable />

### Table Constants
Enumeration: TableConstants

|Constant|Type|Description|
|---|---|---|
|**ROW_SELECTION_COLUMN_WIDTH**|number|The width of the row selection column.|

Enumeration: RowSelectionModes

|Constant|Type|Description|
|---|---|---|
|**SINGLE**|string|Single row selection mode|
|**MULTIPLE**|string|Multiple row selection mode|

### Column
A column specifies the data to render a cell in the header row of the Worklist Data Grid.

Expand Down
6 changes: 6 additions & 0 deletions packages/terra-table/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

* Breaking Changes
* Updated the onRowSelect callback to return an object containing section and row ids.

* Added
* Exported the row selection column width via the `TableConstants.ROW_SELECTION_COLUMN_WIDTH`` constant.

* Changed
* Removed console warning message when no pinned columns exist.

## 5.2.1 - (December 1, 2023)

Expand Down
21 changes: 10 additions & 11 deletions packages/terra-table/src/Table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import Section from './subcomponents/Section';
import ColumnHeader from './subcomponents/ColumnHeader';
import ColumnContext from './utils/ColumnContext';
import columnShape from './proptypes/columnShape';
import ERRORS from './utils/constants';
import GridContext, { GridConstants } from './utils/GridContext';
import rowShape from './proptypes/rowShape';
import validateRowHeaderIndex from './proptypes/validators';
Expand All @@ -24,11 +23,15 @@ import getFocusableElements from './utils/focusManagement';

const cx = classNames.bind(styles);

export const rowSelectionModes = {
const RowSelectionModes = {
SINGLE: 'single',
MULTIPLE: 'multiple',
};

const TableConstants = {
ROW_SELECTION_COLUMN_WIDTH: 40,
};

const propTypes = {
/**
* Unique id used to identify the table.
Expand Down Expand Up @@ -146,7 +149,7 @@ const propTypes = {
* Enables row selection capabilities for the table.
* Use 'single' for single row selection and 'multiple' for multi-row selection.
*/
rowSelectionMode: PropTypes.oneOf(Object.values(rowSelectionModes)),
rowSelectionMode: PropTypes.oneOf(Object.values(RowSelectionModes)),

/**
* Boolean indicating whether or not the table columns should be displayed. Setting the value to false will hide the columns,
Expand Down Expand Up @@ -208,11 +211,6 @@ function Table(props) {
intl,
} = props;

if (pinnedColumns.length === 0) {
// eslint-disable-next-line no-console
console.warn(ERRORS.PINNED_COLUMNS_UNDEFINED);
}

// Manage column resize
const [tableHeight, setTableHeight] = useState(0);
const [activeIndex, setActiveIndex] = useState(null);
Expand Down Expand Up @@ -252,14 +250,14 @@ function Table(props) {
// Create row selection column object
const tableRowSelectionColumn = {
id: 'table-rowSelectionColumn',
width: 40,
width: TableConstants.ROW_SELECTION_COLUMN_WIDTH,
displayName: intl.formatMessage({ id: 'Terra.table.row-selection-header-display' }),
isDisplayVisible: false,
isSelectable: !!onRowSelectionHeaderSelect,
isResizable: false,
};

const hasSelectableRows = rowSelectionMode === rowSelectionModes.MULTIPLE;
const hasSelectableRows = rowSelectionMode === RowSelectionModes.MULTIPLE;
const displayedColumns = (hasSelectableRows ? [tableRowSelectionColumn] : []).concat(pinnedColumns).concat(overflowColumns);
const [tableColumns, setTableColumns] = useState(displayedColumns.map((column) => initializeColumn(column)));

Expand Down Expand Up @@ -312,7 +310,7 @@ function Table(props) {
}

// Since the row selection mode has changed, the row selection mode needs to be updated.
setRowSelectionModeAriaLiveMessage(intl.formatMessage({ id: rowSelectionMode === rowSelectionModes.MULTIPLE ? 'Terra.table.row-selection-mode-enabled' : 'Terra.table.row-selection-mode-disabled' }));
setRowSelectionModeAriaLiveMessage(intl.formatMessage({ id: rowSelectionMode === RowSelectionModes.MULTIPLE ? 'Terra.table.row-selection-mode-enabled' : 'Terra.table.row-selection-mode-disabled' }));

setTableColumns(displayedColumns.map((column) => initializeColumn(column)));
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down Expand Up @@ -607,3 +605,4 @@ Table.propTypes = propTypes;
Table.defaultProps = defaultProps;

export default React.memo(injectIntl(Table));
export { TableConstants, RowSelectionModes };
4 changes: 2 additions & 2 deletions packages/terra-table/src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Table from './Table';
import Table, { TableConstants, RowSelectionModes } from './Table';
import GridContext, { GridConstants } from './utils/GridContext';
import cellShape from './proptypes/cellShape';
import columnShape from './proptypes/columnShape';
Expand All @@ -8,5 +8,5 @@ import validateRowHeaderIndex from './proptypes/validators';

export default Table;
export {
GridContext, GridConstants, cellShape, columnShape, rowShape, sectionShape, validateRowHeaderIndex,
GridContext, GridConstants, TableConstants, RowSelectionModes, cellShape, columnShape, rowShape, sectionShape, validateRowHeaderIndex,
};
1 change: 0 additions & 1 deletion packages/terra-table/src/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const ERRORS = {
ROW_HEADER_INDEX_EXCEEDS_PINNED: 'Prop rowHeaderIndex exceeds the size of pinnedColumns.',
ROW_HEADER_INDEX_LESS_THAN_ZERO: 'Prop rowHeaderIndex must be a positive integer.',
ROW_HEADER_INDEX_NOT_AN_INTEGER: 'Prop rowHeaderIndex must be an integer.',
PINNED_COLUMNS_UNDEFINED: 'To be properly accessible, the row header column should be a pinned column. please set pinned columns',
};

export default ERRORS;
1 change: 0 additions & 1 deletion packages/terra-table/tests/jest/Table.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ describe('with pinned columns', () => {
const pinnedColumnHeaderCells = wrapper.find('.pinned');

expect(pinnedColumnHeaderCells).toHaveLength(1 * (tableData.rows.length + 1));
expect(console.warn).toHaveBeenCalledWith(expect.stringContaining(ERRORS.PINNED_COLUMNS_UNDEFINED)); // eslint-disable-line no-console
});
});

Expand Down

0 comments on commit f0bc90e

Please sign in to comment.