Skip to content

Commit

Permalink
fix updating sectionGroup seats
Browse files Browse the repository at this point in the history
  • Loading branch information
jaroldwong committed Nov 21, 2024
1 parent ec4ba03 commit 2c158a3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/course/directives/courseTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions app/course/services/courseStateService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 2c158a3

Please sign in to comment.