QueryRows.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import React, { PureComponent } from 'react';
  2. import QueryField from './PromQueryField';
  3. class QueryRow extends PureComponent<any, {}> {
  4. onChangeQuery = (value, override?: boolean) => {
  5. const { index, onChangeQuery } = this.props;
  6. if (onChangeQuery) {
  7. onChangeQuery(value, index, override);
  8. }
  9. };
  10. onClickAddButton = () => {
  11. const { index, onAddQueryRow } = this.props;
  12. if (onAddQueryRow) {
  13. onAddQueryRow(index);
  14. }
  15. };
  16. onClickClearButton = () => {
  17. this.onChangeQuery('', true);
  18. };
  19. onClickRemoveButton = () => {
  20. const { index, onRemoveQueryRow } = this.props;
  21. if (onRemoveQueryRow) {
  22. onRemoveQueryRow(index);
  23. }
  24. };
  25. onPressEnter = () => {
  26. const { onExecuteQuery } = this.props;
  27. if (onExecuteQuery) {
  28. onExecuteQuery();
  29. }
  30. };
  31. render() {
  32. const { edited, history, query, request } = this.props;
  33. return (
  34. <div className="query-row">
  35. <div className="query-row-field">
  36. <QueryField
  37. initialQuery={edited ? null : query}
  38. history={history}
  39. portalPrefix="explore"
  40. onPressEnter={this.onPressEnter}
  41. onQueryChange={this.onChangeQuery}
  42. request={request}
  43. />
  44. </div>
  45. <div className="query-row-tools">
  46. <button className="btn navbar-button navbar-button--tight" onClick={this.onClickClearButton}>
  47. <i className="fa fa-times" />
  48. </button>
  49. <button className="btn navbar-button navbar-button--tight" onClick={this.onClickAddButton}>
  50. <i className="fa fa-plus" />
  51. </button>
  52. <button className="btn navbar-button navbar-button--tight" onClick={this.onClickRemoveButton}>
  53. <i className="fa fa-minus" />
  54. </button>
  55. </div>
  56. </div>
  57. );
  58. }
  59. }
  60. export default class QueryRows extends PureComponent<any, {}> {
  61. render() {
  62. const { className = '', queries, ...handlers } = this.props;
  63. return (
  64. <div className={className}>
  65. {queries.map((q, index) => (
  66. <QueryRow key={q.key} index={index} query={q.query} edited={q.edited} {...handlers} />
  67. ))}
  68. </div>
  69. );
  70. }
  71. }