LokiQueryEditor.tsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Libraries
  2. import React from 'react';
  3. // Types
  4. import { InlineFormLabel } from '@grafana/ui';
  5. import { LokiOptionFields } from './LokiOptionFields';
  6. import { LokiQueryField } from './LokiQueryField';
  7. import { LokiQueryEditorProps } from './types';
  8. export function LokiQueryEditor(props: LokiQueryEditorProps) {
  9. const { query, data, datasource, onChange, onRunQuery, range } = props;
  10. const onLegendChange = (e: React.SyntheticEvent<HTMLInputElement>) => {
  11. const nextQuery = { ...query, legendFormat: e.currentTarget.value };
  12. onChange(nextQuery);
  13. };
  14. const legendField = (
  15. <div className="gf-form-inline">
  16. <div className="gf-form">
  17. <InlineFormLabel
  18. width={6}
  19. tooltip="Controls the name of the time series, using name or pattern. For example
  20. {{hostname}} will be replaced with label value for the label hostname. The legend only applies to metric queries."
  21. >
  22. Legend
  23. </InlineFormLabel>
  24. <input
  25. type="text"
  26. className="gf-form-input"
  27. placeholder="legend format"
  28. value={query.legendFormat || ''}
  29. onChange={onLegendChange}
  30. onBlur={onRunQuery}
  31. />
  32. </div>
  33. </div>
  34. );
  35. return (
  36. <LokiQueryField
  37. datasource={datasource}
  38. query={query}
  39. onChange={onChange}
  40. onRunQuery={onRunQuery}
  41. onBlur={onRunQuery}
  42. history={[]}
  43. data={data}
  44. data-testid={testIds.editor}
  45. range={range}
  46. ExtraFieldElement={
  47. <>
  48. <LokiOptionFields
  49. lineLimitValue={query?.maxLines?.toString() || ''}
  50. resolution={query?.resolution || 1}
  51. query={query}
  52. onRunQuery={onRunQuery}
  53. onChange={onChange}
  54. runOnBlur={true}
  55. />
  56. {legendField}
  57. </>
  58. }
  59. />
  60. );
  61. }
  62. export const testIds = {
  63. editor: 'loki-editor',
  64. };