Sonarcloud issues fixes (#3499)

* Sonarcloud issues fixes

* Code smell fixes

* Refactoring to remove new code duplications

* Sonarcloud code smell fixes part I

* Sonarcloud code smell fixes part II

* Missing code smell fix

* Add new ESLint rules to cover fixed SonarCloud issues

* Add missing command

* Add missing is existing check
This commit is contained in:
MichalKinas
2023-11-03 11:43:06 +01:00
committed by GitHub
parent 968febffb0
commit 69c00fc403
72 changed files with 327 additions and 530 deletions

View File

@@ -75,7 +75,6 @@ describe('ActionDirective', () => {
it('should add active route class name', () => {
fixture.detectChanges();
router.navigateByUrl('/dummy');
// fixture.detectChanges();
expect(document.body.querySelector('#test-element').className.includes('active-link-class')).toBe(true);
});

View File

@@ -67,7 +67,7 @@ export class ActiveLinkDirective implements OnInit, AfterContentInit {
}
private render(routerUrl: string, actionUrl: string) {
if (routerUrl && routerUrl.substring(1).startsWith(actionUrl)) {
if (routerUrl?.substring(1).startsWith(actionUrl)) {
this.isLinkActive = true;
this.renderer.addClass(this.element.nativeElement, this.acaActiveLink);
} else {
@@ -82,6 +82,6 @@ export class ActiveLinkDirective implements OnInit, AfterContentInit {
}
private resolveUrl(item): string {
return (item.action && item.action.click && item.action.click.payload) || item.action.route;
return item.action?.click?.payload || item.action?.route;
}
}

View File

@@ -58,7 +58,7 @@ export class ExpansionPanelDirective implements OnInit, OnDestroy {
constructor(private store: Store<any>, private router: Router, private expansionPanel: MatExpansionPanel) {}
hasActiveLinks() {
if (this.acaExpansionPanel && this.acaExpansionPanel.children) {
if (this.acaExpansionPanel?.children) {
return this.acaExpansionPanel.children.some((child) => this.router.url.startsWith(child.url || child.action.payload));
}
return false;

View File

@@ -57,7 +57,7 @@ export class MenuPanelDirective implements OnInit, OnDestroy {
constructor(private store: Store<any>, private router: Router) {}
hasActiveLinks() {
if (this.acaMenuPanel && this.acaMenuPanel.children) {
if (this.acaMenuPanel?.children) {
return this.acaMenuPanel.children.some((child) => this.router.url.startsWith(child.url || child.action.payload));
}
return false;

View File

@@ -57,7 +57,7 @@ export class UserMenuComponent implements OnInit {
ngOnInit() {
this.getUserInfo();
if (this.data && this.data.items) {
if (this.data?.items) {
this.data.items.sort((a, b) => a.order - b.order);
}
}