-
Notifications
You must be signed in to change notification settings - Fork 0
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
Feature/197 edit open absences #210
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ein paar verschachtelte subscribes, sieht sonst gut aus.
// Disable confirmation value select when unexcused | ||
confirmationValueControl.valueChanges | ||
.pipe(takeUntil(this.destroy$)) | ||
.subscribe(this.updateAbsenceTypeIdDisabled.bind(this)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hier hast du auch wieder verschachtelte subscribe
s. Theoretisch könnten auch mehrere FormGroup
s emitted werden, dann solltest du z.B. immer auf das neue valueChanges wechseln (und das alte unsubscriben). Zum Glück macht switchMap
dies bereits von Haus aus.
Ich habe hier mal eine Alternative skizziert, mit zwei neuen Helpers, die wir im shared/utils/form.ts
hinzufügen könnten:
function getControl(
formGroup$: Observable<FormGroup>,
controlName: string
): Observable<Option<AbstractControl>> {
return this.formGroup$.pipe(
map((formGroup) => {
const control = formGroup.get(controlName);
return control || null;
})
);
}
function getControlValueChanges<T>(
formGroup$: Observable<FormGroup>,
controlName: string
): Observable<T> {
return getControl(this.formGroup$, controlName).pipe(
switchMap((control) => (control ? control.valueChanges : empty())) // Mit dem empty() sollte eigentlich kein Wert emitted werden, sondern das innere Observable einfach completen
);
}
// Disable confirmation value select when unexcused
getControlValueChanges(this.formGroup$, "confirmationValue")
.pipe(takeUntil(this.destroy$))
.subscribe(this.updateAbsenceTypeIdDisabled.bind(this));
// Disable form when saving
combineLatest([
getControl(this.formGroup$, "confirmationValue"),
getControl(this.formGroup$, "absenceTypeId"),
this.saving$,
])
.pipe(takeUntil(this.destroy$))
.subscribe(([confirmationValueControl, absenceTypeIdControl, saving]) => {
if (saving) {
confirmationValueControl.disable();
absenceTypeIdControl?.disable();
} else {
confirmationValueControl.enable();
this.updateAbsenceTypeIdDisabled(confirmationValueControl.value);
}
});
// Initially select excused state radio button
combineLatest([
getControl(this.formGroup$, "confirmationValue").pipe(filter(notNull)),
this.excusedState$,
])
.pipe(takeUntil(this.destroy$))
.subscribe(([confirmationValueControl, excusedState]) =>
confirmationValueControl.setValue(excusedState.Key)
);
this.save(confirmationValue, absenceTypeId); | ||
}); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Hier wäre ein
combineLatest
angebracht, mit den beiden Observables, dann ein einzelnessubscribe
wo du beide Werte erhälst. - Aber der Wert vom
excusedState$
wir hier gar nicht mehr gebraucht, das könntest du also noch entfernen.
: absenceTypeIdControl.disable() | ||
); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Da wären wir dann beim combineLatest
:
combineLatest([
getControl(this.formGroup$, 'absenceTypeId').pipe(take(1)), // Das wäre der Helper von weiter oben
this.excusedState$.pipe(take(1)),
]).subscribe(([absenceTypeIdControl, excusedState]) => {
if (absenceTypeIdControl && excusedState) {
confirmationValue === excusedState.Key
? absenceTypeIdControl.enable()
: absenceTypeIdControl.disable();
}
});
@@ -21,6 +21,45 @@ export function getIdsGroupedByPerson( | |||
}); | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wird das getIdsGroupedByPerson
noch sonst wo verwendet? Sonst könnten wir es auch löschen...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Es wird noch in MyAbsencesReportSelectionService
und EditAbsencesSelectionService
verwendet.
06ebc71
to
210f1c6
Compare
210f1c6
to
a9e6c71
Compare
Auf diesem Branch ist zusätzlich noch #208 und die Anzeige der Designation auf "Offene Absenzen" umgesetzt.