QueryRows.tsx 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import React, { PureComponent } from 'react';
  2. // TODO make this datasource-plugin-dependent
  3. import QueryField from './PromQueryField';
  4. class QueryRow extends PureComponent<any, {}> {
  5. onChangeQuery = (value, override?: boolean) => {
  6. const { index, onChangeQuery } = this.props;
  7. if (onChangeQuery) {
  8. onChangeQuery(value, index, override);
  9. }
  10. };
  11. onClickAddButton = () => {
  12. const { index, onAddQueryRow } = this.props;
  13. if (onAddQueryRow) {
  14. onAddQueryRow(index);
  15. }
  16. };
  17. onClickClearButton = () => {
  18. this.onChangeQuery('', true);
  19. };
  20. onClickHintFix = action => {
  21. const { index, onClickHintFix } = this.props;
  22. if (onClickHintFix) {
  23. onClickHintFix(action, index);
  24. }
  25. };
  26. onClickRemoveButton = () => {
  27. const { index, onRemoveQueryRow } = this.props;
  28. if (onRemoveQueryRow) {
  29. onRemoveQueryRow(index);
  30. }
  31. };
  32. onPressEnter = () => {
  33. const { onExecuteQuery } = this.props;
  34. if (onExecuteQuery) {
  35. onExecuteQuery();
  36. }
  37. };
  38. render() {
  39. const { history, query, queryError, queryHint, request, supportsLogs } = this.props;
  40. return (
  41. <div className="query-row">
  42. <div className="query-row-field">
  43. <QueryField
  44. error={queryError}
  45. hint={queryHint}
  46. initialQuery={query}
  47. history={history}
  48. onClickHintFix={this.onClickHintFix}
  49. onPressEnter={this.onPressEnter}
  50. onQueryChange={this.onChangeQuery}
  51. request={request}
  52. supportsLogs={supportsLogs}
  53. />
  54. </div>
  55. <div className="query-row-tools">
  56. <button className="btn navbar-button navbar-button--tight" onClick={this.onClickClearButton}>
  57. <i className="fa fa-times" />
  58. </button>
  59. <button className="btn navbar-button navbar-button--tight" onClick={this.onClickAddButton}>
  60. <i className="fa fa-plus" />
  61. </button>
  62. <button className="btn navbar-button navbar-button--tight" onClick={this.onClickRemoveButton}>
  63. <i className="fa fa-minus" />
  64. </button>
  65. </div>
  66. </div>
  67. );
  68. }
  69. }
  70. export default class QueryRows extends PureComponent<any, {}> {
  71. render() {
  72. const { className = '', queries, queryErrors, queryHints, ...handlers } = this.props;
  73. return (
  74. <div className={className}>
  75. {queries.map((q, index) => (
  76. <QueryRow
  77. key={q.key}
  78. index={index}
  79. query={q.query}
  80. queryError={queryErrors[index]}
  81. queryHint={queryHints[index]}
  82. {...handlers}
  83. />
  84. ))}
  85. </div>
  86. );
  87. }
  88. }