(null)
+ useEffect(() => {
+ if (editorRef.current && editorPanel.initialValue !== currentValue) {
+ const editor = editorRef.current
+ const model = editor.getModel()
+ if (model) {
+ editor.executeEdits('update-value', [
+ {
+ text: editorPanel.initialValue || '',
+ range: model.getFullModelRange(),
+ },
+ ])
+ setCurrentValue(editorPanel.initialValue || '')
+ }
+ }
+ }, [editorPanel.initialValue])
+
const {
complete,
completion,
@@ -119,6 +135,18 @@ const SQLEditor = ({ onChange }: SQLEditorProps) => {
editorRef.current = editor
monacoRef.current = monaco
+ // Set initial value on mount
+ const model = editor.getModel()
+ if (model && editorPanel.initialValue) {
+ editor.executeEdits('initial-value', [
+ {
+ text: editorPanel.initialValue,
+ range: model.getFullModelRange(),
+ },
+ ])
+ setCurrentValue(editorPanel.initialValue)
+ }
+
editor.addAction({
id: 'run-query',
label: 'Run Query',
@@ -239,7 +267,7 @@ const SQLEditor = ({ onChange }: SQLEditorProps) => {
)
})
- console.log('templates:', editorPanel.templates)
+ console.log('templates:', editorPanel.initialValue)
return (
@@ -249,7 +277,6 @@ const SQLEditor = ({ onChange }: SQLEditorProps) => {
className="monaco-editor"
theme="supabase"
language="pgsql"
- defaultValue={editorPanel.initialValue}
onChange={handleChange}
onMount={handleEditorOnMount}
options={{