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
5 changes: 2 additions & 3 deletions modules/ui/src/app/pages/devices/devices.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,15 @@ <h2 class="title" tabindex="-1">Devices</h2>
<ng-container *ngTemplateOutlet="addDeviceButton"></ng-container>
</mat-toolbar>
<div class="device-repository-content">
<ng-container *ngFor="let device of vm.devices">
<ng-container *ngFor="let device of vm.devices; index as i">
<app-device-item
(itemClicked)="
openDialog(vm.devices, vm.testModules, $event, $event, true)
openDialog(vm.devices, vm.testModules, $event, $event, true, 0, i)
"
(startTestrunClicked)="
openStartTestrun($event, vm.devices, vm.testModules)
"
[deviceView]="DeviceView.WithActions"
[class.device-item-selected]="device === vm.selectedDevice"
[device]="device"
[disabled]="
device?.mac_addr === vm.deviceInProgress?.mac_addr
Expand Down
27 changes: 19 additions & 8 deletions modules/ui/src/app/pages/devices/devices.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,6 @@ describe('DevicesComponent', () => {
expect(item.length).toEqual(3);
}));

it('should add device-item-selected class for selected device', fakeAsync(() => {
const item = compiled.querySelector('app-device-item');

expect(item?.classList.contains('device-item-selected')).toBeTrue();
}));

it('should open device dialog on "add device button" click', () => {
const openSpy = spyOn(component.dialog, 'open').and.returnValue({
afterClosed: () => of(true),
Expand Down Expand Up @@ -289,7 +283,15 @@ describe('DevicesComponent', () => {
afterClosed: () => of(true),
} as MatDialogRef<typeof SimpleDialogComponent>);

component.openDeleteDialog([device], MOCK_TEST_MODULES, device, device);
component.openDeleteDialog(
[device],
MOCK_TEST_MODULES,
device,
device,
false,
0,
0
);

const args = mockDevicesStore.deleteDevice.calls.argsFor(0);
// @ts-expect-error config is in object
Expand All @@ -303,14 +305,23 @@ describe('DevicesComponent', () => {
afterClosed: () => of(null),
} as MatDialogRef<typeof SimpleDialogComponent>);

component.openDeleteDialog([device], MOCK_TEST_MODULES, device, device);
component.openDeleteDialog(
[device],
MOCK_TEST_MODULES,
device,
device,
false,
0,
0
);

expect(openDeviceDialogSpy).toHaveBeenCalledWith(
[device],
MOCK_TEST_MODULES,
device,
device,
false,
0,
0
);
});
Expand Down
59 changes: 36 additions & 23 deletions modules/ui/src/app/pages/devices/devices.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ export class DevicesComponent implements OnInit, OnDestroy {
initialDevice?: Device,
selectedDevice?: Device,
isEditDevice = false,
index = 0
index = 0,
deviceIndex?: number
): void {
const dialogRef = this.dialog.open(DeviceQualificationFromComponent, {
ariaLabel: isEditDevice ? 'Edit device' : 'Create Device',
Expand All @@ -145,7 +146,6 @@ export class DevicesComponent implements OnInit, OnDestroy {
?.afterClosed()
.pipe(takeUntil(this.destroy$))
.subscribe((response: FormResponse) => {
this.devicesStore.selectDevice(null);
if (!response) {
this.devicesStore.setIsOpenAddDevice(false);
return;
Expand All @@ -157,29 +157,30 @@ export class DevicesComponent implements OnInit, OnDestroy {
initialDevice,
response.device,
isEditDevice,
response.index
response.index,
deviceIndex
);
} else if (
response.action === FormAction.Save &&
response.device &&
!selectedDevice
) {
} else if (response.action === FormAction.Save && response.device) {
timer(10)
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.focusManagerService.focusFirstElementInContainer();
if (!initialDevice) {
this.focusManagerService.focusFirstElementInContainer();
} else if (deviceIndex !== undefined) {
this.focusSelectedButton(deviceIndex);
}
});
}
if (response.action === FormAction.Delete && initialDevice) {
this.devicesStore.selectDevice(initialDevice);
if (response.device) {
this.openDeleteDialog(
devices,
testModules,
initialDevice,
response.device,
isEditDevice,
response.index
response.index,
deviceIndex!
);
}
}
Expand All @@ -192,7 +193,8 @@ export class DevicesComponent implements OnInit, OnDestroy {
initialDevice?: Device,
device?: Device,
isEditDevice = false,
index = 0
index = 0,
deviceIndex?: number
) {
const dialogRef = this.dialog.open(SimpleDialogComponent, {
ariaLabel: 'Close the Device menu',
Expand All @@ -219,7 +221,10 @@ export class DevicesComponent implements OnInit, OnDestroy {
isEditDevice,
index
);
this.devicesStore.selectDevice(null);
} else if (deviceIndex !== undefined) {
this.focusSelectedButton(deviceIndex);
} else {
this.focusManagerService.focusFirstElementInContainer();
}
});
}
Expand All @@ -230,7 +235,8 @@ export class DevicesComponent implements OnInit, OnDestroy {
initialDevice: Device,
device: Device,
isEditDevice = false,
index = 0
index = 0,
deviceIndex: number
) {
const dialogRef = this.dialog.open(SimpleDialogComponent, {
ariaLabel: 'Delete device',
Expand All @@ -254,8 +260,7 @@ export class DevicesComponent implements OnInit, OnDestroy {
this.devicesStore.deleteDevice({
device: initialDevice,
onDelete: () => {
this.focusNextButton();
this.devicesStore.selectDevice(null);
this.focusNextButton(deviceIndex);
},
});
} else {
Expand All @@ -265,22 +270,30 @@ export class DevicesComponent implements OnInit, OnDestroy {
initialDevice,
device,
isEditDevice,
index
index,
deviceIndex
);
this.devicesStore.selectDevice(null);
}
});
}

private focusNextButton() {
private focusSelectedButton(index: number) {
const selected = this.element.nativeElement.querySelectorAll(
'app-device-item .button-edit'
)[index];
if (selected) {
selected.focus();
}
}
private focusNextButton(index: number) {
this.changeDetectorRef.detectChanges();
// Try to focus next device item, if exist
const next = this.element.nativeElement.querySelector(
'.device-item-selected + app-device-item button'
);
const next = this.element.nativeElement.querySelectorAll(
'app-device-item .button-edit'
)[index];
if (next) {
next.focus();
} else {
this.changeDetectorRef.detectChanges();
// If next device item doest not exist, add device button should be focused
const addButton =
this.element.nativeElement.querySelector('.device-add-button');
Expand Down