@@ -8,13 +8,14 @@ import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
88import { useSelectedProject } from 'hooks/misc/useSelectedProject'
99import { LOCAL_STORAGE_KEYS } from 'lib/constants'
1010import { useProfile } from 'lib/profile'
11+ import { useAppStateSnapshot } from 'state/app-state'
1112import { useSqlEditorV2StateSnapshot } from 'state/sql-editor-v2'
1213import { cn } from 'ui'
14+ import { Admonition } from 'ui-patterns'
15+ import { useIsAssistantV2Enabled } from '../App/FeaturePreview/FeaturePreviewContext'
1316import { untitledSnippetTitle } from './SQLEditor.constants'
1417import type { IStandaloneCodeEditor } from './SQLEditor.types'
1518import { createSqlSnippetSkeletonV2 } from './SQLEditor.utils'
16- import { useIsAssistantV2Enabled } from '../App/FeaturePreview/FeaturePreviewContext'
17- import { useAppStateSnapshot } from 'state/app-state'
1819
1920export type MonacoEditorProps = {
2021 id : string
@@ -50,6 +51,8 @@ const MonacoEditor = ({
5051 )
5152
5253 const snippet = snapV2 . snippets [ id ]
54+ const disableEdit =
55+ snippet ?. snippet . visibility === 'project' && snippet ?. snippet . owner_id !== profile ?. id
5356
5457 const executeQueryRef = useRef ( executeQuery )
5558 executeQueryRef . current = executeQuery
@@ -152,57 +155,68 @@ const MonacoEditor = ({
152155 } , [ ] )
153156
154157 return (
155- < Editor
156- className = { cn ( className , 'monaco-editor' ) }
157- theme = { 'supabase' }
158- onMount = { handleEditorOnMount }
159- onChange = { handleEditorChange }
160- defaultLanguage = "pgsql"
161- defaultValue = { snippet ?. snippet . content . sql }
162- path = { id }
163- options = { {
164- tabSize : 2 ,
165- fontSize : 13 ,
166- minimap : { enabled : false } ,
167- wordWrap : 'on' ,
168- // [Joshen] Commenting the following out as it causes the autocomplete suggestion popover
169- // to be positioned wrongly somehow. I'm not sure if this affects anything though, but leaving
170- // comment just in case anyone might be wondering. Relevant issues:
171- // - https://github.com/microsoft/monaco-editor/issues/2229
172- // - https://github.com/microsoft/monaco-editor/issues/2503
173- // fixedOverflowWidgets: true,
174- suggest : {
175- showMethods : intellisenseEnabled ,
176- showFunctions : intellisenseEnabled ,
177- showConstructors : intellisenseEnabled ,
178- showDeprecated : intellisenseEnabled ,
179- showFields : intellisenseEnabled ,
180- showVariables : intellisenseEnabled ,
181- showClasses : intellisenseEnabled ,
182- showStructs : intellisenseEnabled ,
183- showInterfaces : intellisenseEnabled ,
184- showModules : intellisenseEnabled ,
185- showProperties : intellisenseEnabled ,
186- showEvents : intellisenseEnabled ,
187- showOperators : intellisenseEnabled ,
188- showUnits : intellisenseEnabled ,
189- showValues : intellisenseEnabled ,
190- showConstants : intellisenseEnabled ,
191- showEnums : intellisenseEnabled ,
192- showEnumMembers : intellisenseEnabled ,
193- showKeywords : intellisenseEnabled ,
194- showWords : intellisenseEnabled ,
195- showColors : intellisenseEnabled ,
196- showFiles : intellisenseEnabled ,
197- showReferences : intellisenseEnabled ,
198- showFolders : intellisenseEnabled ,
199- showTypeParameters : intellisenseEnabled ,
200- showIssues : intellisenseEnabled ,
201- showUsers : intellisenseEnabled ,
202- showSnippets : intellisenseEnabled ,
203- } ,
204- } }
205- />
158+ < >
159+ { disableEdit && (
160+ < Admonition
161+ type = "default"
162+ className = "m-0 py-2 rounded-none border-0 border-b [&>h5]:mb-0.5"
163+ title = "This snippet has been shared to the project and is only editable by the owner who created this snippet"
164+ description = 'You may duplicate this snippet into a personal copy by right clicking on the snippet and selecting "Duplicate personal copy"'
165+ />
166+ ) }
167+ < Editor
168+ className = { cn ( className , 'monaco-editor' ) }
169+ theme = { 'supabase' }
170+ onMount = { handleEditorOnMount }
171+ onChange = { handleEditorChange }
172+ defaultLanguage = "pgsql"
173+ defaultValue = { snippet ?. snippet . content . sql }
174+ path = { id }
175+ options = { {
176+ tabSize : 2 ,
177+ fontSize : 13 ,
178+ readOnly : disableEdit ,
179+ minimap : { enabled : false } ,
180+ wordWrap : 'on' ,
181+ // [Joshen] Commenting the following out as it causes the autocomplete suggestion popover
182+ // to be positioned wrongly somehow. I'm not sure if this affects anything though, but leaving
183+ // comment just in case anyone might be wondering. Relevant issues:
184+ // - https://github.com/microsoft/monaco-editor/issues/2229
185+ // - https://github.com/microsoft/monaco-editor/issues/2503
186+ // fixedOverflowWidgets: true,
187+ suggest : {
188+ showMethods : intellisenseEnabled ,
189+ showFunctions : intellisenseEnabled ,
190+ showConstructors : intellisenseEnabled ,
191+ showDeprecated : intellisenseEnabled ,
192+ showFields : intellisenseEnabled ,
193+ showVariables : intellisenseEnabled ,
194+ showClasses : intellisenseEnabled ,
195+ showStructs : intellisenseEnabled ,
196+ showInterfaces : intellisenseEnabled ,
197+ showModules : intellisenseEnabled ,
198+ showProperties : intellisenseEnabled ,
199+ showEvents : intellisenseEnabled ,
200+ showOperators : intellisenseEnabled ,
201+ showUnits : intellisenseEnabled ,
202+ showValues : intellisenseEnabled ,
203+ showConstants : intellisenseEnabled ,
204+ showEnums : intellisenseEnabled ,
205+ showEnumMembers : intellisenseEnabled ,
206+ showKeywords : intellisenseEnabled ,
207+ showWords : intellisenseEnabled ,
208+ showColors : intellisenseEnabled ,
209+ showFiles : intellisenseEnabled ,
210+ showReferences : intellisenseEnabled ,
211+ showFolders : intellisenseEnabled ,
212+ showTypeParameters : intellisenseEnabled ,
213+ showIssues : intellisenseEnabled ,
214+ showUsers : intellisenseEnabled ,
215+ showSnippets : intellisenseEnabled ,
216+ } ,
217+ } }
218+ />
219+ </ >
206220 )
207221}
208222
0 commit comments