Skip to content

Commit ce8bf1c

Browse files
committed
Refactoring and fixing sorting issues.
1 parent 6a635c8 commit ce8bf1c

File tree

6 files changed

+67
-65
lines changed

6 files changed

+67
-65
lines changed

src/components/Assignments/Assignment/AssignmentSync/AssignmentSync.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Row, Col } from 'react-bootstrap';
66
import Button from '../../../widgets/TheButton';
77
import Callout from '../../../widgets/Callout';
88
import DateTime from '../../../widgets/DateTime';
9-
import { getSyncMessages } from '../assignmentSyncHelper';
9+
import { getSyncMessages } from '../../../helpers/assignments';
1010

1111
const AssignmentSync = ({ syncInfo, exerciseSync }) => {
1212
const messages = getSyncMessages(syncInfo);

src/components/Assignments/Assignment/AssignmentSyncIcon/AssignmentSyncIcon.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { OverlayTrigger, Popover } from 'react-bootstrap';
55

66
import DateTime from '../../../widgets/DateTime';
77
import { WarningIcon } from '../../../icons';
8-
import { isUpToDate } from '../assignmentSyncHelper';
8+
import { isUpToDate } from '../../../helpers/assignments';
99

1010
const AssignmentSyncIcon = ({ id, syncInfo, ...props }) => {
1111
return !isUpToDate(syncInfo) ? (

src/components/Assignments/Assignment/AssignmentTableRow/AssignmentTableRow.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ const AssignmentTableRow = ({
7272
)}
7373
<MaybeBonusAssignmentIcon gapLeft id={id} isBonus={isBonus} />
7474

75-
{exerciseSynchronizationInfo && <AssignmentSyncIcon id={id} syncInfo={exerciseSynchronizationInfo} gapLeft />}
75+
{(permissionHints.update || permissionHints.viewAssignmentSolutions) && exerciseSynchronizationInfo && (
76+
<AssignmentSyncIcon id={id} syncInfo={exerciseSynchronizationInfo} gapLeft />
77+
)}
7678
</td>
7779

7880
{showNames && (

src/components/Assignments/Assignment/AssignmentsTable/AssignmentsTable.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ import AssignmentTableRow, { LoadingAssignmentTableRow } from '../AssignmentTabl
1111
import CommentThreadContainer from '../../../../containers/CommentThreadContainer';
1212
import Icon, { DeleteIcon, InvertIcon, LoadingIcon, RefreshIcon, SquareIcon, VisibleIcon } from '../../../icons';
1313
import Button, { TheButtonGroup } from '../../../widgets/TheButton';
14-
import { compareAssignmentsReverted, isBeforeDeadline } from '../../../helpers/assignments';
14+
import { compareAssignmentsReverted, isBeforeDeadline, isUpToDate } from '../../../helpers/assignments';
1515
import { LocalizedExerciseName } from '../../../helpers/LocalizedNames';
1616
import { EMPTY_LIST, EMPTY_OBJ, EMPTY_ARRAY } from '../../../../helpers/common';
1717
import { prepareInitialValues, transformSubmittedData } from '../../../forms/EditAssignmentForm';
18-
import { isUpToDate } from '../assignmentSyncHelper';
1918

2019
const fetchAssignmentStatus = (statuses, assignmentId) => {
2120
const assignStatus =

src/components/Assignments/Assignment/assignmentSyncHelper.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

src/components/helpers/assignments.js

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,62 @@
1+
import React from 'react';
2+
import { FormattedMessage } from 'react-intl';
3+
import { defaultMemoize } from 'reselect';
4+
import Explanation from '../widgets/Explanation';
5+
6+
const syncMessages = {
7+
supplementaryFiles: (
8+
<FormattedMessage id="app.assignment.syncSupplementaryFiles" defaultMessage="Supplementary files" />
9+
),
10+
attachmentFiles: <FormattedMessage id="app.assignment.syncAttachmentFiles" defaultMessage="Text attachment files" />,
11+
exerciseTests: <FormattedMessage id="app.assignment.syncExerciseTests" defaultMessage="Exercise tests" />,
12+
localizedTexts: <FormattedMessage id="app.assignment.syncLocalizedTexts" defaultMessage="Localized texts" />,
13+
configurationType: (
14+
<FormattedMessage
15+
id="app.assignment.syncConfigurationType"
16+
defaultMessage="Configuration was switched to advanced mode"
17+
/>
18+
),
19+
scoreConfig: <FormattedMessage id="app.assignment.syncScoreConfig" defaultMessage="Score configuration" />,
20+
exerciseConfig: <FormattedMessage id="app.assignment.syncExerciseConfig" defaultMessage="Exercise configuration" />,
21+
runtimeEnvironments: (
22+
<FormattedMessage id="app.assignment.syncRuntimeEnvironments" defaultMessage="Selection of runtime environments" />
23+
),
24+
exerciseEnvironmentConfigs: (
25+
<FormattedMessage id="app.assignment.syncExerciseEnvironmentConfigs" defaultMessage="Environment configuration" />
26+
),
27+
hardwareGroups: <FormattedMessage id="app.assignment.syncHardwareGroups" defaultMessage="Hardware groups" />,
28+
limits: <FormattedMessage id="app.assignment.syncLimits" defaultMessage="Limits" />,
29+
mergeJudgeLogs: (
30+
<span>
31+
<FormattedMessage id="app.assignment.syncMergeJudgeLogs" defaultMessage="Judge logs merge flag" />
32+
<Explanation id="syncMergeJudgeLogs">
33+
<FormattedMessage
34+
id="app.exercise.mergeJudgeLogsExplanation"
35+
defaultMessage="The merge flag indicates whether primary (stdout) and secondary (stderr) judge logs are are concatenated in one log (which should be default for built-in judges). If the logs are separated, the visibility of each part may be controlled idividually in assignments. That might be helpful if you need to pass two separate logs from a custom judge (e.g., one is for students and one is for supervisors)."
36+
/>
37+
</Explanation>
38+
</span>
39+
),
40+
};
41+
42+
export const getSyncMessages = syncInfo => {
43+
const res = [];
44+
for (const field in syncMessages) {
45+
if (!syncInfo[field]) {
46+
continue;
47+
}
48+
49+
if (!syncInfo[field].upToDate) {
50+
res.push(<li key={field}>{syncMessages[field]}</li>);
51+
}
52+
}
53+
return res;
54+
};
55+
56+
export const isUpToDate = defaultMemoize(syncInfo =>
57+
Object.keys(syncMessages).every(field => syncInfo[field] && syncInfo[field].upToDate)
58+
);
59+
160
export const compareAssignments = (a, b) => {
261
// first compare by deadline
362
if (a.firstDeadline < b.firstDeadline) {
@@ -19,8 +78,8 @@ export const compareAssignments = (a, b) => {
1978
// if second deadlines are equal, continue
2079
}
2180

22-
// none of them have second deadline or they are queal, compare creation times
23-
return b.createdAt - a.createdAt;
81+
// none of them have second deadline or they are equal, compare creation times
82+
return b.createdAt - a.createdAt || a.id.localeCompare(b.id);
2483
}
2584
} else {
2685
return 1;

0 commit comments

Comments
 (0)