Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(filters): skipCompoundOperatorFilterWithNullInput skip undefined #1568

Merged
merged 1 commit into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/common/src/filters/dateFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class DateFilter implements Filter {
protected _currentDateOrDates?: Date | Date[] | string | string[];
protected _currentDateStrings?: string[];
protected _lastClickIsDate = false;
protected _lastSearchValue?: string;
protected _pickerOptions!: IOptions;
protected _filterElm!: HTMLDivElement;
protected _dateInputElm!: HTMLInputElement;
Expand Down Expand Up @@ -496,7 +497,9 @@ export class DateFilter implements Filter {

// when changing compound operator, we don't want to trigger the filter callback unless the date input is also provided
const skipNullInput = this.columnFilter.skipCompoundOperatorFilterWithNullInput ?? this.gridOptions.skipCompoundOperatorFilterWithNullInput ?? this.gridOptions.skipCompoundOperatorFilterWithNullInput === undefined;
if (!skipNullInput || (skipNullInput && isDefined(this._currentDateOrDates))) {
const hasSkipNullValChanged = (skipNullInput && isDefined(this._currentDateOrDates)) || (this._currentDateOrDates === '' && isDefined(this._lastSearchValue));

if (!skipNullInput || !skipNullInput || hasSkipNullValChanged) {
this.callback(e, { columnDef: this.columnDef, searchTerms: (this._currentValue ? [this._currentValue] : null), operator: selectedOperator || '', shouldTriggerQuery: this._shouldTriggerQuery });
}
}
Expand All @@ -505,5 +508,6 @@ export class DateFilter implements Filter {
// reset both flags for next use
this._clearFilterTriggered = false;
this._shouldTriggerQuery = true;
this._lastSearchValue = this._currentValue;
}
}
8 changes: 6 additions & 2 deletions packages/common/src/filters/sliderFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export class SliderFilter implements Filter {
protected _clearFilterTriggered = false;
protected _currentValue?: number;
protected _currentValues?: number[];
protected _lastSearchValue?: number | string;
protected _shouldTriggerQuery = true;
protected _sliderOptions!: CurrentSliderOption;
protected _operator?: OperatorType | OperatorString;
Expand Down Expand Up @@ -415,8 +416,10 @@ export class SliderFilter implements Filter {
value === '' ? this._filterElm.classList.remove('filled') : this._filterElm.classList.add('filled');

// when changing compound operator, we don't want to trigger the filter callback unless the filter input is also provided
const skipCompoundOperatorFilterWithNullInput = this.columnFilter.skipCompoundOperatorFilterWithNullInput ?? this.gridOptions.skipCompoundOperatorFilterWithNullInput;
if (this.sliderType !== 'compound' || (!skipCompoundOperatorFilterWithNullInput || this._currentValue !== undefined)) {
const skipNullInput = this.columnFilter.skipCompoundOperatorFilterWithNullInput ?? this.gridOptions.skipCompoundOperatorFilterWithNullInput;
const hasSkipNullValChanged = (skipNullInput && isDefined(this._currentValue)) || (!isDefined(this._currentValue) && isDefined(this._lastSearchValue));

if (this.sliderType !== 'compound' || !skipNullInput || hasSkipNullValChanged) {
this.callback(e, { columnDef: this.columnDef, operator: selectedOperator || '', searchTerms: searchTerms! as SearchTerm[], shouldTriggerQuery: this._shouldTriggerQuery });
}
}
Expand All @@ -428,6 +431,7 @@ export class SliderFilter implements Filter {
// trigger mouse enter event on the filter for optionally hooked SlickCustomTooltip
// the minimum requirements for tooltip to work are the columnDef and targetElement
this.grid.onHeaderRowMouseEnter.notify({ column: this.columnDef, grid: this.grid }, new SlickEventData(e));
this._lastSearchValue = value;
}

protected changeBothSliderFocuses(isAddingFocus: boolean): void {
Expand Down
Loading