-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
patch score in backend when edited in the frontend and i18n for page #355
Changes from 5 commits
853d5f6
85ea4e8
9e53391
33bc450
a2fbc0d
f74ea45
a41ace8
00428ad
d845bb8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
{ | ||
"submissionOverview": { | ||
"submissionOverviewHeader": "Project status overview", | ||
"downloadButton": "DOWNLOAD ALL PROJECTS" | ||
"downloadButton": "DOWNLOAD ALL PROJECTS", | ||
"scoreError": "Grade must be between 0 and 20", | ||
"submissionID": "Submission ID", | ||
"student": "Student", | ||
"grading": "Grading", | ||
"status": "Status", | ||
"download": "Download" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"submissionOverview": { | ||
"submissionOverviewHeader": "Project status overzicht", | ||
"downloadButton": "DOWNLOAD ALLE PROJECTEN", | ||
"scoreError": "Score moeten tussen 0 en 20 liggen", | ||
"submissionID": "Indiening ID", | ||
"student": "Student", | ||
"grading": "Score", | ||
"status": "Status", | ||
"download": "Download" | ||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { DataGrid, GridColDef, GridRenderCellParams } from "@mui/x-data-grid"; | ||
import {DataGrid, GridRenderCellParams} from "@mui/x-data-grid"; | ||
import { Box, IconButton } from "@mui/material"; | ||
import CheckCircleIcon from "@mui/icons-material/CheckCircle"; | ||
import { green, red } from "@mui/material/colors"; | ||
|
@@ -7,6 +7,8 @@ import DownloadIcon from "@mui/icons-material/Download"; | |
import download from "downloadjs"; | ||
import { authenticatedFetch } from "../../utils/authenticated-fetch"; | ||
import { Submission } from "../../types/submission"; | ||
import {useTranslation} from "react-i18next"; | ||
import {TFunction} from "i18next"; | ||
|
||
const APIURL = import.meta.env.VITE_APP_API_HOST; | ||
|
||
|
@@ -27,57 +29,88 @@ const fetchSubmissionsFromUser = async (submission_id: string) => { | |
}); | ||
}; | ||
|
||
const columns: GridColDef<Submission>[] = [ | ||
{ field: "submission_id", headerName: "Submission ID", flex: 0.4 }, | ||
{ field: "display_name", headerName: "Student", width: 160, flex: 0.4 }, | ||
{ | ||
field: "grading", | ||
headerName: "Grading", | ||
editable: true, | ||
flex: 0.2, | ||
}, | ||
{ | ||
field: "submission_status", | ||
headerName: "Status", | ||
renderCell: (params: GridRenderCellParams<Submission>) => ( | ||
<> | ||
{params.row.submission_status === "SUCCESS" ? ( | ||
<CheckCircleIcon sx={{ color: green[500] }} /> | ||
) : ( | ||
<CancelIcon sx={{ color: red[500] }} /> | ||
)} | ||
</> | ||
), | ||
}, | ||
{ | ||
field: "submission_path", | ||
headerName: "Download", | ||
renderCell: (params: GridRenderCellParams<Submission>) => ( | ||
<IconButton | ||
onClick={() => fetchSubmissionsFromUser(params.row.submission_id)} | ||
> | ||
<DownloadIcon /> | ||
</IconButton> | ||
), | ||
}, | ||
]; | ||
const editGrade = (submission: Submission, oldSubmission: Submission, errorMessage: string) => { | ||
const submission_id = submission.submission_id; | ||
const newGrade = submission.grading; | ||
|
||
if (newGrade < 0 || newGrade > 20) { | ||
alert(errorMessage); | ||
return oldSubmission; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this get caught anywhere so people know that the submission wasn't changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What he said There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
|
||
const formData = new FormData(); | ||
formData.append('grading', newGrade.toString()); | ||
|
||
authenticatedFetch(`${APIURL}/submissions/${submission_id}`, { | ||
method: "PATCH", | ||
body: formData | ||
}) | ||
|
||
return submission | ||
}; | ||
|
||
const getTranslatedRows = (t: TFunction<string, string>) => { | ||
return [ | ||
{ field: "submission_id", headerName: t("submissionID"), flex: 0.4, editable: false }, | ||
{ field: "display_name", headerName: t("student"), width: 160, flex: 0.4, editable: false }, | ||
{ | ||
field: "grading", | ||
headerName: t("grading"), | ||
editable: true, | ||
flex: 0.2, | ||
}, | ||
{ | ||
field: "submission_status", | ||
headerName: t("status"), | ||
editable: false, | ||
renderCell: (params: GridRenderCellParams<Submission>) => ( | ||
<> | ||
{params.row.submission_status === "SUCCESS" ? ( | ||
<CheckCircleIcon sx={{ color: green[500] }} /> | ||
) : ( | ||
<CancelIcon sx={{ color: red[500] }} /> | ||
)} | ||
</> | ||
), | ||
}, | ||
{ | ||
field: "submission_path", | ||
headerName: t("download"), | ||
renderCell: (params: GridRenderCellParams<Submission>) => ( | ||
<IconButton | ||
onClick={() => fetchSubmissionsFromUser(params.row.submission_id)} | ||
> | ||
<DownloadIcon /> | ||
</IconButton> | ||
), | ||
}, | ||
]; | ||
} | ||
|
||
/** | ||
* @returns the datagrid for displaying submissiosn | ||
* @returns the datagrid for displaying submissions | ||
*/ | ||
export default function ProjectSubmissionsOverviewDatagrid({ | ||
submissions, | ||
}: { | ||
submissions: Submission[]; | ||
}) { | ||
|
||
const { t } = useTranslation('submissionOverview', { keyPrefix: 'submissionOverview' }); | ||
|
||
const errorMsg = t("scoreError"); | ||
|
||
return ( | ||
<Box my={4}> | ||
<DataGrid | ||
getRowId={getRowId} | ||
rows={submissions} | ||
columns={columns} | ||
columns={getTranslatedRows(t)} | ||
pageSizeOptions={[20]} | ||
disableRowSelectionOnClick | ||
processRowUpdate={(updatedRow, oldRow) => | ||
editGrade(updatedRow, oldRow, errorMsg) | ||
} | ||
/> | ||
</Box> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,5 @@ export interface Submission { | |
submission_time: string; | ||
submission_status: string; | ||
uid: string; | ||
grading: number; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No using alert
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do i need to use then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f74ea45