mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
@@ -40,6 +40,7 @@ class CustomColumnTemplateComponent {
|
||||
class FakeDataRow implements DataRow {
|
||||
isDropTarget = false;
|
||||
isSelected = true;
|
||||
id?: string;
|
||||
|
||||
hasValue() {
|
||||
return true;
|
||||
@@ -593,6 +594,45 @@ describe('DataTable', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should unselect the row searching it by row id, when row id is defined', () => {
|
||||
const findSelectionByIdSpy = spyOn(dataTable, 'findSelectionById');
|
||||
dataTable.data = new ObjectDataTableAdapter([],
|
||||
[new ObjectDataColumn({ key: 'name' })]
|
||||
);
|
||||
|
||||
const fakeDataRows = [new FakeDataRow(), new FakeDataRow()];
|
||||
fakeDataRows[0].id = 'fakeRowId';
|
||||
fakeDataRows[1].id = 'fakeRowId2';
|
||||
|
||||
dataTable.data.setRows(fakeDataRows);
|
||||
dataTable.selection = [...fakeDataRows];
|
||||
const indexOfSpy = spyOn(dataTable.selection, 'indexOf');
|
||||
|
||||
dataTable.selectRow(fakeDataRows[0], false);
|
||||
|
||||
expect(indexOfSpy).not.toHaveBeenCalled();
|
||||
expect(findSelectionByIdSpy).toHaveBeenCalledWith(fakeDataRows[0].id);
|
||||
});
|
||||
|
||||
it('should unselect the row by searching for the exact same reference of it (indexOf), when row id is not defined ', () => {
|
||||
const findSelectionByIdSpy = spyOn(dataTable, 'findSelectionById');
|
||||
dataTable.data = new ObjectDataTableAdapter([],
|
||||
[new ObjectDataColumn({ key: 'name' })]
|
||||
);
|
||||
|
||||
const fakeDataRows = [new FakeDataRow(), new FakeDataRow()];
|
||||
dataTable.data.setRows(fakeDataRows);
|
||||
dataTable.selection = [...fakeDataRows];
|
||||
const indexOfSpy = spyOn(dataTable.selection, 'indexOf').and.returnValue(0);
|
||||
|
||||
dataTable.selectRow(fakeDataRows[0], false);
|
||||
|
||||
expect(indexOfSpy).toHaveBeenCalled();
|
||||
expect(findSelectionByIdSpy).not.toHaveBeenCalled();
|
||||
expect(dataTable.selection.length).toEqual(1);
|
||||
expect(dataTable.selection[0]).toEqual(fakeDataRows[1]);
|
||||
});
|
||||
|
||||
it('should select multiple rows with [multiple] selection mode and modifier key', (done) => {
|
||||
dataTable.selectionMode = 'multiple';
|
||||
dataTable.data = new ObjectDataTableAdapter(
|
||||
|
@@ -710,7 +710,7 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
|
||||
selectRow(row: DataRow, value: boolean) {
|
||||
if (row) {
|
||||
row.isSelected = value;
|
||||
const idx = this.selection.indexOf(row);
|
||||
const idx = row?.id ? this.findSelectionById(row.id) : this.selection.indexOf(row);
|
||||
if (value) {
|
||||
if (idx < 0) {
|
||||
this.selection.push(row);
|
||||
@@ -723,6 +723,10 @@ export class DataTableComponent implements AfterContentInit, OnChanges, DoCheck,
|
||||
}
|
||||
}
|
||||
|
||||
findSelectionById(id: string): number {
|
||||
return this.selection.findIndex(selection => selection?.id === id);
|
||||
}
|
||||
|
||||
getCellTooltip(row: DataRow, col: DataColumn): string {
|
||||
if (row && col && col.formatTooltip) {
|
||||
const result: string = col.formatTooltip(row, col);
|
||||
|
Reference in New Issue
Block a user