From 3a622a4587ca47a3d34aa481bf417dfe83937ffc Mon Sep 17 00:00:00 2001 From: ghiscoding Date: Thu, 15 Apr 2021 23:17:45 -0400 Subject: [PATCH] feat(services): remove deprecated hideColumnByIndex form Grid Service --- .../services/__tests__/grid.service.spec.ts | 43 ------------------- packages/common/src/services/grid.service.ts | 32 -------------- 2 files changed, 75 deletions(-) diff --git a/packages/common/src/services/__tests__/grid.service.spec.ts b/packages/common/src/services/__tests__/grid.service.spec.ts index 1e2ead7d8..f48d30163 100644 --- a/packages/common/src/services/__tests__/grid.service.spec.ts +++ b/packages/common/src/services/__tests__/grid.service.spec.ts @@ -1291,49 +1291,6 @@ describe('Grid Service', () => { }); }); - describe('hideColumn method', () => { - it('should call hideColumnByIndex with the column index found', () => { - jest.spyOn(gridStub, 'getColumnIndex').mockReturnValue(2); - const hideColumnIdxSpy = jest.spyOn(service, 'hideColumnByIndex'); - - service.hideColumn({ id: 'field3', field: 'field3' }); - - expect(hideColumnIdxSpy).toHaveBeenCalledWith(2); - }); - }); - - describe('hideColumnByIndex method', () => { - it('should set new columns minus the column to hide and it should keep new set as the new "visibleColumns"', () => { - const mockColumns = [{ id: 'field1', width: 100 }, { id: 'field2', width: 150 }, { id: 'field3', field: 'field3' }] as Column[]; - const mockWithoutColumns = [{ id: 'field1', width: 100 }, { id: 'field3', field: 'field3' }] as Column[]; - jest.spyOn(gridStub, 'getColumns').mockReturnValue(mockColumns); - const setVisibleSpy = jest.spyOn(SharedService.prototype, 'visibleColumns', 'set'); - const setColsSpy = jest.spyOn(gridStub, 'setColumns'); - const pubSubSpy = jest.spyOn(pubSubServiceStub, 'publish'); - - service.hideColumnByIndex(1); - - expect(setVisibleSpy).toHaveBeenCalledWith(mockWithoutColumns); - expect(setColsSpy).toHaveBeenCalledWith(mockWithoutColumns); - expect(pubSubSpy).toHaveBeenCalledWith('onHeaderMenuHideColumns', { columns: mockWithoutColumns }); - }); - - it('should set new columns minus the column to hide but without triggering an event when set to False', () => { - const mockColumns = [{ id: 'field1', width: 100 }, { id: 'field2', width: 150 }, { id: 'field3', field: 'field3' }] as Column[]; - const mockWithoutColumns = [{ id: 'field1', width: 100 }, { id: 'field3', field: 'field3' }] as Column[]; - jest.spyOn(gridStub, 'getColumns').mockReturnValue(mockColumns); - const setVisibleSpy = jest.spyOn(SharedService.prototype, 'visibleColumns', 'set'); - const setColsSpy = jest.spyOn(gridStub, 'setColumns'); - const pubSubSpy = jest.spyOn(pubSubServiceStub, 'publish'); - - service.hideColumnByIndex(1, false); - - expect(setVisibleSpy).toHaveBeenCalledWith(mockWithoutColumns); - expect(setColsSpy).toHaveBeenCalledWith(mockWithoutColumns); - expect(pubSubSpy).not.toHaveBeenCalled(); - }); - }); - describe('hideColumnById method', () => { it('should return -1 when the column id is not found in the list of loaded column definitions', () => { const mockColumns = [{ id: 'field1', width: 100 }, { id: 'field2', width: 150 }, { id: 'field3', field: 'field3' }] as Column[]; diff --git a/packages/common/src/services/grid.service.ts b/packages/common/src/services/grid.service.ts index be7223931..4981278c4 100644 --- a/packages/common/src/services/grid.service.ts +++ b/packages/common/src/services/grid.service.ts @@ -214,38 +214,6 @@ export class GridService { return this.getDataItemByRowIndexes(selectedRowIndexes); } - /** - * @deprecated Hide a Column from the Grid (the column will just become hidden and will still show up in columnPicker/gridMenu) - * @see hideColumnById - * @param column - */ - hideColumn(column: Column) { - if (this._gridOptions && this._grid.getColumnIndex) { - const columnIndex = this._grid.getColumnIndex(column.id); - if (columnIndex >= 0) { - this.hideColumnByIndex(columnIndex); - } - } - } - - /** - * @deprecated Hide a Column from the Grid by its column definition index (the column will just become hidden and will still show up in columnPicker/gridMenu) - * @see hideColumnById Please use "hideColumnById(id)" or "hideColumnByIds([ids])" instead since it has a lot more options - * @param columnIndex - column definition index - * @param triggerEvent - do we want to trigger an event (onHeaderMenuHideColumns) when column becomes hidden? Defaults to true. - */ - hideColumnByIndex(columnIndex: number, triggerEvent = true) { - if (this._grid && this._grid.getColumns && this._grid.setColumns) { - const currentColumns = this._grid.getColumns(); - const visibleColumns = arrayRemoveItemByIndex(currentColumns, columnIndex); - this.sharedService.visibleColumns = visibleColumns; - this._grid.setColumns(visibleColumns); - if (triggerEvent) { - this.pubSubService.publish('onHeaderMenuHideColumns', { columns: visibleColumns }); - } - } - } - /** * Hide a Column from the Grid by its column definition id, the column will just become hidden and will still show up in columnPicker/gridMenu * @param {string | number} columnId - column definition id