DashboardRow.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. this.update = this.update.bind(this);
  25. }
  26. toggle() {
  27. this.dashboard.toggleRow(this.props.panel);
  28. this.setState(prevState => {
  29. return { collapsed: !prevState.collapsed };
  30. });
  31. }
  32. update() {
  33. this.dashboard.processRepeats();
  34. this.forceUpdate();
  35. }
  36. openSettings() {
  37. appEvents.emit('show-modal', {
  38. templateHtml: `<row-options row="model.row" on-updated="model.onUpdated()" dismiss="dismiss()"></row-options>`,
  39. modalClass: 'modal--narrow',
  40. model: {
  41. row: this.props.panel,
  42. onUpdated: this.update.bind(this),
  43. },
  44. });
  45. }
  46. delete() {
  47. appEvents.emit('confirm-modal', {
  48. title: 'Delete Row',
  49. text: 'Are you sure you want to remove this row and all its panels?',
  50. altActionText: 'Delete row only',
  51. icon: 'fa-trash',
  52. onConfirm: () => {
  53. const panelContainer = this.props.getPanelContainer();
  54. const dashboard = panelContainer.getDashboard();
  55. dashboard.removeRow(this.props.panel, true);
  56. },
  57. onAltAction: () => {
  58. const panelContainer = this.props.getPanelContainer();
  59. const dashboard = panelContainer.getDashboard();
  60. dashboard.removeRow(this.props.panel, false);
  61. },
  62. });
  63. }
  64. render() {
  65. const classes = classNames({
  66. 'dashboard-row': true,
  67. 'dashboard-row--collapsed': this.state.collapsed,
  68. });
  69. const chevronClass = classNames({
  70. fa: true,
  71. 'fa-chevron-down': !this.state.collapsed,
  72. 'fa-chevron-right': this.state.collapsed,
  73. });
  74. let title = templateSrv.replaceWithText(this.props.panel.title, this.props.panel.scopedVars);
  75. const hiddenPanels = this.props.panel.panels ? this.props.panel.panels.length : 0;
  76. return (
  77. <div className={classes}>
  78. <a className="dashboard-row__title pointer" onClick={this.toggle}>
  79. <i className={chevronClass} />
  80. {title}
  81. <span className="dashboard-row__panel_count">({hiddenPanels} hidden panels)</span>
  82. </a>
  83. <div className="dashboard-row__actions">
  84. <a className="pointer" onClick={this.openSettings}>
  85. <i className="fa fa-cog" />
  86. </a>
  87. <a className="pointer" onClick={this.delete}>
  88. <i className="fa fa-trash" />
  89. </a>
  90. </div>
  91. <div className="dashboard-row__drag grid-drag-handle" />
  92. </div>
  93. );
  94. }
  95. }