Skip to content

Commit

Permalink
Misc changes for the new tree- and -list api #3696
Browse files Browse the repository at this point in the history
- When applying selection delta need to deselect items first so the selected items could be selected up to defined limit
- Removing item from selected view prior to main deselect routine since top classes rely on counter of selected items in selected view
  • Loading branch information
ashklianko committed Sep 9, 2024
1 parent a4b1c36 commit 5784d32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,18 +313,29 @@ export class FilterableListBoxWrapper<I>
protected applySelection(): void {
const selectionChange: SelectionChange<I> = {selected: [], deselected: []};

// deselecting items first to free selection space for new items if limits are set
this.selectionDelta.forEach((isSelected: boolean, id: string) => {
const item: I = this.getItemById(id);

if (isSelected) {
selectionChange.selected.push(item);
this.doSelect(item);
} else {
if (!isSelected) {
const item: I = this.getItemById(id);
selectionChange.deselected.push(item);
this.doDeselect(item);
}
});

// then selecting items until max limit is reached
this.selectionDelta.forEach((isSelected: boolean, id: string) => {
if (isSelected) {
if (this.selectionLimitReached) {
this.toggleItemWrapperSelected(id, false);
} else {
const item: I = this.getItemById(id);
selectionChange.selected.push(item);
this.doSelect(item);
}

}
});

this.selectionDelta = new Map();
this.listBox.hide();
this.dropdownHandle.up();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ export abstract class FilterableListBoxWrapperWithSelectedView<I>
}

protected doDeselect(itemToDeselect: I): void {
super.doDeselect(itemToDeselect);

const option = this.createSelectedOption(itemToDeselect);
const existing = this.selectedOptionsView.getById(option.getId());

if (existing) {
this.selectedOptionsView.removeOption(this.createSelectedOption(itemToDeselect), true);
}

super.doDeselect(itemToDeselect);
}

abstract createSelectedOption(item: I): Option<I>;
Expand Down

0 comments on commit 5784d32

Please sign in to comment.