prototype delete worked
This commit is contained in:
parent
decd4faf22
commit
74e0ef19db
@ -1,7 +1,7 @@
|
|||||||
import KeyCloakService from '../services/KeyCloakService';
|
import KeyCloakService from '../services/KeyCloakService';
|
||||||
import { API } from '../utils/globals';
|
import { API } from '../utils/globals';
|
||||||
|
|
||||||
const deleteSubmission = (submissionId) => {
|
const deleteSubmission = async (submissionId) => {
|
||||||
fetch(`${API}/delete-submission/${submissionId}`, {
|
fetch(`${API}/delete-submission/${submissionId}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
|
@ -44,12 +44,7 @@ const getChallengeLeaderboard = (
|
|||||||
}
|
}
|
||||||
item = {
|
item = {
|
||||||
...item.evaluations,
|
...item.evaluations,
|
||||||
id: submission.id,
|
...submission,
|
||||||
submitter: submission.submitter,
|
|
||||||
when: submission.when,
|
|
||||||
description: submission.description,
|
|
||||||
entries: submission.times,
|
|
||||||
tags: submission.tags,
|
|
||||||
};
|
};
|
||||||
result.push(item);
|
result.push(item);
|
||||||
item = {};
|
item = {};
|
||||||
|
@ -44,14 +44,12 @@ const getEntries = (
|
|||||||
}
|
}
|
||||||
item = {
|
item = {
|
||||||
...item.evaluations,
|
...item.evaluations,
|
||||||
id: submission.id,
|
...submission,
|
||||||
submitter: submission.submitter,
|
|
||||||
when: submission.when,
|
|
||||||
tags: submission.tags,
|
|
||||||
};
|
};
|
||||||
result.push(item);
|
result.push(item);
|
||||||
item = {};
|
item = {};
|
||||||
}
|
}
|
||||||
|
result = result.filter((item) => !item.deleted);
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
for (let _ of tests) {
|
for (let _ of tests) {
|
||||||
initSetScoreSorted.push(false);
|
initSetScoreSorted.push(false);
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
import { API } from '../utils/globals';
|
|
||||||
import KeyCloakService from '../services/KeyCloakService';
|
|
||||||
|
|
||||||
const getMyEntries = (
|
|
||||||
challengeName,
|
|
||||||
setDataStates,
|
|
||||||
setLoadingState,
|
|
||||||
setScoreSorted
|
|
||||||
) => {
|
|
||||||
fetch(`${API}/challenge-my-submissions/${challengeName}`, {
|
|
||||||
headers: { Authorization: `Bearer ${KeyCloakService.getToken()}` },
|
|
||||||
})
|
|
||||||
.then((response) => response.json())
|
|
||||||
.then((data) => {
|
|
||||||
let item = {};
|
|
||||||
let result = [];
|
|
||||||
let initSetScoreSorted = [];
|
|
||||||
let tests = data.tests;
|
|
||||||
for (let submission of data.submissions) {
|
|
||||||
for (let evaluation of submission.evaluations) {
|
|
||||||
item = {
|
|
||||||
...item,
|
|
||||||
evaluations: {
|
|
||||||
...item.evaluations,
|
|
||||||
[`${evaluation.test.metric}.${evaluation.test.name}`]:
|
|
||||||
evaluation.score,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
for (let test of tests) {
|
|
||||||
if (!item.evaluations) {
|
|
||||||
item.evaluations = {};
|
|
||||||
}
|
|
||||||
if (!Object.hasOwn(item.evaluations, `${test.metric}.${test.name}`)) {
|
|
||||||
item = {
|
|
||||||
...item,
|
|
||||||
evaluations: {
|
|
||||||
...item.evaluations,
|
|
||||||
[`${test.metric}.${test.name}`]: -999999999,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
item = {
|
|
||||||
...item.evaluations,
|
|
||||||
id: submission.id,
|
|
||||||
submitter: submission.submitter,
|
|
||||||
when: submission.when,
|
|
||||||
tags: submission.tags,
|
|
||||||
};
|
|
||||||
result.push(item);
|
|
||||||
item = {};
|
|
||||||
}
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
|
||||||
for (let _ of tests) {
|
|
||||||
initSetScoreSorted.push(false);
|
|
||||||
}
|
|
||||||
for (let setDataState of setDataStates) setDataState(result);
|
|
||||||
if (setScoreSorted) setScoreSorted(initSetScoreSorted);
|
|
||||||
if (setLoadingState) setLoadingState(false);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export default getMyEntries;
|
|
@ -4,10 +4,20 @@ import TableHeader from './components/TableHeader';
|
|||||||
import TableRowItems from './components/TableRowItems';
|
import TableRowItems from './components/TableRowItems';
|
||||||
import RowsBackgroundStyle from './styles/RowsBackgroundStyle';
|
import RowsBackgroundStyle from './styles/RowsBackgroundStyle';
|
||||||
import TableRowFooter from './components/TableRowFooter';
|
import TableRowFooter from './components/TableRowFooter';
|
||||||
|
import deleteSubmission from '../../../api/deleteSubmission';
|
||||||
|
|
||||||
const Table = ({ items, orderedKeys, sortByUpdate, rowFooter = true }) => {
|
const Table = ({ items, orderedKeys, sortByUpdate, rowFooter = true }) => {
|
||||||
const [, updateState] = React.useState();
|
const [, updateState] = React.useState();
|
||||||
const tableUpdate = React.useCallback(() => updateState({}), []);
|
const tableUpdate = React.useCallback(() => updateState({}), []);
|
||||||
|
const [deletedItems, setDeletedItems] = React.useState([]);
|
||||||
|
const itemsToRender = items.filter((item) => !deletedItems.includes(item));
|
||||||
|
|
||||||
|
const deleteItem = async (item) => {
|
||||||
|
await deleteSubmission(item.id);
|
||||||
|
let newDeletedItems = deletedItems.slice();
|
||||||
|
newDeletedItems.push(item);
|
||||||
|
setDeletedItems(newDeletedItems);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TableStyle rowFooter={rowFooter}>
|
<TableStyle rowFooter={rowFooter}>
|
||||||
@ -16,11 +26,16 @@ const Table = ({ items, orderedKeys, sortByUpdate, rowFooter = true }) => {
|
|||||||
sortByUpdate={sortByUpdate}
|
sortByUpdate={sortByUpdate}
|
||||||
tableUpdate={tableUpdate}
|
tableUpdate={tableUpdate}
|
||||||
/>
|
/>
|
||||||
{items.map((item, i) => {
|
{itemsToRender.map((item, i) => {
|
||||||
return (
|
return (
|
||||||
<tr key={`table-row-${i}`} className="TableStyle__tr">
|
<tr key={`table-row-${i}`} className="TableStyle__tr">
|
||||||
<TableRowItems orderedKeys={orderedKeys} item={item} i={i} />
|
<TableRowItems orderedKeys={orderedKeys} item={item} i={i} />
|
||||||
<TableRowFooter rowFooter={rowFooter} item={item} i={i} />
|
<TableRowFooter
|
||||||
|
deleteItem={deleteItem}
|
||||||
|
rowFooter={rowFooter}
|
||||||
|
item={item}
|
||||||
|
i={i}
|
||||||
|
/>
|
||||||
<RowsBackgroundStyle i={i} />
|
<RowsBackgroundStyle i={i} />
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
|
@ -5,7 +5,7 @@ import TableRowButtons from '../TableRowButtons/TableRowButtons';
|
|||||||
import pensilIco from '../../../../../assets/pencil_ico.svg';
|
import pensilIco from '../../../../../assets/pencil_ico.svg';
|
||||||
import deleteIco from '../../../../../assets/delete_ico.svg';
|
import deleteIco from '../../../../../assets/delete_ico.svg';
|
||||||
|
|
||||||
const TableRowFooter = ({ rowFooter, item, i }) => {
|
const TableRowFooter = ({ rowFooter, item, i, deleteItem }) => {
|
||||||
if (rowFooter) {
|
if (rowFooter) {
|
||||||
return (
|
return (
|
||||||
<FlexRow className="TableStyle__row-footer">
|
<FlexRow className="TableStyle__row-footer">
|
||||||
@ -13,7 +13,7 @@ const TableRowFooter = ({ rowFooter, item, i }) => {
|
|||||||
<TableRowButtons
|
<TableRowButtons
|
||||||
buttons={[
|
buttons={[
|
||||||
{ icon: pensilIco, handler: () => console.log('edit') },
|
{ icon: pensilIco, handler: () => console.log('edit') },
|
||||||
{ icon: deleteIco, handler: () => console.log('delete') },
|
{ icon: deleteIco, handler: () => deleteItem(item) },
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
</FlexRow>
|
</FlexRow>
|
||||||
|
@ -2,14 +2,20 @@ import React from 'react';
|
|||||||
import { RENDER_WHEN, RENDER_METRIC_VALUE } from '../../../../../utils/globals';
|
import { RENDER_WHEN, RENDER_METRIC_VALUE } from '../../../../../utils/globals';
|
||||||
|
|
||||||
const TableRowItems = ({ orderedKeys, item, i }) => {
|
const TableRowItems = ({ orderedKeys, item, i }) => {
|
||||||
|
const renderValue = (keyValue) => {
|
||||||
|
if (keyValue === 'when') {
|
||||||
|
return RENDER_WHEN(item[keyValue]);
|
||||||
|
} else {
|
||||||
|
return RENDER_METRIC_VALUE(item[keyValue]);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{orderedKeys.map((keyValue, j) => {
|
{orderedKeys.map((keyValue, j) => {
|
||||||
return (
|
return (
|
||||||
<td key={`table-item-${i}-${j}`} className="TableStyle__td">
|
<td key={`table-item-${i}-${j}`} className="TableStyle__td">
|
||||||
{keyValue === 'when'
|
{renderValue(keyValue)}
|
||||||
? RENDER_WHEN(item[keyValue])
|
|
||||||
: RENDER_METRIC_VALUE(item[keyValue])}
|
|
||||||
</td>
|
</td>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
@ -129,11 +129,13 @@ const NewTablePageTest = (props) => {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
{elements.length > 0 && entries[0] && (
|
{elements.length > 0 && entries[0] && (
|
||||||
|
// <div style={{ width: '100%', overflowX: 'scroll' }}>
|
||||||
<Table
|
<Table
|
||||||
items={elements}
|
items={elements}
|
||||||
orderedKeys={orderKeys(entries[0])}
|
orderedKeys={orderKeys(entries[0])}
|
||||||
sortByUpdate={sortByUpdate}
|
sortByUpdate={sortByUpdate}
|
||||||
/>
|
/>
|
||||||
|
// </div>
|
||||||
)}
|
)}
|
||||||
<Pager
|
<Pager
|
||||||
pageNr={pageNr}
|
pageNr={pageNr}
|
||||||
|
@ -23,7 +23,7 @@ const Leaderboard = (props) => {
|
|||||||
const [scoresSorted, setScoresSorted] = React.useState([]);
|
const [scoresSorted, setScoresSorted] = React.useState([]);
|
||||||
const [idSorted, setIdSorted] = React.useState([]);
|
const [idSorted, setIdSorted] = React.useState([]);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useMemo(() => {
|
||||||
getChallengeLeaderboard(
|
getChallengeLeaderboard(
|
||||||
'leaderboard',
|
'leaderboard',
|
||||||
props.challengeName,
|
props.challengeName,
|
||||||
@ -41,7 +41,8 @@ const Leaderboard = (props) => {
|
|||||||
(elem) => {
|
(elem) => {
|
||||||
let newEntries = entries.slice();
|
let newEntries = entries.slice();
|
||||||
const possibleMetrics = orderKeys(entries[0]).filter(
|
const possibleMetrics = orderKeys(entries[0]).filter(
|
||||||
(key) => !['id', 'submitter', 'when'].includes(key)
|
(key) =>
|
||||||
|
!['id', 'submitter', 'when', 'description', 'times'].includes(key)
|
||||||
);
|
);
|
||||||
let metricIndex = possibleMetrics.indexOf(elem);
|
let metricIndex = possibleMetrics.indexOf(elem);
|
||||||
let newScoresSorted = scoresSorted.slice();
|
let newScoresSorted = scoresSorted.slice();
|
||||||
|
@ -14,7 +14,7 @@ const orderKeys = (elem) => {
|
|||||||
result = result.concat(dev0keys);
|
result = result.concat(dev0keys);
|
||||||
result = result.concat(dev1keys);
|
result = result.concat(dev1keys);
|
||||||
result = result.concat(testAkeys);
|
result = result.concat(testAkeys);
|
||||||
result.push('entries', 'when');
|
result.push('times', 'when');
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user