diff --git a/public/app/features/dashboard/dashgrid/DashboardPanel.tsx b/public/app/features/dashboard/dashgrid/DashboardPanel.tsx index d75e3abc67f..9712cb75bd0 100644 --- a/public/app/features/dashboard/dashgrid/DashboardPanel.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardPanel.tsx @@ -122,7 +122,7 @@ export class DashboardPanel extends PureComponent {
; - withMenuOptions?: (c: typeof PanelHeaderMenu, p: PanelModel) => typeof PanelHeaderMenu; + // withMenuOptions?: (c: typeof PanelHeaderMenu, p: PanelModel) => typeof PanelHeaderMenu; moduleMenu?: any; } @@ -99,18 +99,15 @@ export class PanelChrome extends PureComponent - void; - shortcut?: string; - children?: any; - subMenu?: PanelHeaderMenuItemProps[]; - role?: string; -} +import { PanelHeaderMenuItemProps, PanelHeaderMenuItemTypes } from 'app/types/panel'; export const PanelHeaderMenuItem: SFC = props => { const isSubMenu = props.type === PanelHeaderMenuItemTypes.SubMenu; diff --git a/public/app/features/dashboard/utils/panel_menu.ts b/public/app/features/dashboard/utils/panel_menu.ts index 9d5fec4c6a4..7e0466407f3 100644 --- a/public/app/features/dashboard/utils/panel_menu.ts +++ b/public/app/features/dashboard/utils/panel_menu.ts @@ -1,4 +1,4 @@ -import { PanelHeaderMenuItemTypes, PanelHeaderMenuItemProps } from './../dashgrid/PanelHeader/PanelHeaderMenuItem'; +import { PanelHeaderMenuItemTypes, PanelHeaderMenuItemProps } from 'app/types/panel'; import { store } from 'app/store/configureStore'; import { updateLocation } from 'app/core/actions'; import { PanelModel } from 'app/features/dashboard/panel_model'; diff --git a/public/app/plugins/panel/graph2/module.tsx b/public/app/plugins/panel/graph2/module.tsx index c0a4fef8cfc..d1d607afa94 100644 --- a/public/app/plugins/panel/graph2/module.tsx +++ b/public/app/plugins/panel/graph2/module.tsx @@ -75,5 +75,4 @@ export class GraphOptions extends PureComponent> { } export { Graph2 as PanelComponent, GraphOptions as PanelOptionsComponent }; -export { withMenuOptions } from './withMenuOptions'; export { moduleMenu } from './moduleMenu'; diff --git a/public/app/plugins/panel/graph2/moduleMenu.tsx b/public/app/plugins/panel/graph2/moduleMenu.tsx index 64729e953a8..da08cbf5d9c 100644 --- a/public/app/plugins/panel/graph2/moduleMenu.tsx +++ b/public/app/plugins/panel/graph2/moduleMenu.tsx @@ -6,11 +6,7 @@ import { getTimeSrv } from 'app/features/dashboard/time_srv'; import { store } from 'app/store/configureStore'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import appEvents from 'app/core/app_events'; - -import { - PanelHeaderMenuItemProps, - PanelHeaderMenuItemTypes, -} from 'app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuItem'; +import { PanelHeaderMenuItemProps, PanelHeaderMenuItemTypes } from 'app/types/panel'; export const moduleMenu = (panel, dataSourceApi, timeSeries) => { const onExploreClick = async () => { @@ -70,7 +66,7 @@ export const moduleMenu = (panel, dataSourceApi, timeSeries) => { }; return { - getAdditionalMenuItems: getAdditionalMenuItems(), - getAdditionalSubMenuItems: getAdditionalSubMenuItems(), + additionalMenuItems: getAdditionalMenuItems(), + additionalSubMenuItems: getAdditionalSubMenuItems(), }; }; diff --git a/public/app/plugins/panel/graph2/withMenuOptions.tsx b/public/app/plugins/panel/graph2/withMenuOptions.tsx deleted file mode 100644 index aaa89bf3406..00000000000 --- a/public/app/plugins/panel/graph2/withMenuOptions.tsx +++ /dev/null @@ -1,94 +0,0 @@ -// Libraries -import React, { PureComponent } from 'react'; - -// Services -import { getTimeSrv } from 'app/features/dashboard/time_srv'; -import { contextSrv } from 'app/core/services/context_srv'; -import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; -import { store } from 'app/store/configureStore'; - -// Components -import { PanelHeaderMenu } from 'app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu'; -import config from 'app/core/config'; -import { getExploreUrl } from 'app/core/utils/explore'; -import { updateLocation } from 'app/core/actions'; - -// Types -import { PanelModel } from 'app/features/dashboard/panel_model'; -import { PanelHeaderMenuProps } from 'app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu'; -import { - PanelHeaderMenuItemProps, - PanelHeaderMenuItemTypes, -} from 'app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuItem'; - -interface LocalState { - datasource: any; -} - -export const withMenuOptions = (WrappedPanelHeaderMenu: typeof PanelHeaderMenu, panel: PanelModel) => { - return class extends PureComponent { - private datasourceSrv = getDatasourceSrv(); - private timeSrv = getTimeSrv(); - - constructor(props) { - super(props); - this.state = { - datasource: undefined, - }; - } - - componentDidMount() { - const dsPromise = getDatasourceSrv().get(panel.datasource); - dsPromise.then((datasource: any) => { - this.setState(() => ({ datasource })); - }); - } - - onExploreClick = async () => { - const { datasource } = this.state; - const url = await getExploreUrl(panel, panel.targets, datasource, this.datasourceSrv, this.timeSrv); - if (url) { - store.dispatch(updateLocation({ path: url })); - } - }; - - getAdditionalMenuItems = () => { - const { datasource } = this.state; - const items = []; - if ( - config.exploreEnabled && - contextSrv.isEditor && - datasource && - (datasource.meta.explore || datasource.meta.id === 'mixed') - ) { - items.push({ - type: PanelHeaderMenuItemTypes.Link, - text: 'Explore', - handleClick: this.onExploreClick, - iconClassName: 'fa fa-fw fa-rocket', - shortcut: 'x', - }); - } - return items; - }; - - getAdditionalSubMenuItems = () => { - return [ - { - type: PanelHeaderMenuItemTypes.Link, - text: 'Hello Sub Menu', - handleClick: () => { - alert('Hello world from HOC!'); - }, - shortcut: 's h w', - }, - ] as PanelHeaderMenuItemProps[]; - }; - - render() { - const menu: PanelHeaderMenuItemProps[] = this.getAdditionalMenuItems(); - const subMenu: PanelHeaderMenuItemProps[] = this.getAdditionalSubMenuItems(); - return ; - } - }; -}; diff --git a/public/app/types/panel.ts b/public/app/types/panel.ts index 7febd0cad26..8b12caffe1a 100644 --- a/public/app/types/panel.ts +++ b/public/app/types/panel.ts @@ -12,3 +12,26 @@ export interface PanelOptionsProps { options: T; onChange: (options: T) => void; } + +export enum PanelHeaderMenuItemTypes { // TODO: Evaluate. Remove? + Button = 'Button', // ? + Divider = 'Divider', + Link = 'Link', + SubMenu = 'SubMenu', +} + +export interface PanelHeaderMenuItemProps { + type: PanelHeaderMenuItemTypes; + text?: string; + iconClassName?: string; + handleClick?: () => void; + shortcut?: string; + children?: any; + subMenu?: PanelHeaderMenuItemProps[]; + role?: string; +} + +export interface PanelMenuExtras { + additionalMenuItems: PanelHeaderMenuItemProps[]; + additionalSubMenuItems: PanelHeaderMenuItemProps[]; +} diff --git a/public/app/types/plugins.ts b/public/app/types/plugins.ts index e87eef38c04..0f4b2928595 100644 --- a/public/app/types/plugins.ts +++ b/public/app/types/plugins.ts @@ -13,7 +13,6 @@ export interface PluginExports { PanelCtrl?; PanelComponent?: ComponentClass; PanelOptionsComponent: ComponentClass; - withMenuOptions?: any; moduleMenu?: any; }