The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Address feedback and scaffold create branch side panel
Joshen Lim67c95661b231
diff --git a/studio/components/interfaces/BranchManagement/BranchManagement.tsx b/studio/components/interfaces/BranchManagement/BranchManagement.tsxindex da56682d816..f2e3f37db6e 100644--- a/studio/components/interfaces/BranchManagement/BranchManagement.tsx+++ b/studio/components/interfaces/BranchManagement/BranchManagement.tsx@@ -1,5 +1,6 @@import { partition } from 'lodash'import { useState } from 'react'+import { Button, IconSearch, Input } from 'ui'import { useParams } from 'common'import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'@@ -9,11 +10,11 @@ import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'import { useBranchDeleteMutation } from 'data/branches/branch-delete-mutation'import { Branch, useBranchesQuery } from 'data/branches/branches-query'import { useSelectedProject, useStore } from 'hooks'-import { Button, IconSearch, Input } from 'ui'-import { BranchHeader, BranchPanel, MainBranchPanel } from './BranchPanels'-import UpdateBranchSidePanel from './UpdateBranchSidePanel'-import PullRequests from './PullRequests'+import { MainBranchPanel } from './BranchPanels'+import CreateBranchSidePanel from './CreateBranchSidePanel'import PreviewBranches from './PreviewBranches'+import PullRequests from './PullRequests'+import UpdateBranchSidePanel from './UpdateBranchSidePanel'const BranchManagement = () => {const { ui } = useStore()@@ -24,6 +25,7 @@ const BranchManagement = () => {const projectRef =projectDetails !== undefined ? (isBranch ? projectDetails.parent_project_ref : ref) : undefined+ const [showCreateBranch, setShowCreateBranch] = useState(false)const [selectedBranchToUpdate, setSelectedBranchToUpdate] = useState<Branch>()const [selectedBranchToDelete, setSelectedBranchToDelete] = useState<Branch>()@@ -53,7 +55,7 @@ const BranchManagement = () => {<div className="flex items-center space-x-2"><Input placeholder="Search branch" size="small" icon={<IconSearch />} /></div>- <Button>Create preview branch</Button>+ <Button onClick={() => setShowCreateBranch(true)}>Create preview branch</Button></div><div className="">{isLoading && <GenericSkeletonLoader />}@@ -88,6 +90,11 @@ const BranchManagement = () => {alert="You cannot recover this branch once it is deleted!"/>+ <CreateBranchSidePanel+ visible={showCreateBranch}+ onClose={() => setShowCreateBranch(false)}+ />+<UpdateBranchSidePanelselectedBranch={selectedBranchToUpdate}onClose={() => setSelectedBranchToUpdate(undefined)}diff --git a/studio/components/interfaces/BranchManagement/CreateBranchSidePanel.tsx b/studio/components/interfaces/BranchManagement/CreateBranchSidePanel.tsxnew file mode 100644index 00000000000..2d375152ec6--- /dev/null+++ b/studio/components/interfaces/BranchManagement/CreateBranchSidePanel.tsx@@ -0,0 +1,121 @@+import { useRef } from 'react'+import { Button, Form, Input, Listbox, SidePanel } from 'ui'++import { useParams } from 'common'+import { useBranchCreateMutation } from 'data/branches/branch-create-mutation'+import { useStore } from 'hooks'++interface CreateBranchSidePanelProps {+ visible: boolean+ onClose: () => void+}++const MOCK_BRANCHES = [+ { id: 1, name: 'feat/branch-01' },+ { id: 2, name: 'feat/branch-02' },+]++const CreateBranchSidePanel = ({ visible, onClose }: CreateBranchSidePanelProps) => {+ const { ui } = useStore()+ const submitRef: any = useRef()+ const { ref: projectRef } = useParams()++ const formId = 'create-branch-form'+ const initialValues = { branchName: '', gitBranch: 'no-selection' }+ const { mutate: createBranch, isLoading: isCreating } = useBranchCreateMutation({+ onSuccess: () => {+ ui.setNotification({ category: 'success', message: `Successfully created new branch` })+ onClose()+ },+ })++ const validate = (values: any) => {+ const errors: any = {}+ if (values.branchName.length === 0)+ errors.branchName = 'Please provide a name for your preview branch'+ if (values.gitBranch.length === 0 || values.gitBranch === 'no-selection')+ errors.gitBranch = 'Please select a Git branch to link to this database preview branch'+ return errors+ }++ const onConfirmCreate = (values: any) => {+ if (!projectRef) return console.error('Project ref is required')+ createBranch({ projectRef, ...values })+ }++ return (+ <SidePanel+ visible={visible}+ loading={isCreating}+ onCancel={onClose}+ header="Create a new database preview branch"+ 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={isCreating}+ >+ Cancel+ </Button>+ <Button+ size="tiny"+ type="primary"+ htmlType="button"+ disabled={isCreating}+ loading={isCreating}+ onClick={() => submitRef?.current?.click()}+ >+ Confirm+ </Button>+ </div>+ }+ >+ <div className="py-6">+ <SidePanel.Content>+ <Form+ validateOnBlur+ id={formId}+ initialValues={initialValues}+ validate={validate}+ onSubmit={onConfirmCreate}+ >+ {() => {+ return (+ <div className="space-y-6">+ <Input id="branchName" label="Branch name" />+ <Listbox size="medium" id="gitBranch" name="gitBranch" label="Git branch">+ <Listbox.Option+ label="---"+ key="no-selection"+ id="no-selection"+ value="no-selection"+ >+ ---+ </Listbox.Option>+ {MOCK_BRANCHES.map((branch) => (+ <Listbox.Option+ key={branch.id}+ id={branch.id.toString()}+ value={branch.id}+ label={branch.name}+ >+ <p className="text-scale-1200">{branch.name}</p>+ </Listbox.Option>+ ))}+ </Listbox>++ <button ref={submitRef} type="submit" className="hidden" />+ </div>+ )+ }}+ </Form>+ </SidePanel.Content>+ </div>+ </SidePanel>+ )+}++export default CreateBranchSidePaneldiff --git a/studio/components/layouts/AppLayout/BranchDropdown.tsx b/studio/components/layouts/AppLayout/BranchDropdown.tsxindex 974e3f08085..50672277b06 100644--- a/studio/components/layouts/AppLayout/BranchDropdown.tsx+++ b/studio/components/layouts/AppLayout/BranchDropdown.tsx@@ -16,6 +16,7 @@ import {Command_Shadcn_,IconCheck,IconCode,+ IconGitBranch,IconPlus,PopoverContent_Shadcn_,PopoverTrigger_Shadcn_,@@ -46,9 +47,14 @@ const BranchDropdown = () => {{isSuccess && branches.length > 0 && (<div className="flex items-center space-x-2 px-2">- <Link passHref href={`/project/${projectRef}/branches`}>+ <Link passHref href={`/project/${ref}`}>+ <a ref={branchNameRef} className="flex items-center space-x-2 text-sm">+ {selectedBranch?.name}+ </a>+ </Link>++ <Link passHref href={`/project/${ref}/branches`}><a ref={branchNameRef} className="flex items-center space-x-2">- <p className="text-sm">{selectedBranch?.name}</p>{selectedBranch?.is_default ? (<Badge color="amber">Production</Badge>) : (@@ -86,7 +92,7 @@ const BranchDropdown = () => {<Link passHref href={href} key={branch.id}><CommandItem_Shadcn_asChild- value={branch.id}+ value={branch.name}className="cursor-pointer w-full flex items-center justify-between"onSelect={() => {setOpen(false)@@ -105,24 +111,24 @@ const BranchDropdown = () => {)})}</CommandGroup_Shadcn_>- {/* <CommandGroup_Shadcn_ className="border-t">- <Link passHref href={'/'}>+ <CommandGroup_Shadcn_ className="border-t">+ <Link passHref href={`/project/${ref}/branches`}><CommandItem_Shadcn_asChildclassName="cursor-pointer flex items-center space-x-2 w-full"onSelect={(e) => {setOpen(false)- router.push('/')+ router.push(`/project/${ref}/branches`)}}onClick={() => setOpen(false)}><a>- <IconPlus size={14} strokeWidth={1.5} />- <p>New branch</p>+ <IconGitBranch size={14} strokeWidth={1.5} />+ <p>Manage branches</p></a></CommandItem_Shadcn_></Link>- </CommandGroup_Shadcn_> */}+ </CommandGroup_Shadcn_></CommandList_Shadcn_></Command_Shadcn_></PopoverContent_Shadcn_>diff --git a/studio/components/layouts/AppLayout/ProjectDropdown.tsx b/studio/components/layouts/AppLayout/ProjectDropdown.tsxindex 70cba5c7c7e..db802d7fe65 100644--- a/studio/components/layouts/AppLayout/ProjectDropdown.tsx+++ b/studio/components/layouts/AppLayout/ProjectDropdown.tsx@@ -133,7 +133,7 @@ const ProjectDropdown = () => {return IS_PLATFORM ? (<div className="flex items-center space-x-2 px-2">- <Link href={`/project/${selectedProject?.ref}`}>+ <Link href={`/project/${ref}`}><a ref={projectNameRef} className="flex items-center space-x-2"><p className="text-sm">{selectedProject?.name}</p>{isSuccess && !isOrgBilling && <Badge color="slate">{subscription?.plan.name}</Badge>}