Files
supabase/apps/studio/data/integrations/github-connections-query.ts
Joshen Lim e98a302428 Refactor merge page into smaller components + add admonition if branch cannot be merged via dashboard (#45515)
## Context

Main fix is actually just the disabled check on the "Merge branch"
button

We're preventing merging of branches via the dashboard if the project
has GH integration + "Deploy to production" enabled (the latter we're
checking via if the `git_branch` property from the main branch exists,
from the GET branches API endpoint)

However, the `git_branch` property persists even after disabling the GH
integration (by design), and hence we were incorrectly disabling the
"Merge branch" button if the user removed the GH integration. Hence the
fix is to also check if the project has an active GH integration

## Other changes
- Refactored the merge page into smaller components
- Added an admonition to callout the "Deploy to production" + what steps
to take (otherwise it's not clear at all what to do in this scenario)
<img width="1451" height="524" alt="image"
src="https://github.com/user-attachments/assets/9df7d432-b220-4f71-b8f4-5ed0fd426afc"
/>


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Redesigned merge request page interface with dedicated components for
title, subtitle, and merge actions, improving user clarity and
experience.
* Added GitHub production deployment restriction messaging—users cannot
proceed with merge requests when this integration deployment method is
enabled.

* **Refactor**
* Enhanced GitHub integration connection query patterns and overall code
organization.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-05 16:32:37 +08:00

66 lines
2.1 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { useMemo } from 'react'
import { integrationKeys } from './keys'
import { get, handleError } from '@/data/fetchers'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
import type { ResponseError, UseCustomQueryOptions } from '@/types'
export type GitHubConnectionsVariables = {
organizationId?: number
}
export async function getGitHubConnections(
{ organizationId }: GitHubConnectionsVariables,
signal?: AbortSignal
) {
if (!organizationId) throw new Error('organizationId is required')
const { data, error } = await get('/platform/integrations/github/connections', {
params: {
query: {
organization_id: organizationId,
},
},
signal,
})
if (error) handleError(error)
return data.connections
}
export type GitHubConnectionsData = Awaited<ReturnType<typeof getGitHubConnections>>
export type GitHubConnectionsError = ResponseError
export type GitHubConnection = GitHubConnectionsData[0]
export const useGitHubConnectionsQuery = <TData = GitHubConnectionsData>(
{ organizationId }: GitHubConnectionsVariables,
{
enabled = true,
...options
}: UseCustomQueryOptions<GitHubConnectionsData, GitHubConnectionsError, TData> = {}
) => {
return useQuery<GitHubConnectionsData, GitHubConnectionsError, TData>({
queryKey: integrationKeys.githubConnectionsList(organizationId),
queryFn: ({ signal }) => getGitHubConnections({ organizationId }, signal),
enabled: enabled && typeof organizationId !== 'undefined',
staleTime: 30 * 60 * 1000,
...options,
})
}
export const useProjectGitHubConnectionQuery = ({ ref }: { ref?: string }) => {
const { data: organization } = useSelectedOrganizationQuery()
const { data: connections, ...props } = useGitHubConnectionsQuery(
{ organizationId: organization?.id },
{ enabled: !!ref && !!organization?.id }
)
const existingConnection = useMemo(
() => connections?.find((c) => c.project.ref === ref),
[connections, ref]
)
return { data: existingConnection, ...props }
}