Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,16 @@ export const EditBranchModal = ({ branch, visible, onClose }: EditBranchModalPro

const onSubmit = (data: z.infer<typeof FormSchema>) => {
if (!projectRef) return console.error('Project ref is required')
if (!branch?.id) return console.error('Branch ID is required')
if (!ref) return console.error('Branch ref is required')

const payload: {
branchRef: string
projectRef: string
id: string
branchName: string
gitBranch?: string
} = {
branchRef: ref,
projectRef,
id: branch.id,
branchName: data.branchName,
}

Expand Down
10 changes: 4 additions & 6 deletions apps/studio/components/interfaces/BranchManagement/Overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ const PreviewBranchActions = ({
}) => {
const gitlessBranching = useIsBranching2Enabled()
const queryClient = useQueryClient()
const projectRef = branch.parent_project_ref ?? branch.project_ref
const { project_ref: branchRef, parent_project_ref: projectRef } = branch

const { can: canDeleteBranches } = useAsyncCheckPermissions(
PermissionAction.DELETE,
Expand All @@ -178,7 +178,7 @@ const PreviewBranchActions = ({
'preview_branches'
)

const { data } = useBranchQuery({ projectRef, id: branch.id })
const { data } = useBranchQuery({ projectRef, branchRef })
const isBranchActiveHealthy = data?.status === 'ACTIVE_HEALTHY'

const [showConfirmResetModal, setShowConfirmResetModal] = useState(false)
Expand All @@ -203,13 +203,11 @@ const PreviewBranchActions = ({
})

const onConfirmReset = () => {
if (!projectRef) return
resetBranch({ id: branch.id, projectRef })
resetBranch({ branchRef, projectRef })
}

const onTogglePersistent = () => {
if (!projectRef) return
updateBranch({ id: branch.id, projectRef, persistent: !branch.persistent })
updateBranch({ branchRef, projectRef, persistent: !branch.persistent })
}

return (
Expand Down
12 changes: 4 additions & 8 deletions apps/studio/components/interfaces/BranchManagement/ReviewRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import { MoreVertical, X } from 'lucide-react'
import { useRouter } from 'next/router'

import { useQueryClient } from '@tanstack/react-query'
import { useParams } from 'common'
import { useBranchUpdateMutation } from 'data/branches/branch-update-mutation'
import type { Branch } from 'data/branches/branches-query'
import { branchKeys } from 'data/branches/keys'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { toast } from 'sonner'
import {
Button,
Expand All @@ -23,15 +21,14 @@ interface ReviewRowProps {

export const ReviewRow = ({ branch }: ReviewRowProps) => {
const router = useRouter()
const { data: project } = useSelectedProjectQuery()
const { ref: projectRef } = useParams()
const queryClient = useQueryClient()
const { project_ref: branchRef, parent_project_ref: projectRef } = branch

const { mutate: updateBranch, isLoading: isUpdating } = useBranchUpdateMutation({
onSuccess: () => {
toast.success('Branch marked as not ready for review')
queryClient.invalidateQueries({
queryKey: branchKeys.list(project?.parent_project_ref || projectRef),
queryKey: branchKeys.list(projectRef),
})
},
onError: (error) => {
Expand All @@ -40,16 +37,15 @@ export const ReviewRow = ({ branch }: ReviewRowProps) => {
})

const handleRowClick = () => {
router.push(`/project/${branch.project_ref}/merge`)
router.push(`/project/${branchRef}/merge`)
}

const handleNotReadyForReview = (e?: Event) => {
e?.preventDefault()
e?.stopPropagation()
if (!projectRef) return

updateBranch({
id: branch.id,
branchRef,
projectRef,
requestReview: false,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ const GitHubIntegrationConnectionForm = ({
},
})

if (!prodBranch?.id) {
if (!prodBranch) {
createBranch({
projectRef: selectedProject.ref,
branchName: 'main',
Expand All @@ -251,7 +251,7 @@ const GitHubIntegrationConnectionForm = ({
})
} else {
updateBranch({
id: prodBranch.id,
branchRef: prodBranch.project_ref,
projectRef: selectedProject.ref,
gitBranch: data.branchName,
})
Expand Down Expand Up @@ -291,9 +291,9 @@ const GitHubIntegrationConnectionForm = ({
},
})

if (prodBranch?.id) {
if (prodBranch) {
updateBranch({
id: prodBranch.id,
branchRef: prodBranch.project_ref,
projectRef: selectedProject.ref,
gitBranch: data.enableProductionSync ? data.branchName : '',
branchName: data.branchName || 'main',
Expand Down
12 changes: 9 additions & 3 deletions apps/studio/components/interfaces/UnifiedLogs/UnifiedLogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { useQueryStates } from 'nuqs'
import { useEffect, useMemo, useState } from 'react'

import { useParams } from 'common'
import { useDebounce, useParams } from 'common'
import { arrSome, inDateRange } from 'components/ui/DataTable/DataTable.utils'
import { DataTableFilterCommand } from 'components/ui/DataTable/DataTableFilters/DataTableFilterCommand'
import { DataTableHeaderLayout } from 'components/ui/DataTable/DataTableHeaderLayout'
Expand Down Expand Up @@ -245,7 +245,8 @@ export const UnifiedLogs = () => {
})
}, [facets])

useEffect(() => {
// Debounced filter application to avoid too many API calls when user clicks multiple filters quickly
const applyFilterSearch = () => {
const columnFiltersWithNullable = filterFields.map((field) => {
const filterValue = columnFilters.find((filter) => filter.id === field.value)
if (!filterValue) return { id: field.value, value: null }
Expand All @@ -262,9 +263,14 @@ export const UnifiedLogs = () => {
)

setSearch(search)
}

const debouncedApplyFilterSearch = useDebounce(applyFilterSearch, 1000)

useEffect(() => {
debouncedApplyFilterSearch()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [columnFilters])
}, [columnFilters, debouncedApplyFilterSearch])

useEffect(() => {
setSearch({ sort: sorting?.[0] || null })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const MergeRequestButton = () => {
if (!projectRef || !selectedBranch || selectedBranch.is_default || selectedBranch.git_branch)
return null

const hasReviewRequested = !!selectedBranch?.review_requested_at
const hasReviewRequested = !!selectedBranch.review_requested_at
const buttonLabel = hasReviewRequested ? 'Review merge request' : 'Open merge request'

const handleClick = () => {
Expand All @@ -42,7 +42,7 @@ export const MergeRequestButton = () => {
} else {
updateBranch(
{
id: selectedBranch.id,
branchRef: selectedBranch.project_ref,
projectRef,
requestReview: true,
},
Expand Down
4 changes: 0 additions & 4 deletions apps/studio/csp.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ const SUPABASE_ASSETS_URL =
? 'https://frontend-assets.supabase.green'
: 'https://frontend-assets.supabase.com'
const POSTHOG_URL = isDevOrStaging ? 'https://ph.supabase.green' : 'https://ph.supabase.com'
// Required for feature flags and other PostHog features
const POSTHOG_EXTERNAL_URL = 'https://*.posthog.com'

const USERCENTRICS_URLS = 'https://*.usercentrics.eu'
const USERCENTRICS_APP_URL = 'https://app.usercentrics.eu'
Expand Down Expand Up @@ -104,7 +102,6 @@ module.exports.getCSP = function getCSP() {
STAPE_URL,
GOOGLE_MAPS_API_URL,
POSTHOG_URL,
POSTHOG_EXTERNAL_URL,
...(!!NIMBUS_PROD_PROJECTS_URL ? [NIMBUS_PROD_PROJECTS_URL, NIMBUS_PROD_PROJECTS_URL_WS] : []),
]
const SCRIPT_SRC_URLS = [
Expand All @@ -114,7 +111,6 @@ module.exports.getCSP = function getCSP() {
SUPABASE_ASSETS_URL,
STAPE_URL,
POSTHOG_URL,
POSTHOG_EXTERNAL_URL,
]
const FRAME_SRC_URLS = [HCAPTCHA_ASSET_URL, STRIPE_JS_URL, STAPE_URL]
const IMG_SRC_URLS = [
Expand Down
10 changes: 5 additions & 5 deletions apps/studio/data/branches/branch-delete-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { BranchesData } from './branches-query'
import { branchKeys } from './keys'

export type BranchDeleteVariables = {
id: string
branchRef: string
projectRef: string
}

export async function deleteBranch({ id }: Pick<BranchDeleteVariables, 'id'>) {
export async function deleteBranch({ branchRef }: Pick<BranchDeleteVariables, 'branchRef'>) {
const { data, error } = await del('/v1/branches/{branch_id_or_ref}', {
params: { path: { branch_id_or_ref: id } },
params: { path: { branch_id_or_ref: branchRef } },
})

if (error) handleError(error)
Expand All @@ -35,7 +35,7 @@ export const useBranchDeleteMutation = ({
(vars) => deleteBranch(vars),
{
async onSuccess(data, variables, context) {
const { projectRef } = variables
const { branchRef, projectRef } = variables
setTimeout(() => {
queryClient.invalidateQueries(branchKeys.list(projectRef))
}, 5000)
Expand All @@ -44,7 +44,7 @@ export const useBranchDeleteMutation = ({
branchKeys.list(projectRef)
)
if (branches) {
const updatedBranches = branches.filter((branch) => branch.id !== variables.id)
const updatedBranches = branches.filter((branch) => branch.project_ref !== branchRef)
queryClient.setQueryData(branchKeys.list(projectRef), updatedBranches)
}

Expand Down
16 changes: 8 additions & 8 deletions apps/studio/data/branches/branch-diff-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import type { ResponseError } from 'types'
import { branchKeys } from './keys'

export type BranchDiffVariables = {
branchId: string
branchRef: string
projectRef: string
includedSchemas?: string
}

export async function getBranchDiff({
branchId,
branchRef,
includedSchemas,
}: Pick<BranchDiffVariables, 'branchId' | 'includedSchemas'>) {
}: Pick<BranchDiffVariables, 'branchRef' | 'includedSchemas'>) {
const { data: diffData, error } = await get('/v1/branches/{branch_id_or_ref}/diff', {
params: {
path: { branch_id_or_ref: branchId },
path: { branch_id_or_ref: branchRef },
query: includedSchemas ? { included_schemas: includedSchemas } : undefined,
},
headers: {
Expand All @@ -41,17 +41,17 @@ export async function getBranchDiff({
type BranchDiffData = Awaited<ReturnType<typeof getBranchDiff>>

export const useBranchDiffQuery = (
{ branchId, projectRef, includedSchemas }: BranchDiffVariables,
{ branchRef, projectRef, includedSchemas }: BranchDiffVariables,
{
enabled = true,
...options
}: Omit<UseQueryOptions<BranchDiffData, ResponseError>, 'queryKey' | 'queryFn'> = {}
) =>
useQuery<BranchDiffData, ResponseError>(
branchKeys.diff(projectRef, branchId),
() => getBranchDiff({ branchId, includedSchemas }),
branchKeys.diff(projectRef, branchRef),
() => getBranchDiff({ branchRef, includedSchemas }),
{
enabled: IS_PLATFORM && enabled && typeof branchId !== 'undefined' && branchId !== '',
enabled: IS_PLATFORM && enabled && Boolean(branchRef),
...options,
}
)
11 changes: 3 additions & 8 deletions apps/studio/data/branches/branch-merge-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@ import { getBranchDiff } from './branch-diff-query'
import { upsertMigration } from '../database/migration-upsert-mutation'

export type BranchMergeVariables = {
id: string
branchProjectRef: string
baseProjectRef: string
migration_version?: string
}

export async function mergeBranch({
id,
branchProjectRef,
migration_version,
}: BranchMergeVariables) {
export async function mergeBranch({ branchProjectRef, migration_version }: BranchMergeVariables) {
// Step 1: Get the diff output from the branch
const diffContent = await getBranchDiff({ branchId: id })
const diffContent = await getBranchDiff({ branchRef: branchProjectRef })

let migrationCreated = false

Expand All @@ -41,7 +36,7 @@ export async function mergeBranch({

// Step 3: Call POST /v1/branches/id/merge to merge the branch
const { data, error } = await post('/v1/branches/{branch_id_or_ref}/merge', {
params: { path: { branch_id_or_ref: id } },
params: { path: { branch_id_or_ref: branchProjectRef } },
body: { migration_version },
})

Expand Down
6 changes: 3 additions & 3 deletions apps/studio/data/branches/branch-push-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import type { ResponseError } from 'types'
import { branchKeys } from './keys'

export type BranchPushVariables = {
id: string
branchRef: string
projectRef: string
}

export async function pushBranch({ id }: Pick<BranchPushVariables, 'id'>) {
export async function pushBranch({ branchRef }: Pick<BranchPushVariables, 'branchRef'>) {
const { data, error } = await post('/v1/branches/{branch_id_or_ref}/push', {
params: { path: { branch_id_or_ref: id } },
params: { path: { branch_id_or_ref: branchRef } },
body: {},
})

Expand Down
16 changes: 8 additions & 8 deletions apps/studio/data/branches/branch-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import type { ResponseError } from 'types'
import { branchKeys } from './keys'

export type BranchVariables = {
branchRef?: string
projectRef?: string
id?: string
}

export async function getBranch({ id }: BranchVariables, signal?: AbortSignal) {
if (!id) throw new Error('id is required')
export async function getBranch({ branchRef }: BranchVariables, signal?: AbortSignal) {
if (!branchRef) throw new Error('branchRef is required')

const { data, error } = await get(`/v1/branches/{branch_id_or_ref}`, {
params: { path: { branch_id_or_ref: id } },
params: { path: { branch_id_or_ref: branchRef } },
signal,
})

Expand All @@ -26,14 +26,14 @@ export type BranchData = Awaited<ReturnType<typeof getBranch>>
export type BranchError = ResponseError

export const useBranchQuery = <TData = BranchData>(
{ projectRef, id }: BranchVariables,
{ projectRef, branchRef }: BranchVariables,
{ enabled = true, ...options }: UseQueryOptions<BranchData, BranchError, TData> = {}
) =>
useQuery<BranchData, BranchError, TData>(
branchKeys.detail(projectRef, id),
({ signal }) => getBranch({ id }, signal),
branchKeys.detail(projectRef, branchRef),
({ signal }) => getBranch({ branchRef }, signal),
{
enabled: IS_PLATFORM && enabled && typeof id !== 'undefined',
enabled: IS_PLATFORM && enabled && Boolean(branchRef),
...options,
}
)
6 changes: 3 additions & 3 deletions apps/studio/data/branches/branch-reset-mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import type { ResponseError } from 'types'
import { branchKeys } from './keys'

export type BranchResetVariables = {
id: string
branchRef: string
projectRef: string
}

export async function resetBranch({ id }: Pick<BranchResetVariables, 'id'>) {
export async function resetBranch({ branchRef }: Pick<BranchResetVariables, 'branchRef'>) {
const { data, error } = await post('/v1/branches/{branch_id_or_ref}/reset', {
params: { path: { branch_id_or_ref: id } },
params: { path: { branch_id_or_ref: branchRef } },
body: {},
})

Expand Down
Loading
Loading