From cd663a883b2faa2b16bf5e3b6957c50f73cd43f8 Mon Sep 17 00:00:00 2001 From: Ivan Vasilov Date: Wed, 6 Aug 2025 12:29:09 +0200 Subject: [PATCH] Minor fixes. --- apps/studio/lib/api/snippets.browser.ts | 2 +- .../platform/projects/[ref]/content/index.ts | 20 ++++++++++++------- apps/studio/pages/project/[ref]/sql/[id].tsx | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/apps/studio/lib/api/snippets.browser.ts b/apps/studio/lib/api/snippets.browser.ts index d6f3dcca605..b78b8f11319 100644 --- a/apps/studio/lib/api/snippets.browser.ts +++ b/apps/studio/lib/api/snippets.browser.ts @@ -6,7 +6,7 @@ import { v4 as uuidv4 } from 'uuid' * @param inputs - The array of strings to generate a UUID from * @returns A deterministic UUID v4 string */ -export function generateDeterministicUuid(inputs: (string | null)[]): string { +export function generateDeterministicUuid(inputs: (string | undefined | null)[]): string { const simpleHash = (str: string): number => { let hash = 0 if (str.length === 0) return hash diff --git a/apps/studio/pages/api/platform/projects/[ref]/content/index.ts b/apps/studio/pages/api/platform/projects/[ref]/content/index.ts index 5eb76d9e16b..44d1407fd98 100644 --- a/apps/studio/pages/api/platform/projects/[ref]/content/index.ts +++ b/apps/studio/pages/api/platform/projects/[ref]/content/index.ts @@ -104,18 +104,24 @@ const handlePost = async (req: NextApiRequest, res: NextApiResponse) => { } const handleDelete = async (req: NextApiRequest, res: NextApiResponse) => { - const { id } = req.query + const { ids } = req.query - if (!id || typeof id !== 'string') { - return res.status(400).json({ error: 'Snippet ID is required' }) + if (!ids || typeof ids !== 'string') { + return res.status(400).json({ error: 'Snippet IDs are required' }) + } + const snippetIds = ids.split(',').map((id) => id.trim()) + if (snippetIds.length === 0) { + return res.status(400).json({ error: 'No snippet IDs provided' }) } try { - await deleteSnippet(id) - return res.status(204).send(null) + for (const id of snippetIds) { + await deleteSnippet(id) + } + return res.status(200).send(snippetIds.map((id) => ({ id }))) } catch (error) { - console.error('Error deleting snippet:', error) - return res.status(500).json({ error: 'Failed to delete snippet' }) + console.error('Error deleting snippets:', error) + return res.status(500).json({ error: 'Failed to delete snippets' }) } } diff --git a/apps/studio/pages/project/[ref]/sql/[id].tsx b/apps/studio/pages/project/[ref]/sql/[id].tsx index 92e9567ed37..a0e60708a97 100644 --- a/apps/studio/pages/project/[ref]/sql/[id].tsx +++ b/apps/studio/pages/project/[ref]/sql/[id].tsx @@ -3,6 +3,7 @@ import { useEffect } from 'react' import { useParams } from 'common/hooks/useParams' import { SQLEditor } from 'components/interfaces/SQLEditor/SQLEditor' +import { untitledSnippetTitle } from 'components/interfaces/SQLEditor/SQLEditor.constants' import DefaultLayout from 'components/layouts/DefaultLayout' import { EditorBaseLayout } from 'components/layouts/editors/EditorBaseLayout' import { useEditorType } from 'components/layouts/editors/EditorsLayout.hooks' @@ -16,7 +17,6 @@ import { createTabId, useTabsStateSnapshot } from 'state/tabs' import type { NextPageWithLayout } from 'types' import { Button } from 'ui' import { Admonition } from 'ui-patterns' -import { untitledSnippetTitle } from 'components/interfaces/SQLEditor/SQLEditor.constants' const SqlEditor: NextPageWithLayout = () => { const router = useRouter()