Skip to content

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

Gate certain project settings while on a branch, and fix route validation wrapper

Joshen Lim6aa55fc1fe6a
diff --git a/studio/components/interfaces/App/RouteValidationWrapper.tsx b/studio/components/interfaces/App/RouteValidationWrapper.tsx
index 9fd0b0c8cbf..8e9ef20f0f6 100644
--- a/studio/components/interfaces/App/RouteValidationWrapper.tsx
+++ b/studio/components/interfaces/App/RouteValidationWrapper.tsx
@@ -68,8 +68,9 @@ const RouteValidationWrapper = ({ children }: PropsWithChildren<{}>) => {
// Check validity of project that the user is trying to access
const projects = projectsRef.current ?? []
const isValidProject = projects.some((project) => project.ref === ref)
+ const isValidBranch = projects.some((project) => project.preview_branch_refs.includes(ref))
- if (!isValidProject) {
+ if (!isValidProject && !isValidBranch) {
ui.setNotification({ category: 'error', message: 'This project does not exist' })
router.push(navLayoutV2 ? `/org/${organizations?.[0].slug}` : '/projects')
return
diff --git a/studio/components/interfaces/Settings/Addons/Addons.tsx b/studio/components/interfaces/Settings/Addons/Addons.tsx
index bfc323c04b7..88035a87b70 100644
--- a/studio/components/interfaces/Settings/Addons/Addons.tsx
+++ b/studio/components/interfaces/Settings/Addons/Addons.tsx
@@ -20,11 +20,20 @@ import AlertError from 'components/ui/AlertError'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useInfraMonitoringQuery } from 'data/analytics/infra-monitoring-query'
import { useProjectAddonsQuery } from 'data/subscriptions/project-addons-query'
-import { useFlag } from 'hooks'
+import { useFlag, useProjectByRef } from 'hooks'
import { getCloudProviderArchitecture } from 'lib/cloudprovider-utils'
-import { BASE_PATH, PROJECT_STATUS } from 'lib/constants'
+import { BASE_PATH } from 'lib/constants'
import { SUBSCRIPTION_PANEL_KEYS, useSubscriptionPageStateSnapshot } from 'state/subscription-page'
-import { Alert, Button, IconChevronRight, IconExternalLink } from 'ui'
+import {
+ Alert,
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Alert_Shadcn_,
+ Button,
+ IconAlertCircle,
+ IconChevronRight,
+ IconExternalLink,
+} from 'ui'
import { ComputeInstanceSidePanel, CustomDomainSidePanel, PITRSidePanel } from './'
const Addons = () => {
@@ -34,6 +43,8 @@ const Addons = () => {
const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')
const { project: selectedProject } = useProjectContext()
+ const parentProject = useProjectByRef(selectedProject?.parent_project_ref)
+ const isBranch = parentProject !== undefined
const isProjectActive = useIsProjectActive()
const allowedPanelValues = ['computeInstance', 'pitr', 'customDomain']
if (panel && typeof panel === 'string' && allowedPanelValues.includes(panel)) {
@@ -78,6 +89,25 @@ const Addons = () => {
<ScaffoldDivider />
+ {isBranch && (
+ <ScaffoldContainer>
+ <Alert_Shadcn_ variant="default" className="mt-6">
+ <IconAlertCircle strokeWidth={2} />
+ <AlertTitle_Shadcn_>
+ You are currently on a preview branch of your project
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ Updating addons are not available while you're on a preview branch. To manage your
+ addons, you may return to your{' '}
+ <Link passHref href={`/project/${parentProject.ref}/settings/general`}>
+ <a className="text-brand-900">main branch</a>
+ </Link>
+ .
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ </ScaffoldContainer>
+ )}
+
{isLoading && (
<ScaffoldContainer>
<ScaffoldSection>
@@ -161,7 +191,7 @@ const Addons = () => {
type="default"
className="mt-2 pointer-events-auto"
onClick={() => snap.setPanelKey('computeInstance')}
- disabled={!isProjectActive || projectUpdateDisabled}
+ disabled={isBranch || !isProjectActive || projectUpdateDisabled}
>
Change optimized compute
</Button>
@@ -356,7 +386,7 @@ const Addons = () => {
type="default"
className="mt-2 pointer-events-auto"
onClick={() => snap.setPanelKey('pitr')}
- disabled={!isProjectActive || projectUpdateDisabled}
+ disabled={isBranch || !isProjectActive || projectUpdateDisabled}
>
Change point in time recovery
</Button>
@@ -420,7 +450,7 @@ const Addons = () => {
type="default"
className="mt-2 pointer-events-auto"
onClick={() => snap.setPanelKey('customDomain')}
- disabled={!isProjectActive || projectUpdateDisabled}
+ disabled={isBranch || !isProjectActive || projectUpdateDisabled}
>
Change custom domain
</Button>
diff --git a/studio/components/interfaces/Settings/General/General.tsx b/studio/components/interfaces/Settings/General/General.tsx
index a4f2ac6b4dd..ff3789a44dd 100644
--- a/studio/components/interfaces/Settings/General/General.tsx
+++ b/studio/components/interfaces/Settings/General/General.tsx
@@ -1,6 +1,15 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
import Link from 'next/link'
-import { Button, Form, IconBarChart2, Input } from 'ui'
+import {
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Alert_Shadcn_,
+ Button,
+ Form,
+ IconAlertCircle,
+ IconBarChart2,
+ Input,
+} from 'ui'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import {
@@ -14,15 +23,19 @@ import {
import Panel from 'components/ui/Panel'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useProjectUpdateMutation } from 'data/projects/project-update-mutation'
-import { useCheckPermissions, useSelectedOrganization, useStore } from 'hooks'
+import { useCheckPermissions, useProjectByRef, useSelectedOrganization, useStore } from 'hooks'
import PauseProjectButton from './Infrastructure/PauseProjectButton'
import RestartServerButton from './Infrastructure/RestartServerButton'
+import { useProjectsQuery } from 'data/projects/projects-query'
const General = () => {
const { ui } = useStore()
const { project } = useProjectContext()
const organization = useSelectedOrganization()
+ const parentProject = useProjectByRef(project?.parent_project_ref)
+ const isBranch = parentProject !== undefined
+
const isOrgBilling = !!organization?.subscription_id
const formId = 'project-general-settings'
const initialValues = { name: project?.name ?? '', ref: project?.ref ?? '' }
@@ -41,6 +54,24 @@ const General = () => {
return (
<div>
<FormHeader title="Project Settings" description="" />
+
+ {isBranch && (
+ <Alert_Shadcn_ variant="default" className="mb-6">
+ <IconAlertCircle strokeWidth={2} />
+ <AlertTitle_Shadcn_>
+ You are currently on a preview branch of your project
+ </AlertTitle_Shadcn_>
+ <AlertDescription_Shadcn_>
+ Certain settings are not available while you're on a preview branch. To adjust your
+ project settings, you may return to your{' '}
+ <Link passHref href={`/project/${parentProject.ref}/settings/general`}>
+ <a className="text-brand-900">main branch</a>
+ </Link>
+ .
+ </AlertDescription_Shadcn_>
+ </Alert_Shadcn_>
+ )}
+
{project === undefined ? (
<GenericSkeletonLoader />
) : (
@@ -72,7 +103,7 @@ const General = () => {
id="name"
size="small"
label="Project name"
- disabled={!canUpdateProject}
+ disabled={isBranch || !canUpdateProject}
/>
<Input copy disabled id="ref" size="small" label="Reference ID" />
</FormSectionContent>
@@ -82,7 +113,7 @@ const General = () => {
}}
</Form>
)}
- {isOrgBilling && (
+ {!isBranch && isOrgBilling && (
<>
<div className="mt-6">
<FormPanel>
diff --git a/studio/components/layouts/AppLayout/OrganizationDropdown.tsx b/studio/components/layouts/AppLayout/OrganizationDropdown.tsx
index 035e4073307..79fe2d975e5 100644
--- a/studio/components/layouts/AppLayout/OrganizationDropdown.tsx
+++ b/studio/components/layouts/AppLayout/OrganizationDropdown.tsx
@@ -76,8 +76,6 @@ const OrganizationDropdown = () => {
{organizations?.map((org) => {
const href = router.pathname.includes('[slug]')
? router.pathname.replace('[slug]', org.slug)
- : router.pathname.includes('[ref]/settings')
- ? `/org/${org.slug}/general`
: `/org/${org.slug}`
return (
<Link passHref href={href} key={org.slug}>
diff --git a/studio/hooks/misc/useSelectedProject.ts b/studio/hooks/misc/useSelectedProject.ts
index d5c1d82dfc2..56ec25002ba 100644
--- a/studio/hooks/misc/useSelectedProject.ts
+++ b/studio/hooks/misc/useSelectedProject.ts
@@ -1,8 +1,15 @@
import { useParams } from 'common'
import { useProjectDetailQuery } from 'data/projects/project-detail-query'
+import { useProjectsQuery } from 'data/projects/projects-query'
export function useSelectedProject() {
const { ref } = useParams()
const { data } = useProjectDetailQuery({ ref })
return data
}
+
+export function useProjectByRef(ref?: string) {
+ const { data: projects } = useProjectsQuery()
+ if (!ref) return undefined
+ return projects?.find((project) => project.ref === ref)
+}
diff --git a/studio/pages/project/[ref]/settings/general.tsx b/studio/pages/project/[ref]/settings/general.tsx
index ca94e4d7bbd..9db217b9dff 100644
--- a/studio/pages/project/[ref]/settings/general.tsx
+++ b/studio/pages/project/[ref]/settings/general.tsx
@@ -1,16 +1,19 @@
-import { NextPageWithLayout } from 'types'
-import { SettingsLayout } from 'components/layouts'
import {
- General,
- Infrastructure,
CustomDomainConfig,
DeleteProjectPanel,
+ General,
+ Infrastructure,
TransferProjectPanel,
} from 'components/interfaces/Settings/General'
+import { SettingsLayout } from 'components/layouts'
+import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { useFlag, useSelectedOrganization } from 'hooks'
+import { NextPageWithLayout } from 'types'
const ProjectSettings: NextPageWithLayout = () => {
+ const { project } = useProjectContext()
const organization = useSelectedOrganization()
+ const isBranch = !!project?.parent_project_ref
const isOrgBilling = !!organization?.subscription_id
const transferProjectEnabled = useFlag('transferProject')
@@ -18,10 +21,14 @@ const ProjectSettings: NextPageWithLayout = () => {
return (
<div className="1xl:px-28 mx-auto flex flex-col gap-10 px-5 py-6 lg:px-16 xl:px-24 2xl:px-32 ">
<General />
- {!isOrgBilling && <Infrastructure />}
- <CustomDomainConfig />
- {transferProjectEnabled && <TransferProjectPanel />}
- <DeleteProjectPanel />
+ {!isBranch ? (
+ <>
+ {!isOrgBilling && <Infrastructure />}
+ {<CustomDomainConfig />}
+ {transferProjectEnabled && <TransferProjectPanel />}
+ <DeleteProjectPanel />
+ </>
+ ) : null}
</div>
)
}
diff --git a/studio/types/base.ts b/studio/types/base.ts
index 6cb3096544a..dd506a691b1 100644
--- a/studio/types/base.ts
+++ b/studio/types/base.ts
@@ -22,7 +22,7 @@ export interface ProjectBase {
region: string
inserted_at: string
subscription_id: string
- preview_branches: any[]
+ preview_branch_refs: string[]
}
export interface Project extends ProjectBase {