Skip to content

Commit b29b6bf

Browse files
murnyJeremy Press
authored andcommitted
feat(content-explorer): Add ability to sort contents by size column (#1239)
1 parent 88a5f1c commit b29b6bf

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

flow-typed/box-ui-elements.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
SIZE_LARGE,
4747
FIELD_DATE,
4848
FIELD_NAME,
49+
FIELD_SIZE,
4950
FIELD_RELEVANCE,
5051
DEFAULT_VIEW_RECENTS,
5152
DEFAULT_VIEW_FILES,
@@ -120,7 +121,7 @@ type View =
120121
| typeof VIEW_UPLOAD_EMPTY
121122
| typeof VIEW_UPLOAD_IN_PROGRESS
122123
| typeof VIEW_UPLOAD_SUCCESS;
123-
type SortBy = typeof FIELD_DATE | typeof FIELD_NAME | typeof FIELD_RELEVANCE;
124+
type SortBy = typeof FIELD_DATE | typeof FIELD_NAME | typeof FIELD_RELEVANCE | typeof FIELD_SIZE;
124125
type SortDirection = typeof SORT_ASC | typeof SORT_DESC;
125126
type ItemType = typeof TYPE_FILE | typeof TYPE_FOLDER | typeof TYPE_WEBLINK;
126127
type UploadStatus = typeof STATUS_PENDING | typeof STATUS_IN_PROGRESS | typeof STATUS_COMPLETE | typeof STATUS_ERROR;

src/elements/common/sub-header/Sort.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import MenuItem from '../../../components/menu/MenuItem';
1212
import IconCheck from '../../../icons/general/IconCheck';
1313
import SortButton from './SortButton';
1414
import messages from '../messages';
15-
import { FIELD_NAME, FIELD_DATE, SORT_ASC, SORT_DESC } from '../../../constants';
15+
import { FIELD_NAME, FIELD_DATE, FIELD_SIZE, SORT_ASC, SORT_DESC } from '../../../constants';
1616
import './Sort.scss';
1717

1818
type Props = {
@@ -26,6 +26,8 @@ const SORT_ITEMS: Array<Array<SortBy>> = [
2626
[FIELD_NAME, SORT_DESC],
2727
[FIELD_DATE, SORT_ASC],
2828
[FIELD_DATE, SORT_DESC],
29+
[FIELD_SIZE, SORT_ASC],
30+
[FIELD_SIZE, SORT_DESC],
2931
];
3032

3133
const Sort = ({ sortBy, sortDirection, onSortChange }: Props) => (

src/elements/common/sub-header/__tests__/Sort-test.js

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ describe('elements/SubHeader/Sort', () => {
1414
expect(wrapper.find(SortButton)).toHaveLength(1);
1515
expect(wrapper.find(DropdownMenu)).toHaveLength(1);
1616
expect(wrapper.find(Menu)).toHaveLength(1);
17-
expect(wrapper.find(MenuItem)).toHaveLength(4);
17+
expect(wrapper.find(MenuItem)).toHaveLength(6);
1818
});
1919

20-
test('should render a select with 4 options', () => {
20+
test('should render a select with 6 options', () => {
2121
const wrapper = shallow(<Sort onSortChange={jest.fn()} sortBy="name" sortDirection={SORT_ASC} />);
2222
const options = wrapper.find(MenuItem);
2323

24-
expect(options).toHaveLength(4);
24+
expect(options).toHaveLength(6);
2525
expect(
2626
options
2727
.at(0)
@@ -73,6 +73,32 @@ describe('elements/SubHeader/Sort', () => {
7373
.childAt(1)
7474
.prop('id'),
7575
).toBe(messages.dateDESC.id);
76+
77+
expect(
78+
options
79+
.at(4)
80+
.childAt(0)
81+
.text(),
82+
).toBe('');
83+
expect(
84+
options
85+
.at(4)
86+
.childAt(1)
87+
.prop('id'),
88+
).toBe(messages.sizeASC.id);
89+
90+
expect(
91+
options
92+
.at(5)
93+
.childAt(0)
94+
.text(),
95+
).toBe('');
96+
expect(
97+
options
98+
.at(5)
99+
.childAt(1)
100+
.prop('id'),
101+
).toBe(messages.sizeDESC.id);
76102
});
77103

78104
test('should pass correct parameters when clicked', () => {
@@ -91,13 +117,19 @@ describe('elements/SubHeader/Sort', () => {
91117

92118
options.at(3).simulate('click');
93119
expect(sort).toHaveBeenCalledWith('date', SORT_DESC);
120+
121+
options.at(4).simulate('click');
122+
expect(sort).toHaveBeenCalledWith('size', SORT_ASC);
123+
124+
options.at(5).simulate('click');
125+
expect(sort).toHaveBeenCalledWith('size', SORT_DESC);
94126
});
95127

96128
test('should render a select with correct option selected', () => {
97129
const wrapper = shallow(<Sort onSortChange={jest.fn()} sortBy="date" sortDirection={SORT_DESC} />);
98130
const options = wrapper.find(MenuItem);
99131

100-
expect(options).toHaveLength(4);
132+
expect(options).toHaveLength(6);
101133
expect(
102134
options
103135
.at(3)

src/elements/content-explorer/ItemList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ const ItemList = ({
194194
{isSmall || isMedium ? null : (
195195
<Column
196196
className="bce-item-coloumn"
197-
disableSort
197+
disableSort={!hasSort}
198198
label={intl.formatMessage(messages.size)}
199199
dataKey={FIELD_SIZE}
200200
cellRenderer={sizeAccessCell}

0 commit comments

Comments
 (0)