From d8bd002b025ec5c5b05c3d3e1ca54f04217ce699 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Fri, 27 Oct 2023 13:45:30 +0200 Subject: [PATCH] Sonarcloud code smell fixes part I --- app/proxy.conf.js | 2 +- app/src/main.ts | 2 +- .../viewer/src/tests/viewer-protected.spec.ts | 2 +- .../suites/actions/copy-move/copy.test.ts | 56 +++++++++---------- .../suites/list-views/sort-list.test.ts | 8 +-- .../actions/rule-action.ui-component.ts | 8 +-- .../lib/components/preview.component.spec.ts | 2 +- .../src/lib/components/preview.component.ts | 24 +++----- .../location-link/location-link.component.ts | 8 ++- .../toggle-shared/toggle-shared.component.ts | 2 +- .../context-menu-item.component.ts | 2 +- .../context-menu-outside-event.directive.ts | 8 +-- .../context-menu/context-menu.service.ts | 5 -- .../favorite-libraries.component.ts | 2 +- .../favorites/favorites.component.ts | 4 +- .../lib/components/files/files.component.ts | 30 +++++----- .../library-metadata-form.component.ts | 4 +- .../libraries/libraries.component.ts | 2 +- .../recent-files/recent-files.component.ts | 6 +- .../search-input-control.component.spec.ts | 16 +++--- 20 files changed, 81 insertions(+), 112 deletions(-) diff --git a/app/proxy.conf.js b/app/proxy.conf.js index cd22e0f55a..0d90716bc5 100644 --- a/app/proxy.conf.js +++ b/app/proxy.conf.js @@ -18,7 +18,7 @@ module.exports = { // workaround for REPO-2260 onProxyRes: function (proxyRes) { const header = proxyRes.headers['www-authenticate']; - if (header && header.startsWith('Basic')) { + if (header?.startsWith('Basic')) { proxyRes.headers['www-authenticate'] = 'x' + header; } } diff --git a/app/src/main.ts b/app/src/main.ts index 0e42d77f5c..dcd2f5e328 100644 --- a/app/src/main.ts +++ b/app/src/main.ts @@ -32,4 +32,4 @@ if (environment.production) { enableProdMode(); } -void platformBrowserDynamic().bootstrapModule(AppModule); +platformBrowserDynamic().bootstrapModule(AppModule); diff --git a/e2e/playwright/viewer/src/tests/viewer-protected.spec.ts b/e2e/playwright/viewer/src/tests/viewer-protected.spec.ts index 3f613864a2..91fb4274b2 100644 --- a/e2e/playwright/viewer/src/tests/viewer-protected.spec.ts +++ b/e2e/playwright/viewer/src/tests/viewer-protected.spec.ts @@ -33,7 +33,7 @@ test.describe('viewer file', () => { let folderId: string; let fileDocxId: string; - test.beforeAll(async ({ fileAction, shareAction, favoritesPageAction: favoritesPageAction }) => { + test.beforeAll(async ({ fileAction, shareAction, favoritesPageAction }) => { await apiClientFactory.setUpAcaBackend('hruser'); const node = await apiClientFactory.nodes.createNode('-my-', { name: randomFolderName, nodeType: 'cm:folder', relativePath: '/' }); folderId = node.entry.id; diff --git a/e2e/protractor/suites/actions/copy-move/copy.test.ts b/e2e/protractor/suites/actions/copy-move/copy.test.ts index 73b820d37e..37ac716066 100755 --- a/e2e/protractor/suites/actions/copy-move/copy.test.ts +++ b/e2e/protractor/suites/actions/copy-move/copy.test.ts @@ -206,53 +206,47 @@ describe('Copy content', () => { await dataTable.doubleClickOnRowByName(source); }); - it('[C217135] Copy a file', async () => copyFile(file1, '', destinationPF)); + it('[C217135] Copy a file', async () => copyFile(file1, destinationPF)); - it('[C291888] Copy a folder with content', async () => copyFolderWithContent(folder1, '', destinationPF)); + it('[C291888] Copy a folder with content', async () => copyFolderWithContent(folder1, destinationPF)); - it('[C291889] Copy multiple items', async () => copyMultipleItems([file2, file3], '', destinationPF)); + it('[C291889] Copy multiple items', async () => copyMultipleItems([file2, file3], destinationPF)); it('[C217137] Copy a file with a name that already exists on the destination', async () => - copyFileWithNameThatAlreadyExists(existingFile, '', destinationPF)); + copyFileWithNameThatAlreadyExists(existingFile, destinationPF)); it('[C217138] Copy a folder with a name that already exists on the destination', async () => - copyFolderWithNameThatAlreadyExists(existingFolder, '', destinationPF)); + copyFolderWithNameThatAlreadyExists(existingFolder, destinationPF)); - it('[C280282] Copy items into a library', async () => copyItemsIntoLibrary([file1, folder1], '', folderSitePF)); + it('[C280282] Copy items into a library', async () => copyItemsIntoLibrary([file1, folder1], folderSitePF)); it('[C217139] Copy locked file', async () => - copyLockedFile(fileLocked1, '', destinationPF, () => { + copyLockedFile(fileLocked1, destinationPF, '', () => { locationId = sourceId; destinationId = destinationIdPF; })); it('[C217140] Copy folder that contains locked file', async () => - copyFolderThatContainsLockedFile(folderWithLockedFiles, '', destinationPF, () => { + copyFolderThatContainsLockedFile(folderWithLockedFiles, destinationPF, '', () => { locationId = folderWithLockedFilesId; destinationId = destinationIdPF; })); - it('[C217171] Undo copy of files', async () => undoCopyFile(file4, '', destinationPF)); + it('[C217171] Undo copy of files', async () => undoCopyFile(file4, destinationPF)); - it('[C217172] Undo copy of folders', async () => undoCopyFolder(folder2, '', destinationPF)); + it('[C217172] Undo copy of folders', async () => undoCopyFolder(folder2, destinationPF)); it('[C217173] Undo copy of a file when a file with same name already exists on the destination', async () => - undoCopyFileWithExistingName(fileInFolder, '', folder2, async () => { + undoCopyFileWithExistingName(fileInFolder, folder2, '', async () => { await dataTable.doubleClickOnRowByName(folder1); await dataTable.waitForHeader(); })); it('[C217174] Undo copy of a folder when a folder with same name already exists on the destination', async () => - undoCopyFolderWithExistingName(folderExisting, '', destinationPF)); + undoCopyFolderWithExistingName(folderExisting, destinationPF)); }); - async function baseCopy( - itemName: string | string[], - location: string, - destination: string, - undo: boolean = false, - expectedMsg: string = 'Copied 1 item' - ) { + async function baseCopy(itemName: string | string[], location: string, destination: string, undo = false, expectedMsg = 'Copied 1 item') { if (itemName instanceof Array) { await dataTable.selectMultipleItems(itemName, location); } else { @@ -302,7 +296,7 @@ describe('Copy content', () => { await baseCopy(itemName, location, destination, undo, expectedMsg); } - async function copyFile(fileName: string, location: string = '', destination: string, doBefore?: () => void) { + async function copyFile(fileName: string, destination: string, location = '', doBefore?: () => void) { await baseCopyDoBefore(fileName, location, destination, doBefore); expect(await dataTable.isItemPresent(fileName)).toBe(true, `${fileName} not present in source folder`); await page.clickPersonalFilesAndWait(); @@ -310,7 +304,7 @@ describe('Copy content', () => { expect(await dataTable.isItemPresent(fileName)).toBe(true, `${fileName} not present in ${destination} folder`); } - async function copyFolderWithContent(folderName: string, location: string = '', destination: string, doBefore?: () => void) { + async function copyFolderWithContent(folderName: string, destination: string, location = '', doBefore?: () => void) { await baseCopyDoBefore(folderName, location, destination, doBefore); expect(await dataTable.isItemPresent(folderName)).toBe(true, `${folderName} not present in source folder`); await page.clickPersonalFilesAndWait(); @@ -322,7 +316,7 @@ describe('Copy content', () => { expect(await dataTable.isItemPresent(fileInFolder)).toBe(true, `${fileInFolder} is not present in ${folderName} folder in ${destination}`); } - async function copyMultipleItems(items: string[], location: string = '', destination: string, doBefore?: () => void) { + async function copyMultipleItems(items: string[], destination: string, location = '', doBefore?: () => void) { await baseCopyDoBefore(items, location, destination, doBefore, false, 'Copied 2 items'); expect(await dataTable.isItemPresent(items[0])).toBe(true, `${items[0]} not present in source folder`); expect(await dataTable.isItemPresent(items[1])).toBe(true, `${items[1]} not present in source folder`); @@ -332,7 +326,7 @@ describe('Copy content', () => { expect(await dataTable.isItemPresent(items[1])).toBe(true, `${items[1]} not present in ${destination} folder`); } - async function copyFileWithNameThatAlreadyExists(fileName: string, location: string = '', destination: string, doBefore?: () => void) { + async function copyFileWithNameThatAlreadyExists(fileName: string, destination: string, location = '', doBefore?: () => void) { await baseCopyDoBefore(fileName, location, destination, doBefore); expect(await dataTable.isItemPresent(fileName)).toBe(true, `${fileName}.txt not present in source folder`); await page.clickPersonalFilesAndWait(); @@ -340,7 +334,7 @@ describe('Copy content', () => { expect(await dataTable.isItemPresent(fileName)).toBe(true, `${fileName}.txt not present in ${destination} folder`); } - async function copyFolderWithNameThatAlreadyExists(folderName: string, location: string = '', destination: string, doBefore?: () => void) { + async function copyFolderWithNameThatAlreadyExists(folderName: string, destination: string, location = '', doBefore?: () => void) { await baseCopyDoBefore(folderName, location, destination, doBefore); expect(await dataTable.isItemPresent(folderName)).toBe(true, `${folderName} not present in source folder`); await page.clickPersonalFilesAndWait(); @@ -351,7 +345,7 @@ describe('Copy content', () => { expect(await dataTable.isItemPresent(file3InFolder)).toBe(true, `${file3InFolder} not present in ${destination} folder in ${folderName}`); } - async function copyItemsIntoLibrary(items: string[], location: string = '', destination: string, doBefore?: () => void) { + async function copyItemsIntoLibrary(items: string[], destination: string, location = '', doBefore?: () => void) { if (doBefore) { doBefore(); } @@ -382,7 +376,7 @@ describe('Copy content', () => { } } - async function copyLockedFile(fileName: string, location: string = '', destination: string, doBefore?: () => void) { + async function copyLockedFile(fileName: string, destination: string, location = '', doBefore?: () => void) { await baseCopyDoBefore(fileName, location, destination, doBefore); expect(await dataTable.isItemPresent(fileName)).toBe(true, `${fileName} not present in source folder`); expect(await apis.nodes.isFileLockedByName(fileName, locationId)).toBe(true, `${fileName} not locked in ${location}`); @@ -392,7 +386,7 @@ describe('Copy content', () => { expect(await apis.nodes.isFileLockedByName(fileName, destinationId)).toBe(false, `${fileName} is locked in ${destination}`); } - async function copyFolderThatContainsLockedFile(folderName: string, location: string = '', destination: string, doBefore?: () => void) { + async function copyFolderThatContainsLockedFile(folderName: string, destination: string, location = '', doBefore?: () => void) { await baseCopyDoBefore(folderName, location, destination, doBefore); expect(await dataTable.isItemPresent(folderName)).toBe(true, `${folderName} not present in source folder`); await page.clickPersonalFilesAndWait(); @@ -412,7 +406,7 @@ describe('Copy content', () => { ); } - async function undoCopyFile(fileName: string, location: string = '', destination: string, doBefore?: () => void) { + async function undoCopyFile(fileName: string, destination: string, location = '', doBefore?: () => void) { await baseCopyDoBefore(fileName, location, destination, doBefore, true); await dataTable.doubleClickOnRowByName(destination); expect(await dataTable.isItemPresent(fileName)).toBe(false, `${fileName} present in ${destination} folder`); @@ -421,7 +415,7 @@ describe('Copy content', () => { expect(await dataTable.isEmpty()).toBe(true, 'Trash is not empty'); } - async function undoCopyFolder(folderName: string, location: string = '', destination: string, doBefore?: () => void) { + async function undoCopyFolder(folderName: string, destination: string, location = '', doBefore?: () => void) { await baseCopyDoBefore(folderName, location, destination, doBefore, true); await dataTable.doubleClickOnRowByName(destination); expect(await dataTable.isItemPresent(folderName)).toBe(false, `${folderName} present in ${destination} folder`); @@ -430,7 +424,7 @@ describe('Copy content', () => { expect(await dataTable.isEmpty()).toBe(true, 'Trash is not empty'); } - async function undoCopyFileWithExistingName(fileName: string, location: string = '', destination: string, doBefore?: () => Promise) { + async function undoCopyFileWithExistingName(fileName: string, destination: string, location = '', doBefore?: () => Promise) { await baseCopyDoBeforeAsync(fileName, location, destination, doBefore, true); await dataTable.doubleClickOnRowByName(source); await dataTable.doubleClickOnRowByName(folder2); @@ -441,7 +435,7 @@ describe('Copy content', () => { expect(await dataTable.isEmpty()).toBe(true, 'Trash is not empty'); } - async function undoCopyFolderWithExistingName(folderName: string, location: string = '', destination: string, doBefore?: () => void) { + async function undoCopyFolderWithExistingName(folderName: string, destination: string, location = '', doBefore?: () => void) { await baseCopyDoBefore(folderName, location, destination, doBefore, true); await dataTable.doubleClickOnRowByName(destination); expect(await dataTable.isItemPresent(folderName)).toBe(true, `${folderName} not present in ${destination} folder`); diff --git a/e2e/protractor/suites/list-views/sort-list.test.ts b/e2e/protractor/suites/list-views/sort-list.test.ts index 5afb145178..d826938b17 100644 --- a/e2e/protractor/suites/list-views/sort-list.test.ts +++ b/e2e/protractor/suites/list-views/sort-list.test.ts @@ -26,7 +26,7 @@ import { AdminActions, LoginPage, RepoClient, FILES, BrowsingPage, DataTable, Cr import { BrowserActions, ContentNodeSelectorDialogPage, DocumentListPage, PaginationPage, ViewerPage } from '@alfresco/adf-testing'; describe('Remember sorting', () => { - interface nodesIds { + interface NodesIds { [index: string]: string; } @@ -38,9 +38,9 @@ describe('Remember sorting', () => { const folderToMove = `folder1`; const folderToContain = `folder2`; const uiCreatedFolder = `folder3`; - const filesIdsUser1: nodesIds = {}; - const filesIdsUser2: nodesIds = {}; - const folderIds: nodesIds = {}; + const filesIdsUser1: NodesIds = {}; + const filesIdsUser2: NodesIds = {}; + const folderIds: NodesIds = {}; const testData = { user1: { diff --git a/projects/aca-content/folder-rules/src/rule-details/actions/rule-action.ui-component.ts b/projects/aca-content/folder-rules/src/rule-details/actions/rule-action.ui-component.ts index d61041e070..9e14e9b2bf 100644 --- a/projects/aca-content/folder-rules/src/rule-details/actions/rule-action.ui-component.ts +++ b/projects/aca-content/folder-rules/src/rule-details/actions/rule-action.ui-component.ts @@ -266,13 +266,7 @@ export class RuleActionUiComponent implements ControlValueAccessor, OnInit, OnCh setDefaultParameters() { this.parameters = {}; (this.selectedActionDefinition?.parameterDefinitions ?? []).forEach((paramDef: ActionParameterDefinition) => { - switch (paramDef.type) { - case 'd:boolean': - this.parameters[paramDef.name] = false; - break; - default: - this.parameters[paramDef.name] = ''; - } + this.parameters[paramDef.name] = paramDef.type === 'd:boolean' ? false : ''; }); } diff --git a/projects/aca-content/preview/src/lib/components/preview.component.spec.ts b/projects/aca-content/preview/src/lib/components/preview.component.spec.ts index 7ac2af91ec..efe3522ee7 100644 --- a/projects/aca-content/preview/src/lib/components/preview.component.spec.ts +++ b/projects/aca-content/preview/src/lib/components/preview.component.spec.ts @@ -393,7 +393,7 @@ describe('PreviewComponent', () => { }); it('should return empty nearest nodes for crashed fields id request', async () => { - spyOn(component, 'getFileIds').and.returnValue(Promise.reject('err')); + spyOn(component, 'getFileIds').and.returnValue(Promise.reject(new Error('err'))); const nearest = await component.getNearestNodes('node1', 'folder1'); diff --git a/projects/aca-content/preview/src/lib/components/preview.component.ts b/projects/aca-content/preview/src/lib/components/preview.component.ts index 853e02eed4..a6b0716819 100644 --- a/projects/aca-content/preview/src/lib/components/preview.component.ts +++ b/projects/aca-content/preview/src/lib/components/preview.component.ts @@ -177,7 +177,7 @@ export class PreviewComponent extends PageComponent implements OnInit, OnDestroy this.node = await this.contentApi.getNodeInfo(id).toPromise(); this.store.dispatch(new SetSelectedNodesAction([{ entry: this.node }])); - if (this.node && this.node.isFile) { + if (this.node?.isFile) { const nearest = await this.getNearestNodes(this.node.id, this.node.parentId); this.previousNodeId = nearest.left; @@ -196,11 +196,9 @@ export class PreviewComponent extends PageComponent implements OnInit, OnDestroy @HostListener('document:keydown', ['$event']) handleKeyboardEvent(event: KeyboardEvent) { - const key = event.keyCode; - const rightArrow = 39; - const leftArrow = 37; + const key = event.key; - if (key === rightArrow || key === leftArrow) { + if (key === 'ArrowRight' || key === 'ArrowLeft') { event.preventDefault(); event.stopImmediatePropagation(); } @@ -410,19 +408,11 @@ export class PreviewComponent extends PageComponent implements OnInit, OnDestroy } items.sort((a: any, b: any) => { - let left = ObjectUtils.getValue(a, key); - if (left) { - left = left instanceof Date ? left.valueOf().toString() : left.toString(); - } else { - left = ''; - } + let left = ObjectUtils.getValue(a, key) ?? ''; + left = left instanceof Date ? left.valueOf().toString() : left.toString(); - let right = ObjectUtils.getValue(b, key); - if (right) { - right = right instanceof Date ? right.valueOf().toString() : right.toString(); - } else { - right = ''; - } + let right = ObjectUtils.getValue(b, key) ?? ''; + right = right instanceof Date ? right.valueOf().toString() : right.toString(); return direction === 'asc' ? left.localeCompare(right, undefined, options) : right.localeCompare(left, undefined, options); }); diff --git a/projects/aca-content/src/lib/components/common/location-link/location-link.component.ts b/projects/aca-content/src/lib/components/common/location-link/location-link.component.ts index 74edff4f2c..85d05a87e7 100644 --- a/projects/aca-content/src/lib/components/common/location-link/location-link.component.ts +++ b/projects/aca-content/src/lib/components/common/location-link/location-link.component.ts @@ -83,10 +83,10 @@ export class LocationLinkComponent implements OnInit { ngOnInit() { if (this.context) { const node: NodeEntry = this.context.row.node; - if (node && node.entry && node.entry.path) { + if (node?.entry && node?.entry?.path) { const path = node.entry.path; - if (path && path.name && path.elements) { + if (path?.name && path?.elements) { if (this.showLocation) { this.displayText = of(path.name.substring(1).replace(/\//g, ' › ')); } else { @@ -144,7 +144,9 @@ export class LocationLinkComponent implements OnInit { let result: string = null; - const elements = path.elements.map((e) => Object.assign({}, e)); + const elements = path.elements.map((e) => { + return { ...e }; + }); const personalFiles = this.translationService.instant('APP.BROWSE.PERSONAL.TITLE'); const fileLibraries = this.translationService.instant('APP.BROWSE.LIBRARIES.TITLE'); diff --git a/projects/aca-content/src/lib/components/common/toggle-shared/toggle-shared.component.ts b/projects/aca-content/src/lib/components/common/toggle-shared/toggle-shared.component.ts index 46ac9e9616..40ee19dec5 100644 --- a/projects/aca-content/src/lib/components/common/toggle-shared/toggle-shared.component.ts +++ b/projects/aca-content/src/lib/components/common/toggle-shared/toggle-shared.component.ts @@ -62,7 +62,7 @@ export class ToggleSharedComponent implements OnInit, OnDestroy { this.selectionState = selectionState; this.isShared = - (this.selectionState.first && this.selectionState.first.entry && (this.selectionState.first.entry as any).sharedByUser) || + (this.selectionState?.first?.entry && (this.selectionState.first.entry as any).sharedByUser) || !!this.selectionState?.first?.entry?.properties?.['qshare:sharedId']; this.selectionLabel = this.isShared ? 'APP.ACTIONS.SHARE_EDIT' : 'APP.ACTIONS.SHARE'; diff --git a/projects/aca-content/src/lib/components/context-menu/context-menu-item.component.ts b/projects/aca-content/src/lib/components/context-menu/context-menu-item.component.ts index 54f9b1704d..afe3172789 100644 --- a/projects/aca-content/src/lib/components/context-menu/context-menu-item.component.ts +++ b/projects/aca-content/src/lib/components/context-menu/context-menu-item.component.ts @@ -52,7 +52,7 @@ export class ContextMenuItemComponent { } private hasClickAction(actionRef: ContentActionRef): boolean { - return !!(actionRef && actionRef.actions && actionRef.actions.click); + return !!actionRef?.actions?.click; } trackByActionId(_: number, obj: ContentActionRef): string { diff --git a/projects/aca-content/src/lib/components/context-menu/context-menu-outside-event.directive.ts b/projects/aca-content/src/lib/components/context-menu/context-menu-outside-event.directive.ts index 0a53eaa292..74e2b31bd3 100644 --- a/projects/aca-content/src/lib/components/context-menu/context-menu-outside-event.directive.ts +++ b/projects/aca-content/src/lib/components/context-menu/context-menu-outside-event.directive.ts @@ -36,8 +36,6 @@ export class OutsideEventDirective implements OnInit, OnDestroy { @Output() clickOutside: EventEmitter = new EventEmitter(); - constructor() {} - ngOnInit() { this.subscriptions = this.subscriptions.concat([ fromEvent(document.body, 'click') @@ -54,11 +52,9 @@ export class OutsideEventDirective implements OnInit, OnDestroy { private findAncestor(el: Element): boolean { const className = 'aca-context-menu'; - if (el.classList.contains(className)) { - return true; + while (el && !el.classList.contains(className)) { + el = el.parentElement; } - // eslint-disable-next-line curly - while ((el = el.parentElement) && !el.classList.contains(className)); return !!el; } } diff --git a/projects/aca-content/src/lib/components/context-menu/context-menu.service.ts b/projects/aca-content/src/lib/components/context-menu/context-menu.service.ts index 0719be9e32..c5b7566def 100644 --- a/projects/aca-content/src/lib/components/context-menu/context-menu.service.ts +++ b/projects/aca-content/src/lib/components/context-menu/context-menu.service.ts @@ -68,11 +68,6 @@ export class ContextMenuService { } private createInjector(contextmenuOverlayRef: ContextMenuOverlayRef): Injector { - const injectionTokens = new WeakMap(); - - injectionTokens.set(ContextMenuOverlayRef, contextmenuOverlayRef); - injectionTokens.set(CONTEXT_MENU_DIRECTION, this.direction); - return Injector.create({ parent: this.injector, providers: [ diff --git a/projects/aca-content/src/lib/components/favorite-libraries/favorite-libraries.component.ts b/projects/aca-content/src/lib/components/favorite-libraries/favorite-libraries.component.ts index a2b2461720..ac67baf8c9 100644 --- a/projects/aca-content/src/lib/components/favorite-libraries/favorite-libraries.component.ts +++ b/projects/aca-content/src/lib/components/favorite-libraries/favorite-libraries.component.ts @@ -95,7 +95,7 @@ export class FavoriteLibrariesComponent extends PageComponent implements OnInit } navigateTo(node: SiteEntry) { - if (node && node.entry && node.entry.guid) { + if (node?.entry?.guid) { this.store.dispatch(new NavigateLibraryAction(node.entry.guid, 'favorite/libraries')); } } diff --git a/projects/aca-content/src/lib/components/favorites/favorites.component.ts b/projects/aca-content/src/lib/components/favorites/favorites.component.ts index 5389d3053e..a33692b05e 100644 --- a/projects/aca-content/src/lib/components/favorites/favorites.component.ts +++ b/projects/aca-content/src/lib/components/favorites/favorites.component.ts @@ -83,7 +83,7 @@ export class FavoritesComponent extends PageComponent implements OnInit { const { isFolder, id } = favorite; // TODO: rework as it will fail on non-English setups - const isSitePath = (path: PathInfo): boolean => path && path.elements && path.elements.some(({ name }: PathElement) => name === 'Sites'); + const isSitePath = (path: PathInfo): boolean => path?.elements?.some(({ name }: PathElement) => name === 'Sites'); if (isFolder) { this.contentApi @@ -97,7 +97,7 @@ export class FavoritesComponent extends PageComponent implements OnInit { } onNodeDoubleClick(node: NodeEntry) { - if (node && node.entry) { + if (node?.entry) { if (node.entry.isFolder) { this.navigate(node.entry); } diff --git a/projects/aca-content/src/lib/components/files/files.component.ts b/projects/aca-content/src/lib/components/files/files.component.ts index a5043f6e97..759e780c8e 100644 --- a/projects/aca-content/src/lib/components/files/files.component.ts +++ b/projects/aca-content/src/lib/components/files/files.component.ts @@ -102,7 +102,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { (node) => { this.isValidPath = true; - if (node.entry && node.entry.isFolder) { + if (node?.entry?.isFolder) { this.updateCurrentNode(node.entry); } else { this.router.navigate(['/personal-files', node.entry.parentId], { @@ -190,7 +190,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { } navigateTo(node: NodeEntry) { - if (node && node.entry) { + if (node?.entry) { this.selectedNode = node; const { isFolder } = node.entry; @@ -220,7 +220,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { this.documentList.resetNewFolderPagination(); // todo: review this approach once 5.2.3 is out - if (this.nodePath && this.nodePath.length > 2) { + if (this.nodePath && this.nodePath?.length > 2) { if (this.nodePath[1].name === 'Sites' && this.nodePath[2].id === route.id) { return this.navigate(this.nodePath[3].id); } @@ -232,31 +232,31 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { const node: NodeEntry = event.file.data; // check root and child nodes - if (node && node.entry && node.entry.parentId === this.getParentNodeId()) { + if (node?.entry?.parentId === this.getParentNodeId()) { this.reload(this.selectedNode); return; } // check the child nodes to show dropped folder if (event && event.file.options.parentId === this.getParentNodeId()) { - this.displayFolderParent(event.file.options.path, 0); + this.displayFolderParent(0, event.file.options.path); return; } - if (event && event.file.options.parentId) { + if (event?.file.options.parentId) { if (this.nodePath) { const correspondingNodePath = this.nodePath.find((pathItem) => pathItem.id === event.file.options.parentId); // check if the current folder has the 'trigger-upload-folder' as one of its parents if (correspondingNodePath) { const correspondingIndex = this.nodePath.length - this.nodePath.indexOf(correspondingNodePath); - this.displayFolderParent(event.file.options.path, correspondingIndex); + this.displayFolderParent(correspondingIndex, event.file.options.path); } } } } - displayFolderParent(filePath = '', index: number) { + displayFolderParent(index: number, filePath = '') { const parentName = filePath.split('/')[index]; const currentFoldersDisplayed = (this.documentList.data.getRows() as ShareDataRow[]) || []; @@ -269,7 +269,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { } onContentCopied(nodes: NodeEntry[]) { - const newNode = nodes.find((node) => node && node.entry && node.entry.parentId === this.getParentNodeId()); + const newNode = nodes.find((node) => node?.entry?.parentId === this.getParentNodeId()); if (newNode) { this.reload(this.selectedNode); } @@ -279,10 +279,12 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { private async updateCurrentNode(node: Node) { this.nodePath = null; - if (node && node.path && node.path.elements) { + if (node?.path?.elements) { const elements = node.path.elements; - this.nodePath = elements.map((pathElement) => Object.assign({}, pathElement)); + this.nodePath = elements.map((pathElement) => { + return { ...pathElement }; + }); if (elements.length > 1) { if (elements[1].name === 'User Homes') { @@ -329,14 +331,14 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { } isSiteContainer(node: Node): boolean { - if (node && node.aspectNames && node.aspectNames.length > 0) { + if (node?.aspectNames?.length > 0) { return node.aspectNames.indexOf('st:siteContainer') >= 0; } return false; } isRootNode(nodeId: string): boolean { - if (this.node && this.node.path && this.node.path.elements && this.node.path.elements.length > 0) { + if (this.node?.path?.elements?.length > 0) { return this.node.path.elements[0].id === nodeId; } return false; @@ -359,7 +361,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy { const objectFromMap = {}; activeFilters.forEach((filter: FilterSearch) => { let paramValue; - if (filter.value && filter.value.from && filter.value.to) { + if (filter?.value?.from && filter?.value?.to) { paramValue = `${filter.value.from}||${filter.value.to}`; } else { paramValue = filter.value; diff --git a/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.ts b/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.ts index 9817ff90a5..aac068eae4 100644 --- a/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.ts +++ b/projects/aca-content/src/lib/components/info-drawer/library-metadata-tab/library-metadata-form.component.ts @@ -60,8 +60,8 @@ import { Actions, ofType } from '@ngrx/effects'; export class InstantErrorStateMatcher implements ErrorStateMatcher { isErrorState(control: UntypedFormControl | null, form: FormGroupDirective | NgForm | null): boolean { - const isSubmitted = form && form.submitted; - return !!(control && control.invalid && (control.dirty || control.touched || isSubmitted)); + const isSubmitted = form?.submitted; + return !!(control?.invalid && (control?.dirty || control?.touched || isSubmitted)); } } diff --git a/projects/aca-content/src/lib/components/libraries/libraries.component.ts b/projects/aca-content/src/lib/components/libraries/libraries.component.ts index c6c1369fd7..8475cebd35 100644 --- a/projects/aca-content/src/lib/components/libraries/libraries.component.ts +++ b/projects/aca-content/src/lib/components/libraries/libraries.component.ts @@ -81,7 +81,7 @@ export class LibrariesComponent extends PageComponent implements OnInit { } navigateTo(node: SiteEntry) { - if (node && node.entry && node.entry.guid) { + if (node?.entry?.guid) { this.store.dispatch(new NavigateLibraryAction(node.entry.guid)); } } diff --git a/projects/aca-content/src/lib/components/recent-files/recent-files.component.ts b/projects/aca-content/src/lib/components/recent-files/recent-files.component.ts index d4a4d8fdcf..889114d59d 100644 --- a/projects/aca-content/src/lib/components/recent-files/recent-files.component.ts +++ b/projects/aca-content/src/lib/components/recent-files/recent-files.component.ts @@ -63,10 +63,6 @@ import { TranslateModule } from '@ngx-translate/core'; export class RecentFilesComponent extends PageComponent implements OnInit { columns: DocumentListPresetRef[] = []; - constructor() { - super(); - } - ngOnInit() { super.ngOnInit(); @@ -79,7 +75,7 @@ export class RecentFilesComponent extends PageComponent implements OnInit { } onNodeDoubleClick(node: NodeEntry) { - if (node && node.entry) { + if (node?.entry) { this.showPreview(node, { location: this.router.url }); } } diff --git a/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.spec.ts b/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.spec.ts index eb152b5310..45b5c10ec7 100644 --- a/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.spec.ts +++ b/projects/aca-content/src/lib/components/search/search-input-control/search-input-control.component.spec.ts @@ -42,39 +42,39 @@ describe('SearchInputControlComponent', () => { fixture.detectChanges(); }); - it('should emit submit event on searchSubmit', async () => { + it('should emit submit event on searchSubmit', () => { const keyboardEvent = { target: { value: 'a' } }; let eventArgs = null; component.submit.subscribe((args) => (eventArgs = args)); - await component.searchSubmit(keyboardEvent); + component.searchSubmit(keyboardEvent); expect(eventArgs).toBe(keyboardEvent); }); - it('should emit searchChange event on inputChange', async () => { + it('should emit searchChange event on inputChange', () => { const searchTerm = 'b'; let eventArgs = null; component.searchChange.subscribe((args) => (eventArgs = args)); - await component.inputChange(searchTerm); + component.inputChange(searchTerm); expect(eventArgs).toBe(searchTerm); }); - it('should emit searchChange event on clear', async () => { + it('should emit searchChange event on clear', () => { let eventArgs = null; component.searchChange.subscribe((args) => (eventArgs = args)); - await component.clear(); + component.clear(); expect(eventArgs).toBe(''); }); - it('should clear searchTerm', async () => { + it('should clear searchTerm', () => { component.searchTerm = 'c'; fixture.detectChanges(); - await component.clear(); + component.clear(); expect(component.searchTerm).toBe(''); });