Skip to content

Commit

Permalink
fix(Manage Students): Fix UI not updating immediately sometimes
Browse files Browse the repository at this point in the history
- When creating a new team
- When moving a team to another period
- When moving a student to another team

#1440
  • Loading branch information
geoffreykwan committed Oct 6, 2023
1 parent 44a0995 commit 0ebdb8d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class ConfigServiceStub {
getAllUsersInPeriod() {
return [{ name: 'c' }, { name: 'b' }, { name: 'a' }];
}
retrieveConfig() {}
retrieveConfig() {
return of({});
}
}
class TeacherDataServiceStub {
getCurrentPeriodId() {
Expand All @@ -33,7 +35,9 @@ class TeacherDataServiceStub {
}
class WorkgroupServiceStub {
isUserInAnyWorkgroup() {}
createWorkgroup() {}
createWorkgroup() {
return of(10);
}
}
let component: AddTeamDialogComponent;
let fixture: ComponentFixture<AddTeamDialogComponent>;
Expand Down Expand Up @@ -126,8 +130,7 @@ function createTeam() {
});
it('should not ask for confirmation when initialMember is not in a workgroup', () => {
spyOn(workgroupService, 'isUserInAnyWorkgroup').and.returnValue(false);
const createWorkgroupSpy = spyOn(workgroupService, 'createWorkgroup').and.returnValue(of(1));
spyOn(configService, 'retrieveConfig');
const createWorkgroupSpy = spyOn(workgroupService, 'createWorkgroup').and.returnValue(of(10));
component.createTeam();
expect(dialogSpy).not.toHaveBeenCalled();
expect(createWorkgroupSpy).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ export class AddTeamDialogComponent {
)
.subscribe({
next: (newWorkgroupId: number) => {
this.configService.retrieveConfig(
`/api/config/classroomMonitor/${this.configService.getRunId()}`
);
this.snackBar.open($localize`New Team ${newWorkgroupId} has been created.`);
this.isProcessing = false;
this.dialog.closeAll();
this.configService
.retrieveConfig(`/api/config/classroomMonitor/${this.configService.getRunId()}`)
.subscribe({
next: () => {
this.snackBar.open($localize`New Team ${newWorkgroupId} has been created.`);
this.isProcessing = false;
this.dialog.closeAll();
}
});
},
error: () => {
this.snackBar.open($localize`Error: Could not create team.`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ConfigService } from '../../../../services/configService';

import { ChangeTeamPeriodDialogComponent } from './change-team-period-dialog.component';
import { of } from 'rxjs';

class ConfigServiceStub {
getPeriods() {
Expand All @@ -20,7 +21,7 @@ class ConfigServiceStub {
return 123;
}
retrieveConfig() {
return {};
return of({});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,23 @@ export class ChangeTeamPeriodDialogComponent {
}/change-period`,
this.selectedPeriod.periodId
)
.subscribe(
(response) => {
.subscribe({
next: () => {
this.isChangingPeriod = false;
this.configService.retrieveConfig(
`/api/config/classroomMonitor/${this.configService.getRunId()}`
);
this.snackBar.open(
$localize`Moved Team ${this.team.workgroupId} to Period ${this.selectedPeriod.periodName}.`
);
this.dialog.closeAll();
this.configService
.retrieveConfig(`/api/config/classroomMonitor/${this.configService.getRunId()}`)
.subscribe({
next: () => {
this.snackBar.open(
$localize`Moved Team ${this.team.workgroupId} to Period ${this.selectedPeriod.periodName}.`
);
this.dialog.closeAll();
}
});
},
(err) => {
error: () => {
this.isChangingPeriod = false;
}
);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,13 @@ export class ManageTeamComponent {
previousIndex,
event.currentIndex
);
this.configService.retrieveConfig(
`/api/config/classroomMonitor/${this.configService.getRunId()}`
);
this.snackBar.open($localize`Moved student to Team ${workgroupId}.`);
this.configService
.retrieveConfig(`/api/config/classroomMonitor/${this.configService.getRunId()}`)
.subscribe({
next: () => {
this.snackBar.open($localize`Moved student to Team ${workgroupId}.`);
}
});
},
error: () => {
this.snackBar.open($localize`Error: Could not move student.`);
Expand Down

0 comments on commit 0ebdb8d

Please sign in to comment.