Merge pull request 'submission_description' (#1) from submission_description into master

Reviewed-on: CSI/gonito-frontend#1
This commit is contained in:
Mateusz Tylka 2023-05-10 15:20:52 +02:00
commit bf6fc83ef7

View File

@ -11,7 +11,6 @@ import {
CALC_PAGES, CALC_PAGES,
EVALUATIONS_FORMAT, EVALUATIONS_FORMAT,
RENDER_WHEN, RENDER_WHEN,
} from '../../../utils/globals'; } from '../../../utils/globals';
import Search from '../../generic/Search'; import Search from '../../generic/Search';
import Pager from '../../generic/Pager'; import Pager from '../../generic/Pager';
@ -23,6 +22,7 @@ const Leaderboard = (props) => {
const [pageNr, setPageNr] = React.useState(1); const [pageNr, setPageNr] = React.useState(1);
const [loading, setLoading] = React.useState(true); const [loading, setLoading] = React.useState(true);
const [submitterSorted, setSubmitterSorted] = React.useState(false); const [submitterSorted, setSubmitterSorted] = React.useState(false);
const [descriptionSorted, setDescriptionSorted] = React.useState(false);
const [entriesSorted, setEntriesSorted] = React.useState(false); const [entriesSorted, setEntriesSorted] = React.useState(false);
const [whenSorted, setWhenSorted] = React.useState(false); const [whenSorted, setWhenSorted] = React.useState(false);
const [scoresSorted, setScoresSorted] = React.useState([]); const [scoresSorted, setScoresSorted] = React.useState([]);
@ -65,7 +65,7 @@ const Leaderboard = (props) => {
}; };
const getLeaderboardHeader = () => { const getLeaderboardHeader = () => {
let header = ['#', 'submitter']; let header = ['#', 'submitter', 'description'];
for (let metric of getPossibleMetrics()) { for (let metric of getPossibleMetrics()) {
header.push(metric); header.push(metric);
} }
@ -75,7 +75,7 @@ const Leaderboard = (props) => {
}; };
const getLeaderboardHeaderMobile = () => { const getLeaderboardHeaderMobile = () => {
let header = ['#', 'submitter', 'entries', 'when']; let header = ['#', 'submitter', 'description', 'entries', 'when'];
for (let metric of getPossibleMetrics()) { for (let metric of getPossibleMetrics()) {
header.push(metric); header.push(metric);
} }
@ -107,6 +107,27 @@ const Leaderboard = (props) => {
setSubmitterSorted(true); setSubmitterSorted(true);
} }
break; break;
case 'description':
if (descriptionSorted) {
newEntries = newEntries.sort((a, b) =>
a.description.toLowerCase() < b.description.toLowerCase()
? 1
: b.description.toLowerCase() < a.description.toLowerCase()
? -1
: 0
);
setDescriptionSorted(false);
} else {
newEntries = newEntries.sort((a, b) =>
a.description.toLowerCase() > b.description.toLowerCase()
? 1
: b.description.toLowerCase() > a.description.toLowerCase()
? -1
: 0
);
setDescriptionSorted(true);
}
break;
case 'entries': case 'entries':
if (entriesSorted) { if (entriesSorted) {
newEntries = newEntries.sort((a, b) => b.times - a.times); newEntries = newEntries.sort((a, b) => b.times - a.times);
@ -170,7 +191,7 @@ const Leaderboard = (props) => {
tableType="leaderboard" tableType="leaderboard"
gridTemplateColumns={ gridTemplateColumns={
entries[0] entries[0]
? '1fr 3fr ' + ? '1fr 2fr 3fr ' +
'2fr '.repeat(entries[0].evaluations.length) + '2fr '.repeat(entries[0].evaluations.length) +
'1fr 2fr' '1fr 2fr'
: '' : ''
@ -179,6 +200,7 @@ const Leaderboard = (props) => {
staticColumnElements={[ staticColumnElements={[
{ name: 'id', format: null, order: 1, align: 'left' }, { name: 'id', format: null, order: 1, align: 'left' },
{ name: 'submitter', format: null, order: 2, align: 'left' }, { name: 'submitter', format: null, order: 2, align: 'left' },
{ name: 'description', format: null, order: 3, align: 'left' },
{ name: 'times', format: null, order: 4, align: 'left' }, { name: 'times', format: null, order: 4, align: 'left' },
{ name: 'when', format: RENDER_WHEN, order: 5, align: 'right' }, { name: 'when', format: RENDER_WHEN, order: 5, align: 'right' },
]} ]}
@ -224,7 +246,7 @@ const Leaderboard = (props) => {
headerElements={getLeaderboardHeader()} headerElements={getLeaderboardHeader()}
gridTemplateColumns={ gridTemplateColumns={
entries[0] entries[0]
? '1fr 3fr ' + ? '1fr 2fr 3fr ' +
'2fr '.repeat(entries[0].evaluations.length) + '2fr '.repeat(entries[0].evaluations.length) +
'1fr 2fr' '1fr 2fr'
: '' : ''
@ -233,6 +255,7 @@ const Leaderboard = (props) => {
staticColumnElements={[ staticColumnElements={[
{ name: 'id', format: null, order: 1, align: 'left' }, { name: 'id', format: null, order: 1, align: 'left' },
{ name: 'submitter', format: null, order: 2, align: 'left' }, { name: 'submitter', format: null, order: 2, align: 'left' },
{ name: 'description', format: null, order: 3, align: 'left' },
{ name: 'times', format: null, order: 4, align: 'left' }, { name: 'times', format: null, order: 4, align: 'left' },
{ name: 'when', format: RENDER_WHEN, order: 5, align: 'right' }, { name: 'when', format: RENDER_WHEN, order: 5, align: 'right' },
]} ]}
@ -255,7 +278,6 @@ const Leaderboard = (props) => {
width="72px" width="72px"
borderRadius="64px" borderRadius="64px"
pages={CALC_PAGES(entries, 2)} pages={CALC_PAGES(entries, 2)}
number={`${pageNr} / ${CALC_PAGES(entries, 2)}`} number={`${pageNr} / ${CALC_PAGES(entries, 2)}`}
/> />
</> </>