Skip to content

Commit

Permalink
refactor(NavigationComponent): Convert to standalone (#1799)
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima authored May 16, 2024
1 parent a453b8d commit 60d51dc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
4 changes: 1 addition & 3 deletions src/app/student/vle/student-vle.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { ProjectService } from '../../../assets/wise5/services/projectService';
import { StudentDataService } from '../../../assets/wise5/services/studentDataService';
import { NavigationComponent } from '../../../assets/wise5/themes/default/navigation/navigation.component';
import { StepToolsComponent } from '../../../assets/wise5/themes/default/themeComponents/stepTools/step-tools.component';
import { NavItemComponent } from '../../../assets/wise5/vle/nav-item/nav-item.component';
import { NodeModule } from '../../../assets/wise5/vle/node/node.module';
import { StudentAssetsDialogModule } from '../../../assets/wise5/vle/studentAsset/student-assets-dialog/student-assets-dialog.module';
import { VLEComponent } from '../../../assets/wise5/vle/vle.component';
Expand All @@ -41,7 +40,6 @@ import { NodeStatusIconComponent } from '../../../assets/wise5/themes/default/th
ChooseBranchPathDialogComponent,
GenerateImageDialogComponent,
GroupTabsComponent,
NavigationComponent,
NodeNavigationComponent,
RunEndedAndLockedMessageComponent,
SafeUrl,
Expand All @@ -54,7 +52,7 @@ import { NodeStatusIconComponent } from '../../../assets/wise5/themes/default/th
CommonModule,
ComponentStudentModule,
MatDialogModule,
NavItemComponent,
NavigationComponent,
NodeModule,
NodeStatusIconComponent,
SimpleDialogModule,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { MatDialogModule } from '@angular/material/dialog';
import { StudentTeacherCommonServicesModule } from '../../../../../app/student-teacher-common-services.module';
import { VLEProjectService } from '../../../vle/vleProjectService';
import { NavigationComponent } from './navigation.component';

class MockVLEProjectService {
rootNode = { ids: [] };

getProjectRootNode() {
return this.rootNode;
return { ids: [] };
}
}

Expand All @@ -19,8 +16,7 @@ describe('NavigationComponent', () => {

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [HttpClientTestingModule, MatDialogModule, StudentTeacherCommonServicesModule],
declarations: [NavigationComponent],
imports: [HttpClientTestingModule, NavigationComponent, StudentTeacherCommonServicesModule],
providers: [{ provide: VLEProjectService, useClass: MockVLEProjectService }]
}).compileComponents();
});
Expand Down
22 changes: 12 additions & 10 deletions src/assets/wise5/themes/default/navigation/navigation.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@ import { Component, OnInit } from '@angular/core';
import { Subscription } from 'rxjs';
import { StudentDataService } from '../../../services/studentDataService';
import { VLEProjectService } from '../../../vle/vleProjectService';
import { CommonModule } from '@angular/common';
import { FlexLayoutModule } from '@angular/flex-layout';
import { NavItemComponent } from '../../../vle/nav-item/nav-item.component';

@Component({
imports: [CommonModule, FlexLayoutModule, NavItemComponent],
selector: 'navigation',
templateUrl: './navigation.component.html',
styleUrls: ['./navigation.component.scss']
standalone: true,
styleUrl: './navigation.component.scss',
templateUrl: './navigation.component.html'
})
export class NavigationComponent implements OnInit {
navItemIsExpanded: any = {};
navItemIsExpandedSubscription: Subscription;
rootNode: any;
protected navItemIsExpanded: { [nodeId: string]: boolean } = {};
private navItemIsExpandedSubscription: Subscription;
protected rootNode: any;

constructor(
private projectService: VLEProjectService,
private studentDataService: StudentDataService
) {}
constructor(private dataService: StudentDataService, private projectService: VLEProjectService) {}

ngOnInit(): void {
this.rootNode = this.projectService.getProjectRootNode();
}

ngAfterViewInit(): void {
this.navItemIsExpandedSubscription = this.studentDataService.navItemIsExpanded$.subscribe(
this.navItemIsExpandedSubscription = this.dataService.navItemIsExpanded$.subscribe(
({ nodeId, isExpanded }) => {
this.navItemIsExpanded[nodeId] = isExpanded;
}
Expand Down
2 changes: 1 addition & 1 deletion src/assets/wise5/vle/vle.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ describe('VLEComponent', () => {
MatToolbarModule,
MatSelectModule,
MatSidenavModule,
NavigationComponent,
NodeIconComponent,
NodeStatusIconComponent,
StudentTeacherCommonServicesModule,
TopBarComponent
],
declarations: [
NavigationComponent,
NodeComponent,
NotebookNotesComponent,
SafeUrl,
Expand Down

0 comments on commit 60d51dc

Please sign in to comment.