Skip to content

Commit b00d840

Browse files
committed
First time sort direction logic update and testing
1 parent d2b2f9e commit b00d840

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

components/data-table/private/header-cell.jsx

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import {
2525
DATA_TABLE_COLUMN,
2626
} from '../../../utilities/constants';
2727

28-
const defaultProps = {
29-
firstSortDirection: 'asc'
30-
};
28+
// const defaultProps = {
29+
// firstSortDirection: 'asc'
30+
// };
3131

3232
/**
3333
* Used internally, renders each individual column heading.
@@ -84,7 +84,7 @@ class DataTableHeaderCell extends React.Component {
8484
width: PropTypes.string,
8585
};
8686

87-
static defaultProps = defaultProps;
87+
// static defaultProps = defaultProps;
8888

8989
state = {
9090
sortDirection: null,
@@ -104,10 +104,16 @@ class DataTableHeaderCell extends React.Component {
104104
handleSort = (e) => {
105105
const oldSortDirection =
106106
this.props.sortDirection || this.state.sortDirection;
107-
var sortDirection = this.props.firstSortDirection
108-
if (oldSortDirection) {
109-
sortDirection = oldSortDirection === 'asc' ? 'desc' : 'asc'
110-
}
107+
const sortDirection = (function(sortDirection, firstDirection) {
108+
switch(sortDirection) {
109+
case 'asc':
110+
return 'desc'
111+
case 'desc':
112+
return 'asc'
113+
case null:
114+
return (firstDirection) ? firstDirection : 'asc'
115+
}
116+
})(oldSortDirection, this.props.firstSortDirection)
111117
const data = {
112118
property: this.props.property,
113119
sortDirection,
@@ -127,7 +133,8 @@ class DataTableHeaderCell extends React.Component {
127133
const { fixedHeader, isSorted, label, sortable, width } = this.props;
128134

129135
const labelType = typeof label;
130-
const sortDirection = (!this.props.sortDirection && !this.state.sortDirection && this.props.sortable) ? this.props.firstSortDirection : (this.props.sortDirection || this.state.sortDirection);
136+
// const sortDirection = (!this.props.sortDirection && !this.state.sortDirection && this.props.sortable) ? this.props.firstSortDirection : (this.props.sortDirection || this.state.sortDirection);
137+
const sortDirection = this.props.sortDirection || this.state.sortDirection || this.props.firstSortDirection
131138
const expandedSortDirection =
132139
sortDirection === 'desc' ? 'descending' : 'ascending';
133140
const ariaSort = isSorted ? expandedSortDirection : 'none';

0 commit comments

Comments
 (0)