Skip to content

Commit

Permalink
feat(plugins): move external Header Button into Slickgrid-Universal
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Aug 25, 2021
1 parent 18d74ba commit 69711ad
Show file tree
Hide file tree
Showing 16 changed files with 603 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ describe('GridMenuControl', () => {
expect(buttonImageElm.src).toBe('/images/some-gridmenu-image.png');
expect(helpTextElm.textContent).toBe('Help');
expect(helpIconElm.style.backgroundImage).toBe('url(/images/some-image.png)')
expect(consoleWarnSpy).toHaveBeenCalledWith('[Slickgrid-Universal] The "iconImage" property of a Grid Menu item is no deprecated and will be removed in future version, consider using "iconCssClass" instead.');
expect(consoleWarnSpy).toHaveBeenCalledWith('[Slickgrid-Universal] The "iconImage" property of a Grid Menu item is now deprecated and will be removed in future version, consider using "iconCssClass" instead.');
});

it('should add a custom Grid Menu item with "tooltip" and expect the item title attribute to be part of the item DOM element', () => {
Expand Down
10 changes: 5 additions & 5 deletions packages/common/src/controls/gridMenu.control.ts
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,8 @@ export class GridMenuControl {
let isItemVisible = true;
let isItemUsable = true;
if (typeof item === 'object') {
isItemVisible = this.runOverrideFunctionWhenExists(item.itemVisibilityOverride, callbackArgs);
isItemUsable = this.runOverrideFunctionWhenExists(item.itemUsabilityOverride, callbackArgs);
isItemVisible = this.runOverrideFunctionWhenExists<typeof callbackArgs>(item.itemVisibilityOverride, callbackArgs);
isItemUsable = this.runOverrideFunctionWhenExists<typeof callbackArgs>(item.itemUsabilityOverride, callbackArgs);
}

// if the result is not visible then there's no need to go further
Expand Down Expand Up @@ -440,7 +440,7 @@ export class GridMenuControl {
}

if (item.iconImage) {
console.warn('[Slickgrid-Universal] The "iconImage" property of a Grid Menu item is no deprecated and will be removed in future version, consider using "iconCssClass" instead.');
console.warn('[Slickgrid-Universal] The "iconImage" property of a Grid Menu item is now deprecated and will be removed in future version, consider using "iconCssClass" instead.');
iconElm.style.backgroundImage = `url(${item.iconImage})`;
}

Expand Down Expand Up @@ -521,7 +521,7 @@ export class GridMenuControl {
} as GridMenuEventWithElementCallbackArgs;

// run the override function (when defined), if the result is false then we won't go further
if (controlOptions && !this.runOverrideFunctionWhenExists(controlOptions.menuUsabilityOverride, callbackArgs)) {
if (controlOptions && !this.runOverrideFunctionWhenExists<typeof callbackArgs>(controlOptions.menuUsabilityOverride, callbackArgs)) {
return;
}

Expand Down Expand Up @@ -874,7 +874,7 @@ export class GridMenuControl {
}

/** Run the Override function when it exists, if it returns True then it is usable/visible */
protected runOverrideFunctionWhenExists(overrideFn: any, args: any): boolean {
protected runOverrideFunctionWhenExists<T = any>(overrideFn: any, args: T): boolean {
if (typeof overrideFn === 'function') {
return overrideFn.call(this, args);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ const mockAddon = jest.fn().mockImplementation(() => ({
}));

jest.mock('slickgrid/slick.groupitemmetadataprovider', () => mockAddon);
jest.mock('slickgrid/controls/slick.gridmenu', () => mockAddon);
jest.mock('slickgrid/plugins/slick.cellmenu', () => mockAddon);
jest.mock('slickgrid/plugins/slick.cellexternalcopymanager', () => mockAddon);
jest.mock('slickgrid/plugins/slick.contextmenu', () => mockAddon);
jest.mock('slickgrid/plugins/slick.draggablegrouping', () => mockAddon);
jest.mock('slickgrid/plugins/slick.headerbuttons', () => mockAddon);
jest.mock('slickgrid/plugins/slick.headermenu', () => mockAddon);
jest.mock('slickgrid/plugins/slick.rowselectionmodel', () => mockAddon);
jest.mock('slickgrid/plugins/slick.rowdetailview', () => mockAddon);
Expand Down
105 changes: 0 additions & 105 deletions packages/common/src/extensions/__tests__/headerButtonExtension.spec.ts

This file was deleted.

68 changes: 0 additions & 68 deletions packages/common/src/extensions/headerButtonExtension.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/common/src/extensions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ export * from './contextMenuExtension';
export * from './draggableGroupingExtension';
export * from './extensionUtility';
export * from './groupItemMetaProviderExtension';
export * from './headerButtonExtension';
export * from './headerMenuExtension';
export * from './rowDetailViewExtension';
export * from './rowMoveManagerExtension';
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/interfaces/column.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ export interface Column<T = any> {
/** Options that can be provided to the Header Menu Plugin */
header?: {
/** list of Buttons to show in the header */
buttons?: Array<HeaderButtonItem | 'divider'>;
menu?: { items: Array<MenuCommandItem | 'divider'> };
buttons?: Array<HeaderButtonItem>;
menu?: { items: Array<MenuCommandItem> };
};

/** CSS class that can be added to the column header */
Expand Down
4 changes: 2 additions & 2 deletions packages/common/src/interfaces/headerButton.interface.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { HeaderButtonPlugin } from '../plugins';
import { HeaderButtonOnCommandArgs } from './headerButtonOnCommandArgs.interface';
import { SlickEventData } from './slickEventData.interface';
import { SlickHeaderButtons } from './slickHeaderButtons.interface';

export interface HeaderButton extends HeaderButtonOption {
// --
// Events
// ------------

/** Fired after extension (plugin) is registered by SlickGrid */
onExtensionRegistered?: (plugin: SlickHeaderButtons) => void;
onExtensionRegistered?: (plugin: HeaderButtonPlugin) => void;

/** Fired when a command is clicked */
onCommand?: (e: SlickEventData, args: HeaderButtonOnCommandArgs) => void;
Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/interfaces/headerButtonItem.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ export interface HeaderButtonItem {
/** CSS class to add to the button. */
cssClass?: string;

/** Defaults to false, whether the item/command is disabled. */
disabled?: boolean;

/** Button click handler. */
handler?: (e: Event) => void;

Expand Down
Loading

0 comments on commit 69711ad

Please sign in to comment.