Skip to content

Commit ef8397e

Browse files
committed
fetch mammping via cache service
1 parent d0a5f7d commit ef8397e

File tree

9 files changed

+50
-21
lines changed

9 files changed

+50
-21
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { HttpErrorResponse } from '@angular/common/http'
2+
import { HttpClient } from '@angular/common/http'
3+
import { inject, Injectable } from '@angular/core'
4+
import type { Observable } from 'rxjs'
5+
import { catchError } from 'rxjs'
6+
import { ErrorService } from '@seed/services'
7+
8+
@Injectable({ providedIn: 'root' })
9+
export class CacheService {
10+
private _errorService = inject(ErrorService)
11+
private _httpClient = inject(HttpClient)
12+
13+
getCacheEntry(orgId: number, uniqueId: number): Observable<unknown> {
14+
const url = `/api/v3/cache_entries/${uniqueId}/?organization_id=${orgId}`
15+
return this._httpClient.get<unknown>(url).pipe(
16+
catchError((error: HttpErrorResponse) => {
17+
return this._errorService.handleError(error, 'Error fetching cache entry')
18+
}),
19+
)
20+
}
21+
}

src/@seed/api/cache/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './cache.service'

src/@seed/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from './analysis'
22
export * from './audit-template'
3+
export * from './cache'
34
export * from './column'
45
export * from './column-mapping-profile'
56
export * from './config'

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http'
33
import { inject, Injectable } from '@angular/core'
44
import { catchError, map, type Observable } from 'rxjs'
55
import { ErrorService } from '@seed/services'
6-
import type { MappedData, MappingResultsResponse } from '../dataset'
6+
import type { MappedData } from '../dataset'
77
import type { ProgressResponse, SubProgressResponse } from '../progress'
88
import { UserService } from '../user'
99
import type { FirstFiveRowsResponse, MappingSuggestionsResponse, MatchingResultsResponse, RawColumnNamesResponse } from './mapping.types'
@@ -66,9 +66,9 @@ export class MappingService {
6666
)
6767
}
6868

69-
mappingResults(orgId: number, importFileId: number): Observable<MappingResultsResponse> {
69+
mappingResults(orgId: number, importFileId: number): Observable<ProgressResponse> {
7070
const url = `/api/v3/import_files/${importFileId}/mapping_results/?organization_id=${orgId}`
71-
return this._httpClient.post<MappingResultsResponse>(url, {})
71+
return this._httpClient.post<ProgressResponse>(url, {})
7272
.pipe(
7373
catchError((error: HttpErrorResponse) => {
7474
return this._errorService.handleError(error, 'Error fetching mapping results')

src/@seed/services/uploader/uploader.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class UploaderService {
5151
switchMap(() => this.checkProgress(progressKey)),
5252
tap((response) => {
5353
this._updateProgressBarObj({ data: response, offset, multiplier, progressBarObj })
54-
if (response.status === 'success') successFn()
54+
if (response.status === 'success') successFn(response)
5555
}),
5656
catchError(() => {
5757
// TODO the interval needs to continue if the error was network-related

src/@seed/services/uploader/uploader.types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type CheckProgressLoopParams = {
1616
progressKey: string;
1717
offset?: number;
1818
multiplier?: number;
19-
successFn?: () => void;
19+
successFn?: (response: ProgressResponse) => void;
2020
failureFn?: () => void;
2121
progressBarObj: ProgressBarObj;
2222
subProgress?: boolean;

src/app/modules/datasets/data-mappings/data-mapping.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
</mat-step>
5757

5858
<mat-step [completed]="completed[2]" label="Mapping" editable="false">
59-
<seed-progress-bar [progress]="progressBarObj.progress" [total]="progressBarObj.total" title="Mapping Data..."></seed-progress-bar>
59+
<seed-progress-bar [progress]="progressBarObj.progress" [total]="progressBarObj.total" [title]="progressTitle"></seed-progress-bar>
6060
</mat-step>
6161

6262
<mat-step [completed]="completed[3]" label="Review Mappings" editable="false">

src/app/modules/datasets/data-mappings/data-mapping.component.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { ActivatedRoute } from '@angular/router'
77
import { AgGridAngular } from 'ag-grid-angular'
88
import { catchError, filter, forkJoin, of, Subject, switchMap, take, takeUntil, tap } from 'rxjs'
99
import type { Column, ColumnMappingProfile, ColumnMappingProfileType, Cycle, ImportFile, MappingResultsResponse, MappingSuggestionsResponse, Organization, ProgressResponse } from '@seed/api'
10-
import { ColumnMappingProfileService, ColumnService, CycleService, DatasetService, MappingService, OrganizationService, UserService } from '@seed/api'
10+
import { CacheService, ColumnMappingProfileService, ColumnService, CycleService, DatasetService, MappingService, OrganizationService, UserService } from '@seed/api'
1111
import { PageComponent, ProgressBarComponent } from '@seed/components'
1212
import { MaterialImports } from '@seed/materials'
1313
import { UploaderService } from '@seed/services/uploader'
@@ -40,6 +40,7 @@ export class DataMappingComponent implements OnDestroy, OnInit {
4040
@ViewChild(MapDataComponent) mapDataComponent!: MapDataComponent
4141
@ViewChild(MatchMergeComponent) matchMergeComponent!: MatchMergeComponent
4242
private readonly _unsubscribeAll$ = new Subject<void>()
43+
private _cacheService = inject(CacheService)
4344
private _columnMappingProfileService = inject(ColumnMappingProfileService)
4445
private _columnService = inject(ColumnService)
4546
private _cycleService = inject(CycleService)
@@ -71,11 +72,12 @@ export class DataMappingComponent implements OnDestroy, OnInit {
7172
matchingTaxLotColumns: string[] = []
7273
org: Organization
7374
orgId: number
75+
progressBarObj = this._uploaderService.defaultProgressBarObj
76+
progressTitle = 'Mapping Data...'
7477
propertyColumns: Column[]
7578
rawColumnNames: string[] = []
7679
taxlotColumns: Column[]
7780

78-
progressBarObj = this._uploaderService.defaultProgressBarObj
7981

8082
ngOnInit(): void {
8183
// this._userService.currentOrganizationId$
@@ -181,7 +183,6 @@ export class DataMappingComponent implements OnDestroy, OnInit {
181183
this._snackBar.alert('Error starting mapping')
182184
}
183185
const successFn = () => {
184-
this.nextStep(2)
185186
this.getMappingResults()
186187
}
187188

@@ -214,10 +215,25 @@ export class DataMappingComponent implements OnDestroy, OnInit {
214215
}
215216

216217
getMappingResults(): void {
217-
this.nextStep(2)
218+
this.progressTitle = 'Fetching Mapping Results...'
219+
const successFn = ({ unique_id }: ProgressResponse) => {
220+
this._cacheService.getCacheEntry(this.orgId, unique_id)
221+
.pipe(
222+
tap((response) => {
223+
this.mappingResultsResponse = response as MappingResultsResponse
224+
this.nextStep(2)
225+
}),
226+
)
227+
.subscribe()
228+
}
229+
218230
this._mappingService.mappingResults(this.orgId, this.fileId)
219231
.pipe(
220-
tap((mappingResultsResponse) => { this.mappingResultsResponse = mappingResultsResponse }),
232+
switchMap(({ progress_key }) => this._uploaderService.checkProgressLoop({
233+
progressKey: progress_key,
234+
successFn,
235+
progressBarObj: this.progressBarObj,
236+
})),
221237
)
222238
.subscribe()
223239
}

src/app/modules/datasets/data-mappings/step3/save-mappings.component.html

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,3 @@
7272
>
7373
</ag-grid-angular>
7474
}
75-
76-
@if (loading) {
77-
<div class="m-10">
78-
<div class="mb-5 flex items-center space-x-2">
79-
<mat-icon class="text-primary-600" svgIcon="fa-solid:hourglass-half"></mat-icon>
80-
<div class="text-secondary text-xl font-medium leading-6">Fetching Mapping Results...</div>
81-
</div>
82-
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
83-
</div>
84-
}

0 commit comments

Comments
 (0)