mirror of
https://github.com/supabase/supabase.git
synced 2026-10-15 14:19:11 +03: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 * add review requested at * gitless check * request review * use requestReview * use new review boolean * unnecessary comment * ready for review route * hide removed functions for now * type fix * codegen * Fix the types. --------- 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> Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
70 lines
1.7 KiB
TypeScript
70 lines
1.7 KiB
TypeScript
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { handleError, patch } from 'data/fetchers'
|
|
import type { ResponseError } from 'types'
|
|
import { branchKeys } from './keys'
|
|
|
|
export type BranchUpdateVariables = {
|
|
id: string
|
|
projectRef: string
|
|
branchName?: string
|
|
gitBranch?: string
|
|
persistent?: boolean
|
|
requestReview?: boolean
|
|
}
|
|
|
|
export async function updateBranch({
|
|
id,
|
|
branchName,
|
|
gitBranch,
|
|
persistent,
|
|
requestReview,
|
|
}: BranchUpdateVariables) {
|
|
const { data, error } = await patch('/v1/branches/{branch_id}', {
|
|
params: {
|
|
path: { branch_id: id },
|
|
},
|
|
body: {
|
|
branch_name: branchName,
|
|
git_branch: gitBranch,
|
|
persistent,
|
|
request_review: requestReview,
|
|
},
|
|
})
|
|
|
|
if (error) handleError(error)
|
|
return data
|
|
}
|
|
|
|
type BranchUpdateData = Awaited<ReturnType<typeof updateBranch>>
|
|
|
|
export const useBranchUpdateMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseMutationOptions<BranchUpdateData, ResponseError, BranchUpdateVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
return useMutation<BranchUpdateData, ResponseError, BranchUpdateVariables>(
|
|
(vars) => updateBranch(vars),
|
|
{
|
|
async onSuccess(data, variables, context) {
|
|
const { projectRef } = variables
|
|
await queryClient.invalidateQueries(branchKeys.list(projectRef))
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to update branch: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
}
|
|
)
|
|
}
|