rename filter to disallow

This commit is contained in:
Mads Rasmussen
2024-09-16 12:40:24 +02:00
parent 1bab612cb8
commit 1fcce6749a
4 changed files with 12 additions and 12 deletions

View File

@@ -77,8 +77,8 @@ describe('UmbSelectionManager', () => {
expect(manager).to.have.property('clearSelection').that.is.a('function');
});
it('has a setFilter method', () => {
expect(manager).to.have.property('setFilter').that.is.a('function');
it('has a setDisallow method', () => {
expect(manager).to.have.property('setDisallow').that.is.a('function');
});
});
});
@@ -155,8 +155,8 @@ describe('UmbSelectionManager', () => {
expect(manager.getSelection()).to.deep.equal([]);
});
it('can not select an item if it does not pass the filter', () => {
manager.setFilter((item) => item !== '2');
it('can not select an item if it does not pass the disallow function', () => {
manager.setDisallow((item) => item !== '2');
manager.select('2');
expect(manager.getSelection()).to.deep.equal([]);

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
#selectionFilter = (unique: ValueType) => true;
#disallow = (unique: ValueType) => true;
constructor(host: UmbControllerHost) {
super(host);
@@ -112,7 +112,7 @@ 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.#selectionFilter(unique) === false) {
if (this.#disallow(unique) === false) {
throw new Error('The selection filter does not allow this item to be selected.');
}
const newSelection = this.getMultiple() ? [...this.getSelection(), unique] : [unique];
@@ -154,11 +154,11 @@ export class UmbSelectionManager<ValueType extends string | null = string | null
}
/**
* Sets the selection filter.
* @param filter The selection filter.
* Sets a function that determines if an item is selectable or not.
* @param compareFn A function that determines if an item is selectable or not.
* @memberof UmbSelectionManager
*/
public setFilter(filter: (unique: ValueType) => boolean): void {
this.#selectionFilter = filter;
public setDisallow(compareFn: (unique: ValueType) => boolean): void {
this.#disallow = compareFn;
}
}

View File

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