Browse Source

Task/improve type safety in rule settings dialog component (#7185)

* fix(client): resolve type errors

* feat(client): enforce encapsulation

* feat(client): enforce immutability

* feat(client): replace constructor based DI with inject functions
pull/7188/head
Kenrick Tandrian 2 weeks ago
committed by GitHub
parent
commit
0cbb8f1116
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 21
      apps/client/src/app/components/rule/rule-settings-dialog/rule-settings-dialog.component.ts

21
apps/client/src/app/components/rule/rule-settings-dialog/rule-settings-dialog.component.ts

@ -1,6 +1,6 @@
import { GfValueComponent } from '@ghostfolio/ui/value';
import { ChangeDetectionStrategy, Component, Inject } from '@angular/core';
import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { FormBuilder, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import {
@ -26,20 +26,21 @@ import { RuleSettingsDialogParams } from './interfaces/interfaces';
templateUrl: './rule-settings-dialog.html'
})
export class GfRuleSettingsDialogComponent {
public settingsForm: FormGroup;
protected readonly settingsForm: FormGroup;
public constructor(
@Inject(MAT_DIALOG_DATA) public data: RuleSettingsDialogParams,
public dialogRef: MatDialogRef<GfRuleSettingsDialogComponent>,
private formBuilder: FormBuilder
) {
protected readonly data = inject<RuleSettingsDialogParams>(MAT_DIALOG_DATA);
protected readonly dialogRef =
inject<MatDialogRef<GfRuleSettingsDialogComponent>>(MatDialogRef);
private readonly formBuilder = inject(FormBuilder);
public constructor() {
this.settingsForm = this.formBuilder.group({
thresholdMax: [this.data.settings.thresholdMax],
thresholdMin: [this.data.settings.thresholdMin]
thresholdMax: [this.data.settings?.thresholdMax],
thresholdMin: [this.data.settings?.thresholdMin]
});
}
public onSubmit() {
protected onSubmit() {
this.dialogRef.close({
...this.data.settings,
thresholdMax: this.settingsForm.get('thresholdMax')?.value,

Loading…
Cancel
Save