Skip to content

Commit

Permalink
fix(filter): updateFilters w/BackendService should call query only once
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding-SE committed Nov 26, 2019
1 parent 6233ea6 commit 8228799
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ export const decimalFormatter: Formatter = (row: number, cell: number, value: an
// @deprecated: decimalPlaces, minDecimalPlaces, maxDecimalPlaces
// add these extra checks to support previous way of passing the decimal count
if ((params.minDecimalPlaces !== null && params.minDecimalPlaces) || (params.decimalPlaces !== null && params.decimalPlaces)) {
console.warn('[Angular-Slickgrid] please consider using "minDecimal" (instead of "minDecimalPlaces" or "decimalPlaces").');
minDecimal = (params.minDecimalPlaces !== null && params.minDecimalPlaces) || (params.decimalPlaces !== null && params.decimalPlaces);
}
if (params.maxDecimalPlaces !== null && params.maxDecimalPlaces) {
console.warn('[Angular-Slickgrid] please consider using "maxDecimalPlaces" (instead of "maxDecimalPlacesPlaces").');
maxDecimal = (params.maxDecimalPlaces !== null && params.maxDecimalPlaces);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export interface BackendService {
// -----------------

/** Execute when any of the filters changed */
// @deprecated return output should be string only not Promise
// @deprecated return string output only in the future and remove Promise type
processOnFilterChanged: (event: Event, args: FilterChangedArgs) => string | Promise<string>;

/** Execute when the pagination changed */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,7 @@ describe('FilterService', () => {
const clearSpy = jest.spyOn(service, 'clearFilters');
const emitSpy = jest.spyOn(service, 'emitFilterChanged');
const backendUpdateSpy = jest.spyOn(backendServiceStub, 'updateFilters');
const backendProcessSpy = jest.spyOn(backendServiceStub, 'processOnFilterChanged');

service.init(gridStub);
service.bindBackendOnFilter(gridStub, dataViewStub);
Expand All @@ -1000,6 +1001,7 @@ describe('FilterService', () => {
service.updateFilters(mockNewFilters);

expect(emitSpy).toHaveBeenCalledWith('remote');
expect(backendProcessSpy).not.toHaveBeenCalled();
expect(backendUpdateSpy).toHaveBeenCalledWith(mockNewFilters, true);
expect(service.getColumnFilters()).toEqual({
firstName: { columnId: 'firstName', columnDef: mockColumn1, searchTerms: ['Jane'], operator: 'StartsWith' },
Expand All @@ -1018,6 +1020,7 @@ describe('FilterService', () => {
const clearSpy = jest.spyOn(service, 'clearFilters');
const emitSpy = jest.spyOn(service, 'emitFilterChanged');
const backendUpdateSpy = jest.spyOn(backendServiceStub, 'updateFilters');
const backendProcessSpy = jest.spyOn(backendServiceStub, 'processOnFilterChanged');

service.init(gridStub);
service.bindBackendOnFilter(gridStub, dataViewStub);
Expand All @@ -1026,6 +1029,7 @@ describe('FilterService', () => {
service.updateFilters(mockNewFilters, false, false);

expect(emitSpy).not.toHaveBeenCalled();
expect(backendProcessSpy).not.toHaveBeenCalled();
expect(mockRefreshBackendDataset).not.toHaveBeenCalled();
expect(backendUpdateSpy).toHaveBeenCalledWith(mockNewFilters, true);
expect(service.getColumnFilters()).toEqual({
Expand Down
8 changes: 5 additions & 3 deletions src/app/modules/angular-slickgrid/services/filter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,13 @@ export class FilterService {

// when using backend service, we need to query only once so it's better to do it here
const backendApi = this._gridOptions && this._gridOptions.backendServiceApi;
if (backendApi) {
const callbackArgs = { clearFilterTriggered: true, shouldTriggerQuery: true, grid: this._grid, columnFilters: this._columnFilters };
if (backendApi && triggerChange) {
const callbackArgs = { clearFilterTriggered: true, shouldTriggerQuery: triggerChange, grid: this._grid, columnFilters: this._columnFilters };
const queryResponse = backendApi.service.processOnFilterChanged(undefined, callbackArgs as FilterChangedArgs);
// @deprecated, processOnFilterChanged in the future should be return as a query string NOT a Promise
if (queryResponse instanceof Promise && queryResponse.then) {
// @deprecated, processOnFilterChanged in the future should be returned as a query string NOT as a Promise
console.warn(`[Angular-Slickgrid] please note that the "processOnFilterChanged" method signature, from Backend Service, should return a string instead of a Promise,
returning a Promise will be deprecated in the future.`);
queryResponse.then((query: string) => {
const totalItems = this._gridOptions && this._gridOptions.pagination && this._gridOptions.pagination.totalItems;
executeBackendCallback(backendApi, query, callbackArgs, new Date(), totalItems, this.emitFilterChanged.bind(this));
Expand Down
9 changes: 9 additions & 0 deletions src/app/modules/angular-slickgrid/services/grid.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,13 @@ export class GridService {

/** @deprecated please use "addItem" method instead */
addItemToDatagrid(item: any, shouldHighlightRow = true, shouldResortGrid = false, shouldTriggerEvent = true, shouldSelectRow = true): number {
console.warn('[Angular-Slickgrid - FilterService] please consider using the new "addItem" method since "addItemToDatagrid" will be deprecated in the future');
return this.addItem(item, { highlightRow: shouldHighlightRow, resortGrid: shouldResortGrid, triggerEvent: shouldTriggerEvent, selectRow: shouldSelectRow });
}

/** @deprecated please use "addItems" method instead */
addItemsToDatagrid(items: any[], shouldHighlightRow = true, shouldResortGrid = false, shouldTriggerEvent = true, shouldSelectRow = true): number[] {
console.warn('[Angular-Slickgrid - FilterService] please consider using the new "addItems" method since "addItemsToDatagrid" will be deprecated in the future');
return this.addItems(items, { highlightRow: shouldHighlightRow, resortGrid: shouldResortGrid, triggerEvent: shouldTriggerEvent, selectRow: shouldSelectRow });
}

Expand Down Expand Up @@ -375,21 +377,25 @@ export class GridService {

/** @deprecated please use "deleteItem" method instead */
deleteDataGridItem(item: any, shouldTriggerEvent = true) {
console.warn('[Angular-Slickgrid - FilterService] please consider using the new "deleteItem" method since "deleteDataGridItem" will be deprecated in the future');
this.deleteItem(item, { triggerEvent: shouldTriggerEvent });
}

/** @deprecated please use "deleteItems" method instead */
deleteDataGridItems(items: any[], shouldTriggerEvent = true) {
console.warn('[Angular-Slickgrid - FilterService] please consider using the new "deleteItems" method since "deleteDataGridItems" will be deprecated in the future');
this.deleteItems(items, { triggerEvent: shouldTriggerEvent });
}

/** @deprecated please use "deleteItemById" method instead */
deleteDataGridItemById(itemId: string | number, shouldTriggerEvent = true) {
console.warn('[Angular-Slickgrid - FilterService] please consider using the new "deleteItemById" method since "deleteDataGridItemById" will be deprecated in the future');
this.deleteItemById(itemId, { triggerEvent: shouldTriggerEvent });
}

/** @deprecated please use "deleteItemByIds" method instead */
deleteDataGridItemByIds(itemIds: number[] | string[], shouldTriggerEvent = true) {
console.warn('[Angular-Slickgrid - FilterService] please consider using the new "deleteItemByIds" method since "deleteDataGridItemByIds" will be deprecated in the future');
this.deleteItemByIds(itemIds, { triggerEvent: shouldTriggerEvent });
}

Expand Down Expand Up @@ -492,16 +498,19 @@ export class GridService {

/** @deprecated please use "updateItem" method instead */
updateDataGridItem(item: any, shouldHighlightRow = true, shouldTriggerEvent = true, shouldSelectRow = true): number {
console.warn('[Angular-Slickgrid - FilterService] please consider using the new "updateItem" method since "updateDataGridItem" will be deprecated in the future');
return this.updateItem(item, { highlightRow: shouldHighlightRow, triggerEvent: shouldTriggerEvent, selectRow: shouldSelectRow });
}

/** @deprecated please use "updateItems" method instead */
updateDataGridItems(items: any | any[], shouldHighlightRow = true, shouldTriggerEvent = true, shouldSelectRow = true): number[] {
console.warn('[Angular-Slickgrid - FilterService] please consider using the new "updateItems" method since "updateDataGridItems" will be deprecated in the future');
return this.updateItems(items, { highlightRow: shouldHighlightRow, triggerEvent: shouldTriggerEvent, selectRow: shouldSelectRow });
}

/** @deprecated please use "updateItemById" method instead */
updateDataGridItemById(itemId: number | string, item: any, shouldHighlightRow = true, shouldTriggerEvent = true, shouldSelectRow = true): number {
console.warn('[Angular-Slickgrid - FilterService] please consider using the new "updateItemById" method since "updateDataGridItemById" will be deprecated in the future');
return this.updateItemById(itemId, item, { highlightRow: shouldHighlightRow, triggerEvent: shouldTriggerEvent, selectRow: shouldSelectRow });
}

Expand Down

0 comments on commit 8228799

Please sign in to comment.