LokiQueryBuilderExplained.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import React from 'react';
  2. import { Stack } from '@grafana/experimental';
  3. import { OperationExplainedBox } from 'app/plugins/datasource/prometheus/querybuilder/shared/OperationExplainedBox';
  4. import { OperationListExplained } from 'app/plugins/datasource/prometheus/querybuilder/shared/OperationListExplained';
  5. import { RawQuery } from 'app/plugins/datasource/prometheus/querybuilder/shared/RawQuery';
  6. import { lokiGrammar } from '../../syntax';
  7. import { lokiQueryModeller } from '../LokiQueryModeller';
  8. import { buildVisualQueryFromString } from '../parsing';
  9. import { LokiVisualQuery } from '../types';
  10. export interface Props {
  11. query: string;
  12. }
  13. export const LokiQueryBuilderExplained = React.memo<Props>(({ query }) => {
  14. const visQuery = buildVisualQueryFromString(query || '').query;
  15. const lang = { grammar: lokiGrammar, name: 'lokiql' };
  16. return (
  17. <Stack gap={0} direction="column">
  18. <OperationExplainedBox>
  19. <RawQuery query={query} lang={lang} />
  20. </OperationExplainedBox>
  21. <OperationExplainedBox
  22. stepNumber={1}
  23. title={<RawQuery query={`${lokiQueryModeller.renderLabels(visQuery.labels)}`} lang={lang} />}
  24. >
  25. Fetch all log lines matching label filters.
  26. </OperationExplainedBox>
  27. <OperationListExplained<LokiVisualQuery>
  28. stepNumber={2}
  29. queryModeller={lokiQueryModeller}
  30. query={visQuery}
  31. lang={lang}
  32. />
  33. </Stack>
  34. );
  35. });
  36. LokiQueryBuilderExplained.displayName = 'LokiQueryBuilderExplained';