mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
Sonarcloud issues fixes (#3499)
* Sonarcloud issues fixes * Code smell fixes * Refactoring to remove new code duplications * Sonarcloud code smell fixes part I * Sonarcloud code smell fixes part II * Missing code smell fix * Add new ESLint rules to cover fixed SonarCloud issues * Add missing command * Add missing is existing check
This commit is contained in:
@@ -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;
|
||||
|
||||
|
@@ -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<UnshareNodesAction>(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<PurgeDeletedNodesAction>(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<RestoreDeletedNodesAction>(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<DeleteNodesAction>(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<PrintFileAction>(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<UnlockWriteAction>(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;
|
||||
|
@@ -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();
|
||||
|
@@ -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));
|
||||
}
|
||||
|
||||
|
@@ -101,7 +101,7 @@ export class ViewerEffects {
|
||||
this.actions$.pipe(
|
||||
ofType<ViewFileAction>(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)) {
|
||||
|
Reference in New Issue
Block a user