[ACS-5991] ESLint fixes and code quality improvements (#8893)

* prefer-optional-chain: core

* prefer-optional-chain: content, fix typings

* prefer-optional-chain: process, fix typings

* prefer-optional-chain: process-cloud, fix typings, fix ts configs and eslint

* [ci: force] sonar errors fixes, insights lib

* [ci:force] fix security issues

* [ci:force] fix metadata e2e bug, js assignment bugs

* [ci:force] fix lint issue

* [ci:force] fix tests
This commit is contained in:
Denys Vuika
2023-09-18 09:42:16 +01:00
committed by GitHub
parent 99f591ed67
commit a1dd270c5d
203 changed files with 4155 additions and 4960 deletions

View File

@@ -15,7 +15,7 @@
* limitations under the License.
*/
import { Directive, HostListener, Input, OnChanges, Output, EventEmitter } from '@angular/core';
import { Directive, HostListener, Input, OnChanges, Output, EventEmitter, SimpleChanges } from '@angular/core';
import { FavoriteBodyCreate, FavoritesApi } from '@alfresco/js-api';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { LibraryEntity } from '../interfaces/library-entity.interface';
@@ -59,7 +59,7 @@ export class LibraryFavoriteDirective implements OnChanges {
constructor(private alfrescoApiService: AlfrescoApiService) {}
ngOnChanges(changes) {
ngOnChanges(changes: SimpleChanges) {
if (!changes.library.currentValue) {
this.targetLibrary = null;
return;
@@ -70,7 +70,7 @@ export class LibraryFavoriteDirective implements OnChanges {
}
isFavorite(): boolean {
return this.targetLibrary && this.targetLibrary.isFavorite;
return this.targetLibrary?.isFavorite;
}
private async markFavoriteLibrary(library: LibraryEntity) {

View File

@@ -16,17 +16,11 @@
*/
import { Directive, EventEmitter, HostListener, Input, OnChanges, Output, SimpleChanges } from '@angular/core';
import {
SiteEntry,
SiteMembershipRequestBodyCreate,
SiteMemberEntry,
SiteMembershipRequestEntry,
SitesApi
} from '@alfresco/js-api';
import { SiteEntry, SiteMembershipRequestBodyCreate, SiteMembershipRequestEntry, SitesApi } from '@alfresco/js-api';
import { BehaviorSubject, from, Observable } from 'rxjs';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { LibraryMembershipToggleEvent } from '../interfaces/library-membership-toggle-event.interface';
import { LibraryMembershipErrorEvent} from '../interfaces/library-membership-error-event.interface';
import { LibraryMembershipErrorEvent } from '../interfaces/library-membership-error-event.interface';
import { VersionCompatibilityService } from '../version-compatibility/version-compatibility.service';
import { SitesService } from '../common/services/sites.service';
@@ -39,7 +33,7 @@ export class LibraryMembershipDirective implements OnChanges {
isJoinRequested: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);
_sitesApi: SitesApi;
private _sitesApi: SitesApi;
get sitesApi(): SitesApi {
this._sitesApi = this._sitesApi ?? new SitesApi(this.alfrescoApiService.getInstance());
return this._sitesApi;
@@ -69,11 +63,10 @@ export class LibraryMembershipDirective implements OnChanges {
private alfrescoApiService: AlfrescoApiService,
private sitesService: SitesService,
private versionCompatibilityService: VersionCompatibilityService
) {
}
) {}
ngOnChanges(changes: SimpleChanges) {
if (!changes.selection.currentValue || !changes.selection.currentValue.entry) {
if (!changes.selection.currentValue?.entry) {
this.targetSite = null;
return;
@@ -115,7 +108,7 @@ export class LibraryMembershipDirective implements OnChanges {
this.targetSite.joinRequested = true;
this.isJoinRequested.next(true);
if (createdMembership.entry && createdMembership.entry.site && createdMembership.entry.site.role) {
if (createdMembership.entry?.site?.role) {
const info = {
shouldReload: true,
i18nKey: 'ADF_LIBRARY_MEMBERSHIP_MESSAGES.INFO.JOINED'
@@ -154,8 +147,8 @@ export class LibraryMembershipDirective implements OnChanges {
if (this.isAdmin) {
this.joinLibrary().subscribe(
(createdMembership: SiteMemberEntry) => {
if (createdMembership.entry && createdMembership.entry.role) {
(createdMembership) => {
if (createdMembership.entry?.role) {
const info = {
shouldReload: true,
i18nKey: 'ADF_LIBRARY_MEMBERSHIP_MESSAGES.INFO.JOINED'
@@ -223,7 +216,7 @@ export class LibraryMembershipDirective implements OnChanges {
});
}
private cancelJoinRequest() {
private cancelJoinRequest(): Observable<void> {
return from(this.sitesApi.deleteSiteMembershipRequestForPerson('-me-', this.targetSite.id));
}

View File

@@ -78,10 +78,7 @@ export class NodeDeleteDirective implements OnChanges {
this.process(this.selection);
}
constructor(private alfrescoApiService: AlfrescoApiService,
private translation: TranslationService,
private elementRef: ElementRef) {
}
constructor(private alfrescoApiService: AlfrescoApiService, private translation: TranslationService, private elementRef: ElementRef) {}
ngOnChanges() {
if (!this.selection || (this.selection && this.selection.length === 0)) {
@@ -98,23 +95,21 @@ export class NodeDeleteDirective implements OnChanges {
}
private process(selection: NodeEntry[] | DeletedNodeEntry[]) {
if (selection && selection.length) {
if (selection?.length) {
const batch = this.getDeleteNodesBatch(selection);
forkJoin(...batch)
.subscribe((data: ProcessedNodeData[]) => {
const processedItems: ProcessStatus = this.processStatus(data);
const message = this.getMessage(processedItems);
forkJoin(...batch).subscribe((data: ProcessedNodeData[]) => {
const processedItems: ProcessStatus = this.processStatus(data);
const message = this.getMessage(processedItems);
if (message) {
this.delete.emit(message);
}
});
if (message) {
this.delete.emit(message);
}
});
}
}
private getDeleteNodesBatch(selection: any): Observable<ProcessedNodeData>[] {
private getDeleteNodesBatch(selection: NodeEntry[] | DeletedNodeEntry[]): Observable<ProcessedNodeData>[] {
return selection.map((node) => this.deleteNode(node));
}
@@ -135,10 +130,12 @@ export class NodeDeleteDirective implements OnChanges {
entry: node.entry,
status: 1
})),
catchError(() => of({
entry: node.entry,
status: 0
}))
catchError(() =>
of({
entry: node.entry,
status: 0
})
)
);
}
@@ -147,10 +144,10 @@ export class NodeDeleteDirective implements OnChanges {
success: [],
failed: [],
get someFailed() {
return !!(this.failed.length);
return !!this.failed.length;
},
get someSucceeded() {
return !!(this.success.length);
return !!this.success.length;
},
get oneFailed() {
return this.failed.length === 1;
@@ -166,18 +163,15 @@ export class NodeDeleteDirective implements OnChanges {
}
};
return data.reduce(
(acc, next) => {
if (next.status === 1) {
acc.success.push(next);
} else {
acc.failed.push(next);
}
return data.reduce((acc, next) => {
if (next.status === 1) {
acc.success.push(next);
} else {
acc.failed.push(next);
}
return acc;
},
deleteStatus
);
return acc;
}, deleteStatus);
}
private getMessage(status: ProcessStatus): string | null {
@@ -198,37 +192,25 @@ export class NodeDeleteDirective implements OnChanges {
}
if (status.someFailed && status.someSucceeded && !status.oneSucceeded) {
return this.translation.instant(
'CORE.DELETE_NODE.PARTIAL_PLURAL',
{
success: status.success.length,
failed: status.failed.length
}
);
return this.translation.instant('CORE.DELETE_NODE.PARTIAL_PLURAL', {
success: status.success.length,
failed: status.failed.length
});
}
if (status.someFailed && status.oneSucceeded) {
return this.translation.instant(
'CORE.DELETE_NODE.PARTIAL_SINGULAR',
{
success: status.success.length,
failed: status.failed.length
}
);
return this.translation.instant('CORE.DELETE_NODE.PARTIAL_SINGULAR', {
success: status.success.length,
failed: status.failed.length
});
}
if (status.oneFailed && !status.someSucceeded) {
return this.translation.instant(
'CORE.DELETE_NODE.ERROR_SINGULAR',
{ name: status.failed[0].entry.name }
);
return this.translation.instant('CORE.DELETE_NODE.ERROR_SINGULAR', { name: status.failed[0].entry.name });
}
if (status.oneSucceeded && !status.someFailed) {
return this.translation.instant(
'CORE.DELETE_NODE.SINGULAR',
{ name: status.success[0].entry.name }
);
return this.translation.instant('CORE.DELETE_NODE.SINGULAR', { name: status.success[0].entry.name });
}
return null;

View File

@@ -29,7 +29,6 @@ import { ContentApi, NodeEntry, VersionEntry } from '@alfresco/js-api';
selector: '[adfNodeDownload]'
})
export class NodeDownloadDirective {
_contentApi: ContentApi;
get contentApi(): ContentApi {
this._contentApi = this._contentApi ?? new ContentApi(this.apiService.getInstance());
@@ -49,11 +48,7 @@ export class NodeDownloadDirective {
this.downloadNodes(this.nodes);
}
constructor(
private apiService: AlfrescoApiService,
private downloadService: DownloadService,
private dialog: MatDialog) {
}
constructor(private apiService: AlfrescoApiService, private downloadService: DownloadService, private dialog: MatDialog) {}
/**
* Downloads multiple selected nodes.
@@ -62,7 +57,6 @@ export class NodeDownloadDirective {
* @param selection Multiple selected nodes to download
*/
downloadNodes(selection: NodeEntry | Array<NodeEntry>) {
if (!this.isSelectionValid(selection)) {
return;
}
@@ -84,7 +78,7 @@ export class NodeDownloadDirective {
* @param node Node to download
*/
downloadNode(node: NodeEntry) {
if (node && node.entry) {
if (node?.entry) {
const entry = node.entry;
if (entry.isFile) {
@@ -107,12 +101,12 @@ export class NodeDownloadDirective {
}
private downloadFile(node: NodeEntry) {
if (node && node.entry) {
if (node?.entry) {
// nodeId for Shared node
const id = (node.entry as any).nodeId || node.entry.id;
let url;
let fileName;
let url: string;
let fileName: string;
if (this.version) {
url = this.contentApi.getVersionContentUrl(id, this.version.entry.id, true);
fileName = this.version.entry.name;
@@ -128,7 +122,7 @@ export class NodeDownloadDirective {
private downloadZip(selection: Array<NodeEntry>) {
if (selection && selection.length > 0) {
// nodeId for Shared node
const nodeIds = selection.map((node: any) => (node.entry.nodeId || node.entry.id));
const nodeIds = selection.map((node: any) => node.entry.nodeId || node.entry.id);
this.dialog.open(DownloadZipDialogComponent, {
width: '600px',

View File

@@ -130,7 +130,7 @@ export class NodeFavoriteDirective implements OnChanges {
const node: Node | SharedLink = selected.entry;
// ACS 6.x with 'isFavorite' include
if (node && node.hasOwnProperty('isFavorite')) {
if (node?.hasOwnProperty('isFavorite')) {
return of(selected);
}