-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separate EntityTypeSelectComponent from its EditComponent (#…
- Loading branch information
Showing
10 changed files
with
108 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 0 additions & 55 deletions
55
src/app/core/entity/edit-entity-type-dropdown/edit-entity-type-dropdown.component.ts
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
src/app/core/entity/edit-entity-type/edit-entity-type.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<app-entity-type-select | ||
[formControl]="formControl" | ||
[allowMultiSelect]="multi" | ||
[label]="label" | ||
></app-entity-type-select> |
13 changes: 5 additions & 8 deletions
13
...it-entity-type-dropdown.component.spec.ts → ...y-type/edit-entity-type.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/app/core/entity/edit-entity-type/edit-entity-type.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Component, OnInit } from "@angular/core"; | ||
import { EditComponent } from "../default-datatype/edit-component"; | ||
import { DynamicComponent } from "../../config/dynamic-components/dynamic-component.decorator"; | ||
import { EntityTypeSelectComponent } from "../entity-type-select/entity-type-select.component"; | ||
|
||
/** | ||
* Edit component for selecting an entity type from a dropdown. | ||
*/ | ||
@DynamicComponent("EditEntityType") | ||
@Component({ | ||
selector: "app-edit-entity-type", | ||
templateUrl: "./edit-entity-type.component.html", | ||
imports: [EntityTypeSelectComponent], | ||
standalone: true, | ||
}) | ||
export class EditEntityTypeComponent | ||
extends EditComponent<string | string[]> | ||
implements OnInit | ||
{ | ||
multi = false; | ||
|
||
override ngOnInit() { | ||
super.ngOnInit(); | ||
this.multi = this.formFieldConfig.isArray; | ||
} | ||
} |
5 changes: 3 additions & 2 deletions
5
.../edit-entity-type-dropdown.component.html → ...-select/entity-type-select.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
<mat-form-field> | ||
<mat-label>{{ label }}</mat-label> | ||
|
||
<app-basic-autocomplete | ||
[formControl]="formControl" | ||
[options]="entityTypes" | ||
[optionToString]="optionToLabel" | ||
[valueMapper]="optionToId" | ||
[multi]="multi" | ||
placeholder="Select an entity type" | ||
[multi]="allowMultiSelect" | ||
i18n-placeholder="placeholder for Entity Type dropdown input" | ||
></app-basic-autocomplete> | ||
</mat-form-field> |
28 changes: 28 additions & 0 deletions
28
src/app/core/entity/entity-type-select/entity-type-select.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { ComponentFixture, TestBed } from "@angular/core/testing"; | ||
import { EntityTypeSelectComponent } from "./entity-type-select.component"; | ||
import { MockedTestingModule } from "../../../utils/mocked-testing.module"; | ||
import { FormControl, ReactiveFormsModule } from "@angular/forms"; | ||
|
||
describe("EntityTypeSelectComponent", () => { | ||
let component: EntityTypeSelectComponent; | ||
let fixture: ComponentFixture<EntityTypeSelectComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ | ||
EntityTypeSelectComponent, | ||
MockedTestingModule.withState(), | ||
ReactiveFormsModule, | ||
], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(EntityTypeSelectComponent); | ||
component = fixture.componentInstance; | ||
component.formControl = new FormControl(); | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it("should create", () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
src/app/core/entity/entity-type-select/entity-type-select.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Component, OnInit, Input } from "@angular/core"; | ||
import { BasicAutocompleteComponent } from "../../common-components/basic-autocomplete/basic-autocomplete.component"; | ||
import { FormControl, ReactiveFormsModule } from "@angular/forms"; | ||
import { EntityConstructor } from "../model/entity"; | ||
import { EntityRegistry } from "../database-entity.decorator"; | ||
import { MatFormField, MatLabel } from "@angular/material/form-field"; | ||
|
||
@Component({ | ||
selector: "app-entity-type-select", | ||
templateUrl: "./entity-type-select.component.html", | ||
imports: [ | ||
BasicAutocompleteComponent, | ||
ReactiveFormsModule, | ||
MatFormField, | ||
MatLabel, | ||
], | ||
standalone: true, | ||
}) | ||
export class EntityTypeSelectComponent implements OnInit { | ||
@Input() formControl: FormControl; | ||
@Input() allowMultiSelect = false; | ||
@Input() label: string; | ||
|
||
entityTypes: EntityConstructor[]; | ||
optionToLabel = (option: EntityConstructor) => option.label; | ||
optionToId = (option: EntityConstructor) => option.ENTITY_TYPE; | ||
|
||
constructor(private entityRegistry: EntityRegistry) {} | ||
|
||
ngOnInit() { | ||
this.entityTypes = this.entityRegistry | ||
.getEntityTypes(true) | ||
.map(({ value }) => value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters