[AAE-4841] - Fix content node selector current selection is lost after uploading files (#6862)

* [AAE-4841] - Preserve current selection when preselecting the newly uploaded nodes

* add a method to handle unselection of a preselected row in document list and emit the change

* Fix-refactor unselection

* Fix document list reload

* Partial revert share datatable adapter

* try with overwriting datatable selection

* Sync datatable selection after every page load

* refactor selection/unselection in datatable by using a row id

* Fix/Add some unit tests

* Move preselection from adapter to doc list, fix single selection mode

* Add some unit tests

* Add document list unit tests
This commit is contained in:
arditdomi
2021-04-08 14:55:06 +01:00
committed by GitHub
parent b08e2731bf
commit e589071328
12 changed files with 459 additions and 138 deletions

View File

@@ -45,7 +45,6 @@ export class ShareDataTableAdapter implements DataTableAdapter {
permissionsStyle: PermissionStyleModel[];
selectedRow: DataRow;
allowDropFiles: boolean;
preselectedRows: DataRow[] = [];
set sortingMode(value: string) {
let newValue = (value || 'client').toLowerCase();
@@ -82,10 +81,6 @@ export class ShareDataTableAdapter implements DataTableAdapter {
this.sort();
}
getPreselectedRows(): Array<DataRow> {
return this.preselectedRows;
}
getColumns(): Array<DataColumn> {
return this.columns;
}
@@ -250,7 +245,7 @@ export class ShareDataTableAdapter implements DataTableAdapter {
}
}
public loadPage(nodePaging: NodePaging, merge: boolean = false, allowDropFiles?: boolean, preselectNodes: NodeEntry[] = []) {
public loadPage(nodePaging: NodePaging, merge: boolean = false, allowDropFiles?: boolean) {
let shareDataRows: ShareDataRow[] = [];
if (allowDropFiles !== undefined) {
this.allowDropFiles = allowDropFiles;
@@ -258,8 +253,7 @@ export class ShareDataTableAdapter implements DataTableAdapter {
if (nodePaging?.list) {
const nodeEntries: NodeEntry[] = nodePaging.list.entries;
if (nodeEntries?.length) {
shareDataRows = nodeEntries.map((item) => new ShareDataRow(item, this.contentService, this.permissionsStyle,
this.thumbnailService, this.allowDropFiles));
shareDataRows = nodeEntries.map((item) => new ShareDataRow(item, this.contentService, this.permissionsStyle, this.thumbnailService, this.allowDropFiles));
if (this.filter) {
shareDataRows = shareDataRows.filter(this.filter);
@@ -297,27 +291,13 @@ export class ShareDataTableAdapter implements DataTableAdapter {
} else {
this.rows = shareDataRows;
}
this.selectRowsBasedOnGivenNodes(preselectNodes);
}
selectRowsBasedOnGivenNodes(preselectNodes: NodeEntry[]) {
if (preselectNodes?.length) {
this.rows = this.rows.map((row) => {
preselectNodes.map((preselectedNode) => {
if (row.obj.entry.id === preselectedNode.entry.id) {
row.isSelected = true;
}
});
return row;
});
}
this.preselectedRows = [...this.rows.filter((res) => res.isSelected)];
getSelectedRows(): DataRow[] {
return this.rows.filter((row: DataRow) => row.isSelected);
}
hasPreselectedRows(): boolean {
return this.preselectedRows?.length > 0;
getRowByNodeId(nodeId: string): DataRow {
return this.rows.find((row: DataRow) => row.node.entry.id === nodeId);
}
}