Files
supabase/apps/studio/components/interfaces/BranchManagement/OutOfDateNotice.tsx
ea38c6d153 Review and merge branch (#36795)
* 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>
2025-07-04 14:57:59 +10:00

120 lines
3.8 KiB
TypeScript

import { useState } from 'react'
import { Button } from 'ui'
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from 'ui'
import { GitBranchIcon } from 'lucide-react'
import { Admonition } from 'ui-patterns'
interface OutOfDateNoticeProps {
isBranchOutOfDateMigrations: boolean
missingMigrationsCount: number
hasMissingFunctions: boolean
missingFunctionsCount: number
hasOutOfDateFunctions: boolean
outOfDateFunctionsCount: number
hasEdgeFunctionModifications: boolean
modifiedFunctionsCount: number
isPushing: boolean
onPush: () => void
}
export const OutOfDateNotice = ({
isBranchOutOfDateMigrations,
missingMigrationsCount,
hasMissingFunctions,
missingFunctionsCount,
hasOutOfDateFunctions,
outOfDateFunctionsCount,
hasEdgeFunctionModifications,
modifiedFunctionsCount,
isPushing,
onPush,
}: OutOfDateNoticeProps) => {
const [isDialogOpen, setIsDialogOpen] = useState(false)
const hasOutdatedMigrations = isBranchOutOfDateMigrations && missingMigrationsCount > 0
const getTitle = () => {
if (hasOutdatedMigrations && (hasMissingFunctions || hasOutOfDateFunctions)) {
return 'Your database schema and edge functions are out of date'
} else if (hasOutdatedMigrations) {
return 'Your database schema is out of date'
} else if (hasMissingFunctions || hasOutOfDateFunctions) {
return 'Your functions are out of date'
}
return 'Branch is out of date'
}
const getDescription = () => {
return 'Update this branch to get the latest changes from the production branch.'
}
const handleUpdateClick = () => {
onPush()
}
const handleConfirmUpdate = () => {
setIsDialogOpen(false)
onPush()
}
return (
<Admonition type="warning" className="my-4">
<div className="w-full flex items-center justify-between">
<div>
<h3 className="text-sm font-medium">{getTitle()}</h3>
<p className="text-sm text-foreground-light">{getDescription()}</p>
</div>
{hasEdgeFunctionModifications ? (
<AlertDialog open={isDialogOpen} onOpenChange={setIsDialogOpen}>
<AlertDialogTrigger asChild>
<Button
type="default"
loading={isPushing}
icon={<GitBranchIcon size={16} strokeWidth={1.5} />}
className="shrink-0"
>
{isPushing ? 'Updating...' : 'Update branch'}
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Update branch with modified functions?</AlertDialogTitle>
<AlertDialogDescription>
This branch has {modifiedFunctionsCount} modified edge function
{modifiedFunctionsCount !== 1 ? 's' : ''} that will be overwritten when updating
with the latest functions from the production branch. This action cannot be
undone.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction onClick={handleConfirmUpdate}>Update anyway</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
) : (
<Button
type="default"
loading={isPushing}
onClick={handleUpdateClick}
icon={<GitBranchIcon size={16} strokeWidth={1.5} />}
className="shrink-0"
>
{isPushing ? 'Updating...' : 'Update branch'}
</Button>
)}
</div>
</Admonition>
)
}