Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Implement branch update

Joshen Limd3f362458bfa
diff --git a/studio/components/interfaces/BranchManagement/BranchManagement.tsx b/studio/components/interfaces/BranchManagement/BranchManagement.tsx
index adbca4688e1..3192f449c0d 100644
--- a/studio/components/interfaces/BranchManagement/BranchManagement.tsx
+++ b/studio/components/interfaces/BranchManagement/BranchManagement.tsx
@@ -7,10 +7,11 @@ import AlertError from 'components/ui/AlertError'
import TextConfirmModal from 'components/ui/Modals/TextConfirmModal'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useBranchDeleteMutation } from 'data/branches/branch-delete-mutation'
-import { useBranchUpdateMutation } from 'data/branches/branch-update-mutation'
import { Branch, useBranchesQuery } from 'data/branches/branches-query'
import { useSelectedProject, useStore } from 'hooks'
-import { BranchHeader, BranchPanel } from './BranchPanels'
+import { Button, IconSearch, Input } from 'ui'
+import { BranchHeader, BranchPanel, MainBranchPanel } from './BranchPanels'
+import UpdateBranchSidePanel from './UpdateBranchSidePanel'
const BranchManagement = () => {
const { ui } = useStore()
@@ -27,12 +28,6 @@ const BranchManagement = () => {
const { data: branches, error, isLoading, isError, isSuccess } = useBranchesQuery({ projectRef })
const [[mainBranch], previewBranches] = partition(branches, (branch) => branch.is_default)
- const { mutate: updateBranch, isLoading: isUpdating } = useBranchUpdateMutation({
- onSuccess: () => {
- setSelectedBranchToUpdate(undefined)
- ui.setNotification({ category: 'success', message: 'Successfully updated branch' })
- },
- })
const { mutate: deleteBranch, isLoading: isDeleting } = useBranchDeleteMutation({
onSuccess: () => {
setSelectedBranchToDelete(undefined)
@@ -51,19 +46,25 @@ const BranchManagement = () => {
<ScaffoldContainer>
<ScaffoldSection>
<div className="col-span-12">
- <h3 className="text-lg">Branches</h3>
- <div className="mt-8">
+ <h3 className="text-xl mb-8">Branch Manager</h3>
+ <div className="mb-6 flex items-center justify-between">
+ <div className="flex items-center space-x-2">
+ <Input placeholder="Search branch" size="small" icon={<IconSearch />} />
+ </div>
+ <Button>Create preview branch</Button>
+ </div>
+ <div className="">
{isLoading && <GenericSkeletonLoader />}
{isError && <AlertError error={error} subject="Failed to retrieve branches" />}
{isSuccess && (
<>
- <BranchPanel branch={mainBranch} onSelectUpdate={() => {}} />
+ <MainBranchPanel branch={mainBranch} onSelectUpdate={() => {}} />
<BranchHeader markdown={`#### Preview branches`} />
{previewBranches.map((branch) => (
<BranchPanel
key={branch.id}
branch={branch}
- onSelectUpdate={() => {}}
+ onSelectUpdate={() => setSelectedBranchToUpdate(branch)}
onSelectDelete={() => setSelectedBranchToDelete(branch)}
/>
))}
@@ -87,6 +88,11 @@ const BranchManagement = () => {
text={`This will delete your branch "${selectedBranchToDelete?.name}"`}
alert="You cannot recover this branch once it is deleted!"
/>
+
+ <UpdateBranchSidePanel
+ selectedBranch={selectedBranchToUpdate}
+ onClose={() => setSelectedBranchToUpdate(undefined)}
+ />
</>
)
}
diff --git a/studio/components/interfaces/BranchManagement/BranchPanels.tsx b/studio/components/interfaces/BranchManagement/BranchPanels.tsx
index c39052f64c1..5b23a440225 100644
--- a/studio/components/interfaces/BranchManagement/BranchPanels.tsx
+++ b/studio/components/interfaces/BranchManagement/BranchPanels.tsx
@@ -9,6 +9,7 @@ import {
DropdownMenu_Shadcn_,
IconEdit,
IconGitBranch,
+ IconGitHub,
IconMoreVertical,
IconShield,
IconTrash,
@@ -26,30 +27,31 @@ interface BranchPanelProps {
onSelectDelete?: () => void
}
-const BranchPanel = ({
- branch,
- onSelectUpdate = noop,
- onSelectDelete = noop,
-}: BranchPanelProps) => {
+const MainBranchPanel = ({ branch, onSelectUpdate = noop }: BranchPanelProps) => {
const { ref } = useParams()
const [open, setOpen] = useState(false)
-
const isActive = ref === branch?.project_ref
- const daysFromNow = dayjs().diff(dayjs(branch?.created_at), 'day')
- const formattedTimeFromNow = dayjs(branch?.created_at).fromNow()
- const formattedCreatedAt = dayjs(branch?.created_at).format('DD MMM YYYY, HH:mm:ss (ZZ)')
- if (branch?.is_default) {
- return (
- <div className="bg-surface-100 border shadow-sm flex justify-between items-center pl-8 pr-6 py-4 rounded-lg text-sm">
+ return (
+ <div className="border rounded-lg">
+ <div className="bg-surface-200 shadow-sm flex justify-between items-center pl-8 pr-6 py-3 rounded-t-lg text-sm">
<div className="flex items-center space-x-4">
- <IconShield size={16} strokeWidth={2} />
+ <div className="w-8 h-8 bg-scale-200 rounded-md flex items-center justify-center">
+ <IconGitHub size={18} strokeWidth={2} />
+ </div>
+ <p>Github branch workflow</p>
+ </div>
+ </div>
+ <div className="bg-surface-100 border-t shadow-sm flex justify-between items-center pl-8 pr-6 py-3 rounded-b-lg text-sm">
+ <div className="flex items-center space-x-4">
+ <div className="w-8 h-8 bg-amber-300 rounded-md flex items-center justify-center">
+ <IconShield size={18} strokeWidth={2} className="text-amber-900" />
+ </div>
<p>{branch?.name}</p>
<Badge color="amber">Production</Badge>
{isActive && <Badge color="green">Selected</Badge>}
</div>
<div className="flex items-center space-x-4">
- <Button>Create new branch</Button>
<DropdownMenu_Shadcn_ open={open} onOpenChange={() => setOpen(!open)} modal={false}>
<DropdownMenuTrigger_Shadcn_>
<Button asChild type="text" className="px-1" icon={<IconMoreVertical size={14} />}>
@@ -65,8 +67,22 @@ const BranchPanel = ({
</DropdownMenu_Shadcn_>
</div>
</div>
- )
- }
+ </div>
+ )
+}
+
+const BranchPanel = ({
+ branch,
+ onSelectUpdate = noop,
+ onSelectDelete = noop,
+}: BranchPanelProps) => {
+ const { ref } = useParams()
+ const [open, setOpen] = useState(false)
+
+ const isActive = ref === branch?.project_ref
+ const daysFromNow = dayjs().diff(dayjs(branch?.created_at), 'day')
+ const formattedTimeFromNow = dayjs(branch?.created_at).fromNow()
+ const formattedCreatedAt = dayjs(branch?.created_at).format('DD MMM YYYY, HH:mm:ss (ZZ)')
return (
<li className="list-none ml-6 pl-8 pb-4 border-l border-scale-600 dark:border-scale-400 relative last:!border-transparent">
@@ -129,4 +145,4 @@ const BranchHeader = forwardRef<HTMLDivElement, BranchHeader>(
)
BranchHeader.displayName = 'BranchHeader'
-export { BranchHeader, BranchPanel }
+export { BranchHeader, MainBranchPanel, BranchPanel }
diff --git a/studio/components/interfaces/BranchManagement/UpdateBranchSidePanel.tsx b/studio/components/interfaces/BranchManagement/UpdateBranchSidePanel.tsx
new file mode 100644
index 00000000000..4899a922c11
--- /dev/null
+++ b/studio/components/interfaces/BranchManagement/UpdateBranchSidePanel.tsx
@@ -0,0 +1,97 @@
+import { useParams } from 'common'
+import { useBranchUpdateMutation } from 'data/branches/branch-update-mutation'
+import { Branch } from 'data/branches/branches-query'
+import { useStore } from 'hooks'
+import { useRef } from 'react'
+import { Button, Form, Input, SidePanel } from 'ui'
+
+interface UpdateBranchSidePanelProps {
+ selectedBranch?: Branch
+ onClose: () => void
+}
+
+const UpdateBranchSidePanel = ({ selectedBranch, onClose }: UpdateBranchSidePanelProps) => {
+ const { ui } = useStore()
+ const submitRef: any = useRef()
+ const { ref: projectRef } = useParams()
+ const { mutate: updateBranch, isLoading: isUpdating } = useBranchUpdateMutation({
+ onSuccess: () => {
+ onClose()
+ ui.setNotification({ category: 'success', message: 'Successfully updated branch' })
+ },
+ })
+
+ const formId = 'update-branch-form'
+ const initialValues = {
+ branchName: selectedBranch?.name,
+ gitBranch: selectedBranch?.git_branch,
+ }
+
+ const validate = (values: any) => {
+ const errors: any = {}
+ if (values.branchName.length === 0) errors.branchName = 'Please provide a branch name'
+ if (values.gitBranch.length === 0) errors.gitBranch = 'Please provide a Git branch'
+ return errors
+ }
+
+ const onConfirmUpdate = (values: any) => {
+ if (selectedBranch === undefined) return console.error('No branch selected')
+ if (projectRef === undefined) return console.error('Project ref is required')
+ updateBranch({ ...values, id: selectedBranch.id, projectRef })
+ }
+
+ return (
+ <SidePanel
+ visible={selectedBranch !== undefined}
+ header={`Update branch: ${selectedBranch?.name}`}
+ onCancel={onClose}
+ customFooter={
+ <div className="flex w-full justify-end space-x-3 border-t border-scale-500 px-3 py-4">
+ <Button
+ size="tiny"
+ type="default"
+ htmlType="button"
+ onClick={onClose}
+ disabled={isUpdating}
+ >
+ Cancel
+ </Button>
+ <Button
+ size="tiny"
+ type="primary"
+ htmlType="button"
+ disabled={isUpdating}
+ loading={isUpdating}
+ onClick={() => submitRef?.current?.click()}
+ >
+ Confirm
+ </Button>
+ </div>
+ }
+ >
+ <div className="py-6">
+ <SidePanel.Content>
+ <Form
+ validateOnBlur
+ id={formId}
+ initialValues={initialValues}
+ validate={validate}
+ onSubmit={onConfirmUpdate}
+ >
+ {() => {
+ return (
+ <div className="space-y-6">
+ <Input id="branchName" label="Branch name" />
+ <Input disabled id="gitBranch" label="Git branch" />
+ <button ref={submitRef} type="submit" className="hidden" />
+ </div>
+ )
+ }}
+ </Form>
+ </SidePanel.Content>
+ </div>
+ </SidePanel>
+ )
+}
+
+export default UpdateBranchSidePanel
diff --git a/studio/components/layouts/AppLayout/BranchDropdown.tsx b/studio/components/layouts/AppLayout/BranchDropdown.tsx
index adbbf63d607..974e3f08085 100644
--- a/studio/components/layouts/AppLayout/BranchDropdown.tsx
+++ b/studio/components/layouts/AppLayout/BranchDropdown.tsx
@@ -52,7 +52,7 @@ const BranchDropdown = () => {
{selectedBranch?.is_default ? (
<Badge color="amber">Production</Badge>
) : (
- <Badge color="green">Branch</Badge>
+ <Badge color="green">Preview Branch</Badge>
)}
</a>
</Link>