Menu & MenuItems

All functions implementing Context Menu extensions return an array of MenuItems.

A menu is an array of MenuItems. Each Menu consists of multiple MenuItems, and each MenuItem can have sub-menus.

You must first import a MenuItem before you can use it:

import { MenuItem } from "@teamsql-extensions/ts-extension-sdk/dist/source/menu/MenuItem"

The MenuItem class has a constructor, and the constructor takes three parameters:

constructor(label: string, submenu: Array<MenuItem>, click: IMenuItemAction);

The MenuItem Class: Constructor Parameters

label: Title of the menu item.

submenu: Nested menus under a MenuItem

click: Callback function; when the user clicks on a MenuItem, TeamSQL calls this function. The function implements IMenuItemAction:

-(selectedData: DataGridCellContainer[], allData: DataGridCellContainer[]): void

Usage

Let's create a sample MenuItem:

...

let menuItem = new MenuItem("Open URL", null, (selectedData: DataGridCellContainer[], allData: DataGridCellContainer[]) => {
    if(selectedData !== null && selectedData !== undefined && Array.isArray(selectedData) && selectedData.length === 1 && selectedData[0].cells.length === 1) {
        var selectedCell = selectedData[0].cells[0];
        var result = urlValid.isUri(selectedCell.value);
        if(result) {
            this.openURL(selectedCell.value);
        }
        else {
            this.showAlert("Selected value is not a URI.");
        }

    }
    else {
        this.showAlert("Select only one cell to use this extension.");
    }

});

...

As you see, click returns two parameters: selectedData and allData, which are DataGridCellContainer.

We can also create a more complex Menu:

getMenu(): Array<MenuItem> {
        let me = this;

        // Let's create an empty MenuItem array
        let menu = new Array<MenuItem>();

        let menuItem1 = new MenuItem("Lookup Email", null, (selectedData: DataGridCellContainer[], allData: DataGridCellContainer[]) => {
            me.actionOpenLookup(selectedData, "email");
        });

        let menuItem2 = new MenuItem("Lookup UserID", null, (selectedData: DataGridCellContainer[], allData: DataGridCellContainer[]) => {
            me.actionOpenLookup(selectedData, "userid");
        });

        let menuItem3 = new MenuItem("Lookup ID", null, (selectedData: DataGridCellContainer[], allData: DataGridCellContainer[]) => {
            me.actionOpenLookup(selectedData, "id");
        });

        let menuItem4 = new MenuItem("Set Intercom Access Token", null, (selectedData: DataGridCellContainer[], allData: DataGridCellContainer[]) => {
            me.actionOpenConfigurationWindow();
        });


        let parentMenu = new MenuItem("Intercom Lookup", [menuItem1, menuItem2, menuItem3, menuItem4], null);
        menu.push(parentMenu);
        return menu;
}

results matching ""

    No results matching ""