import React from 'react'; import classNames from 'classnames'; import { PanelModel } from '../panel_model'; import { PanelContainer } from './PanelContainer'; import appEvents from 'app/core/app_events'; export interface DashboardRowProps { panel: PanelModel; getPanelContainer: () => PanelContainer; } export class DashboardRow extends React.Component { constructor(props) { super(props); this.state = { collapsed: this.props.panel.collapsed, }; this.toggle = this.toggle.bind(this); this.openSettings = this.openSettings.bind(this); } toggle() { const panelContainer = this.props.getPanelContainer(); const dashboard = panelContainer.getDashboard(); dashboard.toggleRow(this.props.panel); this.setState(prevState => { return { collapsed: !prevState.collapsed }; }); } openSettings() { appEvents.emit('show-modal', { templateHtml: ``, modalClass: 'modal--narrow', model: { row: this.props.panel, onUpdated: this.forceUpdate.bind(this), onDelete: this.onDelete.bind(this), }, }); } onDelete() { let text2 = ''; if (this.props.panel.panels.length) { text2 = 'This will also remove ' + this.props.panel.panels.length + ' panels'; } appEvents.emit('confirm-modal', { title: 'Delete Row', text: 'Are you sure you want to remove this row?', text2: text2, icon: 'fa-trash', onConfirm: () => { const panelContainer = this.props.getPanelContainer(); const dashboard = panelContainer.getDashboard(); dashboard.removePanel(this.props.panel); }, }); } 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, }); const hiddenPanels = this.props.panel.panels ? this.props.panel.panels.length : 0; return (
{this.props.panel.title} ({hiddenPanels} hidden panels)
); } }