@adaptabletools/adaptable
Version:
Powerful AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements
138 lines (137 loc) • 5.19 kB
TypeScript
import { MenuSeparator } from '@infinite-table/infinite-react';
import { AdaptableContextMenuItemName, AdaptableMenuItem, AgGridMenuItem, ContextMenuContext } from '../AdaptableState/Common/Menu';
import { AdaptableIcon } from '../types';
import { MenuItemFrameworkComponent } from '../agGrid/AdaptableFrameworkComponent';
/**
* Options for managing menus in AdapTable – provided using 2 collections
*/
export interface ContextMenuOptions<TData = any> {
/**
* Customises Context Menu (default context menu items are available in provided context)
*/
customContextMenu?: (menuContext: CustomContextMenuContext<TData>) => CustomContextMenuItem[];
}
/**
* Context info provided when building Custom Context Menus
*/
export interface CustomContextMenuContext<TData = any> extends ContextMenuContext<TData> {
/**
* Flat list of all available AdapTable Menu Items
*/
defaultAdaptableMenuItems: AdaptableSystemContextMenuItem<AdaptableContextMenuItemName>[];
/**
* Flat list of all available AG Grid Menu Items
*/
defaultAgGridMenuItems: AgGridMenuItem<AgGridContextMenuItemType>[];
/**
* Default structure of Adaptable Menu Items
*/
defaultAdaptableMenuStructure: DefaultAdaptableMenuStructure;
/**
* Default structure of AG Grid Menu Items
*/
defaultAgGridMenuStructure: DefaultAgGridMenuStructure;
}
/**
* Custom Context Menu Item
*/
export type CustomContextMenuItem = AgGridMenuItem<AgGridContextMenuItemType> | AdaptableSystemContextMenuItem<AdaptableContextMenuItemName> | UserContextMenuItem | MenuSeparator | CustomGroupContextMenuItem;
/**
* Defines a Grouped Menu Item in the Context Menu
*/
export type CustomGroupContextMenuItem = {
menuType: 'Group';
label: string;
subMenuItems: CustomContextMenuItem[];
disabled?: boolean;
icon?: AdaptableIcon;
};
/**
* System Menu Item that is provided by AdapTable
*/
export interface AdaptableSystemContextMenuItem<MENU_TYPE_NAME extends AdaptableContextMenuItemName> extends AdaptableMenuItem<MENU_TYPE_NAME> {
/**
* Type of Menu - always 'Adaptable'
*/
menuType: 'Adaptable';
}
/**
* Context Menu Item that is provided by User
*/
export interface UserContextMenuItem {
/**
* Type of Menu - always 'User'
*/
menuType: 'User';
/**
* Text to appear in the Menu Item
*/
label: string;
/**
* Function invoked when the Menu Item is clicked
*/
onClick?: (menuContext: ContextMenuContext) => void;
/**
* Whether menu item is disabled
*/
disabled?: boolean;
/**
* Whether menu item is hidden
*/
hidden?: boolean;
/**
* Optional icon to display
*/
icon?: AdaptableIcon;
/**
* Array of Menu Items, enabling limitless levels of menus
*/
subMenuItems?: CustomContextMenuItem[];
/**
* Optional Framework Component (React, Angular or Vue) used to render the
* content of this menu item.
*
* When supplied, AG Grid renders the component inside the menu row using
* its own framework adapter. The component receives AG Grid's
* `CustomMenuItemProps`, with the AdapTable-specific extras
* (`adaptableApi`, `menuContext`, plus anything passed via
* `menuItemParams`) available as `props.menuItemParams`.
*
* Supported in the React, Vue and Angular variants of AdapTable.
*
* For Vue, supply a factory that returns the Vue Component (NOT a render
* call), e.g. `({ adaptableApi }) => MyMenuItem`. AG Grid Vue then
* instantiates the component using its own framework adapter and passes
* `name`, `icon`, `menuItemParams`, ... as props.
*
* For Angular, supply `{ type: MyMenuItemComponent }` where the component
* implements `IMenuItemAngularComp` (with `agInit(params)` to receive
* `params.menuItemParams.adaptableApi` and `params.menuItemParams.menuContext`).
* The `onSetup` callback on `AngularFrameworkComponent` is NOT honoured
* for menu items because AG Grid owns the component lifecycle.
*/
frameworkComponent?: MenuItemFrameworkComponent<ContextMenuContext>;
/**
* Extra parameters passed through to the Framework Component (alongside
* `adaptableApi` and `menuContext`).
*/
menuItemParams?: Record<string, unknown>;
}
/**
* Defines AG Grid Context Menu Items
*/
export type AgGridContextMenuItemType = 'autoSizeAll' | 'expandAll' | 'contractAll' | 'copy' | 'copyWithHeaders' | 'copyWithGroupHeaders' | 'cut' | 'paste' | 'resetColumns' | 'export' | 'csvExport' | 'excelExport' | 'chartRange' | 'pivotChart' | 'separator';
/**
* The Context Menu provided by AadapTable by default
*/
export type DefaultAdaptableMenuStructure = (AdaptableSystemContextMenuItem<AdaptableContextMenuItemName> | MenuSeparator)[];
/**
* AG Grid section of Context Menu provided by AadapTable by default
*/
export type DefaultAgGridMenuStructure = (AgGridMenuItem<AgGridContextMenuItemType> | {
menuType: 'Group';
label: string;
subMenuItems: AgGridMenuItem<AgGridContextMenuItemType>[];
disabled?: boolean;
icon?: AdaptableIcon;
})[];