fix: stable options sorting

This commit is contained in:
Vyacheslav Matyukhin 2022-05-07 01:39:04 +04:00
parent fa57a78cb9
commit 7b1ccc2252
No known key found for this signature in database
GPG Key ID: 3D2A774C5489F96C

View File

@ -81,7 +81,14 @@ const Legend: React.FC<{
const buildDataSets = (question: QuestionWithHistoryFragment) => { const buildDataSets = (question: QuestionWithHistoryFragment) => {
let dataSetsNames = question.options let dataSetsNames = question.options
.sort((a, b) => (a.probability > b.probability ? -1 : 1)) .sort((a, b) => {
if (a.probability > b.probability) {
return -1;
} else if (a.probability < b.probability) {
return 1;
}
return a.name < b.name ? -1 : 1; // needed for stable sorting - otherwise it's possible to get order mismatch in SSR vs client-side
})
.map((o) => o.name) .map((o) => o.name)
.slice(0, MAX_LINES); .slice(0, MAX_LINES);