DashboardRow.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import React from 'react';
  2. import classNames from 'classnames';
  3. import { PanelModel } from '../panel_model';
  4. import { PanelContainer } from './PanelContainer';
  5. import templateSrv from 'app/features/templating/template_srv';
  6. import appEvents from 'app/core/app_events';
  7. export interface DashboardRowProps {
  8. panel: PanelModel;
  9. getPanelContainer: () => PanelContainer;
  10. }
  11. export class DashboardRow extends React.Component<DashboardRowProps, any> {
  12. dashboard: any;
  13. panelContainer: any;
  14. constructor(props) {
  15. super(props);
  16. this.state = {
  17. collapsed: this.props.panel.collapsed,
  18. };
  19. this.panelContainer = this.props.getPanelContainer();
  20. this.dashboard = this.panelContainer.getDashboard();
  21. this.toggle = this.toggle.bind(this);
  22. this.openSettings = this.openSettings.bind(this);
  23. this.delete = this.delete.bind(this);
  24. }
  25. toggle() {
  26. this.dashboard.toggleRow(this.props.panel);
  27. this.setState(prevState => {
  28. return { collapsed: !prevState.collapsed };
  29. });
  30. }
  31. openSettings() {
  32. appEvents.emit('show-modal', {
  33. templateHtml: `<row-options row="model.row" on-updated="model.onUpdated()" dismiss="dismiss()"></row-options>`,
  34. modalClass: 'modal--narrow',
  35. model: {
  36. row: this.props.panel,
  37. onUpdated: this.forceUpdate.bind(this),
  38. },
  39. });
  40. }
  41. delete() {
  42. appEvents.emit('confirm-modal', {
  43. title: 'Delete Row',
  44. text: 'Are you sure you want to remove this row and all its panels?',
  45. altActionText: 'Delete row only',
  46. icon: 'fa-trash',
  47. onConfirm: () => {
  48. const panelContainer = this.props.getPanelContainer();
  49. const dashboard = panelContainer.getDashboard();
  50. dashboard.removeRow(this.props.panel, true);
  51. },
  52. onAltAction: () => {
  53. const panelContainer = this.props.getPanelContainer();
  54. const dashboard = panelContainer.getDashboard();
  55. dashboard.removeRow(this.props.panel, false);
  56. },
  57. });
  58. }
  59. render() {
  60. const classes = classNames({
  61. 'dashboard-row': true,
  62. 'dashboard-row--collapsed': this.state.collapsed,
  63. });
  64. const chevronClass = classNames({
  65. fa: true,
  66. 'fa-chevron-down': !this.state.collapsed,
  67. 'fa-chevron-right': this.state.collapsed,
  68. });
  69. let title = templateSrv.replaceWithText(this.props.panel.title, this.props.panel.scopedVars);
  70. const hiddenPanels = this.props.panel.panels ? this.props.panel.panels.length : 0;
  71. return (
  72. <div className={classes}>
  73. <a className="dashboard-row__title pointer" onClick={this.toggle}>
  74. <i className={chevronClass} />
  75. {title}
  76. <span className="dashboard-row__panel_count">({hiddenPanels} hidden panels)</span>
  77. </a>
  78. <div className="dashboard-row__actions">
  79. <a className="pointer" onClick={this.openSettings}>
  80. <i className="fa fa-cog" />
  81. </a>
  82. <a className="pointer" onClick={this.delete}>
  83. <i className="fa fa-trash" />
  84. </a>
  85. </div>
  86. <div className="dashboard-row__drag grid-drag-handle" />
  87. </div>
  88. );
  89. }
  90. }