import { css, cx } from '@emotion/css';
import { LanguageMap, languages as prismLanguages } from 'prismjs';
import React, { FC, useMemo } from 'react';
import { GrafanaTheme } from '@grafana/data';
import { Editor } from '@grafana/slate-react';
import { makeValue, SlatePrism, useStyles } from '@grafana/ui';
import LogqlSyntax from 'app/plugins/datasource/loki/syntax';
import PromqlSyntax from 'app/plugins/datasource/prometheus/promql';
import { RulesSource } from 'app/types/unified-alerting';
import { DataSourceType, isCloudRulesSource } from '../utils/datasource';
import { Well } from './Well';
interface Props {
expression: string;
rulesSource: RulesSource;
}
export const HighlightedQuery: FC<{ language: 'promql' | 'logql'; expr: string }> = ({ language, expr }) => {
const plugins = useMemo(
() => [
SlatePrism(
{
onlyIn: (node: any) => node.type === 'code_block',
getSyntax: () => language,
},
{ ...(prismLanguages as LanguageMap), [language]: language === 'logql' ? LogqlSyntax : PromqlSyntax }
),
],
[language]
);
const slateValue = useMemo(() => makeValue(expr), [expr]);
return ;
};
export const Expression: FC = ({ expression: query, rulesSource }) => {
const styles = useStyles(getStyles);
return (
{isCloudRulesSource(rulesSource) ? (
) : (
query
)}
);
};
export const getStyles = (theme: GrafanaTheme) => ({
well: css`
font-family: ${theme.typography.fontFamily.monospace};
`,
});