Browse Source

Feature: Manage portfolio filter form state based on permissions

pull/5618/head
Germán Martín 3 months ago
parent
commit
02f37c4d6f
  1. 7
      libs/ui/src/lib/assistant/assistant.component.ts
  2. 28
      libs/ui/src/lib/portfolio-filter-form/portfolio-filter-form.component.ts

7
libs/ui/src/lib/assistant/assistant.component.ts

@ -393,6 +393,13 @@ export class GfAssistantComponent implements OnChanges, OnDestroy, OnInit {
})) as AccountWithValue[]; })) as AccountWithValue[];
} }
// Handle portfolio filter form disabled state
if (this.hasPermissionToChangeFilters) {
this.portfolioFilterFormControl.enable({ emitEvent: false });
} else {
this.portfolioFilterFormControl.disable({ emitEvent: false });
}
this.dateRangeOptions = [ this.dateRangeOptions = [
{ {
label: $localize`Today`, label: $localize`Today`,

28
libs/ui/src/lib/portfolio-filter-form/portfolio-filter-form.component.ts

@ -20,6 +20,7 @@ import {
ControlValueAccessor, ControlValueAccessor,
FormBuilder, FormBuilder,
FormControl, FormControl,
FormGroup,
FormsModule, FormsModule,
NG_VALUE_ACCESSOR, NG_VALUE_ACCESSOR,
ReactiveFormsModule ReactiveFormsModule
@ -67,12 +68,7 @@ export class GfPortfolioFilterFormComponent
@Output() applyFilters = new EventEmitter<void>(); @Output() applyFilters = new EventEmitter<void>();
@Output() resetFilters = new EventEmitter<void>(); @Output() resetFilters = new EventEmitter<void>();
public filterForm = this.formBuilder.group({ public filterForm: FormGroup;
account: new FormControl<string>(null),
assetClass: new FormControl<string>(null),
holding: new FormControl<PortfolioPosition>(null),
tag: new FormControl<string>(null)
});
private onChange: (value: PortfolioFilterFormValue) => void = () => { private onChange: (value: PortfolioFilterFormValue) => void = () => {
// ControlValueAccessor callback - implemented by parent // ControlValueAccessor callback - implemented by parent
@ -85,7 +81,15 @@ export class GfPortfolioFilterFormComponent
public constructor( public constructor(
private changeDetectorRef: ChangeDetectorRef, private changeDetectorRef: ChangeDetectorRef,
private formBuilder: FormBuilder private formBuilder: FormBuilder
) {} ) {
// Create form with initial state (will be updated in ngOnChanges)
this.filterForm = this.formBuilder.group({
account: new FormControl<string>(null),
assetClass: new FormControl<string>(null),
holding: new FormControl<PortfolioPosition>(null),
tag: new FormControl<string>(null)
});
}
public ngOnInit() { public ngOnInit() {
// Subscribe to form changes to notify parent component // Subscribe to form changes to notify parent component
@ -145,7 +149,15 @@ export class GfPortfolioFilterFormComponent
public setDisabledState(isDisabled: boolean): void { public setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled; this.disabled = isDisabled;
this.ngOnChanges();
// Update form disabled state manually since this is called by ControlValueAccessor
if (this.disabled) {
this.filterForm.disable({ emitEvent: false });
} else {
this.filterForm.enable({ emitEvent: false });
}
this.changeDetectorRef.markForCheck();
} }
// Helper methods // Helper methods

Loading…
Cancel
Save