Skip to content

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

Fix tabs renaming via AI not updating tab label (#35218)

Joshen Lim2c05fb388130
diff --git a/apps/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx b/apps/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx
index 591f8a63c04..b40b57692af 100644
--- a/apps/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/RenameQueryModal.tsx
@@ -95,7 +95,6 @@ const RenameQueryModal = ({
// [Joshen] For SQL V2 - content is loaded on demand so we need to fetch the data if its not already loaded in the valtio state
if (!('content' in localSnippet)) {
localSnippet = await getContentById({ projectRef: ref, id })
-
snapV2.addSnippet({ projectRef: ref, snippet: localSnippet })
}
@@ -109,10 +108,12 @@ const RenameQueryModal = ({
})
snapV2.renameSnippet({ id, name: nameInput, description: descriptionInput })
+
if (isSQLEditorTabsEnabled && ref) {
const tabId = createTabId('sql', { id })
updateTab(ref, tabId, { label: nameInput })
}
+
toast.success('Successfully renamed snippet!')
if (onComplete) onComplete()
} catch (error: any) {
diff --git a/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx b/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
index 4a10fc3ad7c..d4577ae1a8f 100644
--- a/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/SQLEditor.tsx
@@ -53,6 +53,7 @@ import {
cn,
} from 'ui'
import { useSnapshot } from 'valtio'
+import { useIsSQLEditorTabsEnabled } from '../App/FeaturePreview/FeaturePreviewContext'
import { subscriptionHasHipaaAddon } from '../Billing/Subscription/Subscription.utils'
import { useSqlEditorDiff, useSqlEditorPrompt } from './hooks'
import { RunQueryWarningModal } from './RunQueryWarningModal'
@@ -98,13 +99,13 @@ export const SQLEditor = () => {
const isOptedInToAI = useOrgOptedIntoAi()
const [selectedSchemas] = useSchemasForAi(project?.ref!)
const includeSchemaMetadata = isOptedInToAI || !IS_PLATFORM
+ const isSQLEditorTabsEnabled = useIsSQLEditorTabsEnabled()
const {
sourceSqlDiff,
setSourceSqlDiff,
selectedDiffType,
setSelectedDiffType,
- pendingTitle,
setIsAcceptDiffLoading,
isDiffOpen,
defaultSqlDiff,
@@ -216,6 +217,10 @@ export const SQLEditor = () => {
try {
const { title: name } = await generateSqlTitle({ sql })
snapV2.renameSnippet({ id, name })
+ if (isSQLEditorTabsEnabled && ref) {
+ const tabId = createTabId('sql', { id })
+ updateTab(ref, tabId, { label: name })
+ }
} catch (error) {
// [Joshen] No error handler required as this happens in the background and not necessary to ping the user
}
@@ -431,10 +436,6 @@ export const SQLEditor = () => {
range: editorModel.getFullModelRange(),
},
])
-
- if (pendingTitle) {
- snapV2.renameSnippet({ id, name: pendingTitle })
- }
}
sendEvent({
@@ -450,16 +451,7 @@ export const SQLEditor = () => {
setIsAcceptDiffLoading(false)
}
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [
- sourceSqlDiff,
- selectedDiffType,
- handleNewQuery,
- generateSqlTitle,
- router,
- id,
- pendingTitle,
- snapV2,
- ])
+ }, [sourceSqlDiff, selectedDiffType, handleNewQuery, generateSqlTitle, router, id, snapV2])
const discardAiHandler = useCallback(() => {
sendEvent({
diff --git a/apps/studio/components/interfaces/SQLEditor/hooks.ts b/apps/studio/components/interfaces/SQLEditor/hooks.ts
index 29d8d0cc824..8c5550ca94a 100644
--- a/apps/studio/components/interfaces/SQLEditor/hooks.ts
+++ b/apps/studio/components/interfaces/SQLEditor/hooks.ts
@@ -67,7 +67,6 @@ export const useNewQuery = () => {
export function useSqlEditorDiff() {
const [sourceSqlDiff, setSourceSqlDiff] = useState<ContentDiff>()
const [selectedDiffType, setSelectedDiffType] = useState<DiffType>()
- const [pendingTitle, setPendingTitle] = useState<string>()
const [isAcceptDiffLoading, setIsAcceptDiffLoading] = useState(false)
const isDiffOpen = !!sourceSqlDiff
@@ -91,7 +90,6 @@ export function useSqlEditorDiff() {
const closeDiff = useCallback(() => {
setSourceSqlDiff(undefined)
- setPendingTitle(undefined)
setSelectedDiffType(undefined)
}, [])
@@ -100,8 +98,6 @@ export function useSqlEditorDiff() {
setSourceSqlDiff,
selectedDiffType,
setSelectedDiffType,
- pendingTitle,
- setPendingTitle,
isAcceptDiffLoading,
setIsAcceptDiffLoading,
isDiffOpen,