correct sorting values in Table
This commit is contained in:
parent
4334e4dfcc
commit
782627a920
@ -1,7 +1,7 @@
|
||||
import {API} from '../utils/globals';
|
||||
import KeyCloakService from '../services/KeyCloakService';
|
||||
|
||||
const getMyEntries = (challengeName, setDataOriginalState, setDataState, setLoadingState) => {
|
||||
const getMyEntries = (challengeName, setDataOriginalState, setDataState, setLoadingState, setScoreSorted) => {
|
||||
fetch(`${API}/challenge-my-submissions/${challengeName}`, {
|
||||
headers: {'Authorization': `Bearer ${KeyCloakService.getToken()}`}
|
||||
})
|
||||
@ -10,6 +10,7 @@ const getMyEntries = (challengeName, setDataOriginalState, setDataState, setLoad
|
||||
setDataOriginalState(data);
|
||||
let item = {};
|
||||
let result = [];
|
||||
let initSetScoreSorted = [];
|
||||
let tests = data.tests;
|
||||
for (let submission of data.submissions) {
|
||||
for (let evaluation of submission.evaluations) {
|
||||
@ -41,6 +42,11 @@ const getMyEntries = (challengeName, setDataOriginalState, setDataState, setLoad
|
||||
result.push(item);
|
||||
item = {};
|
||||
}
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
for (let _ of tests) {
|
||||
initSetScoreSorted.push(false);
|
||||
}
|
||||
setScoreSorted(initSetScoreSorted);
|
||||
setDataState(result);
|
||||
setLoadingState(false);
|
||||
});
|
||||
|
@ -90,10 +90,10 @@ const Leaderboard = (props) => {
|
||||
switch (elem) {
|
||||
case 'submitter':
|
||||
if (submitterSorted) {
|
||||
newEntries = newEntries.sort((a, b) => (a.submitter > b.submitter) ? 1 : ((b.submitter > a.submitter) ? -1 : 0));
|
||||
newEntries = newEntries.sort((a, b) => (a.submitter < b.submitter) ? 1 : ((b.submitter < a.submitter) ? -1 : 0));
|
||||
setSubmitterSorted(false);
|
||||
} else {
|
||||
newEntries = newEntries.sort((a, b) => (a.submitter < b.submitter) ? 1 : ((b.submitter < a.submitter) ? -1 : 0));
|
||||
newEntries = newEntries.sort((a, b) => (a.submitter > b.submitter) ? 1 : ((b.submitter > a.submitter) ? -1 : 0));
|
||||
setSubmitterSorted(true);
|
||||
}
|
||||
break;
|
||||
@ -126,7 +126,6 @@ const Leaderboard = (props) => {
|
||||
}
|
||||
break;
|
||||
}
|
||||
console.log(newEntries);
|
||||
setEntries(newEntries);
|
||||
};
|
||||
|
||||
|
@ -16,7 +16,7 @@ const MyEntries = (props) => {
|
||||
const [loading, setLoading] = React.useState(true);
|
||||
const [pageNr, setPageNr] = React.useState(1);
|
||||
const [whenSorted, setWhenSorted] = React.useState(false);
|
||||
const [scoreSorted, setScoreSorted] = React.useState(false);
|
||||
const [scoresSorted, setScoresSorted] = React.useState([]);
|
||||
/* eslint-disable */
|
||||
|
||||
React.useEffect(() => {
|
||||
@ -62,7 +62,7 @@ const MyEntries = (props) => {
|
||||
};
|
||||
|
||||
const challengesRequest = () => {
|
||||
getMyEntries(props.challengeName, setMyEntriesFromAPI, setMyEntries, setLoading);
|
||||
getMyEntries(props.challengeName, setMyEntriesFromAPI, setMyEntries, setLoading, setScoresSorted);
|
||||
};
|
||||
|
||||
const mobileRender = () => {
|
||||
@ -84,12 +84,16 @@ const MyEntries = (props) => {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (scoreSorted) {
|
||||
newEntries = newEntries.sort((a, b) => a.evaluations[elem] - b.evaluations[elem]);
|
||||
setScoreSorted(false);
|
||||
} else {
|
||||
let metricIndex = getPossibleMetrics().indexOf(elem);
|
||||
let newScoresSorted = scoresSorted;
|
||||
if (scoresSorted[metricIndex]) {
|
||||
newEntries = newEntries.sort((a, b) => b.evaluations[elem] - a.evaluations[elem]);
|
||||
setScoreSorted(true);
|
||||
newScoresSorted[metricIndex] = false;
|
||||
setScoresSorted(newScoresSorted);
|
||||
} else {
|
||||
newEntries = newEntries.sort((a, b) => a.evaluations[elem] - b.evaluations[elem]);
|
||||
newScoresSorted[metricIndex] = true;
|
||||
setScoresSorted(newScoresSorted);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user