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

feat(services): remove deprecated hideColumnByIndex form Grid Service #312

Merged
merged 1 commit into from
Apr 16, 2021
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
43 changes: 0 additions & 43 deletions packages/common/src/services/__tests__/grid.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand Down
32 changes: 0 additions & 32 deletions packages/common/src/services/grid.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,38 +214,6 @@ export class GridService {
return this.getDataItemByRowIndexes<T>(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<Column>(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
Expand Down