From f9490b75787138a15c8dfb7fe80d457a77262541 Mon Sep 17 00:00:00 2001 From: lastminutediorama Date: Thu, 19 Dec 2024 17:11:00 -0600 Subject: [PATCH] make selections async --- .../direct-impacts.state.service.ts | 30 +++++++------------ .../direct-impacts.component.ts | 12 ++++---- ...panded-change-over-time-chart.component.ts | 2 +- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/src/interface/src/app/treatments/direct-impacts.state.service.ts b/src/interface/src/app/treatments/direct-impacts.state.service.ts index 1535a312e..59a575a85 100644 --- a/src/interface/src/app/treatments/direct-impacts.state.service.ts +++ b/src/interface/src/app/treatments/direct-impacts.state.service.ts @@ -1,4 +1,4 @@ -import { BehaviorSubject, combineLatest, map, of } from 'rxjs'; +import { BehaviorSubject, combineLatest, map } from 'rxjs'; import { DEFAULT_SLOT, ImpactsMetric, @@ -37,8 +37,8 @@ export class DirectImpactsStateService { public activeMetric$ = this._activeMetric$.asObservable(); - //TODO: make this async? a behavior subject? - private selectedMetrics: string[] = []; + private _selectedMetrics$ = new BehaviorSubject([]); + public selectedMetrics$ = this._selectedMetrics$.asObservable(); private _filteredTreatmentTypes$ = new BehaviorSubject( [] @@ -52,32 +52,28 @@ export class DirectImpactsStateService { ); public activeTreatmentPlan$ = this._activeTreatmentPlan$.asObservable(); - private _selectedProjectAreaForChanges$ = + private _selectedProjectArea$ = new BehaviorSubject(null); - public selectedProjectAreaForChanges$ = - this._selectedProjectAreaForChanges$.asObservable(); + public selectedProjectArea$ = this._selectedProjectArea$.asObservable(); private _changeOverTimeData$ = new BehaviorSubject< ChangeOverTimeChartItem[][] >([[]]); public changeOverTimeData$ = this._changeOverTimeData$.asObservable(); - // todo: placeholder to fill once we have project area filter - projectArea$ = of('All Project Areas'); - private _showTreatmentPrescription$ = new BehaviorSubject(false); public showTreatmentPrescription$ = this._showTreatmentPrescription$.asObservable(); mapPanelTitle$ = combineLatest([ this.activeMetric$, - this.projectArea$, + this._selectedProjectArea$, this.showTreatmentPrescription$, ]).pipe( map(([activeMetric, pa, showTreatment]) => showTreatment ? 'Applied Treatment Prescription' - : `${activeMetric.metric.label} for ${pa}` + : `${activeMetric.metric.label} for ${pa?.project_area_name ?? 'All Project Areas'}` ) ); @@ -111,11 +107,11 @@ export class DirectImpactsStateService { if (!treatmentPlanId) { return; } - const projId = this._selectedProjectAreaForChanges$.value?.project_area_id; + const projId = this._selectedProjectArea$.value?.project_area_id; this.treatmentsService .getTreatmentImpactCharts( treatmentPlanId, - this.selectedMetrics, + this._selectedMetrics$.value, projId ?? null ) .subscribe({ @@ -125,19 +121,15 @@ export class DirectImpactsStateService { ); this._changeOverTimeData$.next(chartData); }, - error: (error) => { - //TODO: replace with snackbar or similar - }, }); } setSelectedMetrics(selections: string[]) { - //TODO: make this a behavior subject?? - this.selectedMetrics = selections; + this._selectedMetrics$.next(selections); } setProjectAreaForChanges(projectArea: ImpactsProjectArea | null) { - this._selectedProjectAreaForChanges$.next(projectArea); + this._selectedProjectArea$.next(projectArea); //then refresh the changes chart data this.getChangesOverTimeData(); diff --git a/src/interface/src/app/treatments/direct-impacts/direct-impacts.component.ts b/src/interface/src/app/treatments/direct-impacts/direct-impacts.component.ts index cd0fb4d01..94dadcafa 100644 --- a/src/interface/src/app/treatments/direct-impacts/direct-impacts.component.ts +++ b/src/interface/src/app/treatments/direct-impacts/direct-impacts.component.ts @@ -138,7 +138,7 @@ export class DirectImpactsComponent implements OnInit, OnDestroy { activeStand$ = this.directImpactsStateService.activeStand$; selectedChartProjectArea$ = - this.directImpactsStateService.selectedProjectAreaForChanges$; + this.directImpactsStateService.selectedProjectArea$; showTreatmentPrescription = false; changeChartButtons: PanelIconButton[] = [ { icon: 'open_in_full', actionName: 'expand' }, @@ -187,11 +187,6 @@ export class DirectImpactsComponent implements OnInit, OnDestroy { Chart.unregister(ChartDataLabels); } - handleChangedMetrics(data: string[]) { - this.directImpactsStateService.setSelectedMetrics(data); - this.directImpactsStateService.getChangesOverTimeData(); - } - setChartProjectArea(e: ImpactsProjectArea) { this.directImpactsStateService.setProjectAreaForChanges(e); } @@ -217,4 +212,9 @@ export class DirectImpactsComponent implements OnInit, OnDestroy { saveShowTreatmentPrescription(value: MatSlideToggleChange) { this.directImpactsStateService.setShowTreatmentPrescription(value.checked); } + + handleChangedMetrics(data: string[]) { + this.directImpactsStateService.setSelectedMetrics(data); + this.directImpactsStateService.getChangesOverTimeData(); + } } diff --git a/src/interface/src/app/treatments/expanded-change-over-time-chart/expanded-change-over-time-chart.component.ts b/src/interface/src/app/treatments/expanded-change-over-time-chart/expanded-change-over-time-chart.component.ts index 681cae499..d38c2642d 100644 --- a/src/interface/src/app/treatments/expanded-change-over-time-chart/expanded-change-over-time-chart.component.ts +++ b/src/interface/src/app/treatments/expanded-change-over-time-chart/expanded-change-over-time-chart.component.ts @@ -35,7 +35,7 @@ export class ExpandedChangeOverTimeChartComponent { public dialogRef: MatDialogRef ) {} selectedChartProjectArea$ = - this.directImpactsStateService.selectedProjectAreaForChanges$; + this.directImpactsStateService.selectedProjectArea$; availableProjectAreas$ = this.treatmentsState.summary$.pipe( map((summary) => {