Skip to content
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 @@ -48,7 +48,7 @@ export const AssignmentReadingsTable = ({
const getNumQuestionsOrDefault = (numQuestions: Nullable<number>): number => {
const defaultNumQuestions = 1;

return numQuestions ?? defaultNumQuestions;
return Math.max(numQuestions ?? 0, defaultNumQuestions);
};

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,20 @@ interface ActivitiesRequiredCellProps {
itemId: number;
}

const MIN_ACTIVITIES = 1;

export const ActivitiesRequiredCell = ({
value,
exercise,
onUpdate,
itemId
}: ActivitiesRequiredCellProps) => {
const { showToast } = useToastContext();
const [currentValue, setCurrentValue] = useState(value || 0);
const [currentValue, setCurrentValue] = useState(value || MIN_ACTIVITIES);

const handleValueChange = (newValue: number | null | undefined) => {
const numValue = newValue ?? 0;
const activityCount = exercise.numQuestions || 0;
const numValue = newValue ?? MIN_ACTIVITIES;
const activityCount = Math.max(exercise.numQuestions ?? 0, MIN_ACTIVITIES);

if (numValue > activityCount) {
showToast({
Expand All @@ -31,7 +33,7 @@ export const ActivitiesRequiredCell = ({
detail: `# required (${numValue}) must not exceed the activity count (${activityCount}).`
});

setCurrentValue(value || 0);
setCurrentValue(value || MIN_ACTIVITIES);
return;
}

Expand All @@ -43,8 +45,8 @@ export const ActivitiesRequiredCell = ({
<InputNumber
value={currentValue}
onValueChange={(e) => handleValueChange(e.value)}
min={0}
max={exercise.numQuestions || 0}
min={MIN_ACTIVITIES}
max={Math.max(exercise.numQuestions ?? 0, MIN_ACTIVITIES)}
showButtons={false}
style={{
width: "100%",
Expand Down
4 changes: 2 additions & 2 deletions bases/rsptx/assignment_server_api/routers/instructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,9 @@ async def get_assignment_questions(

if aq["reading_assignment"] == True: # noqa: E712
try:
aq["numQuestions"] = countd[q["chapter"]][q["subchapter"]]
aq["numQuestions"] = max(countd[q["chapter"]][q["subchapter"]], 1)
except KeyError:
aq["numQuestions"] = 0
aq["numQuestions"] = 1

# augment the assignment question with additional question data
aq["name"] = q["name"]
Expand Down
Loading