From adbc8ecb21cfb7aab02b232cf35b1bb6e0c96654 Mon Sep 17 00:00:00 2001 From: Dima Alipov Date: Mon, 25 Mar 2024 21:35:57 +0200 Subject: [PATCH] fix: incorrect field validation on the grading page --- .../assignments/AssignmentItem.jsx | 17 +++++++++-------- .../assignment-section/utils/validation.js | 12 +++++++++--- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/grading-settings/assignment-section/assignments/AssignmentItem.jsx b/src/grading-settings/assignment-section/assignments/AssignmentItem.jsx index 68438c3adf..2b7fe5fc68 100644 --- a/src/grading-settings/assignment-section/assignments/AssignmentItem.jsx +++ b/src/grading-settings/assignment-section/assignments/AssignmentItem.jsx @@ -42,14 +42,15 @@ const AssignmentItem = ({ {descriptions} {errorEffort && ( - - {errorMsg} - - )} - {gradeField?.dropCount !== 0 && gradeField?.dropCount > gradeField?.minCount && ( - - {secondErrorMsg} - + gradeField?.dropCount ? ( + + {gradeField?.dropCount !== 0 && gradeField?.dropCount >= gradeField?.minCount ? secondErrorMsg : errorMsg} + + ) : ( + + {errorMsg} + + ) )} diff --git a/src/grading-settings/assignment-section/utils/validation.js b/src/grading-settings/assignment-section/utils/validation.js index 523a1c3806..9711d21719 100644 --- a/src/grading-settings/assignment-section/utils/validation.js +++ b/src/grading-settings/assignment-section/utils/validation.js @@ -51,10 +51,11 @@ export const validationAssignmentFields = ( assignmentDropCount, ) => { const courseGradingTypes = courseGraders?.map(grade => grade.type); + const minCountValue = courseGraders?.find(grade => grade.id === assignmentId).minCount; switch (assignmentName) { case assignmentType: - if (assignmentValue === '') { + if (assignmentValue.trim() === '') { updateAssignmentErrorList(assignmentName, assignmentId, setErrorList, setShowSavePrompt); return; } @@ -77,7 +78,7 @@ export const validationAssignmentFields = ( ); break; case weightOfTotalGrade: - if (assignmentValue < 0 || assignmentValue > 100 || assignmentValue === '-0') { + if (assignmentValue === '' || assignmentValue < 0 || assignmentValue > 100 || assignmentValue === '-0') { updateAssignmentErrorList( assignmentName, assignmentId, @@ -113,7 +114,12 @@ export const validationAssignmentFields = ( ); break; case assignmentDropCount: - if (assignmentValue < 0 || assignmentValue === '' || assignmentValue === '-0') { + if ( + assignmentValue >= minCountValue + || assignmentValue < 0 + || assignmentValue === '' + || assignmentValue === '-0' + ) { updateAssignmentErrorList( assignmentName, assignmentId,