Skip to content

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

Only show save into new snippet button if project ref is present

Joshen Lim6237b0ac1c20
diff --git a/packages/ui/src/components/Command/CommandMenu.tsx b/packages/ui/src/components/Command/CommandMenu.tsx
index cf561b8155b..ccbc505b73f 100644
--- a/packages/ui/src/components/Command/CommandMenu.tsx
+++ b/packages/ui/src/components/Command/CommandMenu.tsx
@@ -61,7 +61,7 @@ const CommandMenu = ({ projectRef }: CommandMenuProps) => {
const router = useRouter()
const commandInputRef = useRef<ElementRef<typeof CommandInput>>(null)
- const { isOpen, setIsOpen, actions, search, setSearch, pages, setPages, currentPage, site } =
+ const { isOpen, setIsOpen, search, setSearch, pages, setPages, currentPage, site } =
useCommandMenu()
const showCommandInput = !currentPage || !CHAT_ROUTES.includes(currentPage)
diff --git a/packages/ui/src/components/Command/CommandMenuProvider.tsx b/packages/ui/src/components/Command/CommandMenuProvider.tsx
index 77c121db76c..c9bb681d4c8 100644
--- a/packages/ui/src/components/Command/CommandMenuProvider.tsx
+++ b/packages/ui/src/components/Command/CommandMenuProvider.tsx
@@ -18,7 +18,7 @@ export interface CommandMenuContextValue {
site: 'studio' | 'docs'
// Project metadata for easy retrieval
- project: { apiKeys: { anon?: string; service?: string } }
+ project: { ref?: string; apiKeys: { anon?: string; service?: string } }
// to do: remove this prop
// this is a temporary hack as ReactMarkdown fails our jest tests if we import the package within this UI package
@@ -85,7 +85,7 @@ const CommandMenuProvider = ({
setPages,
currentPage,
site,
- project: { apiKeys },
+ project: { ref: projectRef, apiKeys },
MarkdownHandler,
onSaveGeneratedSQL,
}}
diff --git a/packages/ui/src/components/Command/GenerateSQL.tsx b/packages/ui/src/components/Command/GenerateSQL.tsx
index 599d44f7bd3..e63f8cf8a96 100644
--- a/packages/ui/src/components/Command/GenerateSQL.tsx
+++ b/packages/ui/src/components/Command/GenerateSQL.tsx
@@ -3,7 +3,6 @@ import type { CreateCompletionResponse } from 'openai'
import { useCallback, useEffect, useReducer, useRef, useState } from 'react'
import {
Button,
- CodeBlock,
IconAlertCircle,
IconAlertTriangle,
IconCheck,
@@ -16,10 +15,9 @@ import {
import { cn } from './../../utils/cn'
import { AiIcon, AiIconChat } from './Command.icons'
-import { CommandGroup, CommandItem } from './Command.utils'
+import { CommandItem } from './Command.utils'
import { useCommandMenu } from './CommandMenuProvider'
import CopyToClipboard from 'react-copy-to-clipboard'
-import { noop } from 'lodash'
import { SAMPLE_QUERIES } from './Command.constants'
function getEdgeFunctionUrl() {
@@ -80,17 +78,13 @@ function promptDataReducer(
return [...current]
}
-const SQLOutputActions = ({
- answer,
- onSaveGeneratedSQL,
-}: {
- answer: string
- onSaveGeneratedSQL?: (answer: string, resolve: any) => void
-}) => {
+const SQLOutputActions = ({ answer }: { answer: string }) => {
const [showCopied, setShowCopied] = useState(false)
const [isSaving, setIsSaving] = useState(false)
const [isSaved, setIsSaved] = useState(false)
+ const { project, onSaveGeneratedSQL } = useCommandMenu()
+
const applyCallback = () =>
onSaveGeneratedSQL !== undefined
? new Promise((resolve) => onSaveGeneratedSQL(answer, resolve))
@@ -132,7 +126,7 @@ const SQLOutputActions = ({
{showCopied ? 'Copied' : 'Copy SQL'}
</Button>
</CopyToClipboard>
- {onSaveGeneratedSQL !== undefined && (
+ {project?.ref !== undefined && onSaveGeneratedSQL !== undefined && (
<Button
type="default"
loading={isSaving}
@@ -299,16 +293,10 @@ Postgres SQL query:
<div className="bg-scale-700 h-[21px] w-[13px] mt-1 animate-pulse animate-bounce"></div>
) : (
<div className="space-y-2 flex-grow">
- {/* @ts-expect-error */}
<MarkdownHandler className="prose dark:prose-dark bg-scale-300 px-4 py-4 rounded-md w-full">
{prompt.answer}
</MarkdownHandler>
- {!isResponding && (
- <SQLOutputActions
- answer={prompt.answer}
- onSaveGeneratedSQL={onSaveGeneratedSQL}
- />
- )}
+ {!isResponding && <SQLOutputActions answer={prompt.answer} />}
</div>
)}
</>