Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Correct type check for the onBlur handler for SQLEditor #116

Merged
merged 4 commits into from
Feb 7, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/sql-editor/components/SQLEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ interface SQLEditorProps {
* Use for inspecting the query as it changes. I.e. for validation.
*/
onChange?: (q: string, processQuery: boolean) => void;
onBlur?: () => void;
onBlur?: (text: string) => void;
language?: LanguageDefinition;
children?: (props: { formatQuery: () => void }) => React.ReactNode;
width?: number;
Expand Down Expand Up @@ -104,6 +104,11 @@ export const SQLEditor: React.FC<SQLEditorProps> = ({
}
}, []);

const onSqlBlur = (text: string) => {
onChange && onChange(text, false);
onBlur && onBlur(text);
};

return (
<div style={{ width }}>
<CodeEditor
Expand All @@ -112,10 +117,7 @@ export const SQLEditor: React.FC<SQLEditorProps> = ({
width={width ? `${width - 2}px` : undefined}
language={id}
value={query}
onBlur={(v) => {
onChange && onChange(v, false);
onBlur && onBlur();
}}
onBlur={onSqlBlur}
showMiniMap={false}
showLineNumbers={true}
// Using onEditorDidMount instead of onBeforeEditorMount to support Grafana < 8.2.x
Expand Down Expand Up @@ -403,13 +405,13 @@ function extendStandardRegistries(id: string, lid: string, customProvider: SQLCo
const columns = await customProvider.columns?.resolve!(tableIdentifier);
oo = columns
? columns.map<CustomSuggestion>((x) => ({
label: x.name,
insertText: x.completion ?? x.name,
kind: CompletionItemKind.Field,
sortText: CompletionItemPriority.High,
detail: x.type,
documentation: x.description,
}))
label: x.name,
insertText: x.completion ?? x.name,
kind: CompletionItemKind.Field,
sortText: CompletionItemPriority.High,
detail: x.type,
documentation: x.description,
}))
: [];
}
return [...o, ...oo];
Expand Down
Loading