Skip to content
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

Cancel button + noscore not in edit #292

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ const DockerFormTab: FC<{ form: FormInstance }> = ({ form }) => {

if (withTemplate) {
switchClassName += ' template-switch-active'
scriptPlaceholder = "bash /shared/input/helloworld.sh > \"/shared/output/helloWorldTest\n"+
"bash /shared/input/helloug.sh > \"/shared/output/helloUGent\n"
scriptPlaceholder = "bash /shared/input/helloworld.sh > \"/shared/output/helloWorldTest\"\n"+
"bash /shared/input/helloug.sh > \"/shared/output/helloUGent\"\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dit lijkt mij per ongeluk aangepast? Want dit heeft niet echt iets te maken met de cancel knop en de "No score" in de submission feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah da was gwn nog een foutje in de placeholder vd template. Kdacht da rechtstreeks op frontend gepushed had ma blijkbaar zat ik nog op deze branch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok dan is alles goed, ik zal mergen

} else {
switchClassName += ' template-switch-inactive'
scriptPlaceholder = "output=$(bash /shared/input/helloworld.sh)\n"+
Expand Down
55 changes: 41 additions & 14 deletions frontend/src/pages/project/components/SubmissionsTable.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Input, List, Table, Tooltip, Typography } from "antd";
import { Button, Input, List, Space, Table, Tooltip, Typography } from "antd";
import { FC, useMemo, useState } from "react";
import { ProjectSubmissionsType } from "./SubmissionsTab";
import { TableProps } from "antd/lib";
Expand Down Expand Up @@ -27,7 +27,8 @@ const SubmissionsTable: FC<{ submissions: ProjectSubmissionsType[] | null; onCha
const { message } = useAppApi();
const API = useApi();
const [editingFeedback, setEditingFeedback] = useState<{ [key: number]: string }>({});
const [isEditing, setIsEditing] = useState<{ [key: number]: boolean }>({});
const [isEditingFeedback, setIsEditingFeedback] = useState<{ [key: number]: boolean }>({});
const [oldFeedback, setOldFeedback] = useState<{ [key: number]: string }>({});

const updateTable = async (groupId: number, feedback: Omit<PUT_Requests[ApiRoutes.PROJECT_SCORE], "projectId" | "groupId">, usePost: boolean) => {
if (!projectId || submissions === null || !groupId) return console.error("No projectId or submissions or groupId found");
Expand Down Expand Up @@ -72,21 +73,21 @@ const SubmissionsTable: FC<{ submissions: ProjectSubmissionsType[] | null; onCha
else score = parseFloat(scoreStr);
if (isNaN(score as number)) score = null;
if (score !== null && score > project.maxScore) return message.error(t("project.scoreTooHigh"));
await updateTable(s.group.groupId, { score: score || null, feedback: s.feedback?.feedback ?? "" }, s.feedback === null);
await updateTable(s.group.groupId, { score: score ?? null, feedback: s.feedback?.feedback ?? "" }, s.feedback === null);
};

const updateFeedback = async (groupId: number) => {
const feedback = editingFeedback[groupId];
if (feedback !== undefined) {
const s = submissions?.find(s => s.group.groupId === groupId)
await updateTable(groupId, { feedback, score: s?.feedback?.score || null }, s?.feedback === null);
await updateTable(groupId, { feedback, score: s?.feedback?.score ?? null }, s?.feedback === null);
setEditingFeedback((prev) => {
const newState = { ...prev };
delete newState[groupId];
return newState;
});
setIsEditing((prev) => ({ ...prev, [groupId]: false }));
}
setIsEditingFeedback((prev) => ({ ...prev, [groupId]: false }));
};

const downloadFile = async (route: ApiRoutes.SUBMISSION_FILE | ApiRoutes.SUBMISSION_ARTIFACT, filename: string) => {
Expand Down Expand Up @@ -120,9 +121,13 @@ const SubmissionsTable: FC<{ submissions: ProjectSubmissionsType[] | null; onCha
};

const handleEditFeedback = (groupId: number) => {
setIsEditing((prev) => ({ ...prev, [groupId]: true }));
setIsEditingFeedback((prev) => {
setOldFeedback((prev) => ({ ...prev, [groupId]: editingFeedback[groupId] }));
return { ...prev, [groupId]: true }
})
};


const columns: TableProps<ProjectSubmissionsType>["columns"] = useMemo(() => {
const cols: TableProps<ProjectSubmissionsType>["columns"] = [
{
Expand Down Expand Up @@ -173,7 +178,11 @@ const SubmissionsTable: FC<{ submissions: ProjectSubmissionsType[] | null; onCha
render: (s: ProjectSubmissionsType) => (
<Typography.Text
type={!s.feedback || s.feedback.score === null ? "secondary" : !project || s.feedback.score < project.maxScore! / 2 ? "danger" : undefined}
editable={{ onChange: (e) => updateScore(s, e), maxLength: 10 }}
editable={{
onChange: (e) => updateScore(s, e),
maxLength: 10,
text: s.feedback?.score ? s.feedback?.score?.toString() : "",
}}
>
{s.feedback?.score ?? t("project.noScoreLabel")}
</Typography.Text>
Expand Down Expand Up @@ -208,7 +217,7 @@ const SubmissionsTable: FC<{ submissions: ProjectSubmissionsType[] | null; onCha
<Typography.Text strong>{t("project.feedback")}:</Typography.Text>
<br/>
<br/>
{isEditing[g.group.groupId] ? (
{isEditingFeedback[g.group.groupId] ? (
<>
<Input.TextArea
autoSize={{ minRows: 3, maxRows: 5 }}
Expand All @@ -220,13 +229,31 @@ const SubmissionsTable: FC<{ submissions: ProjectSubmissionsType[] | null; onCha
}))
}
/>
<Space>
<Button
style={{ float: "right", marginTop: "0.5rem" }}
onClick={() => updateFeedback(g.group.groupId)}
color="primary"
icon={<SaveOutlined />}
title={t("project.saveFeedback")}
>
</Button>

<Button
style={{float: "right", marginTop: "0.5rem"}}
onClick={() => updateFeedback(g.group.groupId)}
color="primary"
icon={<SaveOutlined/>}>
</Button>
<Button
style={{float: "right", marginTop: "0.5rem", marginRight: "0.5rem"}}
onClick={() => setIsEditingFeedback((prev) => {
setEditingFeedback((prev) => {
const feedback = oldFeedback[g.group.groupId];
return { ...prev, [g.group.groupId]: feedback };
})
return { ...prev, [g.group.groupId]: false }
})}
color="primary"
danger={true}
>
{t("cancel")}
</Button>
</Space>
</>
) : (
<>
Expand Down
Loading