diff --git a/src/lib/viewers/archive/ArchiveExplorer.js b/src/lib/viewers/archive/ArchiveExplorer.js index 8541ac219..eb4a1e9e0 100644 --- a/src/lib/viewers/archive/ArchiveExplorer.js +++ b/src/lib/viewers/archive/ArchiveExplorer.js @@ -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]; } diff --git a/src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js b/src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js index 2e53cf4b5..f502bbe88 100644 --- a/src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js +++ b/src/lib/viewers/archive/__tests__/ArchiveExplorer-test-react.js @@ -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]); + }); }); });