Skip to content

Commit

Permalink
fix(common): add missing Filter model Type of FilterConstructor (#…
Browse files Browse the repository at this point in the history
…1430)

- add a `FilterConstructor` type on the `model` prop of a Column filter, this is similar to the recently added `EditorConstructor` type for Editor
  • Loading branch information
ghiscoding committed Mar 13, 2024
1 parent 409115c commit 3f3e952
Show file tree
Hide file tree
Showing 21 changed files with 33 additions and 27 deletions.
8 changes: 4 additions & 4 deletions packages/common/src/filters/autocompleterFilter.ts
Expand Up @@ -78,8 +78,8 @@ export class AutocompleterFilter<T extends AutocompleteItem = any> implements Fi
* Initialize the Filter
*/
constructor(
protected readonly translaterService: TranslaterService,
protected readonly collectionService: CollectionService,
protected readonly translaterService?: TranslaterService,
protected readonly collectionService?: CollectionService,
protected readonly rxjs?: RxJsFacade
) {
this._bindEventService = new BindingEventService();
Expand Down Expand Up @@ -283,7 +283,7 @@ export class AutocompleterFilter<T extends AutocompleteItem = any> implements Fi
if (this.columnFilter && this.columnFilter.collectionFilterBy) {
const filterBy = this.columnFilter.collectionFilterBy;
const filterCollectionBy = this.columnFilter.collectionOptions && this.columnFilter.collectionOptions.filterResultAfterEachPass || null;
outputCollection = this.collectionService.filterCollection(outputCollection, filterBy, filterCollectionBy);
outputCollection = this.collectionService?.filterCollection(outputCollection, filterBy, filterCollectionBy) || [];
}

return outputCollection;
Expand All @@ -300,7 +300,7 @@ export class AutocompleterFilter<T extends AutocompleteItem = any> implements Fi
// user might want to sort the collection
if (this.columnFilter && this.columnFilter.collectionSortBy) {
const sortBy = this.columnFilter.collectionSortBy;
outputCollection = this.collectionService.sortCollection(this.columnDef, outputCollection, sortBy, this.enableTranslateLabel);
outputCollection = this.collectionService?.sortCollection(this.columnDef, outputCollection, sortBy, this.enableTranslateLabel) || [];
}

return outputCollection;
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/compoundDateFilter.ts
Expand Up @@ -3,7 +3,7 @@ import { DateFilter } from './dateFilter';

export class CompoundDateFilter extends DateFilter {
/** Initialize the Filter */
constructor(protected readonly translaterService: TranslaterService) {
constructor(protected readonly translaterService?: TranslaterService) {
super(translaterService);
this.inputFilterType = 'compound';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/compoundInputFilter.ts
Expand Up @@ -5,7 +5,7 @@ export class CompoundInputFilter extends InputFilter {
/**
* Initialize the Filter
*/
constructor(protected readonly translaterService: TranslaterService) {
constructor(protected readonly translaterService?: TranslaterService) {
super(translaterService);
this.inputType = 'text';
this.inputFilterType = 'compound';
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/compoundInputNumberFilter.ts
Expand Up @@ -3,7 +3,7 @@ import type { TranslaterService } from '../services/translater.service';

export class CompoundInputNumberFilter extends InputFilter {
/** Initialize the Filter */
constructor(protected readonly translaterService: TranslaterService) {
constructor(protected readonly translaterService?: TranslaterService) {
super(translaterService);
this.inputType = 'number';
this.inputFilterType = 'compound';
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/compoundInputPasswordFilter.ts
Expand Up @@ -3,7 +3,7 @@ import type { TranslaterService } from '../services/translater.service';

export class CompoundInputPasswordFilter extends InputFilter {
/** Initialize the Filter */
constructor(protected readonly translaterService: TranslaterService) {
constructor(protected readonly translaterService?: TranslaterService) {
super(translaterService);
this.inputType = 'password';
this.inputFilterType = 'compound';
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/compoundSliderFilter.ts
Expand Up @@ -5,7 +5,7 @@ export class CompoundSliderFilter extends SliderFilter {
/**
* Initialize the Filter
*/
constructor(protected readonly translaterService: TranslaterService) {
constructor(protected readonly translaterService?: TranslaterService) {
super(translaterService);
this.sliderType = 'compound';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/dateFilter.ts
Expand Up @@ -48,7 +48,7 @@ export class DateFilter implements Filter {
callback!: FilterCallback;
filterContainerElm!: HTMLDivElement;

constructor(protected readonly translaterService: TranslaterService) {
constructor(protected readonly translaterService?: TranslaterService) {
this._bindEventService = new BindingEventService();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/dateRangeFilter.ts
Expand Up @@ -3,7 +3,7 @@ import type { TranslaterService } from '../services';

export class DateRangeFilter extends DateFilter {
/** Initialize the Filter */
constructor(protected readonly translaterService: TranslaterService) {
constructor(protected readonly translaterService?: TranslaterService) {
super(translaterService);
this.inputFilterType = 'range';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/inputFilter.ts
Expand Up @@ -32,7 +32,7 @@ export class InputFilter implements Filter {
columnDef!: Column;
callback!: FilterCallback;

constructor(protected readonly translaterService: TranslaterService) {
constructor(protected readonly translaterService?: TranslaterService) {
this._bindEventService = new BindingEventService();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/inputMaskFilter.ts
Expand Up @@ -6,7 +6,7 @@ export class InputMaskFilter extends InputFilter {
protected _inputMask = '';

/** Initialize the Filter */
constructor(protected readonly translaterService: TranslaterService) {
constructor(protected readonly translaterService?: TranslaterService) {
super(translaterService);
this.inputType = 'text';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/inputNumberFilter.ts
Expand Up @@ -3,7 +3,7 @@ import type { TranslaterService } from '../services/translater.service';

export class InputNumberFilter extends InputFilter {
/** Initialize the Filter */
constructor(protected readonly translaterService: TranslaterService) {
constructor(protected readonly translaterService?: TranslaterService) {
super(translaterService);
this.inputType = 'number';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/inputPasswordFilter.ts
Expand Up @@ -3,7 +3,7 @@ import type { TranslaterService } from '../services/translater.service';

export class InputPasswordFilter extends InputFilter {
/** Initialize the Filter */
constructor(protected readonly translaterService: TranslaterService) {
constructor(protected readonly translaterService?: TranslaterService) {
super(translaterService);
this.inputType = 'password';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/multipleSelectFilter.ts
Expand Up @@ -7,7 +7,7 @@ export class MultipleSelectFilter extends SelectFilter {
/**
* Initialize the Filter
*/
constructor(protected readonly translaterService: TranslaterService, protected readonly collectionService: CollectionService, protected readonly rxjs?: RxJsFacade) {
constructor(protected readonly translaterService?: TranslaterService, protected readonly collectionService?: CollectionService, protected readonly rxjs?: RxJsFacade) {
super(translaterService, collectionService, rxjs, true);
}
}
4 changes: 2 additions & 2 deletions packages/common/src/filters/nativeSelectFilter.ts
Expand Up @@ -25,7 +25,7 @@ export class NativeSelectFilter implements Filter {
callback!: FilterCallback;
filterContainerElm!: HTMLDivElement;

constructor(protected readonly translater: TranslaterService) {
constructor(protected readonly translater?: TranslaterService) {
this._bindEventService = new BindingEventService();
}

Expand Down Expand Up @@ -171,7 +171,7 @@ export class NativeSelectFilter implements Filter {
}

const labelKey = option.labelKey || option[labelName];
const textLabel = ((option.labelKey || isEnabledTranslate) && typeof this.translater !== undefined && this.translater.getCurrentLanguage?.()) ? this.translater.translate(labelKey || ' ') : labelKey;
const textLabel = ((option.labelKey || isEnabledTranslate) && typeof this.translater !== undefined && this.translater?.getCurrentLanguage?.()) ? this.translater.translate(labelKey || ' ') : labelKey;

selectElm.appendChild(
createDomElement('option', { value: option[valueName], textContent: textLabel })
Expand Down
8 changes: 4 additions & 4 deletions packages/common/src/filters/selectFilter.ts
Expand Up @@ -56,8 +56,8 @@ export class SelectFilter implements Filter {
* Initialize the Filter
*/
constructor(
protected readonly translaterService: TranslaterService,
protected readonly collectionService: CollectionService,
protected readonly translaterService?: TranslaterService,
protected readonly collectionService?: CollectionService,
protected readonly rxjs?: RxJsFacade,
isMultipleSelect = true) {
this._isMultipleSelect = isMultipleSelect;
Expand Down Expand Up @@ -254,7 +254,7 @@ export class SelectFilter implements Filter {
if (this.columnFilter && this.columnFilter.collectionFilterBy) {
const filterBy = this.columnFilter.collectionFilterBy;
const filterCollectionBy = this.columnFilter.collectionOptions?.filterResultAfterEachPass || null;
outputCollection = this.collectionService.filterCollection(outputCollection, filterBy, filterCollectionBy);
outputCollection = this.collectionService?.filterCollection(outputCollection, filterBy, filterCollectionBy) || [];
}

return outputCollection;
Expand All @@ -271,7 +271,7 @@ export class SelectFilter implements Filter {
// user might want to sort the collection
if (this.columnFilter && this.columnFilter.collectionSortBy) {
const sortBy = this.columnFilter.collectionSortBy;
outputCollection = this.collectionService.sortCollection(this.columnDef, outputCollection, sortBy, this.enableTranslateLabel);
outputCollection = this.collectionService?.sortCollection(this.columnDef, outputCollection, sortBy, this.enableTranslateLabel) || [];
}

return outputCollection;
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/singleSelectFilter.ts
Expand Up @@ -7,7 +7,7 @@ export class SingleSelectFilter extends SelectFilter {
/**
* Initialize the Filter
*/
constructor(protected readonly translaterService: TranslaterService, protected readonly collectionService: CollectionService, protected readonly rxjs?: RxJsFacade) {
constructor(protected readonly translaterService?: TranslaterService, protected readonly collectionService?: CollectionService, protected readonly rxjs?: RxJsFacade) {
super(translaterService, collectionService, rxjs, false);
}
}
2 changes: 1 addition & 1 deletion packages/common/src/filters/singleSliderFilter.ts
Expand Up @@ -5,7 +5,7 @@ export class SingleSliderFilter extends SliderFilter {
/**
* Initialize the Filter
*/
constructor(protected readonly translaterService: TranslaterService) {
constructor(protected readonly translaterService?: TranslaterService) {
super(translaterService);
this.sliderType = 'single';
}
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/sliderFilter.ts
Expand Up @@ -52,7 +52,7 @@ export class SliderFilter implements Filter {
columnDef!: Column;
callback!: FilterCallback;

constructor(protected readonly translaterService: TranslaterService) {
constructor(protected readonly translaterService?: TranslaterService) {
this._bindEventService = new BindingEventService();
}

Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/filters/sliderRangeFilter.ts
Expand Up @@ -5,7 +5,7 @@ export class SliderRangeFilter extends SliderFilter {
/**
* Initialize the Filter
*/
constructor(protected readonly translaterService: TranslaterService) {
constructor(protected readonly translaterService?: TranslaterService) {
super(translaterService);
this.sliderType = 'double';
}
Expand Down
3 changes: 2 additions & 1 deletion packages/common/src/interfaces/columnFilter.interface.ts
Expand Up @@ -6,6 +6,7 @@ import type {
CollectionSortBy,
Column,
Filter,
FilterConstructor,
OperatorDetail,
} from './index';
import type { Observable, Subject } from '../services/rxjsFacade';
Expand Down Expand Up @@ -42,7 +43,7 @@ export interface ColumnFilter {
minValue?: number | string;

/** Filter to use (input, multipleSelect, singleSelect, select, custom) */
model?: any;
model?: FilterConstructor;

/** A collection of items/options that will be loaded asynchronously (commonly used with a Select/Multi-Select Filter) */
collectionAsync?: Promise<any> | Observable<any> | Subject<any>;
Expand Down
5 changes: 5 additions & 0 deletions packages/common/src/interfaces/filter.interface.ts
@@ -1,6 +1,7 @@
import type { Column, FilterArguments, FilterCallback } from './index';
import type { OperatorType, OperatorString, SearchTerm, } from '../enums/index';
import type { SlickGrid } from '../core/index';
import type { CollectionService, RxJsFacade, TranslaterService } from '../services';

// export type Filter = (searchTerms: string | number | string[] | number[], columnDef: Column, params?: any) => string;
export interface Filter {
Expand Down Expand Up @@ -45,3 +46,7 @@ export interface Filter {
/** Set value(s) on the DOM element */
setValues: (values: SearchTerm | SearchTerm[], operator?: OperatorType | OperatorString) => void;
}

export type FilterConstructor = {
new(translaterService?: TranslaterService, collectionService?: CollectionService, rxjs?: RxJsFacade): Filter;
};

0 comments on commit 3f3e952

Please sign in to comment.