Skip to content

Commit e874eaa

Browse files
authored
Fix view id navigation bug (#47)
propertyId -> viewId, fix list org bug
1 parent 50c105b commit e874eaa

File tree

9 files changed

+53
-52
lines changed

9 files changed

+53
-52
lines changed

cspell.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"FEMP",
2727
"falsey",
2828
"greenbutton",
29-
"movened",
29+
"moveend",
3030
"NMEC",
3131
"overlaycontainer",
3232
"SRID",

src/@seed/api/analysis/analysis.service.ts

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,7 @@ import { OrganizationService } from '@seed/api/organization'
77
import { ErrorService } from '@seed/services'
88
import { SnackBarService } from 'app/core/snack-bar/snack-bar.service'
99
import { UserService } from '../user'
10-
import type {
11-
AnalysesMessage,
12-
Analysis,
13-
AnalysisResponse,
14-
AnalysisServiceType,
15-
AnalysisSummary,
16-
AnalysisView,
17-
AnalysisViews,
18-
ListAnalysesResponse,
19-
ListMessagesResponse,
20-
OriginalView,
21-
PropertyAnalysesResponse,
22-
View,
23-
} from './analysis.types'
10+
import type { AnalysesMessage, Analysis, AnalysisResponse, AnalysisServiceType, AnalysisSummary, AnalysisView, AnalysisViews, ListAnalysesResponse, ListMessagesResponse, PropertyAnalysesResponse, View } from './analysis.types'
2411

2512
@Injectable({ providedIn: 'root' })
2613
export class AnalysisService {
@@ -33,14 +20,16 @@ export class AnalysisService {
3320
private _analysis = new BehaviorSubject<Analysis>(null)
3421
private _views = new BehaviorSubject<View[]>([])
3522
private _view = new BehaviorSubject<View>(null)
36-
private _originalViews = new BehaviorSubject<OriginalView[]>([])
23+
private _originalView = new BehaviorSubject<number>(null)
24+
private _originalViews = new BehaviorSubject<Record<number, number>>(null)
3725
private _messages = new BehaviorSubject<AnalysesMessage[]>([])
3826
private readonly _unsubscribeAll$ = new Subject<void>()
3927
orgId: number
4028
analyses$ = this._analyses.asObservable()
4129
analysis$ = this._analysis.asObservable()
4230
views$ = this._views.asObservable()
4331
view$ = this._view.asObservable()
32+
originalView$ = this._originalView.asObservable()
4433
originalViews$ = this._originalViews.asObservable()
4534
messages$ = this._messages.asObservable()
4635
pollingStatuses?: Subscription
@@ -143,12 +132,12 @@ export class AnalysisService {
143132
}
144133

145134
// get analysis view
146-
getAnalysisView(orgId: number, analysisId: number, viewId: number): Observable<View> {
135+
getAnalysisView(orgId: number, analysisId: number, viewId: number): Observable<AnalysisView> {
147136
const url = `/api/v3/analyses/${analysisId}/views/${viewId}/?organization_id=${orgId}`
148137
return this._httpClient.get<AnalysisView>(url).pipe(
149-
map((response) => response.view),
150-
tap((view) => {
138+
tap(({ view, original_view }) => {
151139
this._view.next(view)
140+
this._originalView.next(original_view)
152141
}),
153142
catchError((error: HttpErrorResponse) => {
154143
return this._errorService.handleError(error, 'Error fetching analysis view')

src/@seed/api/analysis/analysis.types.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,11 @@ export type AnalysisOutputFile = {
4747
id: number;
4848
}
4949

50-
// OriginalView is an array of key values where the key is a string and the value is a number
51-
export type OriginalView = Record<string, number>
52-
5350
export type ListAnalysesResponse = {
5451
status: 'success';
5552
analyses: Analysis[];
5653
views: View[];
57-
original_views: OriginalView[];
54+
original_views: Record<number, number>;
5855
}
5956

6057
export type AnalysisResponse = {
@@ -75,13 +72,13 @@ export type AnalysesViews = {
7572
export type AnalysisViews = {
7673
status: 'success';
7774
views: View[];
78-
original_views: OriginalView[];
75+
original_views: Record<number, number>;
7976
}
8077

8178
export type AnalysisView = {
8279
status: 'success';
8380
view: View;
84-
original_view: OriginalView;
81+
original_view: number;
8582
}
8683

8784
export type AnalysesMessage = {

src/app/modules/analyses/analysis/analysis.component.ts

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class AnalysisComponent implements OnDestroy, OnInit {
4848
gridTheme$ = this._configService.gridTheme$
4949
gridHeight = 0
5050
messages: AnalysesMessage[]
51+
originalViews: Record<number, number>
5152
orgId: number
5253
views: View[] = []
5354
gridViews: (View & { messages?: string[] })[] = []
@@ -81,20 +82,24 @@ export class AnalysisComponent implements OnDestroy, OnInit {
8182
this._analysisService.getAnalysisViews(this.orgId, this.analysisId)
8283
this._analysisService.getMessages(this.orgId, this.analysisId)
8384

84-
combineLatest([this._analysisService.analysis$, this._analysisService.views$, this._analysisService.messages$])
85-
.pipe(
86-
filter(([analysis, views]) => !!analysis && views.length && analysis.id === this.analysisId),
87-
takeUntil(this._unsubscribeAll$),
88-
tap(([analysis, views, messages]) => {
89-
this.analysis = analysis
90-
this.views = views
91-
this.messages = messages
92-
this.analysisDescription = this._analysisService.getAnalysisDescription(analysis)
93-
this.formatViews()
94-
this.setColumnDefs()
95-
}),
96-
)
97-
.subscribe()
85+
combineLatest([
86+
this._analysisService.analysis$,
87+
this._analysisService.views$,
88+
this._analysisService.messages$,
89+
this._analysisService.originalViews$,
90+
]).pipe(
91+
filter(([analysis, views]) => !!analysis && views.length && analysis.id === this.analysisId),
92+
takeUntil(this._unsubscribeAll$),
93+
tap(([analysis, views, messages, originalViews]) => {
94+
this.analysis = analysis
95+
this.views = views
96+
this.messages = messages
97+
this.originalViews = originalViews
98+
this.analysisDescription = this._analysisService.getAnalysisDescription(analysis)
99+
this.formatViews()
100+
this.setColumnDefs()
101+
}),
102+
).subscribe()
98103
}
99104

100105
formatViews() {
@@ -216,10 +221,12 @@ export class AnalysisComponent implements OnDestroy, OnInit {
216221

217222
const target = event.event.target as HTMLElement
218223
const action = target.getAttribute('data-action')
219-
const { id, output_files, property } = event.data as View
224+
const { id, output_files } = event.data as View
220225

221226
if (action === 'viewProperty') {
222-
void this._router.navigate([`/properties/${property}`])
227+
// map viewId to propertyViewId
228+
const propertyViewId: number = this.originalViews[id]
229+
void this._router.navigate([`/properties/${propertyViewId}`])
223230
} else if (action === 'viewResults') {
224231
void this._router.navigate([`/analyses/${this.analysisId}/views/${id}`])
225232
// this.viewResults(id)

src/app/modules/analyses/analysis_view/analysis-view.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
</div>
2222
<div class="flex gap-4">
2323
<span class="text-secondary w-20">Property </span>
24-
<a class="text-primary dark:text-primary-400" [routerLink]="['/properties/', view.property]">
24+
<a class="text-primary dark:text-primary-400" [routerLink]="['/properties/', propertyViewId]">
2525
<span class="mr-1 text-lg">{{ viewDisplayField$ | async }}</span>
2626
<span class="material-icons text-secondary text-sm">open_in_new</span>
2727
</a>

src/app/modules/analyses/analysis_view/analysis-view.component.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class AnalysisViewComponent implements OnDestroy, OnInit {
4242
orgId: number
4343
apvId = Number(this._route.snapshot.paramMap.get('viewId')) // analysis_property_view_id
4444
view: Partial<View> = {}
45+
propertyViewId: number
4546
gridApi: GridApi
4647
viewDisplayField$: Observable<string>
4748
type: InventoryType = 'properties'
@@ -74,12 +75,16 @@ export class AnalysisViewComponent implements OnDestroy, OnInit {
7475
this.messages = messages.filter((m) => m.analysis_property_view === this.apvId)
7576

7677
return this._analysisService.getAnalysisView(this.orgId, this.analysisId, this.apvId).pipe(
77-
switchMap(() => this._analysisService.view$),
78+
switchMap(() => combineLatest([
79+
this._analysisService.view$,
80+
this._analysisService.originalView$,
81+
])),
7882
takeUntil(this._unsubscribeAll$),
79-
tap((view) => {
83+
tap(([view, originalView]) => {
8084
this.view = view
85+
this.propertyViewId = originalView
8186
this.cycle = cycles.find((c) => c.id === view.cycle)
82-
this.viewDisplayField$ = this._organizationService.getViewDisplayField(view.property, this.type)
87+
this.viewDisplayField$ = this._organizationService.getViewDisplayField(this.propertyViewId, this.type)
8388
this.formatTableResults()
8489
}),
8590
)

src/app/modules/inventory-list/list/grid/grid.component.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ export class InventoryGridComponent implements OnChanges {
8989
const target = event.event.target as HTMLElement
9090
const action = target.getAttribute('data-action') as 'detail' | 'notes' | 'meters' | null
9191
if (!action) return
92-
const { id } = event.data as { id: string; file: string; filename: string }
92+
const { property_view_id } = event.data as { property_view_id: string; file: string; filename: string }
9393

9494
const urlMap = {
95-
detail: [`/${this.inventoryType}`, id],
96-
notes: [`/${this.inventoryType}`, id, 'notes'],
97-
meters: [`/${this.inventoryType}`, id, 'meters'],
95+
detail: [`/${this.inventoryType}`, property_view_id],
96+
notes: [`/${this.inventoryType}`, property_view_id, 'notes'],
97+
meters: [`/${this.inventoryType}`, property_view_id, 'meters'],
9898
}
9999

100100
return void this._router.navigate(urlMap[action])

src/app/modules/inventory-list/list/inventory.component.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { MatTooltipModule } from '@angular/material/tooltip'
1212
import { ActivatedRoute } from '@angular/router'
1313
import type { ColDef, GridApi } from 'ag-grid-community'
1414
import type { Observable } from 'rxjs'
15-
import { BehaviorSubject, combineLatest, filter, map, of, Subject, switchMap, takeUntil, tap } from 'rxjs'
15+
import { BehaviorSubject, catchError, combineLatest, filter, map, of, Subject, switchMap, takeUntil, tap } from 'rxjs'
1616
import type { Cycle } from '@seed/api/cycle'
1717
import { CycleService } from '@seed/api/cycle/cycle.service'
1818
import { InventoryService } from '@seed/api/inventory'
@@ -108,7 +108,6 @@ export class InventoryComponent implements OnDestroy, OnInit {
108108
initPage() {
109109
this._userService.currentOrganizationId$
110110
.pipe(
111-
takeUntil(this._unsubscribeAll$),
112111
switchMap((orgId) => this.getDependencies(orgId)),
113112
map((results) => this.setDependencies(results)),
114113
switchMap((profile_id) => this.getProfile(profile_id)),
@@ -117,6 +116,11 @@ export class InventoryComponent implements OnDestroy, OnInit {
117116
this.setFilterSorts()
118117
this.initStreams()
119118
}),
119+
takeUntil(this._unsubscribeAll$),
120+
catchError((err) => {
121+
console.error('Error initializing inventory:', err)
122+
return of(null)
123+
}),
120124
)
121125
.subscribe()
122126
}

src/app/modules/inventory-list/map/map.component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @cspell/spellchecker */
21
import type { OnDestroy, OnInit } from '@angular/core'
32
import { Component, inject } from '@angular/core'
43
import { MatCheckboxModule } from '@angular/material/checkbox'

0 commit comments

Comments
 (0)