Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: small code cleanups #2744

Merged
merged 1 commit into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ export class EntityFormService {
if (value !== null) {
updatedEntity[key] = value;
} else {
// formControls' value is null if it is empty (untouched or cleared by user) but we don't want entity docs to be full of null properties
delete updatedEntity[key];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ import { FormsModule } from "@angular/forms";
// Use no encapsulation because we want to change the value of children (the mat-form-fields that are
// dynamically created)
encapsulation: ViewEncapsulation.None,
imports: [NgForOf, NgIf, NgClass, EntityFieldEditComponent, FormsModule],
imports: [
FormsModule, // importing FormsModule ensures that buttons anywhere inside do not trigger form submission / page reload
NgForOf,
NgIf,
NgClass,
EntityFieldEditComponent,
],
standalone: true,
})
export class EntityFormComponent<T extends Entity = Entity>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Input } from "@angular/core";
import { Component, Input, OnChanges, SimpleChanges } from "@angular/core";
import { Entity } from "../../entity/model/entity";
import { BehaviorSubject, lastValueFrom } from "rxjs";
import { FormControl, FormsModule, ReactiveFormsModule } from "@angular/forms";
Expand All @@ -7,7 +7,7 @@ import { MatAutocompleteModule } from "@angular/material/autocomplete";
import { UntilDestroy } from "@ngneat/until-destroy";
import { EntityMapperService } from "../../entity/entity-mapper/entity-mapper.service";
import { MatFormFieldModule } from "@angular/material/form-field";
import { AsyncPipe, NgForOf, NgIf } from "@angular/common";
import { AsyncPipe, NgIf } from "@angular/common";
import { EntityBlockComponent } from "../../basic-datatypes/entity/entity-block/entity-block.component";
import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";
import { MatTooltipModule } from "@angular/material/tooltip";
Expand All @@ -34,7 +34,6 @@ import { EntityRegistry } from "../../entity/database-entity.decorator";
ReactiveFormsModule,
MatAutocompleteModule,
MatChipsModule,
NgForOf,
EntityBlockComponent,
FontAwesomeModule,
MatTooltipModule,
Expand All @@ -52,7 +51,8 @@ import { EntityRegistry } from "../../entity/database-entity.decorator";
export class EntitySelectComponent<
E extends Entity,
T extends string[] | string = string[],
> {
> implements OnChanges
{
readonly loadingPlaceholder = $localize`:A placeholder for the input element when select options are not loaded yet:loading...`;

@Input() form: FormControl<T>;
Expand Down Expand Up @@ -135,6 +135,14 @@ export class EntitySelectComponent<

@Input() additionalFilter: (e: E) => boolean = (_) => true;

ngOnChanges(changes: SimpleChanges): void {
if (changes["form"]) {
this.form.valueChanges.subscribe((value) => {
this.updateAvailableOptions().then((_) => {});
});
}
}

private async loadAvailableEntities() {
this.loading.next(true);

Expand Down
Loading