Skip to content

Commit

Permalink
fix(archive): Fix blank screen when sorting (#1153)
Browse files Browse the repository at this point in the history
* fix(archive): Fix blank screen when sorting
* Add try/catch handler for exceptions
* Handle case when sorting data is falsy

* fix(archive): PR Feedback

* fix(archive): Addressing PR feedback
* Remove try/catch
* Add test for comparing to null values in the sort

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mickr and mergify[bot] committed Jan 17, 2020
1 parent 6fd3ce3 commit 5c6cc96
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/lib/viewers/archive/ArchiveExplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ class ArchiveExplorer extends React.Component {
return itemList;
}

const sortedItems = itemList.sort((a, b) => {
const sortedItems = itemList.sort((a = {}, b = {}) => {
if (!a[sortBy] || !b[sortBy]) {
return -1;
}

if (typeof a[sortBy] === 'number' && typeof b[sortBy] === 'number') {
return a[sortBy] - b[sortBy];
}
Expand Down
15 changes: 15 additions & 0 deletions src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,20 @@ describe('lib/viewers/archive/ArchiveExplorer', () => {

expect(sortedList[0]).to.equal(itemList[0]);
});

it('should sort item list with null values', () => {
data[1].modified_at = null;
data[2].modified_at = null;

const component = getComponent({ filename, itemCollection: data });
const instance = component.instance();
const itemList = instance.getItemList(data, 'test/');

instance.handleSort({ sortBy: 'modified_at' });

const sortedList = instance.sortItemList(itemList);

expect(sortedList[0]).to.equal(itemList[0]);
});
});
});

0 comments on commit 5c6cc96

Please sign in to comment.