DashboardRow.tsx 3.3 KB

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