Skip to content

Commit

Permalink
fix(tree): reset to initial tree sort when calling "Clear all Sorting"
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Nov 3, 2021
1 parent 98d4425 commit 8bd3f4f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/common/src/controls/__tests__/slickGridMenu.spec.ts
Expand Up @@ -1092,6 +1092,7 @@ describe('GridMenuControl', () => {
it('should call "clearFrozenColumns" when the command triggered is "clear-pinning"', () => {
const setOptionsSpy = jest.spyOn(gridStub, 'setOptions');
const setColumnsSpy = jest.spyOn(gridStub, 'setColumns');
const pubSubSpy = jest.spyOn(pubSubServiceStub, 'publish');
const copyGridOptionsMock = { ...gridOptionsMock, gridMenu: { commandLabels: gridOptionsMock.gridMenu.commandLabels, hideClearFrozenColumnsCommand: false, } } as unknown as GridOption;
jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(copyGridOptionsMock);
jest.spyOn(gridStub, 'getOptions').mockReturnValue(copyGridOptionsMock);
Expand All @@ -1105,11 +1106,13 @@ describe('GridMenuControl', () => {

expect(setColumnsSpy).toHaveBeenCalled();
expect(setOptionsSpy).toHaveBeenCalledWith({ frozenColumn: -1, frozenRow: -1, frozenBottom: false, enableMouseWheelScrollHandler: false });
expect(pubSubSpy).toHaveBeenCalledWith('onGridMenuClearAllPinning');
});

it('should call "clearFilters" and dataview refresh when the command triggered is "clear-filter"', () => {
const filterSpy = jest.spyOn(filterServiceStub, 'clearFilters');
const refreshSpy = jest.spyOn(SharedService.prototype.dataView, 'refresh');
const pubSubSpy = jest.spyOn(pubSubServiceStub, 'publish');
const copyGridOptionsMock = { ...gridOptionsMock, enableFiltering: true, showHeaderRow: true, } as unknown as GridOption;
jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(copyGridOptionsMock);
jest.spyOn(gridStub, 'getOptions').mockReturnValue(copyGridOptionsMock);
Expand All @@ -1123,11 +1126,13 @@ describe('GridMenuControl', () => {

expect(filterSpy).toHaveBeenCalled();
expect(refreshSpy).toHaveBeenCalled();
expect(pubSubSpy).toHaveBeenCalledWith('onGridMenuClearAllFilters');
});

it('should call "clearSorting" and dataview refresh when the command triggered is "clear-sorting"', () => {
const sortSpy = jest.spyOn(sortServiceStub, 'clearSorting');
const refreshSpy = jest.spyOn(SharedService.prototype.dataView, 'refresh');
const pubSubSpy = jest.spyOn(pubSubServiceStub, 'publish');
const copyGridOptionsMock = { ...gridOptionsMock, enableSorting: true, } as unknown as GridOption;
jest.spyOn(SharedService.prototype, 'gridOptions', 'get').mockReturnValue(copyGridOptionsMock);
jest.spyOn(gridStub, 'getOptions').mockReturnValue(copyGridOptionsMock);
Expand All @@ -1141,6 +1146,7 @@ describe('GridMenuControl', () => {

expect(sortSpy).toHaveBeenCalled();
expect(refreshSpy).toHaveBeenCalled();
expect(pubSubSpy).toHaveBeenCalledWith('onGridMenuClearAllSorting');
});

it('should call "exportToExcel" and expect an error thrown when ExcelExportService is not registered prior to calling the method', () => {
Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/controls/slickGridMenu.ts
Expand Up @@ -689,14 +689,17 @@ export class SlickGridMenu extends MenuBaseClass<GridMenu> {
if (gridOptions.enableAutoSizeColumns) {
this.grid.autosizeColumns();
}
this.pubSubService.publish('onGridMenuClearAllPinning');
break;
case 'clear-filter':
this.filterService.clearFilters();
this.sharedService.dataView.refresh();
this.pubSubService.publish('onGridMenuClearAllFilters');
break;
case 'clear-sorting':
this.sortService.clearSorting();
this.sharedService.dataView.refresh();
this.pubSubService.publish('onGridMenuClearAllSorting');
break;
case 'export-csv':
const exportCsvService: TextExportService = registeredResources.find((service: any) => service.className === 'TextExportService');
Expand Down

0 comments on commit 8bd3f4f

Please sign in to comment.