@dhis2-ui/table 7.11.4 → 7.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/data-table/__tests__/data-table-column-header.test.js +34 -20
- package/build/cjs/data-table/data-table-column-header/data-table-column-header.js +4 -1
- package/build/cjs/data-table/data-table-column-header/sorter.js +3 -1
- package/build/cjs/data-table/data-table.stories.js +4 -2
- package/build/es/data-table/__tests__/data-table-column-header.test.js +34 -20
- package/build/es/data-table/data-table-column-header/data-table-column-header.js +4 -1
- package/build/es/data-table/data-table-column-header/sorter.js +3 -1
- package/build/es/data-table/data-table.stories.js +4 -2
- package/package.json +3 -3
|
@@ -136,26 +136,40 @@ describe('<DataTableColumnHeader>', () => {
|
|
|
136
136
|
}));
|
|
137
137
|
expect(wrapper.find(_index.TableHeaderCell).prop('scope')).toBe(scope);
|
|
138
138
|
});
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
139
|
+
describe('column header sorting', () => {
|
|
140
|
+
it('accepts sortDirection, sortIconTitle, and onSortIconClick props', () => {
|
|
141
|
+
const name = 'test';
|
|
142
|
+
const title = 'Custom title';
|
|
143
|
+
const fakeEvent = {
|
|
144
|
+
target: 'test',
|
|
145
|
+
value: 'test'
|
|
146
|
+
};
|
|
147
|
+
const onClick = jest.fn();
|
|
148
|
+
const wrapper = (0, _enzyme.shallow)( /*#__PURE__*/_react.default.createElement(_dataTableColumnHeader.DataTableColumnHeader, {
|
|
149
|
+
name: name,
|
|
150
|
+
onSortIconClick: onClick,
|
|
151
|
+
sortDirection: 'asc',
|
|
152
|
+
sortIconTitle: title
|
|
153
|
+
}));
|
|
154
|
+
const button = wrapper.find(_sorter.Sorter).dive().find(_index.TableHeaderCellAction).dive().find('button');
|
|
155
|
+
button.simulate('click', fakeEvent);
|
|
156
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
157
|
+
expect(onClick).toHaveBeenCalledWith({
|
|
158
|
+
name,
|
|
159
|
+
// next sort direction
|
|
160
|
+
direction: 'desc'
|
|
161
|
+
}, fakeEvent);
|
|
162
|
+
expect(button.prop('title')).toBe(title);
|
|
163
|
+
});
|
|
164
|
+
it('has a default sort icon title', () => {
|
|
165
|
+
const wrapper = (0, _enzyme.shallow)( /*#__PURE__*/_react.default.createElement(_dataTableColumnHeader.DataTableColumnHeader, {
|
|
166
|
+
name: 'test',
|
|
167
|
+
onSortIconClick: () => {},
|
|
168
|
+
sortDirection: 'asc'
|
|
169
|
+
}));
|
|
170
|
+
const button = wrapper.find(_sorter.Sorter).dive().find(_index.TableHeaderCellAction).dive().find('button');
|
|
171
|
+
expect(button.prop('title')).toBe('Sort items');
|
|
172
|
+
});
|
|
159
173
|
});
|
|
160
174
|
it('accepts a top prop', () => {
|
|
161
175
|
const top = '200px';
|
|
@@ -50,6 +50,7 @@ const DataTableColumnHeader = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
50
50
|
scope,
|
|
51
51
|
showFilter,
|
|
52
52
|
sortDirection,
|
|
53
|
+
sortIconTitle,
|
|
53
54
|
top,
|
|
54
55
|
width,
|
|
55
56
|
onFilterIconClick,
|
|
@@ -79,7 +80,8 @@ const DataTableColumnHeader = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
|
79
80
|
}, children), sortDirection && /*#__PURE__*/_react.default.createElement(_sorter.Sorter, {
|
|
80
81
|
name: name,
|
|
81
82
|
sortDirection: sortDirection,
|
|
82
|
-
onClick: onSortIconClick
|
|
83
|
+
onClick: onSortIconClick,
|
|
84
|
+
title: sortIconTitle
|
|
83
85
|
}), filter && /*#__PURE__*/_react.default.createElement(_filterHandle.FilterHandle, {
|
|
84
86
|
name: name,
|
|
85
87
|
active: showFilter,
|
|
@@ -116,6 +118,7 @@ DataTableColumnHeader.propTypes = {
|
|
|
116
118
|
scope: _propTypes2.default.string,
|
|
117
119
|
showFilter: (0, _propTypes.requiredIf)(props => props.filter, _propTypes2.default.bool),
|
|
118
120
|
sortDirection: (0, _propTypes.requiredIf)(props => props.onSortIconClick, _propTypes2.default.oneOf(_sorter.SORT_DIRECTIONS)),
|
|
121
|
+
sortIconTitle: _propTypes2.default.string,
|
|
119
122
|
|
|
120
123
|
/** Left or top required when fixed */
|
|
121
124
|
top: (0, _propTypes.requiredIf)(props => props.fixed && !props.left, _propTypes2.default.string),
|
|
@@ -41,6 +41,7 @@ exports.getNextSortDirection = getNextSortDirection;
|
|
|
41
41
|
const Sorter = ({
|
|
42
42
|
name,
|
|
43
43
|
sortDirection,
|
|
44
|
+
title,
|
|
44
45
|
onClick
|
|
45
46
|
}) => {
|
|
46
47
|
const nextSortDirection = getNextSortDirection(sortDirection);
|
|
@@ -52,7 +53,7 @@ const Sorter = ({
|
|
|
52
53
|
} : undefined;
|
|
53
54
|
return /*#__PURE__*/_react.default.createElement(_index2.TableHeaderCellAction, {
|
|
54
55
|
onClick: clickHandler,
|
|
55
|
-
title: _index.default.t('Sort items')
|
|
56
|
+
title: title || _index.default.t('Sort items')
|
|
56
57
|
}, /*#__PURE__*/_react.default.createElement("svg", {
|
|
57
58
|
xmlns: "http://www.w3.org/2000/svg",
|
|
58
59
|
width: "16",
|
|
@@ -79,5 +80,6 @@ exports.Sorter = Sorter;
|
|
|
79
80
|
Sorter.propTypes = {
|
|
80
81
|
name: _propTypes2.default.string,
|
|
81
82
|
sortDirection: (0, _propTypes.requiredIf)(props => props.onClick, _propTypes2.default.oneOf(SORT_DIRECTIONS)),
|
|
83
|
+
title: _propTypes2.default.string,
|
|
82
84
|
onClick: _propTypes2.default.func
|
|
83
85
|
};
|
|
@@ -657,11 +657,13 @@ const ColumnHeaderSortingTemplate = args => {
|
|
|
657
657
|
return /*#__PURE__*/_react.default.createElement(_dataTable.DataTable, args, /*#__PURE__*/_react.default.createElement(_dataTableHead.DataTableHead, null, /*#__PURE__*/_react.default.createElement(_dataTableRow.DataTableRow, null, /*#__PURE__*/_react.default.createElement(_dataTableColumnHeader.DataTableColumnHeader, {
|
|
658
658
|
onSortIconClick: onSortIconClick,
|
|
659
659
|
sortDirection: getSortDirection('firstName'),
|
|
660
|
-
name: 'firstName'
|
|
660
|
+
name: 'firstName',
|
|
661
|
+
sortIconTitle: "Sort by first name"
|
|
661
662
|
}, "First name"), /*#__PURE__*/_react.default.createElement(_dataTableColumnHeader.DataTableColumnHeader, {
|
|
662
663
|
onSortIconClick: onSortIconClick,
|
|
663
664
|
sortDirection: getSortDirection('lastName'),
|
|
664
|
-
name: 'lastName'
|
|
665
|
+
name: 'lastName',
|
|
666
|
+
sortIconTitle: "Sort by last name"
|
|
665
667
|
}, "Last name"))), /*#__PURE__*/_react.default.createElement(_dataTableBody.DataTableBody, null, rows.sort((a, b) => {
|
|
666
668
|
const strA = a[column];
|
|
667
669
|
const strB = b[column];
|
|
@@ -125,26 +125,40 @@ describe('<DataTableColumnHeader>', () => {
|
|
|
125
125
|
}));
|
|
126
126
|
expect(wrapper.find(TableHeaderCell).prop('scope')).toBe(scope);
|
|
127
127
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
128
|
+
describe('column header sorting', () => {
|
|
129
|
+
it('accepts sortDirection, sortIconTitle, and onSortIconClick props', () => {
|
|
130
|
+
const name = 'test';
|
|
131
|
+
const title = 'Custom title';
|
|
132
|
+
const fakeEvent = {
|
|
133
|
+
target: 'test',
|
|
134
|
+
value: 'test'
|
|
135
|
+
};
|
|
136
|
+
const onClick = jest.fn();
|
|
137
|
+
const wrapper = shallow( /*#__PURE__*/React.createElement(DataTableColumnHeader, {
|
|
138
|
+
name: name,
|
|
139
|
+
onSortIconClick: onClick,
|
|
140
|
+
sortDirection: 'asc',
|
|
141
|
+
sortIconTitle: title
|
|
142
|
+
}));
|
|
143
|
+
const button = wrapper.find(Sorter).dive().find(TableHeaderCellAction).dive().find('button');
|
|
144
|
+
button.simulate('click', fakeEvent);
|
|
145
|
+
expect(onClick).toHaveBeenCalledTimes(1);
|
|
146
|
+
expect(onClick).toHaveBeenCalledWith({
|
|
147
|
+
name,
|
|
148
|
+
// next sort direction
|
|
149
|
+
direction: 'desc'
|
|
150
|
+
}, fakeEvent);
|
|
151
|
+
expect(button.prop('title')).toBe(title);
|
|
152
|
+
});
|
|
153
|
+
it('has a default sort icon title', () => {
|
|
154
|
+
const wrapper = shallow( /*#__PURE__*/React.createElement(DataTableColumnHeader, {
|
|
155
|
+
name: 'test',
|
|
156
|
+
onSortIconClick: () => {},
|
|
157
|
+
sortDirection: 'asc'
|
|
158
|
+
}));
|
|
159
|
+
const button = wrapper.find(Sorter).dive().find(TableHeaderCellAction).dive().find('button');
|
|
160
|
+
expect(button.prop('title')).toBe('Sort items');
|
|
161
|
+
});
|
|
148
162
|
});
|
|
149
163
|
it('accepts a top prop', () => {
|
|
150
164
|
const top = '200px';
|
|
@@ -28,6 +28,7 @@ export const DataTableColumnHeader = /*#__PURE__*/forwardRef(({
|
|
|
28
28
|
scope,
|
|
29
29
|
showFilter,
|
|
30
30
|
sortDirection,
|
|
31
|
+
sortIconTitle,
|
|
31
32
|
top,
|
|
32
33
|
width,
|
|
33
34
|
onFilterIconClick,
|
|
@@ -57,7 +58,8 @@ export const DataTableColumnHeader = /*#__PURE__*/forwardRef(({
|
|
|
57
58
|
}, children), sortDirection && /*#__PURE__*/React.createElement(Sorter, {
|
|
58
59
|
name: name,
|
|
59
60
|
sortDirection: sortDirection,
|
|
60
|
-
onClick: onSortIconClick
|
|
61
|
+
onClick: onSortIconClick,
|
|
62
|
+
title: sortIconTitle
|
|
61
63
|
}), filter && /*#__PURE__*/React.createElement(FilterHandle, {
|
|
62
64
|
name: name,
|
|
63
65
|
active: showFilter,
|
|
@@ -93,6 +95,7 @@ DataTableColumnHeader.propTypes = {
|
|
|
93
95
|
scope: PropTypes.string,
|
|
94
96
|
showFilter: requiredIf(props => props.filter, PropTypes.bool),
|
|
95
97
|
sortDirection: requiredIf(props => props.onSortIconClick, PropTypes.oneOf(SORT_DIRECTIONS)),
|
|
98
|
+
sortIconTitle: PropTypes.string,
|
|
96
99
|
|
|
97
100
|
/** Left or top required when fixed */
|
|
98
101
|
top: requiredIf(props => props.fixed && !props.left, PropTypes.string),
|
|
@@ -17,6 +17,7 @@ export const getNextSortDirection = currentDirection => {
|
|
|
17
17
|
export const Sorter = ({
|
|
18
18
|
name,
|
|
19
19
|
sortDirection,
|
|
20
|
+
title,
|
|
20
21
|
onClick
|
|
21
22
|
}) => {
|
|
22
23
|
const nextSortDirection = getNextSortDirection(sortDirection);
|
|
@@ -28,7 +29,7 @@ export const Sorter = ({
|
|
|
28
29
|
} : undefined;
|
|
29
30
|
return /*#__PURE__*/React.createElement(TableHeaderCellAction, {
|
|
30
31
|
onClick: clickHandler,
|
|
31
|
-
title: i18n.t('Sort items')
|
|
32
|
+
title: title || i18n.t('Sort items')
|
|
32
33
|
}, /*#__PURE__*/React.createElement("svg", {
|
|
33
34
|
xmlns: "http://www.w3.org/2000/svg",
|
|
34
35
|
width: "16",
|
|
@@ -53,5 +54,6 @@ export const Sorter = ({
|
|
|
53
54
|
Sorter.propTypes = {
|
|
54
55
|
name: PropTypes.string,
|
|
55
56
|
sortDirection: requiredIf(props => props.onClick, PropTypes.oneOf(SORT_DIRECTIONS)),
|
|
57
|
+
title: PropTypes.string,
|
|
56
58
|
onClick: PropTypes.func
|
|
57
59
|
};
|
|
@@ -618,11 +618,13 @@ const ColumnHeaderSortingTemplate = args => {
|
|
|
618
618
|
return /*#__PURE__*/React.createElement(DataTable, args, /*#__PURE__*/React.createElement(DataTableHead, null, /*#__PURE__*/React.createElement(DataTableRow, null, /*#__PURE__*/React.createElement(DataTableColumnHeader, {
|
|
619
619
|
onSortIconClick: onSortIconClick,
|
|
620
620
|
sortDirection: getSortDirection('firstName'),
|
|
621
|
-
name: 'firstName'
|
|
621
|
+
name: 'firstName',
|
|
622
|
+
sortIconTitle: "Sort by first name"
|
|
622
623
|
}, "First name"), /*#__PURE__*/React.createElement(DataTableColumnHeader, {
|
|
623
624
|
onSortIconClick: onSortIconClick,
|
|
624
625
|
sortDirection: getSortDirection('lastName'),
|
|
625
|
-
name: 'lastName'
|
|
626
|
+
name: 'lastName',
|
|
627
|
+
sortIconTitle: "Sort by last name"
|
|
626
628
|
}, "Last name"))), /*#__PURE__*/React.createElement(DataTableBody, null, rows.sort((a, b) => {
|
|
627
629
|
const strA = a[column];
|
|
628
630
|
const strB = b[column];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dhis2-ui/table",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.13.0",
|
|
4
4
|
"description": "UI Table",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@dhis2/prop-types": "^3.0.0-beta.1",
|
|
36
|
-
"@dhis2/ui-constants": "7.
|
|
37
|
-
"@dhis2/ui-icons": "7.
|
|
36
|
+
"@dhis2/ui-constants": "7.13.0",
|
|
37
|
+
"@dhis2/ui-icons": "7.13.0",
|
|
38
38
|
"classnames": "^2.3.1",
|
|
39
39
|
"prop-types": "^15.7.2"
|
|
40
40
|
},
|