DashboardRow.tsx 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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(
  70. this.props.panel.title,
  71. this.props.panel.scopedVars
  72. );
  73. const hiddenPanels = this.props.panel.panels
  74. ? this.props.panel.panels.length
  75. : 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">
  82. ({hiddenPanels} hidden panels)
  83. </span>
  84. </a>
  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. <div className="dashboard-row__drag grid-drag-handle" />
  94. </div>
  95. );
  96. }
  97. }