mirror of
https://github.com/supabase/supabase.git
synced 2026-10-18 15:49:09 +03:00
* Migrate all API calls to data folder. * Remove unused mutation. * MInor leftover type fixes. * chore: Make the `StorageExplorerStore` fully typed (#23397) * Migrate all API calls to data folder. * Convert the poor man enums into proper enums. * Add types to most of the methods. * Add types around the methods for uploading files. * Add types for file cache. * Add types for buckets. * Fix bunch of type errors. * Add types to all store methods. Fix all types in components related to the store. * Remove all anys from the Storage components. * Fix the multiple selection. * Fix the selected checkbox. * Set all private methods to private and delete some unneeded code. * Remove unneeded mutation. * Update all mutations for storage explorer to follow template syntax * Update apps/studio/components/to-be-cleaned/Storage/StorageExplorer/PreviewPane.tsx Co-authored-by: Alaister Young <alaister@users.noreply.github.com> --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com> Co-authored-by: Alaister Young <alaister@users.noreply.github.com>
64 lines
1.6 KiB
TypeScript
64 lines
1.6 KiB
TypeScript
import { UseMutationOptions, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
|
|
import { del, handleError } from 'data/fetchers'
|
|
import toast from 'react-hot-toast'
|
|
import { ResponseError } from 'types'
|
|
|
|
type DeleteBucketObjectParams = {
|
|
projectRef: string
|
|
bucketId?: string
|
|
paths: string[]
|
|
}
|
|
export const deleteBucketObject = async (
|
|
{ projectRef, bucketId, paths }: DeleteBucketObjectParams,
|
|
signal?: AbortSignal
|
|
) => {
|
|
if (!bucketId) throw new Error('bucketId is required')
|
|
|
|
const { data, error } = await del('/platform/storage/{ref}/buckets/{id}/objects', {
|
|
params: {
|
|
path: {
|
|
ref: projectRef,
|
|
id: bucketId,
|
|
},
|
|
},
|
|
body: {
|
|
paths,
|
|
},
|
|
signal,
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type BucketObjectDeleteData = Awaited<ReturnType<typeof deleteBucketObject>>
|
|
|
|
export const useBucketObjectDeleteMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseMutationOptions<BucketObjectDeleteData, ResponseError, DeleteBucketObjectParams>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
return useMutation<BucketObjectDeleteData, ResponseError, DeleteBucketObjectParams>(
|
|
(vars) => deleteBucketObject(vars),
|
|
{
|
|
async onSuccess(data, variables, context) {
|
|
// [Joshen] TODO figure out what queries to invalidate
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to delete bucket object: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
}
|
|
)
|
|
}
|