turn filter around to allow + fix test

This commit is contained in:
Mads Rasmussen
2024-09-16 13:41:27 +02:00
parent 1fcce6749a
commit ee7ef67846
4 changed files with 10 additions and 10 deletions

View File

@@ -155,9 +155,9 @@ describe('UmbSelectionManager', () => {
expect(manager.getSelection()).to.deep.equal([]);
});
it('can not select an item if it does not pass the disallow function', () => {
manager.setDisallow((item) => item !== '2');
manager.select('2');
it('can not select an item if it does not pass the allow function', () => {
manager.setAllow((item) => item !== '2');
expect(() => manager.select('2')).to.throw();
expect(manager.getSelection()).to.deep.equal([]);
manager.select('1');

View File

@@ -19,7 +19,7 @@ export class UmbSelectionManager<ValueType extends string | null = string | null
public readonly multiple = this.#multiple.asObservable();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
#disallow = (unique: ValueType) => true;
#allow = (unique: ValueType) => true;
constructor(host: UmbControllerHost) {
super(host);
@@ -112,8 +112,8 @@ export class UmbSelectionManager<ValueType extends string | null = string | null
public select(unique: ValueType) {
if (this.getSelectable() === false) return;
if (this.isSelected(unique)) return;
if (this.#disallow(unique) === false) {
throw new Error('The selection filter does not allow this item to be selected.');
if (this.#allow(unique) === false) {
throw new Error('The item is now allowed to be selected');
}
const newSelection = this.getMultiple() ? [...this.getSelection(), unique] : [unique];
this.#selection.setValue(newSelection);
@@ -158,7 +158,7 @@ export class UmbSelectionManager<ValueType extends string | null = string | null
* @param compareFn A function that determines if an item is selectable or not.
* @memberof UmbSelectionManager
*/
public setDisallow(compareFn: (unique: ValueType) => boolean): void {
this.#disallow = compareFn;
public setAllow(compareFn: (unique: ValueType) => boolean): void {
this.#allow = compareFn;
}
}

View File

@@ -44,7 +44,7 @@ export class UmbDocumentScheduleModalElement extends UmbModalBaseElement<
const pickableFilter = this.data?.pickableFilter;
if (pickableFilter) {
this.#selectionManager.setDisallow((unique) => {
this.#selectionManager.setAllow((unique) => {
const option = this.data?.options.find((o) => o.unique === unique);
return option ? pickableFilter(option) : true;
});

View File

@@ -50,7 +50,7 @@ export class UmbDocumentVariantLanguagePickerElement extends UmbLitElement {
super.updated(_changedProperties);
if (this.selectionManager && this.pickableFilter) {
this.#selectionManager.setDisallow((unique) => {
this.#selectionManager.setAllow((unique) => {
const option = this.variantLanguageOptions.find((o) => o.unique === unique);
return option ? this.pickableFilter!(option) : true;
});