QueryRows.tsx 1.9 KB

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