Fix: Duration sorting (#691)
This commit is contained in:
parent
2ce0aa6731
commit
ae54ee6277
|
@ -51,7 +51,7 @@ const dom = {
|
|||
header.querySelector('#results-table-head > tr').appendChild(t.content)
|
||||
})
|
||||
|
||||
header.querySelector(`.sortable[data-column-type="${sortAttr}"]`).classList.add(sortAsc ? 'desc' : 'asc')
|
||||
header.querySelector(`.sortable[data-column-type="${sortAttr}"]`)?.classList.add(sortAsc ? 'desc' : 'asc')
|
||||
|
||||
return header
|
||||
},
|
||||
|
|
|
@ -24,6 +24,24 @@ const genericSort = (list, key, ascending, customOrder) => {
|
|||
return sorted
|
||||
}
|
||||
|
||||
const durationSort = (list, ascending) => {
|
||||
const parseDuration = (duration) => {
|
||||
if (duration.includes(':')) {
|
||||
// If it's in the format "HH:mm:ss"
|
||||
const [hours, minutes, seconds] = duration.split(':').map(Number)
|
||||
return (hours * 3600 + minutes * 60 + seconds) * 1000
|
||||
} else {
|
||||
// If it's in the format "nnn ms"
|
||||
return parseInt(duration)
|
||||
}
|
||||
}
|
||||
const sorted = list.sort((a, b) => parseDuration(a['duration']) - parseDuration(b['duration']))
|
||||
if (ascending) {
|
||||
sorted.reverse()
|
||||
}
|
||||
return sorted
|
||||
}
|
||||
|
||||
const doInitSort = () => {
|
||||
const type = storageModule.getSort()
|
||||
const ascending = storageModule.getSortDirection()
|
||||
|
@ -32,7 +50,18 @@ const doInitSort = () => {
|
|||
if (type?.toLowerCase() === 'original') {
|
||||
manager.setRender(list)
|
||||
} else {
|
||||
const sortedList = genericSort(list, type, ascending, initialOrder)
|
||||
let sortedList
|
||||
switch (type) {
|
||||
case 'duration':
|
||||
sortedList = durationSort(list, ascending)
|
||||
break
|
||||
case 'result':
|
||||
sortedList = genericSort(list, type, ascending, initialOrder)
|
||||
break
|
||||
default:
|
||||
sortedList = genericSort(list, type, ascending)
|
||||
break
|
||||
}
|
||||
manager.setRender(sortedList)
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +74,7 @@ const doSort = (type) => {
|
|||
storageModule.setSortDirection(ascending)
|
||||
const list = manager.testSubset
|
||||
|
||||
const sortedList = genericSort(list, type, ascending)
|
||||
const sortedList = type === 'duration' ? durationSort(list, ascending) : genericSort(list, type, ascending)
|
||||
manager.setRender(sortedList)
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ describe('Sort tests', () => {
|
|||
|
||||
afterEach(() => [sortMock, sortDirectionMock, managerSpy].forEach((fn) => fn.restore()))
|
||||
it('has no stored sort', () => {
|
||||
sortMock = sinon.stub(storageModule, 'getSort').returns(null)
|
||||
sortMock = sinon.stub(storageModule, 'getSort').returns('result')
|
||||
sortDirectionMock = sinon.stub(storageModule, 'getSortDirection').returns(null)
|
||||
managerSpy = sinon.spy(dataModule.manager, 'setRender')
|
||||
|
||||
|
|
Loading…
Reference in New Issue