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

Loading…
Cancel
Save