Skip to content

Commit

Permalink
fix: content param doesn't work in the SQL editor (supabase#18176)
Browse files Browse the repository at this point in the history
* Fix the content parameter for the SQL editor.

* Add comment.
  • Loading branch information
ivasilov committed Oct 16, 2023
1 parent 599bf0e commit cde1731
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions studio/components/interfaces/SQLEditor/MonacoEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import Editor, { Monaco, OnMount } from '@monaco-editor/react'
import { useParams } from 'common'
import { debounce } from 'lodash'
import { useRouter } from 'next/router'
import { MutableRefObject, useRef } from 'react'
import { MutableRefObject, useEffect, useRef } from 'react'
import { cn } from 'ui'
import { debounce, memoize } from 'lodash'

import { SqlSnippet } from 'data/content/sql-snippets-query'
import { useSelectedProject } from 'hooks'
Expand Down Expand Up @@ -100,14 +100,22 @@ const MonacoEditor = ({
}
}

// if an SQL query is passed by the content parameter, set the editor value to its content. This
// is usually used for sending the user to SQL editor from other pages with SQL.
useEffect(() => {
if (content && content.length > 0) {
handleEditorChange(content)
}
}, [])

return (
<Editor
className={cn(className, 'monaco-editor')}
theme={'supabase'}
onMount={handleEditorOnMount}
onChange={handleEditorChange}
defaultLanguage="pgsql"
defaultValue={snippet?.snippet.content.sql ?? content}
defaultValue={snippet?.snippet.content.sql}
path={id}
options={{
tabSize: 2,
Expand Down

0 comments on commit cde1731

Please sign in to comment.