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
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Change Log

All notable changes to this project will be documented in this file.
## v1.7.10

- Tweaks in type definitions for the `SQLEditor` component on the `blur` method

## v1.7.9

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@grafana/experimental",
"version": "1.7.9",
"version": "1.7.10",
"description": "Experimental Grafana components and APIs",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down
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