mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 18:13:32 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
63 lines
1.7 KiB
TypeScript
63 lines
1.7 KiB
TypeScript
import { css, cx } from '@emotion/css';
|
|
import React, { FC, useMemo } from 'react';
|
|
import AutoSizer from 'react-virtualized-auto-sizer';
|
|
|
|
import { GrafanaTheme, StandardEditorProps } from '@grafana/data';
|
|
import {
|
|
CodeEditor,
|
|
stylesFactory,
|
|
useTheme,
|
|
CodeEditorSuggestionItem,
|
|
variableSuggestionToCodeEditorSuggestion,
|
|
} from '@grafana/ui';
|
|
|
|
import { PanelOptions, TextMode } from './models.gen';
|
|
|
|
export const TextPanelEditor: FC<StandardEditorProps<string, any, PanelOptions>> = ({ value, onChange, context }) => {
|
|
const language = useMemo(() => context.options?.mode ?? TextMode.Markdown, [context]);
|
|
const theme = useTheme();
|
|
const styles = getStyles(theme);
|
|
|
|
const getSuggestions = (): CodeEditorSuggestionItem[] => {
|
|
if (!context.getSuggestions) {
|
|
return [];
|
|
}
|
|
return context.getSuggestions().map((v) => variableSuggestionToCodeEditorSuggestion(v));
|
|
};
|
|
|
|
return (
|
|
<div className={cx(styles.editorBox)}>
|
|
<AutoSizer disableHeight>
|
|
{({ width }) => {
|
|
if (width === 0) {
|
|
return null;
|
|
}
|
|
return (
|
|
<CodeEditor
|
|
value={value}
|
|
onBlur={onChange}
|
|
onSave={onChange}
|
|
language={language}
|
|
width={width}
|
|
showMiniMap={false}
|
|
showLineNumbers={false}
|
|
height="500px"
|
|
getSuggestions={getSuggestions}
|
|
/>
|
|
);
|
|
}}
|
|
</AutoSizer>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
const getStyles = stylesFactory((theme: GrafanaTheme) => ({
|
|
editorBox: css`
|
|
label: editorBox;
|
|
border: ${theme.border.width.sm} solid ${theme.colors.border2};
|
|
border-radius: ${theme.border.radius.sm};
|
|
margin: ${theme.spacing.xs} 0;
|
|
width: 100%;
|
|
`,
|
|
}));
|