| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- import React from 'react';
- import classNames from 'classnames';
- import { PanelModel } from '../../state/PanelModel';
- import { DashboardModel } from '../../state/DashboardModel';
- import templateSrv from 'app/features/templating/template_srv';
- import appEvents from 'app/core/app_events';
- export interface DashboardRowProps {
- panel: PanelModel;
- dashboard: DashboardModel;
- }
- export class DashboardRow extends React.Component<DashboardRowProps, any> {
- constructor(props) {
- super(props);
- this.state = {
- collapsed: this.props.panel.collapsed,
- };
- appEvents.on('template-variable-value-updated', this.onVariableUpdated);
- }
- componentWillUnmount() {
- appEvents.off('template-variable-value-updated', this.onVariableUpdated);
- }
- onVariableUpdated = () => {
- this.forceUpdate();
- }
- onToggle = () => {
- this.props.dashboard.toggleRow(this.props.panel);
- this.setState(prevState => {
- return { collapsed: !prevState.collapsed };
- });
- }
- onUpdate = () => {
- this.props.dashboard.processRepeats();
- this.forceUpdate();
- }
- onOpenSettings = () => {
- 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.onUpdate,
- },
- });
- }
- onDelete = () => {
- 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: () => {
- this.props.dashboard.removeRow(this.props.panel, true);
- },
- onAltAction: () => {
- this.props.dashboard.removeRow(this.props.panel, false);
- },
- });
- }
- 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 title = templateSrv.replaceWithText(this.props.panel.title, this.props.panel.scopedVars);
- const count = this.props.panel.panels ? this.props.panel.panels.length : 0;
- const panels = count === 1 ? 'panel' : 'panels';
- const canEdit = this.props.dashboard.meta.canEdit === true;
- return (
- <div className={classes}>
- <a className="dashboard-row__title pointer" onClick={this.onToggle}>
- <i className={chevronClass} />
- {title}
- <span className="dashboard-row__panel_count">
- ({count} {panels})
- </span>
- </a>
- {canEdit && (
- <div className="dashboard-row__actions">
- <a className="pointer" onClick={this.onOpenSettings}>
- <i className="fa fa-cog" />
- </a>
- <a className="pointer" onClick={this.onDelete}>
- <i className="fa fa-trash" />
- </a>
- </div>
- )}
- {this.state.collapsed === true && (
- <div className="dashboard-row__toggle-target" onClick={this.onToggle}>
-
- </div>
- )}
- {canEdit && <div className="dashboard-row__drag grid-drag-handle" />}
- </div>
- );
- }
- }
|