From 2c158a3e03a92c1db7b97094dca6b6652b65a268 Mon Sep 17 00:00:00 2001 From: Jarold Wong Date: Thu, 21 Nov 2024 13:25:47 -0800 Subject: [PATCH] fix updating sectionGroup seats --- app/course/directives/courseTable.js | 12 +++++++++--- .../sectionGroupDetails/sectionGroupDetails.js | 2 ++ app/course/services/courseStateService.js | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/course/directives/courseTable.js b/app/course/directives/courseTable.js index 735d96f7d..f0b2f87bd 100644 --- a/app/course/directives/courseTable.js +++ b/app/course/directives/courseTable.js @@ -511,6 +511,9 @@ let courseTable = function ($rootScope, $timeout, CourseActionCreators, $compile var sectionGroup = _.findWhere(scope.view.state.sectionGroups.list, { courseId: courseId, termCode: termCode }); // eslint-disable-line no-undef var plannedSeats = $el.val() === "" ? null : parseInt($el.val()); + const course = scope.view.state.courses.list[courseId]; + const isNumericSection = isNumber(course.sequencePattern); + if (isNaN(plannedSeats)) { return; } if (sectionGroup) { @@ -525,8 +528,10 @@ let courseTable = function ($rootScope, $timeout, CourseActionCreators, $compile // Save existing sectionGroup sectionGroup.plannedSeats = plannedSeats; - if (plannedSeats >= proposedSectionSeatTotal) { - CourseActionCreators.updateSectionGroup(sectionGroup); + if (!isNumericSection) { + if (plannedSeats >= proposedSectionSeatTotal) { + CourseActionCreators.updateSectionGroup(sectionGroup); + } // Check if any overflowed sections can be updated. If yes, update them. if (currentSectionSeatTotal !== proposedSectionSeatTotal) { @@ -535,10 +540,11 @@ let courseTable = function ($rootScope, $timeout, CourseActionCreators, $compile } // If sequence is numeric sync the seats on the section to the new sectionGroup value - if (sectionGroup.sections.length === 1 && isNumber(sectionGroup.sections[0].sequenceNumber)) { + if (isNumericSection && sectionGroup.sections.length === 1) { let section = scope.view.state.sections.list[sectionGroup.sections[0].id]; section.seats = sectionGroup.plannedSeats; CourseActionCreators.updateSection(section); + CourseActionCreators.updateSectionGroup(sectionGroup); } } else if (plannedSeats) { // Create a new sectionGroup diff --git a/app/course/directives/sectionGroupDetails/sectionGroupDetails.js b/app/course/directives/sectionGroupDetails/sectionGroupDetails.js index 8ff1ae51c..dc9e94063 100644 --- a/app/course/directives/sectionGroupDetails/sectionGroupDetails.js +++ b/app/course/directives/sectionGroupDetails/sectionGroupDetails.js @@ -75,6 +75,8 @@ let sectionGroupDetails = function (CourseActionCreators, Term) { return Number(proposedSectionSeats !== originalSectionSeats) + acc; }, 0); + if (outOfSyncSections === 0) { return; } // prevent extra update on input blur + // sync with sectionGroup if single numeric section if (proposedSections.length === 1 && isNumber(section.sequenceNumber)) { sectionGroup.plannedSeats = section.seats; diff --git a/app/course/services/courseStateService.js b/app/course/services/courseStateService.js index 910c8646e..11c23157b 100644 --- a/app/course/services/courseStateService.js +++ b/app/course/services/courseStateService.js @@ -298,6 +298,7 @@ class CourseStateService { return sectionGroups; case ActionTypes.UPDATE_SECTION: var sectionGroup = sectionGroups.selectedSectionGroup || sectionGroups.list[action.payload.section.sectionGroupId]; + sectionGroup.sections = sectionGroup.sections.map(slotSection => slotSection.id === action.payload.section.id ? action.payload.section : slotSection); sectionGroup.requiresAttention = action.payload.requiresAttention; return sectionGroups; case ActionTypes.REMOVE_SECTION: