From 9f6683de2c67bf1db3af798c9146cbbfeb321c66 Mon Sep 17 00:00:00 2001 From: Johannes Schill Date: Thu, 25 Oct 2018 12:47:09 +0200 Subject: [PATCH] wip: Initial commit for PanelHeaderMenu --- .../features/dashboard/dashgrid/DataPanel.tsx | 1 - .../dashboard/dashgrid/PanelChrome.tsx | 2 +- .../dashboard/dashgrid/PanelHeader.tsx | 83 ------------- .../dashgrid/PanelHeader/PanelHeader.tsx | 50 ++++++++ .../dashgrid/PanelHeader/PanelHeaderMenu.tsx | 109 ++++++++++++++++++ .../PanelHeader/PanelHeaderMenuItem.tsx | 34 ++++++ public/sass/components/_dropdown.scss | 5 + public/sass/pages/_dashboard.scss | 1 - 8 files changed, 199 insertions(+), 86 deletions(-) delete mode 100644 public/app/features/dashboard/dashgrid/PanelHeader.tsx create mode 100644 public/app/features/dashboard/dashgrid/PanelHeader/PanelHeader.tsx create mode 100644 public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx create mode 100644 public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuItem.tsx diff --git a/public/app/features/dashboard/dashgrid/DataPanel.tsx b/public/app/features/dashboard/dashgrid/DataPanel.tsx index d0122363668..a42d392c018 100644 --- a/public/app/features/dashboard/dashgrid/DataPanel.tsx +++ b/public/app/features/dashboard/dashgrid/DataPanel.tsx @@ -38,7 +38,6 @@ export class DataPanel extends Component { constructor(props: Props) { super(props); - this.state = { loading: LoadingState.NotStarted, response: { diff --git a/public/app/features/dashboard/dashgrid/PanelChrome.tsx b/public/app/features/dashboard/dashgrid/PanelChrome.tsx index 953dfd62368..d4bfce67c48 100644 --- a/public/app/features/dashboard/dashgrid/PanelChrome.tsx +++ b/public/app/features/dashboard/dashgrid/PanelChrome.tsx @@ -5,7 +5,7 @@ import React, { ComponentClass, PureComponent } from 'react'; import { getTimeSrv } from '../time_srv'; // Components -import { PanelHeader } from './PanelHeader'; +import { PanelHeader } from './PanelHeader/PanelHeader'; import { DataPanel } from './DataPanel'; // Types diff --git a/public/app/features/dashboard/dashgrid/PanelHeader.tsx b/public/app/features/dashboard/dashgrid/PanelHeader.tsx deleted file mode 100644 index 12d5cd37253..00000000000 --- a/public/app/features/dashboard/dashgrid/PanelHeader.tsx +++ /dev/null @@ -1,83 +0,0 @@ -import React from 'react'; -import classNames from 'classnames'; -import { PanelModel } from '../panel_model'; -import { DashboardModel } from '../dashboard_model'; -import { store } from 'app/store/configureStore'; -import { updateLocation } from 'app/core/actions'; - -interface PanelHeaderProps { - panel: PanelModel; - dashboard: DashboardModel; -} - -export class PanelHeader extends React.Component { - onEditPanel = () => { - store.dispatch( - updateLocation({ - query: { - panelId: this.props.panel.id, - edit: true, - fullscreen: true, - }, - }) - ); - }; - - onViewPanel = () => { - store.dispatch( - updateLocation({ - query: { - panelId: this.props.panel.id, - edit: false, - fullscreen: true, - }, - }) - ); - }; - - render() { - const isFullscreen = false; - const isLoading = false; - const panelHeaderClass = classNames({ 'panel-header': true, 'grid-drag-handle': !isFullscreen }); - - return ( -
- - - - - - {isLoading && ( - - - - )} - -
- - - {this.props.panel.title} - - - - - - 4m - - -
-
- ); - } -} diff --git a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeader.tsx b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeader.tsx new file mode 100644 index 00000000000..a5e30d9396e --- /dev/null +++ b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeader.tsx @@ -0,0 +1,50 @@ +import React from 'react'; +import classNames from 'classnames'; +import { PanelModel } from 'app/features/dashboard/panel_model'; +import { DashboardModel } from 'app/features/dashboard/dashboard_model'; +// import { store } from 'app/store/configureStore'; +// import { updateLocation } from 'app/core/actions'; +import { PanelHeaderMenu } from './PanelHeaderMenu'; +// import appEvents from 'app/core/app_events'; + +interface PanelHeaderProps { + panel: PanelModel; + dashboard: DashboardModel; +} + +export class PanelHeader extends React.Component { + render() { + const isFullscreen = false; + const isLoading = false; + const panelHeaderClass = classNames({ 'panel-header': true, 'grid-drag-handle': !isFullscreen }); + + return ( +
+ + + + + + {isLoading && ( + + + + )} + +
+
+ + + {this.props.panel.title} + + + + + 4m + +
+
+
+ ); + } +} diff --git a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx new file mode 100644 index 00000000000..6bc6bb54509 --- /dev/null +++ b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenu.tsx @@ -0,0 +1,109 @@ +import React, { PureComponent } from 'react'; +// import { store } from 'app/store/configureStore'; +import { PanelHeaderMenuItem, PanelHeaderMenuItemTypes } from './PanelHeaderMenuItem'; +import appEvents from 'app/core/app_events'; +import { store } from 'app/store/configureStore'; +import { updateLocation } from 'app/core/actions'; + +export interface PanelHeaderMenuProps { + panelId: number; +} + +export class PanelHeaderMenu extends PureComponent { + onEditPanel = () => { + store.dispatch( + updateLocation({ + query: { + panelId: this.props.panelId, + edit: true, + fullscreen: true, + }, + }) + ); + }; + + onViewPanel = () => { + store.dispatch( + updateLocation({ + query: { + panelId: this.props.panelId, + edit: false, + fullscreen: true, + }, + }) + ); + }; + + onRemovePanel = () => { + appEvents.emit('panel-remove', { + panelId: this.props.panelId, + }); + }; + + render() { + return ( +
+
    + + + {}} + shortcut="p s" + /> + {}} + > +
      + {}} + shortcut="p d" + /> + + {}} /> + + {}} /> + + {}} /> + + {}} + shortcut="p l" + /> +
    +
    + + +
+
+ ); + } +} diff --git a/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuItem.tsx b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuItem.tsx new file mode 100644 index 00000000000..3eb4e72ca9d --- /dev/null +++ b/public/app/features/dashboard/dashgrid/PanelHeader/PanelHeaderMenuItem.tsx @@ -0,0 +1,34 @@ +import React, { SFC } from 'react'; + +export enum PanelHeaderMenuItemTypes { + Button = 'Button', // ? + Divider = 'Divider', + Link = 'Link', + SubMenu = 'SubMenu', +} + +export interface PanelHeaderMenuItemProps { + type: PanelHeaderMenuItemTypes; + text?: string; + iconClassName?: string; + handleClick?: () => void; + shortcut?: string; + children?: any; +} + +export const PanelHeaderMenuItem: SFC = props => { + const isSubMenu = props.type === PanelHeaderMenuItemTypes.SubMenu; + const isDivider = props.type === PanelHeaderMenuItemTypes.Divider; + return isDivider ? ( +
  • + ) : ( +
  • + + {props.iconClassName && } + {props.text} + {props.shortcut && {props.shortcut}} + + {props.children} +
  • + ); +}; diff --git a/public/sass/components/_dropdown.scss b/public/sass/components/_dropdown.scss index 37dbdcd89ef..9e7f46fe514 100644 --- a/public/sass/components/_dropdown.scss +++ b/public/sass/components/_dropdown.scss @@ -183,6 +183,11 @@ display: block; } + & > .dropdown > .dropdown-menu { + // Panel menu. TODO: See if we can merge this with above + display: block; + } + &.cascade-open { .dropdown-menu { display: block; diff --git a/public/sass/pages/_dashboard.scss b/public/sass/pages/_dashboard.scss index 795766a22de..125edac500f 100644 --- a/public/sass/pages/_dashboard.scss +++ b/public/sass/pages/_dashboard.scss @@ -138,7 +138,6 @@ div.flot-text { padding: 3px 5px; visibility: hidden; opacity: 0; - position: absolute; width: 16px; height: 16px; left: 1px;