fix(StudyListWithData): Fix InvalidDate and broken date sorting in Study List (#495)
Fixes #492
This commit is contained in:
parent
0fbd47f502
commit
bd2fa615cc
@ -69,32 +69,40 @@ class StudyListWithData extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const { field, order } = searchData.sortData;
|
const { field, order } = searchData.sortData;
|
||||||
const sortedStudies = studies
|
let sortedStudies = studies.map(study => {
|
||||||
.sort(function(a, b) {
|
if (!moment(study.studyDate, 'MMM DD, YYYY', true).isValid()) {
|
||||||
if (order === 'desc') {
|
|
||||||
if (a[field] < b[field]) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (a[field] > b[field]) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
} else {
|
|
||||||
if (a[field] > b[field]) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (a[field] < b[field]) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.map(study => {
|
|
||||||
study.studyDate = moment(study.studyDate, 'YYYYMMDD').format(
|
study.studyDate = moment(study.studyDate, 'YYYYMMDD').format(
|
||||||
'MMM DD, YYYY'
|
'MMM DD, YYYY'
|
||||||
);
|
);
|
||||||
return study;
|
}
|
||||||
});
|
return study;
|
||||||
|
});
|
||||||
|
|
||||||
|
sortedStudies.sort(function(a, b) {
|
||||||
|
let fieldA = a[field];
|
||||||
|
let fieldB = b[field];
|
||||||
|
if (field === 'studyDate') {
|
||||||
|
fieldA = moment(fieldA).toISOString();
|
||||||
|
fieldB = moment(fieldB).toISOString();
|
||||||
|
}
|
||||||
|
if (order === 'desc') {
|
||||||
|
if (fieldA < fieldB) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (fieldA > fieldB) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
} else {
|
||||||
|
if (fieldA > fieldB) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (fieldA < fieldB) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
studies: sortedStudies,
|
studies: sortedStudies,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user