grafana/public/app/features/dashboard/dashgrid/DashboardRow.tsx

104 lines
3.1 KiB
TypeScript
Raw Normal View History

2017-10-13 10:01:38 -05:00
import React from 'react';
2017-10-16 09:09:23 -05:00
import classNames from 'classnames';
import { PanelModel } from '../panel_model';
import { PanelContainer } from './PanelContainer';
import templateSrv from 'app/features/templating/template_srv';
2017-10-24 08:46:03 -05:00
import appEvents from 'app/core/app_events';
2017-10-13 10:01:38 -05:00
export interface DashboardRowProps {
panel: PanelModel;
2017-10-16 09:09:23 -05:00
getPanelContainer: () => PanelContainer;
2017-10-13 10:01:38 -05:00
}
2017-10-16 02:55:55 -05:00
export class DashboardRow extends React.Component<DashboardRowProps, any> {
dashboard: any;
panelContainer: any;
2017-10-13 10:01:38 -05:00
constructor(props) {
super(props);
2017-10-16 09:09:23 -05:00
this.state = {
2017-10-17 07:53:52 -05:00
collapsed: this.props.panel.collapsed,
2017-10-16 09:09:23 -05:00
};
this.panelContainer = this.props.getPanelContainer();
this.dashboard = this.panelContainer.getDashboard();
2017-10-13 10:01:38 -05:00
this.toggle = this.toggle.bind(this);
this.openSettings = this.openSettings.bind(this);
this.delete = this.delete.bind(this);
2017-10-13 10:01:38 -05:00
}
2017-10-16 09:09:23 -05:00
toggle() {
this.dashboard.toggleRow(this.props.panel);
2017-10-16 09:09:23 -05:00
this.setState(prevState => {
return { collapsed: !prevState.collapsed };
2017-10-16 09:09:23 -05:00
});
}
2017-10-13 10:01:38 -05:00
2017-10-24 08:46:03 -05:00
openSettings() {
appEvents.emit('show-modal', {
templateHtml: `<row-options row="model.row" on-updated="model.onUpdated()" dismiss="dismiss()"></row-options>`,
modalClass: 'modal--narrow',
model: {
row: this.props.panel,
onUpdated: this.forceUpdate.bind(this),
},
});
}
delete() {
appEvents.emit('confirm-modal', {
title: 'Delete Row',
text: 'Are you sure you want to remove this row and all its panels?',
altActionText: 'Delete row only',
icon: 'fa-trash',
onConfirm: () => {
const panelContainer = this.props.getPanelContainer();
const dashboard = panelContainer.getDashboard();
dashboard.removeRow(this.props.panel, true);
},
onAltAction: () => {
const panelContainer = this.props.getPanelContainer();
const dashboard = panelContainer.getDashboard();
dashboard.removeRow(this.props.panel, false);
},
2017-10-24 08:46:03 -05:00
});
}
2017-10-13 10:01:38 -05:00
render() {
const classes = classNames({
'dashboard-row': true,
'dashboard-row--collapsed': this.state.collapsed,
});
const chevronClass = classNames({
fa: true,
'fa-chevron-down': !this.state.collapsed,
'fa-chevron-right': this.state.collapsed,
});
2017-10-25 05:37:34 -05:00
let title = templateSrv.replaceWithText(this.props.panel.title, this.props.panel.scopedVars);
2017-10-17 05:04:18 -05:00
const hiddenPanels = this.props.panel.panels ? this.props.panel.panels.length : 0;
2017-10-16 09:09:23 -05:00
2017-10-13 10:01:38 -05:00
return (
2017-10-16 09:09:23 -05:00
<div className={classes}>
<a className="dashboard-row__title pointer" onClick={this.toggle}>
2017-10-16 09:09:23 -05:00
<i className={chevronClass} />
{title}
2017-10-17 05:04:18 -05:00
<span className="dashboard-row__panel_count">({hiddenPanels} hidden panels)</span>
</a>
<div className="dashboard-row__actions">
<a className="pointer" onClick={this.openSettings}>
<i className="fa fa-cog" />
2017-10-13 10:01:38 -05:00
</a>
<a className="pointer" onClick={this.delete}>
<i className="fa fa-trash" />
</a>
2017-10-13 10:01:38 -05:00
</div>
<div className="dashboard-row__drag grid-drag-handle" />
</div>
);
}
}