Skip to content

Commit 3958697

Browse files
committed
feat: avoid reloading AMT Summary when updating AMT Features
1 parent 4ce9d94 commit 3958697

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

src/app/devices/general/general.component.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@
6363
<mat-card-title>{{ 'general.amtEnabledFeatures.value' | translate }}</mat-card-title>
6464
<mat-card-subtitle>{{ 'general.amtEnabledFeaturesDescription.value' | translate }}</mat-card-subtitle>
6565
</mat-card-header>
66+
@if (isUpdatingFeatures()) {
67+
<mat-progress-bar mode="indeterminate"></mat-progress-bar>
68+
}
6669
<mat-card-content class="amt-features" [formGroup]="amtEnabledFeatures">
6770
<div class="flex-row flex-wrap">
6871
@if (isRedirectionRequired && !amtEnabledFeatures.get('redirection')?.value) {

src/app/devices/general/general.component.spec.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { of } from 'rxjs'
1111
import { DevicesService } from '../devices.service'
1212
import { provideTranslateService } from '@ngx-translate/core'
1313
import { By } from '@angular/platform-browser'
14+
import { Subject } from 'rxjs'
1415

1516
describe('GeneralComponent', () => {
1617
let component: GeneralComponent
@@ -32,7 +33,8 @@ describe('GeneralComponent', () => {
3233
'bulkPowerAction',
3334
'sendDeactivate',
3435
'sendBulkDeactivate',
35-
'getWsmanOperations'
36+
'getWsmanOperations',
37+
'setAmtFeatures'
3638
])
3739
const amtFeaturesResponse = {
3840
userConsent: 'ALL',
@@ -143,4 +145,38 @@ describe('GeneralComponent', () => {
143145
jasmine.objectContaining({ remoteErase: true })
144146
)
145147
})
148+
149+
it('should update only feature loading state while setAmtFeatures is in flight', () => {
150+
const response$ = new Subject<any>()
151+
devicesServiceSpy.setAmtFeatures.and.returnValue(response$)
152+
const loadingBefore = component.isLoading()
153+
154+
component.setAmtFeatures()
155+
156+
expect(component.isUpdatingFeatures()).toBeTrue()
157+
expect(component.isLoading()).toBe(loadingBefore)
158+
159+
response$.next({ redirection: true, status: 'ok' })
160+
response$.complete()
161+
162+
expect(component.isUpdatingFeatures()).toBeFalse()
163+
expect(component.isLoading()).toBe(loadingBefore)
164+
})
165+
166+
it('keeps summary loading state independent from feature update state', () => {
167+
const response$ = new Subject<any>()
168+
devicesServiceSpy.setAmtFeatures.and.returnValue(response$)
169+
170+
component.isLoading.set(false)
171+
component.setAmtFeatures()
172+
173+
expect(component.isLoading()).toBeFalse()
174+
expect(component.isUpdatingFeatures()).toBeTrue()
175+
176+
response$.next({ redirection: true, status: 'ok' })
177+
response$.complete()
178+
179+
expect(component.isLoading()).toBeFalse()
180+
expect(component.isUpdatingFeatures()).toBeFalse()
181+
})
146182
})

src/app/devices/general/general.component.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export class GeneralComponent implements OnInit, OnDestroy {
7878
})
7979

8080
public isLoading = signal(true)
81+
public isUpdatingFeatures = signal(false)
8182
public amtDHCPDNSSuffix: string | null = null
8283
public amtTrustedDNSSuffix: string | null = null
8384
public amtVersion: string | null = null
@@ -180,15 +181,15 @@ export class GeneralComponent implements OnInit, OnDestroy {
180181
}
181182

182183
setAmtFeatures(): void {
183-
this.isLoading.set(true)
184+
this.isUpdatingFeatures.set(true)
184185
this.devicesService
185186
.setAmtFeatures(this.deviceId(), {
186187
...this.amtEnabledFeatures.getRawValue(),
187188
remoteErase: this.amtFeatures.remoteErase
188189
} as AMTFeaturesRequest)
189190
.pipe(
190191
finalize(() => {
191-
this.isLoading.set(false)
192+
this.isUpdatingFeatures.set(false)
192193
})
193194
)
194195
.subscribe({

0 commit comments

Comments
 (0)