import { css } from '@emotion/css'; import { useMemo, useState } from 'react'; import { useMeasure } from 'react-use'; import AutoSizer from 'react-virtualized-auto-sizer'; import { GrafanaTheme2 } from '@grafana/data'; import { Trans, t } from '@grafana/i18n'; import { reportInteraction } from '@grafana/runtime'; import { Modal, useStyles2, useTheme2 } from '@grafana/ui'; import { SQLQuery, QueryEditorProps } from '../../types'; import { QueryEditorRaw } from './QueryEditorRaw'; import { QueryToolbox } from './QueryToolbox'; interface RawEditorProps extends Omit { onRunQuery: () => void; onChange: (q: SQLQuery, processQuery: boolean) => void; onValidate: (isValid: boolean) => void; queryToValidate: SQLQuery; } export function RawEditor({ db, query, onChange, onRunQuery, onValidate, queryToValidate, range }: RawEditorProps) { const theme = useTheme2(); const styles = useStyles2(getStyles); const [isExpanded, setIsExpanded] = useState(false); const [toolboxRef, toolboxMeasure] = useMeasure(); const [editorRef, editorMeasure] = useMeasure(); const editorLanguageDefinition = useMemo(() => db.getEditorLanguageDefinition(), [db]); const renderQueryEditor = (width?: number, height?: number) => { return ( {({ formatQuery }) => { return (
); }}
); }; const renderEditor = (standalone = false) => { return standalone ? ( {({ width, height }) => { return renderQueryEditor(width, height); }} ) : (
{renderQueryEditor()}
); }; const renderPlaceholder = () => { return (
Editing in expanded code editor
); }; return ( <> {isExpanded ? renderPlaceholder() : renderEditor()} {isExpanded && ( { reportInteraction('grafana_sql_editor_expand', { datasource: query.datasource?.type, expanded: false, }); setIsExpanded(false); }} > {renderEditor(true)} )} ); } function getStyles(theme: GrafanaTheme2) { return { modal: css({ width: '95vw', height: '95vh', }), modalContent: css({ height: '100%', paddingTop: 0, }), }; }