LogsQueryEditor.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // Libraries
  2. import { css } from '@emotion/css';
  3. import React, { memo } from 'react';
  4. // Types
  5. import { AbsoluteTimeRange, QueryEditorProps } from '@grafana/data';
  6. import { InlineFormLabel } from '@grafana/ui';
  7. import { CloudWatchDatasource } from '../datasource';
  8. import { CloudWatchJsonData, CloudWatchLogsQuery, CloudWatchQuery } from '../types';
  9. import CloudWatchLink from './CloudWatchLink';
  10. import { CloudWatchLogsQueryField } from './LogsQueryField';
  11. type Props = QueryEditorProps<CloudWatchDatasource, CloudWatchQuery, CloudWatchJsonData> & {
  12. allowCustomValue?: boolean;
  13. };
  14. const labelClass = css`
  15. margin-left: 3px;
  16. flex-grow: 0;
  17. `;
  18. export const CloudWatchLogsQueryEditor = memo(function CloudWatchLogsQueryEditor(props: Props) {
  19. const { query, data, datasource, onRunQuery, onChange, exploreId, allowCustomValue = false } = props;
  20. let absolute: AbsoluteTimeRange;
  21. if (data?.request?.range?.from) {
  22. const { range } = data.request;
  23. absolute = {
  24. from: range.from.valueOf(),
  25. to: range.to.valueOf(),
  26. };
  27. } else {
  28. absolute = {
  29. from: Date.now() - 10000,
  30. to: Date.now(),
  31. };
  32. }
  33. return (
  34. <CloudWatchLogsQueryField
  35. exploreId={exploreId}
  36. datasource={datasource}
  37. query={query}
  38. onChange={onChange}
  39. onRunQuery={onRunQuery}
  40. history={[]}
  41. data={data}
  42. absoluteRange={absolute}
  43. allowCustomValue={allowCustomValue}
  44. ExtraFieldElement={
  45. <InlineFormLabel className={`gf-form-label--btn ${labelClass}`} width="auto" tooltip="Link to Graph in AWS">
  46. <CloudWatchLink query={query as CloudWatchLogsQuery} panelData={data} datasource={datasource} />
  47. </InlineFormLabel>
  48. }
  49. />
  50. );
  51. });
  52. export default CloudWatchLogsQueryEditor;