[AAE-10253] It shouldn't be possible to right click in a drag&drop empty area (#2611)

* [AAE-10253] It shouldn't be possible to right click in a drag&drop empty area

* changed expect

* add method isEmptyTable
This commit is contained in:
Ketevani Kvirikashvili 2022-09-16 11:40:22 +01:00 committed by GitHub
parent 77ee0f5073
commit 50c84a0e8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -63,4 +63,23 @@ describe('ContextActionsDirective', () => {
expect(storeMock.dispatch).toHaveBeenCalledWith(new ContextMenu(mouseEventMock));
}));
it('should not call service to render context menu if the datatable is empty', fakeAsync(() => {
const el = document.createElement('div');
el.className = 'adf-no-content-container';
const fragment = document.createDocumentFragment();
fragment.appendChild(el);
const target = fragment.querySelector('div');
const mouseEventMock: any = { preventDefault: () => {}, target };
directive.ngOnInit();
directive.onContextMenuEvent(mouseEventMock);
tick(500);
expect(storeMock.dispatch).not.toHaveBeenCalled();
}));
});

View File

@ -73,6 +73,10 @@ export class ContextActionsDirective implements OnInit, OnDestroy {
target.dispatchEvent(new MouseEvent('click'));
}
if (this.isEmptyTable(target)) {
return null;
}
this.execute$.next(event);
}
@ -89,6 +93,10 @@ export class ContextActionsDirective implements OnInit, OnDestroy {
return this.findAncestor(target, 'adf-datatable-row').classList.contains('adf-is-selected');
}
private isEmptyTable(target: Element): boolean {
return this.findAncestor(target, 'adf-datatable-cell').classList.contains('adf-no-content-container');
}
private findAncestor(el: Element, className: string): Element {
if (el.classList.contains(className)) {
return el;