mirror of
https://github.com/supabase/supabase.git
synced 2026-09-22 13:37:53 +08:00
0bebe50a76
## Summary * serialize SQL folder IDs as the comma-delimited API query value * add regression coverage for the folder deletion request ## Testing * `pnpm --filter studio exec vitest run data/content/sql-folders-delete-mutation.test.ts` * `pnpm exec prettier --check apps/studio/data/content/sql-folders-delete-mutation.ts apps/studio/data/content/sql-folders-delete-mutation.test.ts` * `pnpm --filter studio exec eslint data/content/sql-folders-delete-mutation.ts data/content/sql-folders-delete-mutation.test.ts` * `pnpm --filter studio exec tsc --noEmit --pretty false` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Fixed SQL snippet folder deletion requests so multiple selected folders are processed correctly. * Improved request handling by formatting folder identifiers consistently when submitting bulk deletions. * **Tests** * Added coverage to verify that deleting multiple SQL snippet folders sends the expected folder identifiers. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
65 lines
1.9 KiB
TypeScript
65 lines
1.9 KiB
TypeScript
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { contentKeys } from './keys'
|
|
import { del, handleError } from '@/data/fetchers'
|
|
import type { ResponseError, UseCustomMutationOptions } from '@/types'
|
|
|
|
export type DeleteSQLSnippetFoldersVariables = {
|
|
projectRef: string
|
|
ids: string[]
|
|
}
|
|
|
|
export async function deleteSQLSnippetFolders(
|
|
{ projectRef, ids }: DeleteSQLSnippetFoldersVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
const { data, error } = await del('/platform/projects/{ref}/content/folders', {
|
|
// @ts-expect-error The generated endpoint type omits its required `{ref}` path parameter.
|
|
params: { path: { ref: projectRef }, query: { ids: ids.join(',') } },
|
|
signal,
|
|
})
|
|
|
|
if (error) throw handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type DeleteSQLSnippetFoldersData = Awaited<ReturnType<typeof deleteSQLSnippetFolders>>
|
|
|
|
export const useSQLSnippetFoldersDeleteMutation = ({
|
|
onError,
|
|
onSuccess,
|
|
invalidateQueriesOnSuccess = true,
|
|
...options
|
|
}: Omit<
|
|
UseCustomMutationOptions<
|
|
DeleteSQLSnippetFoldersData,
|
|
ResponseError,
|
|
DeleteSQLSnippetFoldersVariables
|
|
>,
|
|
'mutationFn'
|
|
> & {
|
|
invalidateQueriesOnSuccess?: boolean
|
|
} = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation<DeleteSQLSnippetFoldersData, ResponseError, DeleteSQLSnippetFoldersVariables>({
|
|
mutationFn: (args) => deleteSQLSnippetFolders(args),
|
|
async onSuccess(data, variables, context) {
|
|
const { projectRef } = variables
|
|
if (invalidateQueriesOnSuccess) {
|
|
await queryClient.invalidateQueries({ queryKey: contentKeys.folders(projectRef) })
|
|
}
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to delete folder: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|