Custom Menu API
The Custom Menu API provides lifecycle methods, props, and SDK functions for building custom menus in Quick BI.
Lifecycle
A custom menu is a lifecycle object. For more information, see lifecycle.
LifecycleProps
The LifecycleProps interface defines the props parameter for each lifecycle method of a custom menu. It includes the customProps property. For details, see LifecycleProps.
interface LifecycleProps {
customProps?: MenuComponentProps;
}
Example
class MyComponent {
mount(props: LifecycleProps) {...}// props is of type LifecycleProps
update(props: LifecycleProps) {...}
unmount(props: LifecycleProps) {...}
}
const MyReactComponent: React.FC<LifecycleProps> = (props) => <div>...<div/> // props is of type LifecycleProps
The @quickbi/bi-open-Menu-sdk provides the createBIComponent function to create custom menus. It encapsulates LifecycleProps and passes them through React props as menuComponentProps.
menuComponentProps
menuComponentProps contains runtime information for a custom menu. Its interface is as follows:
/**
* Interface for custom menu props
*/
export interface MenuComponentProps {
/** Page information */
pageConfig: MenuPageConfig;
/** Actions */
dispatch?: MenuComponentPropsDispatch;
/** The custom menu display mode */
menuMode?: CustomMenuMode;
}
-
menuComponentProps.menuModeThe display mode of the custom menu. Valid values:
-
1-tile: The menu is displayed directly in the UI. -
2-collapse: The menu is collapsed into a "More" dropdown.
-
In Quick BI, all custom menus inherit MenuComponentProps.
menuComponentProps.pageConfig
Contains the configuration of the current page. Its interface is as follows:
interface MenuPageConfig {
/** The ID of the current workspace. */
workspaceId: string;
/** The ID of the current page. */
id: string;
/** The current device. */
device: 'pc' | 'mobile';
/** The ID of the current user. */
userId: string;
/** The account name of the current user. */
userName: string;
/** The nickname of the current user. */
nickName?: string;
/** The ID of the page owner. */
ownerUserId: string;
/** The username of the page owner. */
ownerUserName: string;
/** The page title. */
title: string;
/** The page route key. */
routeKey?: RouteKey;
}
-
workspaceId: The ID of the current workspace. -
id: The ID of the current page. -
mode: The mode of the current page.
-
preview: The view mode, for example, when viewing a dashboard. -
edit: The edit mode, for example, when editing a dashboard.
The following table lists examples for different pages.
|
Parameter |
Route key |
Example |
|
Dashboard edit page (host page) |
dashboardEdit |
|
|
Dashboard preview page (host page) |
dashboardView |
|
|
Spreadsheet edit page (host page) |
workbookEdit |
|
|
Custom menu management page |
customMenu |
|
menuComponentProps.dispatch
A function that dispatches actions to modify the properties or behavior of a custom menu.
(param: {
type: 'openModal' | 'closeModal'
payload: any
}) => void
Parameter
-
paramAn object that contains the action parameters.
param.typeaccepts one of the following values:-
openModalOpens a modal.
In this case, the
payloadis of typeMenuModalFuncProps. The interface forMenuModalFuncPropsis defined as follows:export interface MenuModalFuncProps { /** Width of the modal on PC. */ width?: string | number; /** Callback invoked when the Cancel button is clicked on PC or mobile devices. */ onCancel?: (...args: any[]) => any; /** Content to display in the modal. */ content?: React.ReactNode; /** Title of the modal. */ title?: string; /** Callback invoked when the OK button is clicked on PC. Returning a promise can delay the closing of the modal. */ onOk?: (...args: any[]) => any; /** Text for the OK button on PC. */ okText?: React.ReactNode; /** Text for the Cancel button on PC. */ cancelText?: React.ReactNode; /** Properties of the OK button on PC. */ okButtonProps?: { style?: React.CSSProperties; disabled?: boolean | undefined; }; /** Properties of the Cancel button on PC. */ cancelButtonProps?: { style?: React.CSSProperties; disabled?: boolean | undefined; }; } -
closeModalCloses the most recently opened modal.
In this case, no
payloadis required.
-
menuComponentProps.chart
The chart property is available only for menus within chart cards. It contains the data field configuration for the chart. Its interface is defined as follows:
export interface MenuComponentChartProps extends MenuComponentProps {
/** Chart information. */
chart: MenuChart;
}
The MenuChart interface is identical to the customProps of a custom component. For details, see customProps.
menuComponentProps.sheets
The sheets property is available only for spreadsheet menus. It provides the data field configuration for the spreadsheet. Its interface is as follows:
export interface MenuComponentExcelProps extends MenuComponentProps {
sheets: MenuSheet[];
}
MenuSheet represents spreadsheet data, which is structured as an array.
interface MenuSheet {
/** Sheet tab ID */
sheetId: string;
/** Sheet tab name */
sheetName: string;
/** Sheet tab order */
sheetOrder: number;
}
@quickbi/bi-open-menu-sdk API
createBIComponent
Creates a Quick BI custom menu and returns a Lifecycle object that represents the component.
(option: IOption) => Lifecycle
Parameter
-
option
A configuration object.
interface IBiComponent {
mount?: Interfaces.LifecycleMount<Interfaces.ComponentProps>;
umount?: Interfaces.LifecycleUnmount<Interfaces.ComponentProps>;
update?: Interfaces.LifecycleUpdate<Interfaces.ComponentProps>;
}
interface IBiComponentConstructor {
new (): IBiComponent;
}
interface IOption {
element: IBiComponentConstructor | React.ComponentType
}
-
elementThe element must be a React component of type
React.ComponentType.
Example
import { createBIComponent } from '@quickbi/bi-open-menu-sdk'
const MyComponent = (props) => <div>...</div>
const { bootstrap, mount, unmount, update } = createBIComponent({
element: MyComponent,
})
MenuItem
The @quickbi/bi-open-menu-sdk package provides a ready-to-use React component MenuItem.
Example
import { Interfaces, MenuItem, createBIComponent } from '@quickbi/bi-open-menu-sdk';
// Custom menu
const MyCardMenu: React.FC<Interfaces.MenuComponentChartProps> = React.memo(props => {
// Click handler
const handleClick = React.useCallback(() => {
console.log('click');
console.log('props', props);
props.dispatch({
type: 'openModal',
payload: {
title: 'My Title',
content: <iframe src="https://www.yuque.com/u2227425/ia1pn8/nvg5q6" width="100%"></iframe>,
onCancel: () => {
console.log('Close event');
},
onOk: () => {
console.log('OK event');
return new Promise((resolve, reject) => {
setTimeout(Math.random() > 0.5 ? resolve : reject, 1000);
}).catch(() => console.log('Oops errors!'));
},
cancelText: 'Cancel',
okText: 'Go',
cancelButtonProps: {
style: { display: 'none' },
},
okButtonProps: {
disabled: true,
},
},
});
}, [props]);
return (
<MenuItem
title="Custom Menu"
onClick={handleClick}
/>
);
});
// Export the custom menu
export const { bootstrap, mount, unmount, update } = createBIComponent<Interfaces.MenuComponentChartProps>({
element: MyCardMenu,
});
This component accepts the following props:
interface MenuItemProps {
/** The class name of the root element. */
className?: string;
/** The style of the root element. */
style?: React.StyleHTMLAttributes<HTMLDivElement>['style'];
/** The menu title. */
title?: string | React.ReactNode;
/** Specifies whether the menu is disabled. */
disabled?: boolean;
/** The tooltip text to display on hover. */
hoverTip?: string;
/** Specifies whether the menu is in a loading state. */
loading?: boolean;
/** The callback function for the click event. */
onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
}
MenuItem.title
The custom menu title.
Example
// ...
<MenuItem
title="Custom Menu"
/>

MenuItem.disabled
Specifies whether the custom menu is disabled.
Example
// ...
<MenuItem
title="Custom Menu"
disabled={true}
/>

MenuItem.loading
Specifies whether the custom menu is in a loading state.
Example
// ...
<MenuItem
title="Custom Menu"
loading={true}
/>

MenuItem.hoverTip
The tooltip text to display when hovering over the custom menu.
Example
// ...
<MenuItem
title="Custom Menu"
disabled={true}
hoverTip="This is the tooltip text"
/>

MenuItem.onClick
A callback function that is triggered when the custom menu is clicked.
Example
// ...
<MenuItem
title="Custom Menu"
onClick={() => {}}
/>
MenuItem.showTitle
Specifies whether to display the custom menu title.
Example
// ...
<MenuItem
showTitle={false}
/>
MenuItem.showIcon
Specifies whether to display the custom menu icon.
Example
// ...
<MenuItem
showIcon={false}
/>



