mirror of
https://github.com/supabase/supabase.git
synced 2026-07-03 18:54:26 +08:00
* Init changes for sql fodlers * Added upsert logic in sql-editor-v2 valtio, hooked up with templates and quickstarts * Do up logic for creating new snippets by typing in /new or by clicking new query button * Do up logic for updating and deleting snippets * Do up logic for favourites and shared snippets * Do up logic for favourites and shared snippets * Fix * Fix saving indicator, add empty states for favorites and shared snippets * Implement sorting * Some minor QOL improvements * Minor fix on empty state for private snippets * Add delete folder mutation * Implement create and update folder * Fix reinstate with AI renaming for new snippets under folder * Support controlled multi select behaviour in private snippets * Undo changes to tree-view-multi-select * Support bulk deletes * Support moving queries + rendering queries in folders * Support deleting folders and creating a new folder when moving a query * Fix bug where renaming query removes content * Add initial loading state in sql editor nav + handle fallback if cannot retrieve content by id * Fix some spelling * Fix TS issue in sql folders mutation keys * Fix toggling favorite * Lint * Revert fallback behaviour in ]id] for now * Fix favorites and shared snippets not showing * Fix moving currently opened snippet leads to loading * Support bulk moving * Improve multi select logic a little * Nit lint * Reinstate AI retitling for untitled snippets when running query * Remove hardcode in useAFlag * Support creating new snippet in a folder directly * Fix sharing snippets that are within a folder * Fix sharing snippets within a folder * Fix favorite * Add loading state when fetching folder contents * Fix favoriting snippets in folders
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
|
|
import toast from 'react-hot-toast'
|
|
|
|
import { del, handleError } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
import { contentKeys } from './keys'
|
|
|
|
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-ignore [Joshen] API codegen issue
|
|
params: { path: { ref: projectRef }, query: { ids } },
|
|
signal,
|
|
})
|
|
|
|
if (error) throw handleError(error)
|
|
return data
|
|
}
|
|
|
|
export type DeleteSQLSnippetFoldersData = Awaited<ReturnType<typeof deleteSQLSnippetFolders>>
|
|
|
|
export const useSQLSnippetFoldersDeleteMutation = ({
|
|
onError,
|
|
onSuccess,
|
|
invalidateQueriesOnSuccess = true,
|
|
...options
|
|
}: Omit<
|
|
UseMutationOptions<DeleteSQLSnippetFoldersData, ResponseError, DeleteSQLSnippetFoldersVariables>,
|
|
'mutationFn'
|
|
> & {
|
|
invalidateQueriesOnSuccess?: boolean
|
|
} = {}) => {
|
|
const queryClient = useQueryClient()
|
|
|
|
return useMutation<DeleteSQLSnippetFoldersData, ResponseError, DeleteSQLSnippetFoldersVariables>(
|
|
(args) => deleteSQLSnippetFolders(args),
|
|
{
|
|
async onSuccess(data, variables, context) {
|
|
const { projectRef } = variables
|
|
if (invalidateQueriesOnSuccess) {
|
|
await queryClient.invalidateQueries(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,
|
|
}
|
|
)
|
|
}
|