Skip to content

Assign entries for voting #2889

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

Merged
merged 12 commits into from
Apr 6, 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
1 change: 1 addition & 0 deletions src/commons/assessment/AssessmentTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export type AssessmentOverview = {
isPublished?: boolean;
hasVotingFeatures: boolean;
hasTokenCounter?: boolean;
isVotingPublished?: boolean;
maxXp: number;
earlySubmissionXp: number;
number?: string; // For mission control
Expand Down
23 changes: 23 additions & 0 deletions src/commons/sagas/BackendSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
GradingQuestion
} from '../../features/grading/GradingTypes';
import {
ASSIGN_ENTRIES_FOR_VOTING,
CHANGE_DATE_ASSESSMENT,
CHANGE_TEAM_SIZE_ASSESSMENT,
CONFIGURE_ASSESSMENT,
Expand Down Expand Up @@ -1386,6 +1387,28 @@ function* BackendSaga(): SagaIterator {
yield call(showSuccessMessage, 'Updated successfully!', 1000);
}
);

yield takeEvery(
ASSIGN_ENTRIES_FOR_VOTING,
function* (action: ReturnType<typeof actions.assignEntriesForVoting>): any {
const tokens: Tokens = yield selectTokens();
const id = action.payload.id;

const resp: Response | null = yield updateAssessment(
id,
{
assignEntriesForVoting: true
},
tokens
);
if (!resp || !resp.ok) {
return yield handleResponseError(resp);
}

yield put(actions.fetchAssessmentOverviews());
yield call(showSuccessMessage, 'Updated successfully!', 1000);
}
);
}

function* handleReautogradeResponse(resp: Response | null): any {
Expand Down
1 change: 1 addition & 0 deletions src/commons/sagas/RequestsSaga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,7 @@ export const updateAssessment = async (
maxTeamSize?: number;
hasTokenCounter?: boolean;
hasVotingFeatures?: boolean;
assignEntriesForVoting?: boolean;
},
tokens: Tokens
): Promise<Response | null> => {
Expand Down
5 changes: 5 additions & 0 deletions src/features/groundControl/GroundControlActions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createAction } from '@reduxjs/toolkit';

import {
ASSIGN_ENTRIES_FOR_VOTING,
CHANGE_DATE_ASSESSMENT,
CHANGE_TEAM_SIZE_ASSESSMENT,
CONFIGURE_ASSESSMENT,
Expand Down Expand Up @@ -39,3 +40,7 @@ export const configureAssessment = createAction(
payload: { id, hasVotingFeatures, hasTokenCounter }
})
);

export const assignEntriesForVoting = createAction(ASSIGN_ENTRIES_FOR_VOTING, (id: number) => ({
payload: { id }
}));
1 change: 1 addition & 0 deletions src/features/groundControl/GroundControlTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export const DELETE_ASSESSMENT = 'DELETE_ASSESSMENT';
export const PUBLISH_ASSESSMENT = 'PUBLISH_ASSESSMENT';
export const UPLOAD_ASSESSMENT = 'UPLOAD_ASSESSMENT';
export const CONFIGURE_ASSESSMENT = 'CONFIGURE_ASSESSMENT';
export const ASSIGN_ENTRIES_FOR_VOTING = 'ASSIGN_ENTRIES_FOR_VOTING';
4 changes: 3 additions & 1 deletion src/pages/academy/groundControl/GroundControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type DispatchProps = {
hasVotingFeatures: boolean,
hasTokenCounter: boolean
) => void;
handleAssignEntriesForVoting: (id: number) => void;
handleFetchCourseConfigs: () => void;
};

Expand Down Expand Up @@ -163,7 +164,8 @@ const GroundControl: React.FC<Props> = props => {
field: 'placeholderConfigure' as any,
cellRenderer: ConfigureCell,
cellRendererParams: {
handleConfigureAssessment: props.handleConfigureAssessment
handleConfigureAssessment: props.handleConfigureAssessment,
handleAssignEntriesForVoting: props.handleAssignEntriesForVoting
},
width: 80,
filter: false,
Expand Down
4 changes: 3 additions & 1 deletion src/pages/academy/groundControl/GroundControlContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '../../../commons/application/actions/SessionActions';
import { OverallState } from '../../../commons/application/ApplicationTypes';
import {
assignEntriesForVoting,
changeDateAssessment,
changeTeamSizeAssessment,
configureAssessment,
Expand All @@ -28,7 +29,8 @@ const mapDispatchToProps: MapDispatchToProps<DispatchProps, {}> = (dispatch: Dis
handleUploadAssessment: uploadAssessment,
handlePublishAssessment: publishAssessment,
handleFetchCourseConfigs: fetchCourseConfig,
handleConfigureAssessment: configureAssessment
handleConfigureAssessment: configureAssessment,
handleAssignEntriesForVoting: assignEntriesForVoting
},
dispatch
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,40 @@ import React, { useCallback, useState } from 'react';

import { AssessmentOverview } from '../../../../commons/assessment/AssessmentTypes';
import ControlButton from '../../../../commons/ControlButton';
import AssignEntriesButton from './configureControls/AssignEntriesButton';

type Props = {
handleConfigureAssessment: (
id: number,
hasVotingFeatures: boolean,
hasTokenCounter: boolean
) => void;
handleAssignEntriesForVoting: (id: number) => void;
data: AssessmentOverview;
};

const ConfigureCell: React.FC<Props> = ({ handleConfigureAssessment, data }) => {
const ConfigureCell: React.FC<Props> = ({
handleConfigureAssessment,
handleAssignEntriesForVoting,
data
}) => {
const [isDialogOpen, setDialogState] = useState(false);
const [hasVotingFeatures, setHasVotingFeatures] = useState(!!data.hasVotingFeatures);
const [hasTokenCounter, setHasTokenCounter] = useState(!!data.hasTokenCounter);
const [isTeamAssessment, setIsTeamAssessment] = useState(false);
const [isVotingPublished] = useState(!!data.isVotingPublished);

const handleOpenDialog = useCallback(() => setDialogState(true), []);
const handleCloseDialog = useCallback(() => setDialogState(false), []);

// Updates assessment overview with changes to hasVotingFeatures and hasTokenCounter
const handleConfigure = useCallback(() => {
const { id } = data;
handleConfigureAssessment(id, hasVotingFeatures, hasTokenCounter);
handleCloseDialog();
}, [data, handleCloseDialog, handleConfigureAssessment, hasTokenCounter, hasVotingFeatures]);

// Toggles in configuration pannel
const toggleHasTokenCounter = useCallback(() => setHasTokenCounter(prev => !prev), []);
const toggleVotingFeatures = useCallback(() => setHasVotingFeatures(prev => !prev), []);
const toggleIsTeamAssessment = useCallback(() => setIsTeamAssessment(prev => !prev), []);
Expand Down Expand Up @@ -117,11 +126,10 @@ const ConfigureCell: React.FC<Props> = ({ handleConfigureAssessment, data }) =>
label="Export Score Leaderboard (Coming soon!)"
/>
</div>
<Switch
className="publish-voting"
disabled={true}
inline
label="Publish Voting (Coming soon!)"
<AssignEntriesButton
handleAssignEntriesForVoting={handleAssignEntriesForVoting}
assessmentId={data.id}
isVotingPublished={isVotingPublished}
/>
</div>
</Collapse>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { Button, ButtonGroup, Icon } from '@blueprintjs/core';
import { IconNames, InfoSign } from '@blueprintjs/icons';
import { useCallback, useState } from 'react';
import ControlButton from 'src/commons/ControlButton';
import classes from 'src/styles/ConfigureControls.module.scss';

type Props = {
handleAssignEntriesForVoting: (id: number) => void;
assessmentId: number;
isVotingPublished: boolean;
};

const AssignEntriesButton: React.FC<Props> = ({
handleAssignEntriesForVoting,
assessmentId,
isVotingPublished
}) => {
const [confirmAssignEntries, setConfirmAssignEntries] = useState(false);

// OnClick and Handler functions for confirmation warnings when assigning entries for voting
const onAssignClick = useCallback(() => setConfirmAssignEntries(true), []);
const handleConfirmAssign = useCallback(() => {
handleAssignEntriesForVoting(assessmentId);
}, [assessmentId, handleAssignEntriesForVoting]);
const handleCancelAssign = useCallback(() => setConfirmAssignEntries(false), []);

return (
<>
<div className={classes['current-voting-status']}>
<InfoSign />
<p className={classes['voting-status-text']}>
Current Voting Status: Entries have {!isVotingPublished && <b>not </b>} been assigned
</p>
</div>
{!confirmAssignEntries ? (
<div className={'control-button-container'}>
<ControlButton
icon={IconNames.RESET}
onClick={onAssignClick}
label={`${!isVotingPublished ? 'Assign' : 'Reassign'} entries for voting`}
/>
</div>
) : (
<div className={classes['confirm-assign-voting']}>
<Icon icon="reset" />
<p className={classes['confirm-assign-text']}>
Are you sure you want to <b>{isVotingPublished ? 're-assign' : 'assign'} entries?</b>
</p>
<ButtonGroup>
<Button small intent="success" onClick={handleConfirmAssign}>
Assign
</Button>
<Button small intent="danger" onClick={handleCancelAssign}>
Cancel
</Button>
</ButtonGroup>
</div>
)}
{isVotingPublished && (
<p className={classes['reassign-voting-warning']}>
<b>All existing votes</b> will be <b>deleted</b> upon reassigning entries!
</p>
)}
</>
);
};

export default AssignEntriesButton;
22 changes: 22 additions & 0 deletions src/styles/ConfigureControls.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* Container for warnings upon clicking assign entries button */
.reassign-voting-warning {
font-size: 11px;
margin-left: 38px;
}

.confirm-assign-voting,
.current-voting-status {
max-height: 30px;
display: flex;
align-items: center;
gap: 6px;
margin-left: 15px;

.confirm-assign-text {
margin-top: 9px;
}

.voting-status-text {
margin-top: 10px;
}
}
4 changes: 0 additions & 4 deletions src/styles/_groundcontrol.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,6 @@
display: flex;
margin-left: 5px;
}

.publish-voting {
margin-top: 5px;
}
}

.numeric-input-container {
Expand Down