Skip to content

Commit b27b0e8

Browse files
idastambukiwysiu
andauthored
SQLEditor: Use queryRef to call onChange (#209)
* Use queryRef to call onChange * Update src/components/QueryEditor.tsx Co-authored-by: Isabella Siu <[email protected]> Co-authored-by: Isabella Siu <[email protected]>
1 parent b3ca571 commit b27b0e8

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/components/QueryEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ export function QueryEditor(props: Props) {
165165
<SQLEditor
166166
query={query}
167167
onRunQuery={props.onRunQuery}
168-
onChange={(rawQuery) => props.onChange({ ...props.query, rawQuery })}
168+
onChange={props.onChange}
169169
datasource={props.datasource}
170170
/>
171171
</div>

src/components/SQLEditor.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import timestreamLanguageDefinition from 'language/definition';
99
interface RawEditorProps {
1010
query: TimestreamQuery;
1111
onRunQuery: () => void;
12-
onChange: (q: string) => void;
12+
onChange: (query: TimestreamQuery) => void;
1313
datasource: DataSource;
1414
}
1515

@@ -19,6 +19,10 @@ export default function SQLEditor({ query, datasource, onRunQuery, onChange }: R
1919
queryRef.current = query;
2020
}, [query]);
2121

22+
const onChangeRawQuery = (rawQuery: string) => {
23+
onChange({ ...queryRef.current, rawQuery });
24+
};
25+
2226
const getDatabases = useCallback(async () => {
2327
const databases: string[] = await datasource.postResource('databases').catch(() => []);
2428
return databases.map((database) => ({ name: database, completion: database }));
@@ -67,7 +71,7 @@ export default function SQLEditor({ query, datasource, onRunQuery, onChange }: R
6771
<SQLCodeEditor
6872
query={query.rawQuery ?? ''}
6973
onBlur={() => onRunQuery()}
70-
onChange={(rawQuery) => onChange(rawQuery)}
74+
onChange={onChangeRawQuery}
7175
language={{
7276
...timestreamLanguageDefinition,
7377
completionProvider,

0 commit comments

Comments
 (0)