Skip to content

Commit

Permalink
Principal Combobox: show removed selected items #3714
Browse files Browse the repository at this point in the history
  • Loading branch information
ashklianko committed Sep 19, 2024
1 parent 247eacf commit 9979408
Showing 1 changed file with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Q from 'q';
import {Option} from '../selector/Option';
import {Principal} from '../../security/Principal';
import {Principal, PrincipalBuilder} from '../../security/Principal';
import {PrincipalLoader} from '../../security/PrincipalLoader';
import {SelectedOption} from '../selector/combobox/SelectedOption';
import {BaseSelectedOptionsView} from '../selector/combobox/BaseSelectedOptionsView';
Expand Down Expand Up @@ -105,9 +105,22 @@ export class PrincipalComboBox

setSelectedItems(items: PrincipalKey[]): void {
this.preSelectedItems = items || [];
this.deselectAll();

if (items.length === 0) {
return;
}

new GetPrincipalsByKeysRequest(items).setPostfixUri(this.postfixUri).sendAndParse().then((principals: Principal[]) => {
this.select(principals, true);
const itemsToSelect = [];

items.forEach((item: PrincipalKey) => {
const principal = principals.find((p) => p.getKey().equals(item));

itemsToSelect.push(principal || new MissingPrincipal(item));
});

this.select(itemsToSelect);
}).catch(DefaultErrorHandler.handle);
}
}
Expand Down Expand Up @@ -143,7 +156,8 @@ export class PrincipalSelectedOptionsView
}

createSelectedOption(option: Option<Principal>): SelectedOption<Principal> {
let optionView = !option.isEmpty() ? new PrincipalSelectedOptionView(option) : new RemovedPrincipalSelectedOptionView(option);
let optionView = option.getDisplayValue() instanceof MissingPrincipal ? new RemovedPrincipalSelectedOptionView(option) : new PrincipalSelectedOptionView(option);

if (this.readonly) {
optionView.setReadonly(true);
}
Expand Down Expand Up @@ -193,3 +207,9 @@ export class PrincipalComboBoxWrapper extends FormInputEl {
return this.selector.getSelectedOptions().map((option) => option.getOption().getValue()).join(';');
}
}

class MissingPrincipal extends Principal {
constructor(key: PrincipalKey) {
super(new PrincipalBuilder().setKey(key).setDisplayName(key.toString()));
}
}

0 comments on commit 9979408

Please sign in to comment.