Skip to content

Commit b342e39

Browse files
committed
fix: address review comments
1 parent f9a4bf8 commit b342e39

3 files changed

Lines changed: 20 additions & 24 deletions

File tree

src/app/devices/device-toolbar/device-toolbar.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
mat-icon-button
5656
type="button"
5757
[matTooltip]="powerState() | translate"
58-
aria-label="Refresh power status"
58+
[attr.aria-label]="'deviceToolbar.power.refreshAriaLabel.value' | translate"
5959
style="padding: 0 18px 0 12px"
6060
[style.color]="
6161
powerState() === 'deviceToolbar.power.on.value'

src/app/devices/device-toolbar/device-toolbar.component.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -233,35 +233,26 @@ export class DeviceToolbarComponent implements OnInit {
233233

234234
private loadPowerState(): void {
235235
// Use cached to dedupe simultaneous requests (KVM deep-link + toolbar both loading).
236-
this.isLoading().set(true)
237-
this.devicesService
238-
.getPowerStateCached(this.deviceId())
239-
.pipe(
240-
catchError(() => {
241-
// Network/backend failure; silently skip update and let UI show previous state.
242-
return EMPTY
243-
}),
244-
finalize(() => {
245-
this.isLoading().set(false)
246-
}),
247-
takeUntilDestroyed(this.destroyRef)
248-
)
249-
.subscribe((powerState) => {
250-
this.setPowerStateLabel(powerState.powerstate)
251-
})
236+
this.fetchPowerState(this.devicesService.getPowerStateCached(this.deviceId()))
252237
}
253238

254239
refreshPowerState(): void {
240+
// Bypass the cache so manual refresh always fetches the latest state from the device.
241+
this.fetchPowerState(this.devicesService.getPowerState(this.deviceId()), () => {
242+
const msg: string = this.translate.instant('kvm.errorRetrievePower.value')
243+
this.snackBar.open(msg, undefined, SnackbarDefaults.defaultError)
244+
})
245+
}
246+
247+
private fetchPowerState(source: Observable<any>, onError?: () => void): void {
255248
this.isLoading().set(true)
256-
// Bypass the cache so manual refresh always fetches the latest state from the
257-
// device rather than returning a previously cached value.
258-
this.devicesService
259-
.getPowerState(this.deviceId())
249+
source
260250
.pipe(
261251
catchError((err) => {
262-
console.error(err)
263-
const msg: string = this.translate.instant('kvm.errorRetrievePower.value')
264-
this.snackBar.open(msg, undefined, SnackbarDefaults.defaultError)
252+
if (onError) {
253+
console.error(err)
254+
onError()
255+
}
265256
return EMPTY
266257
}),
267258
finalize(() => {
@@ -475,6 +466,7 @@ export class DeviceToolbarComponent implements OnInit {
475466
const msg: string = this.translate.instant('devices.powerActionSent.value')
476467
console.log('Power action sent successfully:', data)
477468
this.snackBar.open(msg, undefined, SnackbarDefaults.defaultSuccess)
469+
this.refreshPowerState()
478470
} else {
479471
console.log('Power action failed:', data)
480472
const msg: string = this.translate.instant('devices.failPowerAction.value')

src/assets/i18n/en.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,6 +1253,10 @@
12531253
"description": "Power tooltip for Off",
12541254
"value": "Power: Off"
12551255
},
1256+
"deviceToolbar.power.refreshAriaLabel": {
1257+
"description": "Aria label for the refresh power status button",
1258+
"value": "Refresh power status"
1259+
},
12561260
"deviceUserConsent.description": {
12571261
"description": "Description for user consent for devices",
12581262
"value": "A user consent code generated by Intel AMT is required to access the system."

0 commit comments

Comments
 (0)