mirror of
https://github.com/supabase/supabase.git
synced 2026-07-06 21:44:22 +08:00
* allow creating branching without git * update branching modals * add account connections * edit branch * copy * update copy * enable branch modal changes * add gitless branching flag * update account connections * merge page * merge experiment * update merge * update pull requests empty state * use diff query * branch diffing * diff query * Clean up * refinements to gitless branching * branching merge and status * link * branch function diffing * update styling * refactor * remove hook * error handling * move * remove enable branching modal * re-add github linker * abstract away enable and disable * toggle fixes * update logic to lean on connection status * update form logic * sheet layout * gitless flag * style and workflow updates * fix side panel size * fix duplicate onerror * copy changes * refetch * merge mutation copy * remove import * add cost * allow connection details on create * initial queries * push button * merge cleanup * Fix TS issues * Fix TS issues * Couple of clean ups * Revert hardcode in useFlag * Fix TS * layout issues and github check * refactor * refactor to use new field * cleanup * style * failed merge * error positioning * refactoring merge * workflow refactor * hook move * clarification with github integration * replace branch dropdown button * update repo picker * updates * remove modal * fix small nits * change defaults * clean up * disable if not gitless and no connection * clean up * always show workflow run id * optimistic * fix branch query * fix issues * fetch edge diff * confirm merge * update edge functions key --------- Co-authored-by: Joshen Lim <joshenlimek@gmail.com> Co-authored-by: Kevin Grüneberg <k.grueneberg1994@gmail.com> Co-authored-by: Alaister Young <a@alaisteryoung.com>
81 lines
2.3 KiB
TypeScript
81 lines
2.3 KiB
TypeScript
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
|
import { constructHeaders, fetchHandler, handleError } from 'data/fetchers'
|
|
import { BASE_PATH, IS_PLATFORM } from 'lib/constants'
|
|
import { ResponseError } from 'types'
|
|
import { edgeFunctionsKeys } from './keys'
|
|
|
|
export type EdgeFunctionBodyVariables = {
|
|
projectRef?: string
|
|
slug?: string
|
|
}
|
|
|
|
export type EdgeFunctionFile = {
|
|
name: string
|
|
content: string
|
|
}
|
|
|
|
export type EdgeFunctionBodyResponse = {
|
|
files: EdgeFunctionFile[]
|
|
}
|
|
|
|
export async function getEdgeFunctionBody(
|
|
{ projectRef, slug }: EdgeFunctionBodyVariables,
|
|
signal?: AbortSignal
|
|
) {
|
|
if (!projectRef) throw new Error('projectRef is required')
|
|
if (!slug) throw new Error('slug is required')
|
|
|
|
try {
|
|
// Get authorization headers
|
|
const headers = await constructHeaders({
|
|
'Content-Type': 'application/json',
|
|
})
|
|
|
|
// Send to our API for processing (the API will handle the fetch from v1 endpoint)
|
|
const parseResponse = await fetchHandler(`${BASE_PATH}/api/edge-functions/body`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({ projectRef, slug }),
|
|
headers,
|
|
credentials: 'include',
|
|
signal,
|
|
})
|
|
|
|
if (!parseResponse.ok) {
|
|
const { error } = await parseResponse.json()
|
|
handleError(
|
|
typeof error === 'object'
|
|
? error
|
|
: typeof error === 'string'
|
|
? { message: error }
|
|
: { message: 'Unknown error' }
|
|
)
|
|
}
|
|
|
|
const { files } = await parseResponse.json()
|
|
return files as EdgeFunctionFile[]
|
|
} catch (error) {
|
|
handleError(error)
|
|
return []
|
|
}
|
|
}
|
|
|
|
export type EdgeFunctionBodyData = Awaited<ReturnType<typeof getEdgeFunctionBody>>
|
|
export type EdgeFunctionBodyError = ResponseError
|
|
|
|
export const useEdgeFunctionBodyQuery = <TData = EdgeFunctionBodyData>(
|
|
{ projectRef, slug }: EdgeFunctionBodyVariables,
|
|
{
|
|
enabled = true,
|
|
...options
|
|
}: UseQueryOptions<EdgeFunctionBodyData, EdgeFunctionBodyError, TData> = {}
|
|
) =>
|
|
useQuery<EdgeFunctionBodyData, EdgeFunctionBodyError, TData>(
|
|
edgeFunctionsKeys.body(projectRef, slug),
|
|
({ signal }) => getEdgeFunctionBody({ projectRef, slug }, signal),
|
|
{
|
|
enabled:
|
|
IS_PLATFORM && enabled && typeof projectRef !== 'undefined' && typeof slug !== 'undefined',
|
|
...options,
|
|
}
|
|
)
|