Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Small fixes

Joshen Limba4c54fa64c8
diff --git a/studio/components/interfaces/App/CommandMenuWrapper.tsx b/studio/components/interfaces/App/CommandMenuWrapper.tsx
index 81745e56e65..2e0366b33fa 100644
--- a/studio/components/interfaces/App/CommandMenuWrapper.tsx
+++ b/studio/components/interfaces/App/CommandMenuWrapper.tsx
@@ -3,24 +3,24 @@ import ReactMarkdown from 'react-markdown'
import { PropsWithChildren } from 'react'
import { useParams } from 'common'
import { CommandMenuProvider } from 'ui'
+import { observer } from 'mobx-react-lite'
import { PermissionAction } from '@supabase/shared-types/out/constants'
+import { uuidv4 } from 'lib/helpers'
import { checkPermissions, useStore } from 'hooks'
import { createSqlSnippetSkeleton } from '../SQLEditor/SQLEditor.utils'
import { useSqlEditorStateSnapshot } from 'state/sql-editor'
import { useProfileQuery } from 'data/profile/profile-query'
import { SqlSnippet } from 'data/content/sql-snippets-query'
import { useProjectApiQuery } from 'data/config/project-api-query'
-import { useContentCreateMutation } from 'data/content/content-create-mutation'
-const CommandMenuWrapper = ({ children }: PropsWithChildren<{}>) => {
+const CommandMenuWrapper = observer(({ children }: PropsWithChildren<{}>) => {
const { ref } = useParams()
const { ui } = useStore()
const snap = useSqlEditorStateSnapshot()
const { data: profile } = useProfileQuery()
const { data: settings } = useProjectApiQuery({ projectRef: ref })
- const { mutateAsync: createContent } = useContentCreateMutation()
const canCreateSQLSnippet = checkPermissions(PermissionAction.CREATE, 'user_content', {
resource: { type: 'sql', owner_id: profile?.id },
subject: { id: profile?.id },
@@ -34,10 +34,11 @@ const CommandMenuWrapper = ({ children }: PropsWithChildren<{}>) => {
const onSaveGeneratedSQL = async (answer: string, resolve: any) => {
if (!ref) return console.error('Project ref is required')
if (!canCreateSQLSnippet) {
- return ui.setNotification({
+ ui.setNotification({
category: 'info',
- message: 'Your queries will not be saved as you do not have sufficient permissions',
+ message: 'Unable to save query as you do not have sufficient permissions for this project',
})
+ return resolve()
}
// Remove markdown syntax from returned answer
@@ -52,23 +53,17 @@ ${answer}
`.trim()
try {
- const payload = createSqlSnippetSkeleton({
+ const snippet = createSqlSnippetSkeleton({
name: 'Generated query',
owner_id: profile?.id,
sql: formattedSql,
})
- await createContent(
- { projectRef: ref, payload },
- {
- onSuccess(data) {
- snap.addSnippet(data.content[0] as SqlSnippet, ref)
- ui.setNotification({
- category: 'success',
- message: `Successfully saved snippet!`,
- })
- },
- }
- )
+ const data = { ...snippet, id: uuidv4() }
+ snap.addSnippet(data as SqlSnippet, ref, true)
+ ui.setNotification({
+ category: 'success',
+ message: `Successfully saved snippet!`,
+ })
} catch (error: any) {
ui.setNotification({
category: 'error',
@@ -90,6 +85,6 @@ ${answer}
{children}
</CommandMenuProvider>
)
-}
+})
export default CommandMenuWrapper
diff --git a/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx b/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx
index 7aae99dc9f0..43548b7ec7d 100644
--- a/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx
+++ b/studio/components/interfaces/SQLEditor/SQLTemplates/SQLTemplates.tsx
@@ -7,12 +7,12 @@ import { checkPermissions, useStore } from 'hooks'
import { useProfileQuery } from 'data/profile/profile-query'
import { SQL_TEMPLATES } from 'components/interfaces/SQLEditor/SQLEditor.constants'
import SQLCard from './SQLCard'
-import { useContentCreateMutation } from 'data/content/content-create-mutation'
import { createSqlSnippetSkeleton } from '../SQLEditor.utils'
import { useParams } from 'common'
import { useRouter } from 'next/router'
import { SqlSnippet } from 'data/content/sql-snippets-query'
import { useSqlEditorStateSnapshot } from 'state/sql-editor'
+import { uuidv4 } from 'lib/helpers'
const SQLTemplates = observer(() => {
const { ui } = useStore()
@@ -22,7 +22,6 @@ const SQLTemplates = observer(() => {
const [sql, quickStart] = partition(SQL_TEMPLATES, { type: 'template' })
const snap = useSqlEditorStateSnapshot()
- const { mutateAsync: createContent } = useContentCreateMutation()
const canCreateSQLSnippet = checkPermissions(PermissionAction.CREATE, 'user_content', {
resource: { type: 'sql', owner_id: profile?.id },
subject: { id: profile?.id },
@@ -40,17 +39,10 @@ const SQLTemplates = observer(() => {
}
try {
- const payload = createSqlSnippetSkeleton({ sql, name, owner_id: profile?.id })
- const response = await createContent(
- { projectRef: ref, payload },
- {
- onSuccess(data) {
- snap.addSnippet(data.content[0] as SqlSnippet, ref)
- },
- }
- )
- const snippetId = response.content[0].id
- router.push(`/project/${ref}/sql/${snippetId}`)
+ const snippet = createSqlSnippetSkeleton({ name, sql, owner_id: profile?.id })
+ const data = { ...snippet, id: uuidv4() }
+ snap.addSnippet(data as SqlSnippet, ref, true)
+ router.push(`/project/${ref}/sql/${data.id}`)
} catch (error: any) {
ui.setNotification({
category: 'error',
diff --git a/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx b/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
index 0fa952f2fcc..6ba77a93994 100644
--- a/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
+++ b/studio/components/layouts/SQLEditorLayout/SQLEditorMenu.tsx
@@ -54,8 +54,6 @@ const SideBarContent = observer(() => {
subject: { id: profile?.id },
})
- // [Joshen TODO] Removed optimistic query creation logic for now, need to figure out
- // how to do that after using ids as part of the URL
const handleNewQuery = async () => {
if (!ref) return console.error('Project ref is required')
if (!canCreateSQLSnippet) {
diff --git a/studio/hooks/misc/useCheckPermissions.ts b/studio/hooks/misc/useCheckPermissions.ts
index 9f9aa4f5883..3866b4295ad 100644
--- a/studio/hooks/misc/useCheckPermissions.ts
+++ b/studio/hooks/misc/useCheckPermissions.ts
@@ -1,4 +1,4 @@
-import { useFlag, useStore } from 'hooks'
+import { useStore } from 'hooks'
import jsonLogic from 'json-logic-js'
import { IS_PLATFORM } from 'lib/constants'