mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Loki: Use expr as state for visual editor * Loki: Use query with line filter as default for visual editor * Refactor based on feedback * fix background for query text row Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import React from 'react';
|
|
import { useTheme2 } from '@grafana/ui';
|
|
import { GrafanaTheme2 } from '@grafana/data';
|
|
import { css, cx } from '@emotion/css';
|
|
import { EditorField, EditorFieldGroup, EditorRow } from '@grafana/experimental';
|
|
import Prism from 'prismjs';
|
|
import { lokiGrammar } from '../../syntax';
|
|
|
|
export interface Props {
|
|
query: string;
|
|
}
|
|
|
|
export function QueryPreview({ query }: Props) {
|
|
const theme = useTheme2();
|
|
const styles = getStyles(theme);
|
|
const highlighted = Prism.highlight(query, lokiGrammar, 'lokiql');
|
|
|
|
return (
|
|
<EditorRow>
|
|
<EditorFieldGroup>
|
|
<EditorField label="Raw query">
|
|
<div
|
|
className={cx(styles.editorField, 'prism-syntax-highlight')}
|
|
aria-label="selector"
|
|
dangerouslySetInnerHTML={{ __html: highlighted }}
|
|
/>
|
|
</EditorField>
|
|
</EditorFieldGroup>
|
|
</EditorRow>
|
|
);
|
|
}
|
|
|
|
const getStyles = (theme: GrafanaTheme2) => {
|
|
return {
|
|
editorField: css({
|
|
fontFamily: theme.typography.fontFamilyMonospace,
|
|
fontSize: theme.typography.bodySmall.fontSize,
|
|
}),
|
|
};
|
|
};
|