From 23fa59ced29c9811fb521b1eabd45834230648f5 Mon Sep 17 00:00:00 2001 From: Geoffrey Kwan Date: Fri, 20 Oct 2023 18:11:21 -0400 Subject: [PATCH] feat(Authoring): Move component info retrieval inside dialog #1457 --- .../component-info-dialog.component.html | 6 ++--- .../component-info-dialog.component.spec.ts | 11 ++------- .../component-info-dialog.component.ts | 23 ++++++++++++++++++- .../component-selector.component.html | 8 ++----- .../component-selector.component.ts | 10 +------- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/assets/wise5/authoringTool/components/component-info-dialog/component-info-dialog.component.html b/src/assets/wise5/authoringTool/components/component-info-dialog/component-info-dialog.component.html index ab66d9458c5..a8b4578926e 100644 --- a/src/assets/wise5/authoringTool/components/component-info-dialog/component-info-dialog.component.html +++ b/src/assets/wise5/authoringTool/components/component-info-dialog/component-info-dialog.component.html @@ -1,11 +1,11 @@ -

{{ data.label }}

+

{{ label }}

-

{{ data.description }}

+

{{ description }}

Example
- +
diff --git a/src/assets/wise5/authoringTool/components/component-info-dialog/component-info-dialog.component.spec.ts b/src/assets/wise5/authoringTool/components/component-info-dialog/component-info-dialog.component.spec.ts index 3d838707509..f86f9e20d1b 100644 --- a/src/assets/wise5/authoringTool/components/component-info-dialog/component-info-dialog.component.spec.ts +++ b/src/assets/wise5/authoringTool/components/component-info-dialog/component-info-dialog.component.spec.ts @@ -6,7 +6,7 @@ import { PreviewComponentModule } from '../preview-component/preview-component.m import { HttpClientTestingModule } from '@angular/common/http/testing'; import { PreviewComponentComponent } from '../preview-component/preview-component.component'; import { ProjectService } from '../../../services/projectService'; -import { Component } from '../../../common/Component'; +import { ComponentInfoService } from '../../../services/componentInfoService'; describe('ComponentInfoDialogComponent', () => { let component: ComponentInfoDialogComponent; @@ -16,14 +16,7 @@ describe('ComponentInfoDialogComponent', () => { await TestBed.configureTestingModule({ declarations: [ComponentInfoDialogComponent, PreviewComponentComponent], imports: [HttpClientTestingModule, MatDialogModule, MatDividerModule, PreviewComponentModule], - providers: [ - { - provide: MAT_DIALOG_DATA, - useValue: { - component: new Component({ id: 'abcde12345', type: 'OpenResponse' }, 'node1') - } - } - ] + providers: [ComponentInfoService, { provide: MAT_DIALOG_DATA, useValue: 'OpenResponse' }] }).compileComponents(); fixture = TestBed.createComponent(ComponentInfoDialogComponent); const projectService = TestBed.inject(ProjectService); diff --git a/src/assets/wise5/authoringTool/components/component-info-dialog/component-info-dialog.component.ts b/src/assets/wise5/authoringTool/components/component-info-dialog/component-info-dialog.component.ts index 60eacf266b4..6a0e6d246c7 100644 --- a/src/assets/wise5/authoringTool/components/component-info-dialog/component-info-dialog.component.ts +++ b/src/assets/wise5/authoringTool/components/component-info-dialog/component-info-dialog.component.ts @@ -1,5 +1,8 @@ import { Component, Inject } from '@angular/core'; import { MAT_DIALOG_DATA } from '@angular/material/dialog'; +import { ComponentInfoService } from '../../../services/componentInfoService'; +import { ComponentInfo } from '../../../components/ComponentInfo'; +import { ComponentFactory } from '../../../common/ComponentFactory'; @Component({ selector: 'component-info-dialog', @@ -7,5 +10,23 @@ import { MAT_DIALOG_DATA } from '@angular/material/dialog'; styleUrls: ['./component-info-dialog.component.scss'] }) export class ComponentInfoDialogComponent { - constructor(@Inject(MAT_DIALOG_DATA) protected data: any) {} + protected component: any; + private componentInfo: ComponentInfo; + protected description: string; + protected label: string; + + constructor( + private componentInfoService: ComponentInfoService, + @Inject(MAT_DIALOG_DATA) private componentType: string + ) {} + + ngOnInit(): void { + this.componentInfo = this.componentInfoService.getInfo(this.componentType); + this.label = this.componentInfo.getLabel(); + this.description = this.componentInfo.getDescription(); + this.component = new ComponentFactory().getComponent( + this.componentInfo.getPreviewContent(), + 'node1' + ); + } } diff --git a/src/assets/wise5/authoringTool/components/component-selector/component-selector.component.html b/src/assets/wise5/authoringTool/components/component-selector/component-selector.component.html index 34413f15212..221e1b20edd 100644 --- a/src/assets/wise5/authoringTool/components/component-selector/component-selector.component.html +++ b/src/assets/wise5/authoringTool/components/component-selector/component-selector.component.html @@ -1,8 +1,4 @@
- - + +
diff --git a/src/assets/wise5/authoringTool/components/component-selector/component-selector.component.ts b/src/assets/wise5/authoringTool/components/component-selector/component-selector.component.ts index 8463d0bbe84..259c79a17bc 100644 --- a/src/assets/wise5/authoringTool/components/component-selector/component-selector.component.ts +++ b/src/assets/wise5/authoringTool/components/component-selector/component-selector.component.ts @@ -1,5 +1,4 @@ import { Component, EventEmitter, Input, Output } from '@angular/core'; -import { ComponentFactory } from '../../../common/ComponentFactory'; import { MatDialog } from '@angular/material/dialog'; import { ComponentInfoService } from '../../../services/componentInfoService'; import { ComponentInfoDialogComponent } from '../component-info-dialog/component-info-dialog.component'; @@ -24,14 +23,7 @@ export class ComponentSelectorComponent { protected preview(): void { this.dialog.open(ComponentInfoDialogComponent, { - data: { - component: new ComponentFactory().getComponent( - this.componentInfo.getPreviewContent(), - 'node1' - ), - description: this.componentInfo.getDescription(), - label: this.label - }, + data: this.componentType, panelClass: 'dialog-lg' }); }