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

fix(plugin): providing usability override via grid option should work #557

Merged
merged 1 commit into from
Nov 23, 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
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