From 92d4c40707ecb3ad0b55c8c6f9a179b8f1c17e08 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Fri, 27 Oct 2023 15:32:53 +0200 Subject: [PATCH] Sonarcloud code smell fixes part II --- .../tests/special-permissions-actions.test.ts | 8 ++-- ...ch-libraries-query-builder.service.spec.ts | 4 +- .../search-libraries-query-builder.service.ts | 6 +-- .../search-libraries-results.component.ts | 4 +- .../search-results-row.component.ts | 2 +- .../search-results.component.spec.ts | 20 ++-------- .../search-results.component.ts | 2 +- .../shared-link-view.component.spec.ts | 2 +- .../directives/active-link.directive.spec.ts | 1 - .../directives/active-link.directive.ts | 4 +- .../directives/expansion-panel.directive.ts | 2 +- .../directives/menu-panel.directive.ts | 2 +- .../sidenav/user-menu/user-menu.component.ts | 2 +- .../toggle-edit-offline.component.spec.ts | 2 +- .../src/lib/services/node-actions.service.ts | 14 +++---- .../services/node-template.service.spec.ts | 6 +-- .../src/lib/services/node-template.service.ts | 2 +- .../src/lib/store/effects/library.effects.ts | 6 +-- .../src/lib/store/effects/node.effects.ts | 26 ++++++------- .../store/effects/template.effects.spec.ts | 18 ++------- .../src/lib/store/effects/upload.effects.ts | 10 +---- .../src/lib/store/effects/viewer.effects.ts | 4 +- .../src/lib/store/reducers/app.reducer.ts | 4 +- .../lib/components/viewer/viewer.component.ts | 26 ++++--------- .../src/api/file-actions.ts | 4 +- .../dataTable/mat-menu.component.ts | 3 +- .../components/viewer.component.ts | 3 +- .../src/page-objects/pages/base.page.ts | 21 +++++----- projects/aca-shared/rules/src/app.rules.ts | 38 +++++++------------ .../aca-shared/rules/src/navigation.rules.ts | 24 ++++++------ .../document-base-page.component.ts | 4 +- .../document-base-page.spec.ts | 4 -- .../toolbar-button.component.ts | 2 +- .../toolbar-menu-item.component.ts | 2 +- .../contextmenu/contextmenu.directive.ts | 6 +-- .../src/lib/services/app.extension.service.ts | 8 ++-- .../store/src/actions/router.actions.ts | 2 - .../store/src/actions/search.actions.ts | 1 - .../store/src/actions/template.actions.ts | 4 -- .../store/src/effects/router.effects.ts | 8 ++-- .../src/components/login/login.ts | 5 --- .../src/utilities/admin-actions.ts | 4 -- 42 files changed, 118 insertions(+), 202 deletions(-) diff --git a/e2e/playwright/special-permissions-actions-available/src/tests/special-permissions-actions.test.ts b/e2e/playwright/special-permissions-actions-available/src/tests/special-permissions-actions.test.ts index b04b18e865..70701c387e 100644 --- a/e2e/playwright/special-permissions-actions-available/src/tests/special-permissions-actions.test.ts +++ b/e2e/playwright/special-permissions-actions-available/src/tests/special-permissions-actions.test.ts @@ -108,12 +108,12 @@ test.describe('Special permissions : ', () => { await managerSiteActions.addSiteMember(sitePrivate, userCollaborator, Site.RoleEnum.SiteCollaborator); await managerSiteActions.addSiteMember(sitePrivate, userDemoted, Site.RoleEnum.SiteManager); - await managerFileActions.uploadFileWithRename(TEST_FILES.DOCX.path, docLibId, testData.fileDocx.name); - fileDocxFavId = (await managerFileActions.uploadFileWithRename(TEST_FILES.DOCX.path, docLibId, testData.fileDocxFav.name)).entry.id; + await managerFileActions.uploadFileWithRename(TEST_FILES.DOCX.path, testData.fileDocx.name, docLibId); + fileDocxFavId = (await managerFileActions.uploadFileWithRename(TEST_FILES.DOCX.path, testData.fileDocxFav.name, docLibId)).entry.id; await managerNodeActions.createFile(testData.file.name, docLibId); fileFavId = (await managerNodeActions.createFile(testData.fileFav.name, docLibId)).entry.id; - fileDocxSharedId = (await managerFileActions.uploadFileWithRename(TEST_FILES.DOCX.path, docLibId, testData.fileDocxShared.name)).entry.id; - fileDocxSharedFavId = (await managerFileActions.uploadFileWithRename(TEST_FILES.DOCX.path, docLibId, testData.fileDocxSharedFav.name)).entry.id; + fileDocxSharedId = (await managerFileActions.uploadFileWithRename(TEST_FILES.DOCX.path, testData.fileDocxShared.name, docLibId)).entry.id; + fileDocxSharedFavId = (await managerFileActions.uploadFileWithRename(TEST_FILES.DOCX.path, testData.fileDocxSharedFav.name, docLibId)).entry.id; fileSharedId = (await managerNodeActions.createFile(testData.fileShared.name, docLibId)).entry.id; fileSharedFavId = (await managerNodeActions.createFile(testData.fileSharedFav.name, docLibId)).entry.id; fileLockedId = (await managerNodeActions.createFile(testData.fileLocked.name, docLibId)).entry.id; diff --git a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-query-builder.service.spec.ts b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-query-builder.service.spec.ts index 97303d0c0b..06d8e234e4 100644 --- a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-query-builder.service.spec.ts +++ b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-query-builder.service.spec.ts @@ -53,13 +53,13 @@ describe('SearchLibrariesQueryBuilderService', () => { expect(builder.userQuery).toEqual('something'); }); - it('should build query and raise an event on update', async () => { + it('should build query and raise an event on update', () => { spyOn(builder, 'buildQuery').and.returnValue(query); let eventArgs = null; builder.updated.subscribe((args) => (eventArgs = args)); - await builder.update(); + builder.update(); expect(eventArgs).toBe(query); }); diff --git a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-query-builder.service.ts b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-query-builder.service.ts index 2e9122efa3..a6dbb2741b 100644 --- a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-query-builder.service.ts +++ b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-query-builder.service.ts @@ -80,12 +80,12 @@ export class SearchLibrariesQueryBuilderService { buildQuery(): LibrarySearchQuery { const query = this.userQuery; - if (query && query.length > 1) { + if (query?.length > 1) { return { term: query, opts: { - skipCount: this.paging && this.paging.skipCount, - maxItems: this.paging && this.paging.maxItems + skipCount: this.paging?.skipCount, + maxItems: this.paging?.maxItems } }; } diff --git a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.ts b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.ts index 145f5501f0..908e19eff2 100644 --- a/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.ts +++ b/projects/aca-content/src/lib/components/search/search-libraries-results/search-libraries-results.component.ts @@ -158,7 +158,7 @@ export class SearchLibrariesResultsComponent extends PageComponent implements On } getNumberOfResults() { - if (this.data && this.data.list && this.data.list.pagination) { + if (this.data?.list?.pagination) { return this.data.list.pagination.totalItems; } return 0; @@ -173,7 +173,7 @@ export class SearchLibrariesResultsComponent extends PageComponent implements On } 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/search/search-results-row/search-results-row.component.ts b/projects/aca-content/src/lib/components/search/search-results-row/search-results-row.component.ts index 3c99761faf..2bb23bd140 100644 --- a/projects/aca-content/src/lib/components/search/search-results-row/search-results-row.component.ts +++ b/projects/aca-content/src/lib/components/search/search-results-row/search-results-row.component.ts @@ -74,7 +74,7 @@ export class SearchResultsRowComponent implements OnInit, OnDestroy { if (entry.id === node.id) { entry.name = node.name; - entry.properties = Object.assign({}, node.properties); + entry.properties = { ...node.properties }; this.updateValues(); } diff --git a/projects/aca-content/src/lib/components/search/search-results/search-results.component.spec.ts b/projects/aca-content/src/lib/components/search/search-results/search-results.component.spec.ts index 2229e648e5..e8614b0a6f 100644 --- a/projects/aca-content/src/lib/components/search/search-results/search-results.component.spec.ts +++ b/projects/aca-content/src/lib/components/search/search-results/search-results.component.spec.ts @@ -95,11 +95,7 @@ describe('SearchComponent', () => { }); it('should raise an error if search fails', fakeAsync(() => { - spyOn(queryBuilder['searchApi'], 'search').and.returnValue( - Promise.reject({ - message: `{ "error": { "statusCode": 500 } } ` - }) - ); + spyOn(queryBuilder['searchApi'], 'search').and.returnValue(Promise.reject(new Error('{ "error": { "statusCode": 500 } }'))); spyOn(queryBuilder, 'buildQuery').and.returnValue(searchRequest); spyOn(store, 'dispatch').and.stub(); @@ -118,11 +114,7 @@ describe('SearchComponent', () => { return key; }); - spyOn(queryBuilder['searchApi'], 'search').and.returnValue( - Promise.reject({ - message: `{ "error": { "statusCode": 401 } } ` - }) - ); + spyOn(queryBuilder['searchApi'], 'search').and.returnValue(Promise.reject(new Error('{ "error": { "statusCode": 401 } }'))); spyOn(queryBuilder, 'buildQuery').and.returnValue(searchRequest); spyOn(store, 'dispatch').and.stub(); @@ -141,11 +133,7 @@ describe('SearchComponent', () => { return key; }); - spyOn(queryBuilder['searchApi'], 'search').and.returnValue( - Promise.reject({ - message: `{ "error": { "statusCode": 401 } } ` - }) - ); + spyOn(queryBuilder['searchApi'], 'search').and.returnValue(Promise.reject(new Error('{ "error": { "statusCode": 401 } }'))); spyOn(queryBuilder, 'buildQuery').and.returnValue(searchRequest); spyOn(store, 'dispatch').and.stub(); @@ -191,7 +179,7 @@ describe('SearchComponent', () => { }); it('should format user input as cm:name if configuration not provided', () => { - const query = component.formatSearchQuery('hello', undefined); + const query = component.formatSearchQuery('hello'); expect(query).toBe(`(cm:name:"hello*")`); }); diff --git a/projects/aca-content/src/lib/components/search/search-results/search-results.component.ts b/projects/aca-content/src/lib/components/search/search-results/search-results.component.ts index 14585c19a7..84bdd04727 100644 --- a/projects/aca-content/src/lib/components/search/search-results/search-results.component.ts +++ b/projects/aca-content/src/lib/components/search/search-results/search-results.component.ts @@ -266,7 +266,7 @@ export class SearchResultsComponent extends PageComponent implements OnInit { } onNodeDoubleClick(node: NodeEntry) { - if (node && node.entry) { + if (node?.entry) { if (node.entry.isFolder) { this.store.dispatch(new NavigateToFolder(node)); return; diff --git a/projects/aca-content/src/lib/components/shared-link-view/shared-link-view.component.spec.ts b/projects/aca-content/src/lib/components/shared-link-view/shared-link-view.component.spec.ts index 6a6c3f8ab1..1157dd42cb 100644 --- a/projects/aca-content/src/lib/components/shared-link-view/shared-link-view.component.spec.ts +++ b/projects/aca-content/src/lib/components/shared-link-view/shared-link-view.component.spec.ts @@ -95,7 +95,7 @@ describe('SharedLinkViewComponent', () => { })); it('should not update store on error', fakeAsync(() => { - spyGetSharedLink.and.returnValue(Promise.reject('error')); + spyGetSharedLink.and.returnValue(Promise.reject(new Error('error'))); fixture.detectChanges(); tick(); diff --git a/projects/aca-content/src/lib/components/sidenav/directives/active-link.directive.spec.ts b/projects/aca-content/src/lib/components/sidenav/directives/active-link.directive.spec.ts index 7c156c7d9b..9c96c78f6d 100644 --- a/projects/aca-content/src/lib/components/sidenav/directives/active-link.directive.spec.ts +++ b/projects/aca-content/src/lib/components/sidenav/directives/active-link.directive.spec.ts @@ -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); }); diff --git a/projects/aca-content/src/lib/components/sidenav/directives/active-link.directive.ts b/projects/aca-content/src/lib/components/sidenav/directives/active-link.directive.ts index d2f3e7a579..5ccc7150e6 100644 --- a/projects/aca-content/src/lib/components/sidenav/directives/active-link.directive.ts +++ b/projects/aca-content/src/lib/components/sidenav/directives/active-link.directive.ts @@ -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; } } diff --git a/projects/aca-content/src/lib/components/sidenav/directives/expansion-panel.directive.ts b/projects/aca-content/src/lib/components/sidenav/directives/expansion-panel.directive.ts index 9af098c6e6..76243e03b5 100644 --- a/projects/aca-content/src/lib/components/sidenav/directives/expansion-panel.directive.ts +++ b/projects/aca-content/src/lib/components/sidenav/directives/expansion-panel.directive.ts @@ -58,7 +58,7 @@ export class ExpansionPanelDirective implements OnInit, OnDestroy { constructor(private store: Store, 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; diff --git a/projects/aca-content/src/lib/components/sidenav/directives/menu-panel.directive.ts b/projects/aca-content/src/lib/components/sidenav/directives/menu-panel.directive.ts index 3401d78940..0a7767a2f4 100644 --- a/projects/aca-content/src/lib/components/sidenav/directives/menu-panel.directive.ts +++ b/projects/aca-content/src/lib/components/sidenav/directives/menu-panel.directive.ts @@ -57,7 +57,7 @@ export class MenuPanelDirective implements OnInit, OnDestroy { constructor(private store: Store, 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; diff --git a/projects/aca-content/src/lib/components/sidenav/user-menu/user-menu.component.ts b/projects/aca-content/src/lib/components/sidenav/user-menu/user-menu.component.ts index d1b13a8d43..a4c7e2fae5 100644 --- a/projects/aca-content/src/lib/components/sidenav/user-menu/user-menu.component.ts +++ b/projects/aca-content/src/lib/components/sidenav/user-menu/user-menu.component.ts @@ -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); } } diff --git a/projects/aca-content/src/lib/components/toolbar/toggle-edit-offline/toggle-edit-offline.component.spec.ts b/projects/aca-content/src/lib/components/toolbar/toggle-edit-offline/toggle-edit-offline.component.spec.ts index e061c2a599..ab1d849afd 100644 --- a/projects/aca-content/src/lib/components/toolbar/toggle-edit-offline/toggle-edit-offline.component.spec.ts +++ b/projects/aca-content/src/lib/components/toolbar/toggle-edit-offline/toggle-edit-offline.component.spec.ts @@ -69,7 +69,7 @@ describe('ToggleEditOfflineComponent', () => { fixture.detectChanges(); - expect(component.selection).toEqual(selection.file as any); + expect(component.selection).toEqual(selection.file); }); it('should download content when node is locked', async () => { diff --git a/projects/aca-content/src/lib/services/node-actions.service.ts b/projects/aca-content/src/lib/services/node-actions.service.ts index 7b2c1493d2..ee3443e718 100644 --- a/projects/aca-content/src/lib/services/node-actions.service.ts +++ b/projects/aca-content/src/lib/services/node-actions.service.ts @@ -143,8 +143,8 @@ export class NodeActionsService { } isEntryEntitiesArray(contentEntities: any[]): boolean { - if (contentEntities && contentEntities.length) { - const nonEntryNode = contentEntities.find((node) => !node || !node.entry || !(node.entry.nodeId || node.entry.id)); + if (contentEntities?.length) { + const nonEntryNode = contentEntities.find((node) => !(node?.entry?.nodeId || node?.entry?.id)); return !nonEntryNode; } return false; @@ -160,7 +160,7 @@ export class NodeActionsService { if (nodeEntry.parentId) { entryParentId = nodeEntry.parentId; - } else if (nodeEntry.path && nodeEntry.path.elements && nodeEntry.path.elements.length) { + } else if (nodeEntry.path?.elements?.length) { entryParentId = nodeEntry.path.elements[nodeEntry.path.elements.length - 1].id; } @@ -255,7 +255,7 @@ export class NodeActionsService { // todo: review this approach once 5.2.3 is out private customizeBreadcrumb(node: Node) { - if (node && node.path && node.path.elements) { + if (node?.path?.elements) { const elements = node.path.elements; if (elements.length > 1) { @@ -316,7 +316,7 @@ export class NodeActionsService { } 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; @@ -658,7 +658,7 @@ export class NodeActionsService { const folderMoveResponseData = this.flatten(next); const foundError = folderMoveResponseData.find((node) => node instanceof Error); // data might contain also items of form: { itemMoved, initialParentId } - const foundEntry = folderMoveResponseData.find((node) => (node.itemMoved && node.itemMoved.entry) || (node && node.entry)); + const foundEntry = folderMoveResponseData.find((node) => node.itemMoved?.entry || node?.entry); if (!foundError) { // consider success if NONE of the items from the folder move response is an error @@ -677,7 +677,7 @@ export class NodeActionsService { return acc; }, moveStatus); } else { - if ((data.itemMoved && data.itemMoved.entry) || (data && data.entry)) { + if (data.itemMoved?.entry || data?.entry) { moveStatus.succeeded.push(data); } else { moveStatus.failed.push(data); diff --git a/projects/aca-content/src/lib/services/node-template.service.spec.ts b/projects/aca-content/src/lib/services/node-template.service.spec.ts index 19fb9bd050..fff43b1926 100644 --- a/projects/aca-content/src/lib/services/node-template.service.spec.ts +++ b/projects/aca-content/src/lib/services/node-template.service.spec.ts @@ -153,11 +153,7 @@ describe('NodeTemplateService', () => { })); it('should raise an error when getNodeInfo fails', fakeAsync(() => { - spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue( - Promise.reject({ - message: `{ "error": { "statusCode": 404 } } ` - }) - ); + spyOn(nodeTemplateService['searchApi'], 'search').and.returnValue(Promise.reject(new Error('{ "error": { "statusCode": 404 } }'))); spyOn(store, 'dispatch'); nodeTemplateService.selectTemplateDialog(fileTemplateConfig); diff --git a/projects/aca-content/src/lib/services/node-template.service.ts b/projects/aca-content/src/lib/services/node-template.service.ts index d6e264b0af..744367d5e9 100644 --- a/projects/aca-content/src/lib/services/node-template.service.ts +++ b/projects/aca-content/src/lib/services/node-template.service.ts @@ -125,7 +125,7 @@ export class NodeTemplateService { } private transformNode(node: Node): Node { - if (node && node.path && node.path && node.path.elements instanceof Array) { + if (node?.path?.elements instanceof Array) { node.path.elements = this.getPathElements(node); } return node; diff --git a/projects/aca-content/src/lib/store/effects/library.effects.ts b/projects/aca-content/src/lib/store/effects/library.effects.ts index 61585ffec8..59b4c49406 100644 --- a/projects/aca-content/src/lib/store/effects/library.effects.ts +++ b/projects/aca-content/src/lib/store/effects/library.effects.ts @@ -62,7 +62,7 @@ export class LibraryEffects { .select(getAppSelection) .pipe(take(1)) .subscribe((selection) => { - if (selection && selection.library) { + if (selection?.library) { this.content.deleteLibrary(selection.library.entry.id); } }); @@ -84,7 +84,7 @@ export class LibraryEffects { .select(getAppSelection) .pipe(take(1)) .subscribe((selection) => { - if (selection && selection.library) { + if (selection?.library) { this.content.leaveLibrary(selection.library.entry.id, action.configuration?.focusedElementOnCloseSelector); } }); @@ -138,7 +138,7 @@ export class LibraryEffects { .select(getAppSelection) .pipe(take(1)) .subscribe((selection) => { - if (selection && selection.library) { + if (selection?.library) { const { id } = selection.library.entry; const { title, description, visibility } = action.payload; diff --git a/projects/aca-content/src/lib/store/effects/node.effects.ts b/projects/aca-content/src/lib/store/effects/node.effects.ts index 15e2efd928..06594660d1 100644 --- a/projects/aca-content/src/lib/store/effects/node.effects.ts +++ b/projects/aca-content/src/lib/store/effects/node.effects.ts @@ -78,7 +78,7 @@ export class NodeEffects { .select(getAppSelection) .pipe(take(1)) .subscribe((selection) => { - if (selection && selection.file) { + if (selection?.file) { this.contentService.shareNode(selection.file, action.configuration?.focusedElementOnCloseSelector); } }); @@ -93,7 +93,7 @@ export class NodeEffects { this.actions$.pipe( ofType(NodeActionTypes.Unshare), map((action) => { - if (action && action.payload && action.payload.length > 0) { + if (action?.payload?.length > 0) { this.contentService.unshareNodes(action.payload); } else { this.store @@ -115,7 +115,7 @@ export class NodeEffects { this.actions$.pipe( ofType(NodeActionTypes.PurgeDeleted), map((action) => { - if (action && action.payload && action.payload.length > 0) { + if (action?.payload?.length > 0) { this.contentService.purgeDeletedNodes(action.payload); } else { this.store @@ -137,7 +137,7 @@ export class NodeEffects { this.actions$.pipe( ofType(NodeActionTypes.RestoreDeleted), map((action) => { - if (action && action.payload && action.payload.length > 0) { + if (action?.payload?.length > 0) { this.contentService.restoreDeletedNodes(action.payload); } else { this.store @@ -160,7 +160,7 @@ export class NodeEffects { ofType(NodeActionTypes.Delete), map((action) => { this.store.dispatch(new ShowLoaderAction(true)); - if (action && action.payload && action.payload.length > 0) { + if (action?.payload?.length > 0) { this.contentService.deleteNodes(action.payload); } else { this.store @@ -202,7 +202,7 @@ export class NodeEffects { .select(getCurrentFolder) .pipe(take(1)) .subscribe((node) => { - if (node && node.id) { + if (node?.id) { this.contentService.createFolder(node.id); } }); @@ -224,7 +224,7 @@ export class NodeEffects { .select(getAppSelection) .pipe(take(1)) .subscribe((selection) => { - if (selection && selection.folder) { + if (selection?.folder) { this.contentService.editFolder(selection.folder, action.configuration?.focusedElementOnCloseSelector); } }); @@ -347,7 +347,7 @@ export class NodeEffects { .select(getAppSelection) .pipe(take(1)) .subscribe((selection) => { - if (selection && selection.file) { + if (selection?.file) { this.contentService.manageVersions(selection.file, action.configuration?.focusedElementOnCloseSelector); } }); @@ -362,14 +362,14 @@ export class NodeEffects { this.actions$.pipe( ofType(NodeActionTypes.PrintFile), map((action) => { - if (action && action.payload) { + if (action?.payload) { this.printFile(action.payload); } else { this.store .select(getAppSelection) .pipe(take(1)) .subscribe((selection) => { - if (selection && selection.file) { + if (selection?.file) { this.printFile(selection.file); } }); @@ -384,14 +384,14 @@ export class NodeEffects { this.actions$.pipe( ofType(NodeActionTypes.UnlockForWriting), map((action) => { - if (action && action.payload) { + if (action?.payload) { this.contentService.unlockNode(action.payload); } else { this.store .select(getAppSelection) .pipe(take(1)) .subscribe((selection) => { - if (selection && selection.file) { + if (selection?.file) { this.contentService.unlockNode(selection.file); } }); @@ -424,7 +424,7 @@ export class NodeEffects { ); printFile(node: any) { - if (node && node.entry) { + if (node?.entry) { // shared and favorite const id = node.entry.nodeId || node.entry.guid || node.entry.id; const mimeType = node.entry.content.mimeType; diff --git a/projects/aca-content/src/lib/store/effects/template.effects.spec.ts b/projects/aca-content/src/lib/store/effects/template.effects.spec.ts index 89de4c16d8..94b00a07b2 100644 --- a/projects/aca-content/src/lib/store/effects/template.effects.spec.ts +++ b/projects/aca-content/src/lib/store/effects/template.effects.spec.ts @@ -156,11 +156,7 @@ describe('TemplateEffects', () => { })); it('should raise generic error when copyNode api fails', fakeAsync(() => { - copyNodeSpy.and.returnValue( - Promise.reject({ - message: `{ "error": { "statusCode": 404 } } ` - }) - ); + copyNodeSpy.and.returnValue(Promise.reject(new Error('{ "error": { "statusCode": 404 } }'))); store.dispatch(new CreateFromTemplate(node)); tick(); @@ -170,11 +166,7 @@ describe('TemplateEffects', () => { })); it('should raise name conflict error when copyNode api returns 409', fakeAsync(() => { - copyNodeSpy.and.returnValue( - Promise.reject({ - message: `{ "error": { "statusCode": 409 } } ` - }) - ); + copyNodeSpy.and.returnValue(Promise.reject(new Error('{ "error": { "statusCode": 409 } }'))); store.dispatch(new CreateFromTemplate(node)); tick(); @@ -195,11 +187,7 @@ describe('TemplateEffects', () => { } as NodeEntry; copyNodeSpy.and.returnValue(of(TEST_NODE)); - updateNodeSpy.and.returnValue( - Promise.reject({ - message: `{ "error": { "statusCode": 404 } } ` - }) - ); + updateNodeSpy.and.returnValue(Promise.reject(new Error('{ "error": { "statusCode": 404 } }'))); store.dispatch(new CreateFromTemplate(TEST_NODE.entry)); tick(); diff --git a/projects/aca-content/src/lib/store/effects/upload.effects.ts b/projects/aca-content/src/lib/store/effects/upload.effects.ts index 4c4f8f302d..1ae59fc288 100644 --- a/projects/aca-content/src/lib/store/effects/upload.effects.ts +++ b/projects/aca-content/src/lib/store/effects/upload.effects.ts @@ -150,7 +150,7 @@ export class UploadEffects { .select(getCurrentFolder) .pipe(take(1)) .subscribe((node) => { - if (node && node.id) { + if (node?.id) { const input = event.currentTarget as HTMLInputElement; const files = FileUtils.toFileArray(input.files).map( (file: any) => @@ -186,13 +186,7 @@ export class UploadEffects { this.uploadService.uploadFilesInTheQueue(); const subscription = this.uploadService.fileUploadComplete.subscribe((completed) => { - if ( - file.data && - file.data.entry && - file.data.entry.properties && - file.data.entry.properties['cm:lockType'] === 'WRITE_LOCK' && - file.data.entry.id === completed.data.entry.id - ) { + if (file.data?.entry?.properties?.['cm:lockType'] === 'WRITE_LOCK' && file.data?.entry?.id === completed.data.entry.id) { this.store.dispatch(new UnlockWriteAction(completed.data)); } diff --git a/projects/aca-content/src/lib/store/effects/viewer.effects.ts b/projects/aca-content/src/lib/store/effects/viewer.effects.ts index 819d61d2cc..c78b754412 100644 --- a/projects/aca-content/src/lib/store/effects/viewer.effects.ts +++ b/projects/aca-content/src/lib/store/effects/viewer.effects.ts @@ -101,7 +101,7 @@ export class ViewerEffects { this.actions$.pipe( ofType(ViewerActionTypes.ViewFile), map((action) => { - if (action.payload && action.payload.entry) { + if (action.payload?.entry) { const { id, nodeId, isFile } = action.payload.entry as any; if (this.extensions.canPreviewNode(action.payload) && (isFile || nodeId)) { @@ -112,7 +112,7 @@ export class ViewerEffects { .select(fileToPreview) .pipe(take(1)) .subscribe((result) => { - if (result.selection && result.selection.file) { + if (result.selection?.file) { const { id, nodeId, isFile } = result.selection.file.entry as any; if (this.extensions.canPreviewNode(action.payload) && (isFile || nodeId)) { diff --git a/projects/aca-content/src/lib/store/reducers/app.reducer.ts b/projects/aca-content/src/lib/store/reducers/app.reducer.ts index 7cb29e0b80..7c4695cfb7 100644 --- a/projects/aca-content/src/lib/store/reducers/app.reducer.ts +++ b/projects/aca-content/src/lib/store/reducers/app.reducer.ts @@ -47,7 +47,7 @@ export function appReducer(state: AppState = INITIAL_APP_STATE, action: Action): switch (action.type) { case AppActionTypes.SetInitialState: - newState = Object.assign({}, (action as SetInitialStateAction).payload); + newState = { ...(action as SetInitialStateAction).payload }; break; case NodeActionTypes.SetSelection: newState = updateSelectedNodes(state, action as SetSelectedNodesAction); @@ -198,7 +198,7 @@ function updateSelectedNodes(state: AppState, action: SetSelectedNodesAction): A const libraries: any[] = [...action.payload].filter((node: any) => node.isLibrary); if (libraries.length === 1) { - library = libraries[0] as any; + library = libraries[0]; } if (isEmpty) { diff --git a/projects/aca-content/viewer/src/lib/components/viewer/viewer.component.ts b/projects/aca-content/viewer/src/lib/components/viewer/viewer.component.ts index f336a91998..ada20bc3af 100644 --- a/projects/aca-content/viewer/src/lib/components/viewer/viewer.component.ts +++ b/projects/aca-content/viewer/src/lib/components/viewer/viewer.component.ts @@ -182,7 +182,7 @@ export class AcaViewerComponent implements OnInit, OnDestroy { this.navigationPath = params.path || params.location; }); - if (this.route.snapshot.data && this.route.snapshot.data.navigateSource) { + if (this.route.snapshot.data?.navigateSource) { const source = this.route.snapshot.data.navigateSource.toLowerCase(); if (this.navigationSources.includes(source)) { this.navigateSource = this.route.snapshot.data.navigateSource; @@ -239,7 +239,7 @@ export class AcaViewerComponent implements OnInit, OnDestroy { return; } - if (this.node && this.node.isFile) { + if (this.node?.isFile) { const nearest = await this.getNearestNodes(this.node.id, this.node.parentId); this.nodeId = this.node.id; this.previousNodeId = nearest.left; @@ -420,11 +420,9 @@ export class AcaViewerComponent 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(); } @@ -438,19 +436,11 @@ export class AcaViewerComponent 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-playwright-shared/src/api/file-actions.ts b/projects/aca-playwright-shared/src/api/file-actions.ts index 6f6c254ffe..f2883c5383 100644 --- a/projects/aca-playwright-shared/src/api/file-actions.ts +++ b/projects/aca-playwright-shared/src/api/file-actions.ts @@ -50,7 +50,7 @@ export class FileActionsApi { }); } - async uploadFileWithRename(fileLocation: string, parentId: string = '-my-', newName: string, title: string = '', description: string = '') { + async uploadFileWithRename(fileLocation: string, newName: string, parentId: string = '-my-', title: string = '', description: string = '') { const file = fs.createReadStream(fileLocation); const nodeProps = { properties: { @@ -93,7 +93,7 @@ export class FileActionsApi { async getNodeProperty(nodeId: string, property: string): Promise { try { const node = await this.getNodeById(nodeId); - return (node.entry.properties && node.entry.properties[property]) || ''; + return (node.entry.properties?.[property]) || ''; } catch (error) { Logger.error(`${this.constructor.name} ${this.getNodeProperty.name}`, error); return ''; diff --git a/projects/aca-playwright-shared/src/page-objects/components/dataTable/mat-menu.component.ts b/projects/aca-playwright-shared/src/page-objects/components/dataTable/mat-menu.component.ts index cc9881b83a..d9e5085f96 100644 --- a/projects/aca-playwright-shared/src/page-objects/components/dataTable/mat-menu.component.ts +++ b/projects/aca-playwright-shared/src/page-objects/components/dataTable/mat-menu.component.ts @@ -22,9 +22,8 @@ * from Hyland Software. If not, see . */ -import { Page } from '@playwright/test'; +import { Page, expect } from '@playwright/test'; import { BaseComponent } from '../base.component'; -import { expect } from '@playwright/test'; export class MatMenuComponent extends BaseComponent { private static rootElement = '.mat-menu-content'; diff --git a/projects/aca-playwright-shared/src/page-objects/components/viewer.component.ts b/projects/aca-playwright-shared/src/page-objects/components/viewer.component.ts index dc3dd5613c..8c06ae37a4 100644 --- a/projects/aca-playwright-shared/src/page-objects/components/viewer.component.ts +++ b/projects/aca-playwright-shared/src/page-objects/components/viewer.component.ts @@ -22,11 +22,10 @@ * from Hyland Software. If not, see . */ -import { Page } from '@playwright/test'; +import { Page, expect } from '@playwright/test'; import { BaseComponent } from './base.component'; import { AcaHeader } from './aca-header.component'; import { timeouts } from '../../utils'; -import { expect } from '@playwright/test'; export class ViewerComponent extends BaseComponent { private static rootElement = 'adf-viewer'; diff --git a/projects/aca-playwright-shared/src/page-objects/pages/base.page.ts b/projects/aca-playwright-shared/src/page-objects/pages/base.page.ts index e4812d171f..a4f0f6666e 100644 --- a/projects/aca-playwright-shared/src/page-objects/pages/base.page.ts +++ b/projects/aca-playwright-shared/src/page-objects/pages/base.page.ts @@ -69,20 +69,17 @@ export abstract class BasePage extends PlaywrightBase { await this.page.goto(actualOptions.remoteUrl, { waitUntil: actualOptions.waitUntil }); + } else if (this.urlRequest && actualOptions.waitForRequest) { + await Promise.all([ + this.page.goto(`./#/${this.pageUrl}${actualOptions.query}`, { waitUntil: 'load' }), + this.page.waitForResponse(this.urlRequest) + ]); } else { - if (this.urlRequest && actualOptions.waitForRequest) { - await Promise.all([ - this.page.goto(`./#/${this.pageUrl}${actualOptions.query}`, { waitUntil: 'load' }), - this.page.waitForResponse(this.urlRequest) - ]); - } else { - await this.page.goto(`./#/${this.pageUrl}${actualOptions.query}`, { - waitUntil: actualOptions.waitUntil, - timeout: 60000 - }); - } + await this.page.goto(`./#/${this.pageUrl}${actualOptions.query}`, { + waitUntil: actualOptions.waitUntil, + timeout: 60000 + }); } - await this.spinner.waitForReload(); } diff --git a/projects/aca-shared/rules/src/app.rules.ts b/projects/aca-shared/rules/src/app.rules.ts index 71333f4bc6..a77daaad66 100644 --- a/projects/aca-shared/rules/src/app.rules.ts +++ b/projects/aca-shared/rules/src/app.rules.ts @@ -178,7 +178,7 @@ export function isShared(context: RuleContext): boolean { } if (navigation.isNotTrashcan(context) && !context.selection.isEmpty && context.selection.file) { - return !!(context.selection.file.entry && context.selection.file.entry.properties && context.selection.file.entry.properties['qshare:sharedId']); + return !!context.selection.file.entry?.properties?.['qshare:sharedId']; } return false; @@ -268,14 +268,7 @@ export const canCreateLibrary = (context: AcaRuleContext): boolean => * JSON ref: `app.navigation.folder.canUpload` */ export function canUpload(context: AcaRuleContext): boolean { - if (isContentServiceEnabled(context) && (navigation.isPersonalFiles(context) || navigation.isLibraryContent(context))) { - const { currentFolder } = context.navigation; - - if (currentFolder) { - return context.permissions.check(currentFolder, ['create']); - } - } - return false; + return canCreateFolder(context); } /** @@ -307,7 +300,7 @@ export const hasLibrarySelected = (context: RuleContext): boolean => !!context.s */ export function isPrivateLibrary(context: RuleContext): boolean { const library = context.selection.library; - return library ? !!(library.entry && library.entry.visibility && library.entry.visibility === 'PRIVATE') : false; + return library ? !!(library.entry?.visibility === 'PRIVATE') : false; } /** @@ -316,7 +309,7 @@ export function isPrivateLibrary(context: RuleContext): boolean { */ export function hasLibraryRole(context: RuleContext): boolean { const library = context.selection.library; - return library ? !!(library.entry && library.entry.role) : false; + return library ? !!library.entry?.role : false; } /** @@ -329,7 +322,7 @@ export const hasNoLibraryRole = (context: RuleContext): boolean => !hasLibraryRo * Checks if user has selected a file. * JSON ref: `app.selection.file` */ -export const hasFileSelected = (context: RuleContext): boolean => !!(context && context.selection && context.selection.file); +export const hasFileSelected = (context: RuleContext): boolean => !!context?.selection?.file; /** * Checks if user can update the first selected node. @@ -376,13 +369,13 @@ export function canUpdateSelectedFolder(context: RuleContext): boolean { * JSON ref: `app.selection.file.isLocked` */ export function hasLockedFiles(context: RuleContext): boolean { - if (context && context.selection && context.selection.nodes) { + if (context?.selection?.nodes) { return context.selection.nodes.some((node) => { if (!node.entry.isFile) { return false; } - return node.entry.isLocked || (node.entry.properties && node.entry.properties['cm:lockType'] === 'READ_ONLY_LOCK'); + return node.entry.isLocked || node.entry.properties?.['cm:lockType'] === 'READ_ONLY_LOCK'; }); } @@ -395,13 +388,8 @@ export function hasLockedFiles(context: RuleContext): boolean { */ export const isWriteLocked = (context: RuleContext): boolean => !!( - context && - context.selection && - context.selection.file && - context.selection.file.entry && - context.selection.file.entry.properties && - (context.selection.file.entry.properties['cm:lockType'] === 'WRITE_LOCK' || - context.selection.file.entry.properties['cm:lockType'] === 'READ_ONLY_LOCK') + context?.selection?.file?.entry?.properties?.['cm:lockType'] === 'WRITE_LOCK' || + context?.selection?.file?.entry?.properties?.['cm:lockType'] === 'READ_ONLY_LOCK' ); /** @@ -589,17 +577,17 @@ export function canOpenWithOffice(context: AcaRuleContext): boolean { return false; } - if (context.navigation && context.navigation.url && context.navigation.url.startsWith('/trashcan')) { + if (context.navigation?.url?.startsWith('/trashcan')) { return false; } - if (!context || !context.selection) { + if (!context?.selection) { return false; } const { file } = context.selection; - if (!file || !file.entry) { + if (!file?.entry) { return false; } @@ -626,7 +614,7 @@ export function canOpenWithOffice(context: AcaRuleContext): boolean { } // workaround for Shared files - if (context.navigation && context.navigation.url && context.navigation.url.startsWith('/shared')) { + if (context.navigation?.url?.startsWith('/shared')) { // eslint-disable-next-line no-prototype-builtins if (file.entry.hasOwnProperty('allowableOperationsOnTarget')) { return context.permissions.check(file, ['update'], { diff --git a/projects/aca-shared/rules/src/navigation.rules.ts b/projects/aca-shared/rules/src/navigation.rules.ts index 02d6a6df93..8a3abc762c 100644 --- a/projects/aca-shared/rules/src/navigation.rules.ts +++ b/projects/aca-shared/rules/src/navigation.rules.ts @@ -39,7 +39,7 @@ export function isPreview(context: RuleContext): boolean { */ export function isFavorites(context: RuleContext): boolean { const { url } = context.navigation; - return url && url.startsWith('/favorites') && !isPreview(context); + return url?.startsWith('/favorites') && !isPreview(context); } /** @@ -54,7 +54,7 @@ export const isNotFavorites = (context: RuleContext): boolean => !isFavorites(co */ export function isSharedFiles(context: RuleContext): boolean { const { url } = context.navigation; - return url && url.startsWith('/shared') && !isPreview(context); + return url?.startsWith('/shared') && !isPreview(context); } /** @@ -69,7 +69,7 @@ export const isNotSharedFiles = (context: RuleContext): boolean => !isSharedFile */ export function isTrashcan(context: RuleContext): boolean { const { url } = context.navigation; - return url && url.startsWith('/trashcan'); + return url?.startsWith('/trashcan'); } /** @@ -84,7 +84,7 @@ export const isNotTrashcan = (context: RuleContext): boolean => !isTrashcan(cont */ export function isPersonalFiles(context: RuleContext): boolean { const { url } = context.navigation; - return url && url.startsWith('/personal-files'); + return url?.startsWith('/personal-files'); } /** @@ -93,7 +93,7 @@ export function isPersonalFiles(context: RuleContext): boolean { */ export function isLibraryFiles(context: RuleContext): boolean { const { url } = context.navigation; - return url && url.startsWith('/libraries'); + return url?.startsWith('/libraries'); } /** @@ -102,12 +102,12 @@ export function isLibraryFiles(context: RuleContext): boolean { */ export function isLibraries(context: RuleContext): boolean { const { url } = context.navigation; - return url && (url.endsWith('/libraries') || url.startsWith('/search-libraries')); + return url?.endsWith('/libraries') || url?.startsWith('/search-libraries'); } export function isLibraryContent(context: RuleContext): boolean { const { url } = context.navigation; - return url && (url.endsWith('/libraries') || url.includes('/libraries/') || url.startsWith('/search-libraries')); + return url?.endsWith('/libraries') || url?.includes('/libraries/') || url?.startsWith('/search-libraries'); } /** @@ -122,7 +122,7 @@ export const isNotLibraries = (context: RuleContext): boolean => !isLibraries(co */ export function isRecentFiles(context: RuleContext): boolean { const { url } = context.navigation; - return url && url.startsWith('/recent-files'); + return url?.startsWith('/recent-files'); } /** @@ -140,7 +140,7 @@ export function isSearchResults( // ...args: RuleParameter[] ): boolean { const { url } = context.navigation; - return url && url.startsWith('/search'); + return url?.startsWith('/search'); } /** @@ -155,7 +155,7 @@ export const isNotSearchResults = (context: RuleContext): boolean => !isSearchRe */ export function isSharedPreview(context: RuleContext): boolean { const { url } = context.navigation; - return url && (url.startsWith('/shared/preview/') || (url.startsWith('/shared') && url.includes('viewer:view'))); + return url?.startsWith('/shared/preview/') || (url?.startsWith('/shared') && url?.includes('viewer:view')); } /** @@ -164,7 +164,7 @@ export function isSharedPreview(context: RuleContext): boolean { */ export function isFavoritesPreview(context: RuleContext): boolean { const { url } = context.navigation; - return url && (url.startsWith('/favorites/preview/') || (url.startsWith('/favorites') && url.includes('viewer:view'))); + return url?.startsWith('/favorites/preview/') || (url?.startsWith('/favorites') && url?.includes('viewer:view')); } /** @@ -173,5 +173,5 @@ export function isFavoritesPreview(context: RuleContext): boolean { */ export function isSharedFileViewer(context: RuleContext): boolean { const { url } = context.navigation; - return url && url.startsWith('/preview/s/'); + return url?.startsWith('/preview/s/'); } diff --git a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.component.ts b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.component.ts index 7c72919a75..baf04f2522 100644 --- a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.component.ts +++ b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.component.ts @@ -130,7 +130,7 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges { } ngOnChanges(changes: SimpleChanges) { - if (changes.nodeResult && changes.nodeResult.currentValue) { + if (changes.nodeResult?.currentValue) { this.nodeResult = changes.nodeResult.currentValue; } } @@ -145,7 +145,7 @@ export abstract class PageComponent implements OnInit, OnDestroy, OnChanges { } showPreview(node: NodeEntry, extras?: ViewNodeExtras) { - if (node && node.entry) { + if (node?.entry) { if (this.fileAutoDownloadService?.shouldFileAutoDownload(node.entry?.content?.sizeInBytes)) { this.fileAutoDownloadService.autoDownloadFile(node); } else { diff --git a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts index bee443e72c..d6517af7d1 100644 --- a/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts +++ b/projects/aca-shared/src/lib/components/document-base-page/document-base-page.spec.ts @@ -91,10 +91,6 @@ class DocumentBasePageServiceMock extends DocumentBasePageService { class TestComponent extends PageComponent { node: any; - constructor() { - super(); - } - addSubscription(entry: Subscription) { this.subscriptions.push(entry); } diff --git a/projects/aca-shared/src/lib/components/toolbar/toolbar-button/toolbar-button.component.ts b/projects/aca-shared/src/lib/components/toolbar/toolbar-button/toolbar-button.component.ts index e2d27cb6fb..c1cca81490 100644 --- a/projects/aca-shared/src/lib/components/toolbar/toolbar-button/toolbar-button.component.ts +++ b/projects/aca-shared/src/lib/components/toolbar/toolbar-button/toolbar-button.component.ts @@ -74,6 +74,6 @@ export class ToolbarButtonComponent { } private hasClickAction(actionRef: ContentActionRef): boolean { - return !!(actionRef && actionRef.actions && actionRef.actions.click); + return !!actionRef?.actions?.click; } } diff --git a/projects/aca-shared/src/lib/components/toolbar/toolbar-menu-item/toolbar-menu-item.component.ts b/projects/aca-shared/src/lib/components/toolbar/toolbar-menu-item/toolbar-menu-item.component.ts index 56b3845ec1..be244db81b 100644 --- a/projects/aca-shared/src/lib/components/toolbar/toolbar-menu-item/toolbar-menu-item.component.ts +++ b/projects/aca-shared/src/lib/components/toolbar/toolbar-menu-item/toolbar-menu-item.component.ts @@ -71,7 +71,7 @@ export class ToolbarMenuItemComponent { } 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-shared/src/lib/directives/contextmenu/contextmenu.directive.ts b/projects/aca-shared/src/lib/directives/contextmenu/contextmenu.directive.ts index f61f5a7c16..5429de3d75 100644 --- a/projects/aca-shared/src/lib/directives/contextmenu/contextmenu.directive.ts +++ b/projects/aca-shared/src/lib/directives/contextmenu/contextmenu.directive.ts @@ -98,11 +98,9 @@ export class ContextActionsDirective implements OnInit, OnDestroy { } private findAncestor(el: Element, className: string): Element { - if (el.classList.contains(className)) { - return el; + 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-shared/src/lib/services/app.extension.service.ts b/projects/aca-shared/src/lib/services/app.extension.service.ts index 00e9e8ab8f..81c01e6a0c 100644 --- a/projects/aca-shared/src/lib/services/app.extension.service.ts +++ b/projects/aca-shared/src/lib/services/app.extension.service.ts @@ -180,7 +180,7 @@ export class AppExtensionService implements RuleContext { this.withCredentials = this.appConfig.get('auth.withCredentials', false); - if (config.features && config.features.viewer) { + if (config.features?.viewer) { this.viewerRules = (config.features.viewer['rules'] as ViewerRules) || {}; } @@ -340,7 +340,7 @@ export class AppExtensionService implements RuleContext { private setActionDisabledFromRule(action: ContentActionRef) { let disabled = false; - if (action && action.rules && action.rules.enabled) { + if (action?.rules?.enabled) { disabled = !this.extensions.evaluateRule(action.rules.enabled, this); } @@ -483,7 +483,7 @@ export class AppExtensionService implements RuleContext { } filterVisible(action: ContentActionRef | SettingsGroupRef | SidebarTabRef | DocumentListPresetRef): boolean { - if (action && action.rules && action.rules.visible) { + if (action?.rules?.visible) { return this.extensions.evaluateRule(action.rules.visible, this); } return true; @@ -495,7 +495,7 @@ export class AppExtensionService implements RuleContext { return true; } - if (extension.rules && extension.rules.disabled) { + if (extension.rules?.disabled) { return this.extensions.evaluateRule(extension.rules.disabled, this); } } diff --git a/projects/aca-shared/store/src/actions/router.actions.ts b/projects/aca-shared/store/src/actions/router.actions.ts index b56bf6b2a0..d79e0a8ad5 100644 --- a/projects/aca-shared/store/src/actions/router.actions.ts +++ b/projects/aca-shared/store/src/actions/router.actions.ts @@ -52,6 +52,4 @@ export class NavigateToParentFolder implements Action { export class NavigateToPreviousPage implements Action { readonly type = RouterActionTypes.NavigateToPreviousPage; - - constructor() {} } diff --git a/projects/aca-shared/store/src/actions/search.actions.ts b/projects/aca-shared/store/src/actions/search.actions.ts index bac13da10f..c7ad773bf0 100644 --- a/projects/aca-shared/store/src/actions/search.actions.ts +++ b/projects/aca-shared/store/src/actions/search.actions.ts @@ -32,7 +32,6 @@ export enum SearchActionTypes { export class SearchAction implements Action { readonly type = SearchActionTypes.Search; - constructor() {} } export class SearchByTermAction implements Action { diff --git a/projects/aca-shared/store/src/actions/template.actions.ts b/projects/aca-shared/store/src/actions/template.actions.ts index 79a1797edb..01e077d90e 100644 --- a/projects/aca-shared/store/src/actions/template.actions.ts +++ b/projects/aca-shared/store/src/actions/template.actions.ts @@ -28,14 +28,10 @@ import { TemplateActionTypes } from './template-action-types'; export class FileFromTemplate implements Action { readonly type = TemplateActionTypes.FileFromTemplate; - - constructor() {} } export class FolderFromTemplate implements Action { readonly type = TemplateActionTypes.FolderFromTemplate; - - constructor() {} } export class CreateFromTemplate implements Action { diff --git a/projects/aca-shared/store/src/effects/router.effects.ts b/projects/aca-shared/store/src/effects/router.effects.ts index c000c87dca..08f101a7ab 100644 --- a/projects/aca-shared/store/src/effects/router.effects.ts +++ b/projects/aca-shared/store/src/effects/router.effects.ts @@ -67,7 +67,7 @@ export class RouterEffects { this.actions$.pipe( ofType(RouterActionTypes.NavigateFolder), map((action) => { - if (action.payload && action.payload.entry) { + if (action.payload?.entry) { this.navigateToFolder(action.payload.entry); } }) @@ -80,7 +80,7 @@ export class RouterEffects { this.actions$.pipe( ofType(RouterActionTypes.NavigateParentFolder), map((action) => { - if (action.payload && action.payload.entry) { + if (action.payload?.entry) { this.navigateToParentFolder(action.payload.entry); } }) @@ -101,7 +101,7 @@ export class RouterEffects { let link: any[] = null; const { path, id } = node; - if (path && path.name && path.elements) { + if (path?.name && path?.elements) { const isLibraryPath = this.isLibraryContent(path); const parent = path.elements[path.elements.length - 1]; @@ -126,7 +126,7 @@ export class RouterEffects { let link: any[] = null; const { path } = node; - if (path && path.name && path.elements) { + if (path?.name && path?.elements) { const isLibraryPath = this.isLibraryContent(path); const parent = path.elements[path.elements.length - 1]; diff --git a/projects/aca-testing-shared/src/components/login/login.ts b/projects/aca-testing-shared/src/components/login/login.ts index dddb2df33a..0878f5debe 100755 --- a/projects/aca-testing-shared/src/components/login/login.ts +++ b/projects/aca-testing-shared/src/components/login/login.ts @@ -58,12 +58,7 @@ export class LoginComponent extends Component { const type = await this.passwordInput.getAttribute('type'); if (type === 'text') { return true; - } else { - if (type === 'password') { - return false; - } } - return false; } diff --git a/projects/aca-testing-shared/src/utilities/admin-actions.ts b/projects/aca-testing-shared/src/utilities/admin-actions.ts index 8ce6a74801..3c413b427a 100755 --- a/projects/aca-testing-shared/src/utilities/admin-actions.ts +++ b/projects/aca-testing-shared/src/utilities/admin-actions.ts @@ -28,10 +28,6 @@ import { UserActions } from './user-actions'; import { browser } from 'protractor'; export class AdminActions extends UserActions { - constructor() { - super(); - } - sites: SitesApi = new SitesApi(); upload: UploadApi = new UploadApi(); nodes: NodesApi = new NodesApi();