Skip to content

Commit

Permalink
clean up links to point to specific questions/parts where possible (a…
Browse files Browse the repository at this point in the history
…nd only do the string-interpolation once, to ensure they're all consistent)
  • Loading branch information
Ben Lerner committed Nov 22, 2023
1 parent 99968f7 commit 4ac881f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 29 deletions.
47 changes: 38 additions & 9 deletions app/packs/components/workflows/grading/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,7 @@ const RenderQnumTree : React.FC<{
info: GradingLockInfo[][][],
examId: string,
qpPairs: QPInfo,
RenderItem: React.FC<{ item: GradingLockInfo, examId: string }>,
RenderItem: React.FC<{ item: GradingLockInfo, examId: string, singlePart: boolean }>,
}> = (props) => {
const {
className,
Expand Down Expand Up @@ -1851,7 +1851,7 @@ const CollapsibleQnumTree : React.FC<{
info: GradingLockInfo[][],
examId: string,
multipart: boolean,
RenderItem: React.FC<{ item: GradingLockInfo, examId: string }>,
RenderItem: React.FC<{ item: GradingLockInfo, examId: string, singlePart: boolean }>,
}> = (props) => {
const {
qnum,
Expand Down Expand Up @@ -1889,7 +1889,7 @@ const RenderPnumTree : React.FC<{
info: GradingLockInfo[][],
examId: string,
multipart: boolean,
RenderItem: React.FC<{ item: GradingLockInfo, examId: string }>,
RenderItem: React.FC<{ item: GradingLockInfo, examId: string, singlePart: boolean }>,
}> = (props) => {
const {
className,
Expand All @@ -1906,6 +1906,7 @@ const RenderPnumTree : React.FC<{
key={`reg-${item.registration.id}-q${item.qnum}-p${item.pnum}`}
item={item}
examId={examId}
singlePart
/>
))}
</ul>
Expand All @@ -1932,7 +1933,7 @@ const CollapsiblePnumTree : React.FC<{
pnum: number,
items: GradingLockInfo[],
examId: string,
RenderItem: React.FC<{ item: GradingLockInfo, examId: string }>,
RenderItem: React.FC<{ item: GradingLockInfo, examId: string, singlePart: boolean }>,
}> = (props) => {
const {
pnum,
Expand All @@ -1954,13 +1955,29 @@ const CollapsiblePnumTree : React.FC<{
</span>
<Collapse in={open}>
<ul>
{items.map((item) => <RenderItem key={item.id} item={item} examId={examId} />)}
{items.map((item) => (
<RenderItem
key={item.id}
item={item}
examId={examId}
singlePart={false}
/>
))}
</ul>
</Collapse>
</>
);
};

export function gradingLink(
examId: string,
registrationId: string,
qnum: number,
pnum: number,
): string {
return `/exams/${examId}/grading/${registrationId}/${qnum}/${pnum}`;
}

const RenderLinkToGrading : React.FC<{
item: GradingLockInfo,
examId: string,
Expand All @@ -1978,7 +1995,7 @@ const RenderLinkToGrading : React.FC<{
<Link
className="ml-2"
target="_blank"
to={`/exams/${examId}/grading/${registration.id}/${qnum}/${pnum}`}
to={gradingLink(examId, registration.id, qnum, pnum)}
>
{describeTime(DateTime.fromISO(updatedAt))}
</Link>
Expand All @@ -1987,11 +2004,23 @@ const RenderLinkToGrading : React.FC<{
);
};

export function submissionLink(
examId: string,
registrationId: string,
singlePart: boolean,
qnum: number,
pnum: number,
): string {
const anchor = singlePart ? `question-${qnum}` : `question-${qnum}-part-${pnum}`;
return `/exams/${examId}/submissions/${registrationId}#${anchor}`;
}

const RenderLinkToSubmission : React.FC<{
item: GradingLockInfo,
examId: string,
singlePart: boolean,
}> = (props) => {
const { item, examId } = props;
const { item, examId, singlePart } = props;
const {
registration,
updatedAt,
Expand All @@ -2005,7 +2034,7 @@ const RenderLinkToSubmission : React.FC<{
<Link
className="ml-2"
target="_blank"
to={`/exams/${examId}/submissions/${registration.id}`}
to={submissionLink(examId, registration.id, singlePart, qnum, pnum)}
>
<span className="mr-2">{describeTime(DateTime.fromISO(updatedAt))}</span>
</Link>
Expand Down Expand Up @@ -2146,7 +2175,7 @@ const BeginGradingButton: React.FC<{
qnum,
pnum,
} = gradeNext;
history.push(`/exams/${examId}/grading/${registrationId}/${qnum}/${pnum}`);
history.push(gradingLink(examId, registrationId, qnum, pnum));
},
onError: (err) => {
if (err.cause?.[0]?.extensions && !err.cause[0].extensions.anyRemaining) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from 'react-bootstrap';
import { Link } from 'react-router-dom';
import Icon from '@student/exams/show/components/Icon';
import { iconForPoints, variantForPoints } from '@hourglass/workflows/grading';
import { iconForPoints, submissionLink, variantForPoints } from '@hourglass/workflows/grading';
import { pluralize } from '@hourglass/common/helpers';
import { IconType } from 'react-icons';
import { RiMessage2Line } from 'react-icons/ri';
Expand Down Expand Up @@ -62,15 +62,14 @@ export const ShowLinks: React.FC<{
<Modal.Body>
<table>
{comments.map(({ comment, registration }) => {
const anchor = singlePart ? `question-${qnum}` : `question-${qnum}-part-${pnum}`;
const submissionLink = `/exams/${examId}/submissions/${registration.id}#${anchor}`;
const link = submissionLink(examId, registration.id, singlePart, qnum, pnum);
return (
<tr>
<td style={{ whiteSpace: 'nowrap' }} className="pr-3">
<Link
key={comment.id}
target="blank"
to={submissionLink}
to={link}
>
{`${registration.user.displayName}:`}
</Link>
Expand All @@ -79,7 +78,7 @@ export const ShowLinks: React.FC<{
<Link
key={comment.id}
target="blank"
to={submissionLink}
to={link}
>
<Alert
variant={variantForPoints(comment.points)}
Expand Down
28 changes: 13 additions & 15 deletions app/packs/components/workflows/professor/exams/stats/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
XAxis,
YAxis,
} from 'recharts';
import { submissionLink } from '@hourglass/workflows/grading';
import { pluralize } from '@hourglass/common/helpers';
import { QuestionName } from '@student/exams/show/components/ShowQuestion';
import { PartName } from '@student/exams/show/components/Part';
Expand Down Expand Up @@ -303,21 +304,18 @@ const GradingAnomalies: React.FC<{
/>
</b>
<table>
{anomalies.map((a) => {
const anchor = singlePart ? `question-${qnum}` : `question-${qnum}-part-${pnum}`;
return (
<tr>
<Link
key={a.registration.id}
target="blank"
to={`/exams/${examId}/submissions/${a.registration.id}#${anchor}`}
>
{a.registration.user.displayName}
</Link>
{` (${a.scores[qnum][pnum]} / ${pluralize(dbQuestions[qnum].parts[pnum].points, 'point', 'points')})`}
</tr>
);
})}
{anomalies.map((a) => (
<tr>
<Link
key={a.registration.id}
target="blank"
to={submissionLink(examId, a.registration.id, singlePart, qnum, pnum)}
>
{a.registration.user.displayName}
</Link>
{` (${a.scores[qnum][pnum]} / ${pluralize(dbQuestions[qnum].parts[pnum].points, 'point', 'points')})`}
</tr>
))}
</table>
</div>
);
Expand Down

0 comments on commit 4ac881f

Please sign in to comment.