Skip to content

Commit

Permalink
fix(filters): skipCompoundOperatorFilterWithNullInput skip undefined (#…
Browse files Browse the repository at this point in the history
…1568)

- review Compound Date & Compound Slider Filters to be more aligned with Compound Input Text Filter after PR #1566
  • Loading branch information
ghiscoding committed Jun 11, 2024
1 parent 0697a07 commit 711b03e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
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

0 comments on commit 711b03e

Please sign in to comment.