Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions modules/ui/src/app/pages/devices/devices.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ export class DevicesStore extends ComponentStore<DevicesComponentState> {
exhaustMap(({ device, onDelete }) => {
return this.testRunService.deleteDevice(device).pipe(
withLatestFrom(this.devices$),
tap(([, devices]) => {
this.removeDevice(device, devices);
onDelete();
tap(([deleted, devices]) => {
if (deleted) {
this.removeDevice(device, devices);
onDelete();
}
})
);
})
Expand All @@ -81,9 +83,11 @@ export class DevicesStore extends ComponentStore<DevicesComponentState> {
exhaustMap(({ device, onSuccess }) => {
return this.testRunService.saveDevice(device).pipe(
withLatestFrom(this.devices$),
tap(([, devices]) => {
this.addDevice(device, devices);
onSuccess();
tap(([added, devices]) => {
if (added) {
this.addDevice(device, devices);
onSuccess();
}
})
);
})
Expand All @@ -100,9 +104,11 @@ export class DevicesStore extends ComponentStore<DevicesComponentState> {
exhaustMap(({ device, mac_addr, onSuccess }) => {
return this.testRunService.editDevice(device, mac_addr).pipe(
withLatestFrom(this.devices$),
tap(([, devices]) => {
this.updateDevice(device, mac_addr, devices);
onSuccess();
tap(([edited, devices]) => {
if (edited) {
this.updateDevice(device, mac_addr, devices);
onSuccess();
}
})
);
})
Expand Down
15 changes: 12 additions & 3 deletions modules/ui/src/app/services/test-run.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ export class TestRunService {
saveDevice(device: Device): Observable<boolean> {
return this.http
.post<boolean>(`${API_URL}/device`, JSON.stringify(device))
.pipe(map(() => true));
.pipe(
map(() => true),
catchError(() => of(false))
);
}

editDevice(device: Device, mac_addr: string): Observable<boolean> {
Expand All @@ -145,14 +148,20 @@ export class TestRunService {

return this.http
.post<boolean>(`${API_URL}/device/edit`, JSON.stringify(request))
.pipe(map(() => true));
.pipe(
map(() => true),
catchError(() => of(false))
);
}
deleteDevice(device: Device): Observable<boolean> {
return this.http
.delete<boolean>(`${API_URL}/device`, {
body: JSON.stringify(device),
})
.pipe(map(() => true));
.pipe(
map(() => true),
catchError(() => of(false))
);
}

getHistory(): Observable<TestrunStatus[] | null> {
Expand Down