Skip to content

Commit

Permalink
fix(plugin): providing usability override via grid option should work
Browse files Browse the repository at this point in the history
- after merging the big controls/plugins PR #555 that rewrote all the plugins, I just found out this simple option got missed
  • Loading branch information
ghiscoding committed Nov 23, 2021
1 parent d15022b commit 6446a10
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'jest-extended';

import { Column, GridOption, OnDragEventArgs, SlickGrid, SlickNamespace, } from '../../interfaces/index';
import { Column, DragRowMove, GridOption, OnDragEventArgs, SlickGrid, SlickNamespace, } from '../../interfaces/index';
import { SlickRowMoveManager } from '../slickRowMoveManager';

declare const Slick: SlickNamespace;
Expand Down Expand Up @@ -196,7 +196,15 @@ describe('SlickRowMoveManager Plugin', () => {
});
});

it('should process the "checkboxSelectionFormatter" and expect necessary Formatter to return null when selectableOverride is returning False', () => {
it('should process the "checkboxSelectionFormatter" and expect necessary Formatter to return null when usabilityOverride is provided as plugin option and is returning False', () => {
plugin.init(gridStub, { usabilityOverride: () => false });
const output = plugin.getColumnDefinition().formatter(0, 0, null, { id: '_move', field: '' } as Column, { firstName: 'John', lastName: 'Doe', age: 33 }, gridStub);

expect(plugin).toBeTruthy();
expect(output).toEqual('');
});

it('should process the "checkboxSelectionFormatter" and expect necessary Formatter to return null when usabilityOverride is defined and returning False', () => {
plugin.usabilityOverride(() => false);
plugin.create(mockColumns, {});
const output = plugin.getColumnDefinition().formatter(0, 0, null, { id: '_move', field: '' } as Column, { firstName: 'John', lastName: 'Doe', age: 33 }, gridStub);
Expand Down Expand Up @@ -231,7 +239,7 @@ describe('SlickRowMoveManager Plugin', () => {
const stopImmediatePropagationSpy = jest.spyOn(mouseEvent, 'stopImmediatePropagation');
gridStub.onDragInit.notify({
count: 1, deltaX: 0, deltaY: 1, offsetX: 2, offsetY: 3, proxy: document.createElement('div'), guide: document.createElement('div'), row: 2, rows: [2],
} as unknown as OnDragEventArgs, mouseEvent);
} as unknown as DragRowMove, mouseEvent);

expect(stopImmediatePropagationSpy).toHaveBeenCalled();
});
Expand All @@ -250,7 +258,7 @@ describe('SlickRowMoveManager Plugin', () => {
guide: document.createElement('div'),
selectionProxy: document.createElement('div'),
clonedSlickRow: document.createElement('div'),
} as unknown as OnDragEventArgs;
} as unknown as DragRowMove;
gridStub.onDragEnd.notify(mockArgs, mouseEvent);

expect(stopImmediatePropagationSpy).not.toHaveBeenCalled();
Expand Down
6 changes: 6 additions & 0 deletions packages/common/src/extensions/slickRowMoveManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ export class SlickRowMoveManager {
this._addonOptions = { ...this._defaults, ...options };
this._grid = grid;
this._canvas = this._grid.getCanvasNode();

// user could override the expandable icon logic from within the options or after instantiating the plugin
if (this._addonOptions && typeof this._addonOptions.usabilityOverride === 'function') {
this.usabilityOverride(this._addonOptions.usabilityOverride);
}

this._eventHandler.subscribe(this._grid.onDragInit, this.handleDragInit.bind(this))
.subscribe(this._grid.onDragStart, this.handleDragStart.bind(this))
.subscribe(this._grid.onDrag, this.handleDrag.bind(this))
Expand Down

0 comments on commit 6446a10

Please sign in to comment.