diff --git a/studio/components/layouts/AppLayout/AppHeader.tsx b/studio/components/layouts/AppLayout/AppHeader.tsx index e6bcbe9bca9..74483659353 100644 --- a/studio/components/layouts/AppLayout/AppHeader.tsx +++ b/studio/components/layouts/AppLayout/AppHeader.tsx @@ -2,7 +2,7 @@ import Link from 'next/link' import { useRouter } from 'next/router' import { useParams } from 'common' -import { useFlag, useSelectedOrganization } from 'hooks' +import { useFlag, useSelectedOrganization, useSelectedProject } from 'hooks' import FeedbackDropdown from '../ProjectLayout/LayoutHeader/FeedbackDropdown' import HelpPopover from '../ProjectLayout/LayoutHeader/HelpPopover' import NotificationsPopover from '../ProjectLayout/LayoutHeader/NotificationsPopover' @@ -11,13 +11,20 @@ import ProjectDropdown from './ProjectDropdown' import SettingsButton from './SettingsButton' import UserSettingsDropdown from './UserSettingsDropdown' import BranchDropdown from './BranchDropdown' +import { useProjectsQuery } from 'data/projects/projects-query' +import EnableBranchingButton from './EnableBranchingButton' const AppHeader = () => { const router = useRouter() const { ref } = useParams() + const { data: projects } = useProjectsQuery() const organization = useSelectedOrganization() const enableBranchManagement = useFlag('branchManagement') + const project = projects?.find((project) => project.ref === ref) + const isBranchingAllowed = project?.cloud_provider === 'FLY' + const isBranchingEnabled = (project?.preview_branch_refs ?? []).length > 0 + return (
@@ -32,7 +39,9 @@ const AppHeader = () => { {ref !== undefined && } - {ref !== undefined && enableBranchManagement && } + {ref !== undefined && isBranchingAllowed && enableBranchManagement && ( + <>{isBranchingEnabled ? : } + )}
diff --git a/studio/components/layouts/AppLayout/EnableBranchingButton.tsx b/studio/components/layouts/AppLayout/EnableBranchingButton.tsx new file mode 100644 index 00000000000..ffdf401e774 --- /dev/null +++ b/studio/components/layouts/AppLayout/EnableBranchingButton.tsx @@ -0,0 +1,148 @@ +import { useParams } from 'common' +import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only' +import { useSelectedOrganization } from 'hooks' +import { useState } from 'react' +import { Badge, Button, IconFileText, IconGitBranch, Modal } from 'ui' + +const EnableBranchingButton = () => { + const { ref } = useParams() + const [open, setOpen] = useState(false) + const selectedOrg = useSelectedOrganization() + + const { + data: integrations, + error: integrationsError, + isLoading: isLoadingIntegrations, + isSuccess: isSuccessIntegrations, + isError: isErrorIntegrations, + } = useOrgIntegrationsQuery({ + orgSlug: selectedOrg?.slug, + }) + + const githubIntegration = integrations?.find( + (integration) => + integration.integration.name === 'GitHub' && + integration.connections.some((connection) => connection.supabase_project_ref === ref) + ) + const vercelIntegration = integrations?.find( + (integration) => + integration.integration.name === 'Vercel' && + integration.connections.some((connection) => connection.supabase_project_ref === ref) + ) + const hasVercelIntegration = false + + console.log({ githubIntegration, vercelIntegration }) + + return ( + <> + + setOpen(false)}> + +
+ +
+

Enable database branching

+

Management environments in Supabase

+
+
+
+ + {githubIntegration !== undefined ? ( + <> + + +
+ +
+

Enable database branching

+

Management environments in Supabase

+
+
+
+ + + ) : ( +
+ +
+
+

Git Connection

+ Required +
+

+ Your database will make preview branches based on your branches in the Git + repository that your project is connected with. +

+ +
+
+
+ )} + + {/* +
+
+

Frontend Cloud Previews

+ Optional +
+

+ Previews can be available by connecting your Supabase project to a Vercel project. +

+ +
+
*/} + + {/* */} + + {/* [Joshen TODO] Feels like this copy writing needs some relooking before we ship, make sure they are factual too */} + +
+

Please keep in mind the following:

+
+
+
+ +
+
+
+

+ You will not be able to use the dashboard to make changes to the database +

+

+ Schema changes for database preview branches must be done via Git. We are + nonetheless working on allowing the dashboard to make schema changes for preview + branches. +

+
+
+
+
+ + + + +
+ + +
+
+
+ + ) +} + +export default EnableBranchingButton