From 772ab7812ff52385ff3f06a44dc8f1537334d563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Mon, 16 Oct 2017 09:55:55 +0200 Subject: [PATCH] ux: worked on add panel function --- .../dashboard/dashgrid/AddPanelPanel.tsx | 72 ++++++++++ .../dashboard/dashgrid/DashboardGrid.tsx | 1 + .../dashboard/dashgrid/DashboardPanel.tsx | 18 ++- .../dashboard/dashgrid/DashboardRow.tsx | 2 +- .../features/dashboard/dashnav/dashnav.html | 53 ++++---- .../app/features/dashboard/dashnav/dashnav.ts | 4 +- public/app/features/dashboard/panel_model.ts | 1 + public/sass/_grafana.scss | 1 + public/sass/components/_panel_add_panel.scss | 41 ++++++ public/sass/components/_row.scss | 124 ------------------ public/sass/components/_sidemenu.scss | 2 +- public/sass/pages/_dashboard.scss | 2 + 12 files changed, 164 insertions(+), 157 deletions(-) create mode 100644 public/app/features/dashboard/dashgrid/AddPanelPanel.tsx create mode 100644 public/sass/components/_panel_add_panel.scss diff --git a/public/app/features/dashboard/dashgrid/AddPanelPanel.tsx b/public/app/features/dashboard/dashgrid/AddPanelPanel.tsx new file mode 100644 index 00000000000..9b1d941567e --- /dev/null +++ b/public/app/features/dashboard/dashgrid/AddPanelPanel.tsx @@ -0,0 +1,72 @@ +import React from 'react'; +import config from 'app/core/config'; +import {PanelModel} from '../panel_model'; +import {PanelContainer} from './PanelContainer'; +import _ from 'lodash'; + +export interface AddPanelPanelProps { + panel: PanelModel; + getPanelContainer: () => PanelContainer; +} + +export interface AddPanelPanelState { + filter: string; + panelPlugins: any[]; +} + +export class AddPanelPanel extends React.Component { + constructor(props) { + super(props); + + this.state = { + panelPlugins: this.getPanelPlugins(), + filter: '', + }; + + this.onPanelSelected = this.onPanelSelected.bind(this); + } + + getPanelPlugins() { + return _.chain(config.panels) + .filter({hideFromList: false}) + .map(item => item) + .orderBy('sort') + .value(); + } + + onPanelSelected(panelPluginInfo) { + const panelContainer = this.props.getPanelContainer(); + const dashboard = panelContainer.getDashboard(); + + // remove add-panel panel + dashboard.removePanel(this.props.panel); + + dashboard.addPanel({ + type: panelPluginInfo.id, + title: 'Panel Title', + gridPos: { + x: this.props.panel.gridPos.x, + y: this.props.panel.gridPos.y, + w: this.props.panel.gridPos.w, + h: this.props.panel.gridPos.h + } + }); + } + + renderPanelItem(panel) { + return ( +
this.onPanelSelected(panel)} title={panel.name}> + +
{panel.name}
+
+ ); + } + + render() { + return ( +
+
{this.state.panelPlugins.map(this.renderPanelItem.bind(this))}
+
+ ); + } +} diff --git a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx index 725f66e9798..2359dc1e3a1 100644 --- a/public/app/features/dashboard/dashgrid/DashboardGrid.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardGrid.tsx @@ -91,6 +91,7 @@ export class DashboardGrid extends React.Component { y: panel.gridPos.y, w: panel.gridPos.w, h: panel.gridPos.h, + static: panel.gridPos.static, }); } diff --git a/public/app/features/dashboard/dashgrid/DashboardPanel.tsx b/public/app/features/dashboard/dashgrid/DashboardPanel.tsx index 11f06113617..c72824aa0de 100644 --- a/public/app/features/dashboard/dashgrid/DashboardPanel.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardPanel.tsx @@ -2,6 +2,8 @@ import React from 'react'; import {PanelModel} from '../panel_model'; import {PanelContainer} from './PanelContainer'; import {AttachedPanel} from './PanelLoader'; +import {DashboardRow} from './DashboardRow'; +import {AddPanelPanel} from './AddPanelPanel'; export interface DashboardPanelProps { panel: PanelModel; @@ -18,10 +20,13 @@ export class DashboardPanel extends React.Component { } componentDidMount() { + if (!this.element) { + return; + } + const panelContainer = this.props.getPanelContainer(); const dashboard = panelContainer.getDashboard(); const loader = panelContainer.getPanelLoader(); - this.attachedPanel = loader.load(this.element, this.props.panel, dashboard); } @@ -31,9 +36,16 @@ export class DashboardPanel extends React.Component { } } - - render() { + // special handling for rows + if (this.props.panel.type === 'row') { + return ; + } + + if (this.props.panel.type === 'add-panel') { + return ; + } + return (
this.element = element} /> ); diff --git a/public/app/features/dashboard/dashgrid/DashboardRow.tsx b/public/app/features/dashboard/dashgrid/DashboardRow.tsx index 8b6aaf45722..d5723ccfe07 100644 --- a/public/app/features/dashboard/dashgrid/DashboardRow.tsx +++ b/public/app/features/dashboard/dashgrid/DashboardRow.tsx @@ -5,7 +5,7 @@ export interface DashboardRowProps { panel: PanelModel; } -export class DashboardPanel extends React.Component { +export class DashboardRow extends React.Component { constructor(props) { super(props); diff --git a/public/app/features/dashboard/dashnav/dashnav.html b/public/app/features/dashboard/dashnav/dashnav.html index dc538fb5500..889c34d436d 100644 --- a/public/app/features/dashboard/dashnav/dashnav.html +++ b/public/app/features/dashboard/dashnav/dashnav.html @@ -22,32 +22,33 @@