Skip to content

Commit

Permalink
feat(filters): add "target" prop to onBeforeSearchChange (#796)
Browse files Browse the repository at this point in the history
- add event target to the `onBeforeSearchChange` event so that we know if the filter was changed from the filter input or from the operator select dropdown
  • Loading branch information
ghiscoding committed Nov 5, 2022
1 parent 5fbd9c9 commit c4606fd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 6 additions & 3 deletions packages/common/src/services/__tests__/filter.service.spec.ts
Expand Up @@ -372,7 +372,8 @@ describe('FilterService', () => {
operator: 'EQ',
searchTerms: ['John'],
parsedSearchTerms: ['John'],
grid: gridStub
grid: gridStub,
target: null,
}, expect.anything());
expect(spyEmit).toHaveBeenCalledWith('local');
done();
Expand Down Expand Up @@ -402,7 +403,8 @@ describe('FilterService', () => {
operator: 'EQ',
searchTerms: ['John'],
parsedSearchTerms: ['John'],
grid: gridStub
grid: gridStub,
target: { value: 'John', },
}, expect.anything());
});

Expand Down Expand Up @@ -436,7 +438,8 @@ describe('FilterService', () => {
operator: 'EQ',
searchTerms: [''],
parsedSearchTerms: [''],
grid: gridStub
grid: gridStub,
target: null,
}, expect.anything());
expect(service.getCurrentLocalFilters()).toEqual([{ columnId: 'firstName', operator: 'EQ', searchTerms: [''] }]);
});
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/services/filter.service.ts
Expand Up @@ -50,6 +50,7 @@ interface OnSearchChangeEventArgs {
parsedSearchTerms?: SearchTerm | SearchTerm[] | undefined;
searchTerms: SearchTerm[] | undefined;
grid: SlickGrid;
target?: HTMLElement;
}

export class FilterService {
Expand Down Expand Up @@ -1160,7 +1161,8 @@ export class FilterService {
operator: operator || mapOperatorByFieldType(fieldType),
searchTerms,
parsedSearchTerms,
grid: this._grid
grid: this._grid,
target: event?.target
} as OnSearchChangeEventArgs;

const onBeforeDispatchResult = this.pubSubService.publish('onBeforeSearchChange', eventArgs);
Expand Down

0 comments on commit c4606fd

Please sign in to comment.