diff --git a/src/app/components/favorites/favorites.component.html b/src/app/components/favorites/favorites.component.html
index 891235405..a6c71fa4e 100644
--- a/src/app/components/favorites/favorites.component.html
+++ b/src/app/components/favorites/favorites.component.html
@@ -3,14 +3,14 @@
-
+
@@ -18,16 +18,16 @@
mat-icon-button
color="primary"
title="{{ 'APP.ACTIONS.DOWNLOAD' | translate }}"
- [adfNodeDownload]="selectedNodes">
+ [adfNodeDownload]="selection.nodes">
get_app
@@ -49,39 +49,39 @@
[overlapTrigger]="false">
@@ -169,7 +169,7 @@
diff --git a/src/app/components/files/files.component.html b/src/app/components/files/files.component.html
index e24f683c7..446090a0d 100644
--- a/src/app/components/files/files.component.html
+++ b/src/app/components/files/files.component.html
@@ -6,13 +6,13 @@
(navigate)="onBreadcrumbNavigate($event)">
-
+
@@ -20,16 +20,16 @@
color="primary"
mat-icon-button
title="{{ 'APP.ACTIONS.DOWNLOAD' | translate }}"
- [adfNodeDownload]="selectedNodes">
+ [adfNodeDownload]="selection.nodes">
get_app
@@ -52,40 +52,40 @@
[overlapTrigger]="false">
@@ -167,7 +167,7 @@
diff --git a/src/app/components/page.component.spec.ts b/src/app/components/page.component.spec.ts
index 680eee69b..ee65afb82 100644
--- a/src/app/components/page.component.spec.ts
+++ b/src/app/components/page.component.spec.ts
@@ -24,15 +24,10 @@
*/
import { PageComponent } from './page.component';
-import { MinimalNodeEntity } from 'alfresco-js-api';
class TestClass extends PageComponent {
node: any;
- setSelection(selection: MinimalNodeEntity[] = []) {
- this.onSelectionChanged(selection);
- }
-
constructor() {
super(null, null, null);
}
@@ -58,47 +53,4 @@ describe('PageComponent', () => {
expect(component.getParentNodeId()).toBe(null);
});
});
-
- describe('hasSelection()', () => {
- it('returns true when it has nodes selected', () => {
- component.setSelection([
- { entry: { isFile: true } },
- { entry: { isFile: true } }
- ]);
- expect(component.hasSelection).toBe(true);
- });
-
- it('returns false when it has no selections', () => {
- component.setSelection([]);
- expect(component.hasSelection).toBe(false);
- });
- });
-
- describe('selectedFile', () => {
- it('returns true if selected node is file', () => {
- const selection = [ { entry: { isFile: true } } ];
- component.setSelection(selection);
- expect(component.selectedFile).toBe(selection[0]);
- });
-
- it('returns false if selected node is folder', () => {
- const selection = [ { entry: { isFile: false, isFolder: true } } ];
- component.setSelection(selection);
- expect(component.selectedFile).toBeFalsy();
- });
- });
-
- describe('selectedFolder', () => {
- it('returns true if selected node is folder', () => {
- const selection = [ { entry: { isFile: false, isFolder: true } } ];
- component.setSelection(selection);
- expect(component.selectedFolder).toBe(selection[0]);
- });
-
- it('returns false if selected node is file', () => {
- const selection = [ { entry: { isFile: true, isFolder: false } } ];
- component.setSelection(selection);
- expect(component.selectedFolder).toBeFalsy();
- });
- });
});
diff --git a/src/app/components/page.component.ts b/src/app/components/page.component.ts
index a81857959..3bb25af10 100644
--- a/src/app/components/page.component.ts
+++ b/src/app/components/page.component.ts
@@ -32,12 +32,13 @@ import { MinimalNodeEntity, MinimalNodeEntryEntity, Pagination } from 'alfresco-
import { takeUntil } from 'rxjs/operators';
import { Subject, Subscription } from 'rxjs/Rx';
import { SnackbarErrorAction, ViewNodeAction, SetSelectedNodesAction } from '../store/actions';
-import { selectedNodes } from '../store/selectors/app.selectors';
+import { appSelection } from '../store/selectors/app.selectors';
import { AppStore } from '../store/states/app.state';
+import { SelectionState } from '../store/states/selection.state';
export abstract class PageComponent implements OnInit, OnDestroy {
- onDestroy$: Subject = new Subject();
+ onDestroy$: Subject = new Subject();
@ViewChild(DocumentListComponent)
documentList: DocumentListComponent;
@@ -45,13 +46,7 @@ export abstract class PageComponent implements OnInit, OnDestroy {
title = 'Page';
infoDrawerOpened = false;
node: MinimalNodeEntryEntity;
-
- selectedFolder: MinimalNodeEntity;
- selectedFile: MinimalNodeEntity;
-
- hasSelection = false;
- lastSelectedNode: MinimalNodeEntity;
- selectedNodes: MinimalNodeEntity[];
+ selection: SelectionState;
protected subscriptions: Subscription[] = [];
@@ -70,35 +65,24 @@ export abstract class PageComponent implements OnInit, OnDestroy {
ngOnInit() {
this.store
- .select(selectedNodes)
+ .select(appSelection)
.pipe(takeUntil(this.onDestroy$))
- .subscribe(selection => this.onSelectionChanged(selection));
+ .subscribe(selection => {
+ this.selection = selection;
+ if (selection.isEmpty) {
+ this.infoDrawerOpened = false;
+ }
+ });
}
ngOnDestroy() {
this.subscriptions.forEach(subscription => subscription.unsubscribe());
this.subscriptions = [];
+
+ this.onDestroy$.next(true);
this.onDestroy$.complete();
}
- // Precalculates all the "static state" flags so that UI does not re-evaluate that on every tick
- protected onSelectionChanged(selection: MinimalNodeEntity[] = []) {
- this.selectedNodes = selection;
- this.hasSelection = selection.length > 0;
- this.selectedFolder = null;
- this.selectedFile = null;
-
- if (selection.length > 0) {
- if (selection.length === 1) {
- this.selectedFile = selection.find(entity => entity.entry.isFile);
- this.selectedFolder = selection.find(entity => entity.entry.isFolder);
- }
- } else {
- this.lastSelectedNode = null;
- this.infoDrawerOpened = false;
- }
- }
-
showPreview(node: MinimalNodeEntity) {
if (node && node.entry) {
const { id, nodeId, name, isFile, isFolder } = node.entry;
@@ -130,7 +114,6 @@ export abstract class PageComponent implements OnInit, OnDestroy {
this.unSelectLockedNodes(documentList);
}
- this.lastSelectedNode = event.detail.node;
this.store.dispatch(new SetSelectedNodesAction(documentList.selection));
}
}
diff --git a/src/app/components/preview/preview.component.html b/src/app/components/preview/preview.component.html
index 666879f6e..8a19b3151 100644
--- a/src/app/components/preview/preview.component.html
+++ b/src/app/components/preview/preview.component.html
@@ -35,10 +35,10 @@
diff --git a/src/app/components/recent-files/recent-files.component.html b/src/app/components/recent-files/recent-files.component.html
index 70eb1765e..18ce84406 100644
--- a/src/app/components/recent-files/recent-files.component.html
+++ b/src/app/components/recent-files/recent-files.component.html
@@ -3,14 +3,14 @@
-
+
@@ -18,7 +18,7 @@
mat-icon-button
color="primary"
title="{{ 'APP.ACTIONS.DOWNLOAD' | translate }}"
- [adfNodeDownload]="selectedNodes">
+ [adfNodeDownload]="selection.nodes">
get_app
@@ -41,40 +41,40 @@
[overlapTrigger]="false">
@@ -157,7 +157,7 @@
diff --git a/src/app/components/search/search.component.html b/src/app/components/search/search.component.html
index 614de260e..d1af64136 100644
--- a/src/app/components/search/search.component.html
+++ b/src/app/components/search/search.component.html
@@ -2,13 +2,13 @@
diff --git a/src/app/components/shared-files/shared-files.component.html b/src/app/components/shared-files/shared-files.component.html
index 7cce92bfd..451525317 100644
--- a/src/app/components/shared-files/shared-files.component.html
+++ b/src/app/components/shared-files/shared-files.component.html
@@ -3,13 +3,13 @@
-
+
@@ -17,7 +17,7 @@
color="primary"
mat-icon-button
title="{{ 'APP.ACTIONS.DOWNLOAD' | translate }}"
- [adfNodeDownload]="selectedNodes">
+ [adfNodeDownload]="selection.nodes">
get_app
@@ -40,32 +40,32 @@
[overlapTrigger]="false">