AnnotationQueryEditor.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import React from 'react';
  2. import { AnnotationQuery } from '@grafana/data';
  3. import { EditorRow, EditorField, EditorSwitch, Space, EditorRows } from '@grafana/experimental';
  4. import { Input } from '@grafana/ui';
  5. import { PromQueryCodeEditor } from '../querybuilder/components/PromQueryCodeEditor';
  6. import { AutoSizeInput } from '../querybuilder/shared/AutoSizeInput';
  7. import { PromQuery } from '../types';
  8. import { PromQueryEditorProps } from './types';
  9. type Props = PromQueryEditorProps & {
  10. annotation?: AnnotationQuery<PromQuery>;
  11. onAnnotationChange?: (annotation: AnnotationQuery<PromQuery>) => void;
  12. };
  13. export function AnnotationQueryEditor(props: Props) {
  14. // This is because of problematic typing. See AnnotationQueryEditorProps in grafana-data/annotations.ts.
  15. const annotation = props.annotation!;
  16. const onAnnotationChange = props.onAnnotationChange!;
  17. const query = { expr: annotation.expr, refId: annotation.name, interval: annotation.step };
  18. return (
  19. <>
  20. <EditorRows>
  21. <PromQueryCodeEditor
  22. {...props}
  23. query={query}
  24. onChange={(query) => {
  25. onAnnotationChange({
  26. ...annotation,
  27. expr: query.expr,
  28. });
  29. }}
  30. />
  31. <EditorRow>
  32. <EditorField
  33. label="Min step"
  34. tooltip={
  35. <>
  36. An additional lower limit for the step parameter of the Prometheus query and for the{' '}
  37. <code>$__interval</code> and <code>$__rate_interval</code> variables.
  38. </>
  39. }
  40. >
  41. <AutoSizeInput
  42. type="text"
  43. aria-label="Set lower limit for the step parameter"
  44. placeholder={'auto'}
  45. minWidth={10}
  46. onCommitChange={(ev) => {
  47. onAnnotationChange({
  48. ...annotation,
  49. step: ev.currentTarget.value,
  50. });
  51. }}
  52. defaultValue={query.interval}
  53. />
  54. </EditorField>
  55. </EditorRow>
  56. </EditorRows>
  57. <Space v={0.5} />
  58. <EditorRow>
  59. <EditorField
  60. label="Title"
  61. tooltip={
  62. 'Use either the name or a pattern. For example, {{instance}} is replaced with label value for the label instance.'
  63. }
  64. >
  65. <Input
  66. type="text"
  67. placeholder="{{alertname}}"
  68. value={annotation.titleFormat}
  69. onChange={(event) => {
  70. onAnnotationChange({
  71. ...annotation,
  72. titleFormat: event.currentTarget.value,
  73. });
  74. }}
  75. />
  76. </EditorField>
  77. <EditorField label="Tags">
  78. <Input
  79. type="text"
  80. placeholder="label1,label2"
  81. value={annotation.tagKeys}
  82. onChange={(event) => {
  83. onAnnotationChange({
  84. ...annotation,
  85. tagKeys: event.currentTarget.value,
  86. });
  87. }}
  88. />
  89. </EditorField>
  90. <EditorField
  91. label="Text"
  92. tooltip={
  93. 'Use either the name or a pattern. For example, {{instance}} is replaced with label value for the label instance.'
  94. }
  95. >
  96. <Input
  97. type="text"
  98. placeholder="{{instance}}"
  99. value={annotation.textFormat}
  100. onChange={(event) => {
  101. onAnnotationChange({
  102. ...annotation,
  103. textFormat: event.currentTarget.value,
  104. });
  105. }}
  106. />
  107. </EditorField>
  108. <EditorField
  109. label="Series value as timestamp"
  110. tooltip={
  111. 'The unit of timestamp is milliseconds. If the unit of the series value is seconds, multiply its range vector by 1000.'
  112. }
  113. >
  114. <EditorSwitch
  115. value={annotation.useValueForTime}
  116. onChange={(event) => {
  117. onAnnotationChange({
  118. ...annotation,
  119. useValueForTime: event.currentTarget.value,
  120. });
  121. }}
  122. />
  123. </EditorField>
  124. </EditorRow>
  125. </>
  126. );
  127. }