Skip to content

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

Deprecate useProjectByRefQuery, replace all usage with just useProjec… (#39316)

Joshen Limaa22af8ecd39
diff --git a/apps/studio/components/interfaces/BranchManagement/ReviewWithAI.tsx b/apps/studio/components/interfaces/BranchManagement/ReviewWithAI.tsx
index 9a93e5eaac3..fe63f11d8dd 100644
--- a/apps/studio/components/interfaces/BranchManagement/ReviewWithAI.tsx
+++ b/apps/studio/components/interfaces/BranchManagement/ReviewWithAI.tsx
@@ -1,9 +1,9 @@
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { Branch } from 'data/branches/branches-query'
+import { useProjectDetailQuery } from 'data/projects/project-detail-query'
import { useTablesQuery } from 'data/tables/tables-query'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
-import { useProjectByRefQuery } from 'hooks/misc/useSelectedProject'
import { tablesToSQL } from 'lib/helpers'
import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
import { AiIconAnimation } from 'ui'
@@ -28,7 +28,7 @@ export const ReviewWithAI = ({
const { mutate: sendEvent } = useSendEventMutation()
// Get parent project for production schema
- const { data: parentProject } = useProjectByRefQuery(parentProjectRef)
+ const { data: parentProject } = useProjectDetailQuery({ ref: parentProjectRef })
// Fetch production schema tables
const { data: productionTables } = useTablesQuery(
diff --git a/apps/studio/components/interfaces/Home/Home.tsx b/apps/studio/components/interfaces/Home/Home.tsx
index 555019324c8..a2caf9d860b 100644
--- a/apps/studio/components/interfaces/Home/Home.tsx
+++ b/apps/studio/components/interfaces/Home/Home.tsx
@@ -16,16 +16,13 @@ import { InlineLink } from 'components/ui/InlineLink'
import { ProjectUpgradeFailedBanner } from 'components/ui/ProjectUpgradeFailedBanner'
import { useBranchesQuery } from 'data/branches/branches-query'
import { useEdgeFunctionsQuery } from 'data/edge-functions/edge-functions-query'
+import { useProjectDetailQuery } from 'data/projects/project-detail-query'
import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
import { useTablesQuery } from 'data/tables/tables-query'
import { useCustomContent } from 'hooks/custom-content/useCustomContent'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
-import {
- useIsOrioleDb,
- useProjectByRefQuery,
- useSelectedProjectQuery,
-} from 'hooks/misc/useSelectedProject'
+import { useIsOrioleDb, useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { DOCS_URL, IS_PLATFORM, PROJECT_STATUS } from 'lib/constants'
import { useAppStateSnapshot } from 'state/app-state'
import {
@@ -44,7 +41,7 @@ import ShimmeringLoader from 'ui-patterns/ShimmeringLoader'
export const Home = () => {
const { data: project } = useSelectedProjectQuery()
const { data: organization } = useSelectedOrganizationQuery()
- const { data: parentProject } = useProjectByRefQuery(project?.parent_project_ref)
+ const { data: parentProject } = useProjectDetailQuery({ ref: project?.parent_project_ref })
const isOrioleDb = useIsOrioleDb()
const snap = useAppStateSnapshot()
const { ref, enableBranching } = useParams()
diff --git a/apps/studio/components/interfaces/HomeNew/Home.tsx b/apps/studio/components/interfaces/HomeNew/Home.tsx
index 36868977f6f..4e2baa81de5 100644
--- a/apps/studio/components/interfaces/HomeNew/Home.tsx
+++ b/apps/studio/components/interfaces/HomeNew/Home.tsx
@@ -3,18 +3,15 @@ import { arrayMove, SortableContext, verticalListSortingStrategy } from '@dnd-ki
import { useEffect, useRef } from 'react'
import { IS_PLATFORM, useParams } from 'common'
-import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { SortableSection } from 'components/interfaces/HomeNew/SortableSection'
import { TopSection } from 'components/interfaces/HomeNew/TopSection'
import { ScaffoldContainer, ScaffoldSection } from 'components/layouts/Scaffold'
import { useBranchesQuery } from 'data/branches/branches-query'
+import { useProjectDetailQuery } from 'data/projects/project-detail-query'
+import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { useLocalStorage } from 'hooks/misc/useLocalStorage'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
-import {
- useIsOrioleDb,
- useProjectByRefQuery,
- useSelectedProjectQuery,
-} from 'hooks/misc/useSelectedProject'
+import { useIsOrioleDb, useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { PROJECT_STATUS } from 'lib/constants'
import { useAppStateSnapshot } from 'state/app-state'
import { AdvisorSection } from './AdvisorSection'
@@ -31,7 +28,7 @@ export const HomeV2 = () => {
const snap = useAppStateSnapshot()
const { data: project } = useSelectedProjectQuery()
const { data: organization } = useSelectedOrganizationQuery()
- const { data: parentProject } = useProjectByRefQuery(project?.parent_project_ref)
+ const { data: parentProject } = useProjectDetailQuery({ ref: project?.parent_project_ref })
const { mutate: sendEvent } = useSendEventMutation()
const hasShownEnableBranchingModalRef = useRef(false)
diff --git a/apps/studio/components/interfaces/Settings/Addons/Addons.tsx b/apps/studio/components/interfaces/Settings/Addons/Addons.tsx
index bb72a78db3b..0b200b9a810 100644
--- a/apps/studio/components/interfaces/Settings/Addons/Addons.tsx
+++ b/apps/studio/components/interfaces/Settings/Addons/Addons.tsx
@@ -25,16 +25,13 @@ import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import ShimmeringLoader, { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { useInfraMonitoringQuery } from 'data/analytics/infra-monitoring-query'
import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
+import { useProjectDetailQuery } from 'data/projects/project-detail-query'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import { useProjectAddonsQuery } from 'data/subscriptions/project-addons-query'
import type { ProjectAddonVariantMeta } from 'data/subscriptions/types'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
-import {
- useIsOrioleDbInAws,
- useProjectByRefQuery,
- useSelectedProjectQuery,
-} from 'hooks/misc/useSelectedProject'
+import { useIsOrioleDbInAws, useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { getCloudProviderArchitecture } from 'lib/cloudprovider-utils'
import { BASE_PATH, DOCS_URL, INSTANCE_MICRO_SPECS, INSTANCE_NANO_SPECS } from 'lib/constants'
import { getDatabaseMajorVersion, getSemanticVersion } from 'lib/helpers'
@@ -59,7 +56,9 @@ export const Addons = () => {
const { data: selectedOrg } = useSelectedOrganizationQuery()
const { data: selectedProject, isLoading: isLoadingProject } = useSelectedProjectQuery()
- const { data: parentProject } = useProjectByRefQuery(selectedProject?.parent_project_ref)
+ const { data: parentProject } = useProjectDetailQuery({
+ ref: selectedProject?.parent_project_ref,
+ })
const isBranch = parentProject !== undefined
const { data: settings } = useProjectSettingsV2Query({ projectRef })
diff --git a/apps/studio/components/interfaces/Settings/General/General.tsx b/apps/studio/components/interfaces/Settings/General/General.tsx
index 46d19f4d588..61c0f7d2236 100644
--- a/apps/studio/components/interfaces/Settings/General/General.tsx
+++ b/apps/studio/components/interfaces/Settings/General/General.tsx
@@ -8,11 +8,12 @@ import { FormPanel } from 'components/ui/Forms/FormPanel'
import { FormSection, FormSectionContent, FormSectionLabel } from 'components/ui/Forms/FormSection'
import Panel from 'components/ui/Panel'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
+import { useProjectDetailQuery } from 'data/projects/project-detail-query'
import { useProjectUpdateMutation } from 'data/projects/project-update-mutation'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
-import { useProjectByRefQuery, useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
+import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import {
AlertDescription_Shadcn_,
AlertTitle_Shadcn_,
@@ -29,7 +30,7 @@ const General = () => {
const { data: project } = useSelectedProjectQuery()
const { data: organization } = useSelectedOrganizationQuery()
- const { data: parentProject } = useProjectByRefQuery(project?.parent_project_ref)
+ const { data: parentProject } = useProjectDetailQuery({ ref: project?.parent_project_ref })
const isBranch = parentProject !== undefined
const { projectSettingsRestartProject } = useIsFeatureEnabled([
diff --git a/apps/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsx b/apps/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsx
index 2533fdfdf1d..85b6e5d1569 100644
--- a/apps/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsx
+++ b/apps/studio/components/interfaces/Settings/Integrations/IntegrationsSettings.tsx
@@ -2,8 +2,9 @@ import Link from 'next/link'
import SidePanelVercelProjectLinker from 'components/interfaces/Organization/IntegrationSettings/SidePanelVercelProjectLinker'
import { ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'
+import { useProjectDetailQuery } from 'data/projects/project-detail-query'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
-import { useProjectByRefQuery, useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
+import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { BASE_PATH } from 'lib/constants'
import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, WarningIcon } from 'ui'
import GitHubSection from './GithubIntegration/GithubSection'
@@ -21,7 +22,7 @@ export const IntegrationImageHandler = ({ title }: { title: 'vercel' | 'github'
const IntegrationSettings = () => {
const { data: project } = useSelectedProjectQuery()
- const { data: parentProject } = useProjectByRefQuery(project?.parent_project_ref)
+ const { data: parentProject } = useProjectDetailQuery({ ref: project?.parent_project_ref })
const isBranch = project?.parent_project_ref !== undefined
const showVercelIntegration = useIsFeatureEnabled('integrations:vercel')
diff --git a/apps/studio/data/config/project-upgrade-eligibility-query.ts b/apps/studio/data/config/project-upgrade-eligibility-query.ts
index 4515776f210..90ddc5962c3 100644
--- a/apps/studio/data/config/project-upgrade-eligibility-query.ts
+++ b/apps/studio/data/config/project-upgrade-eligibility-query.ts
@@ -3,7 +3,7 @@ import { useQuery, UseQueryOptions } from '@tanstack/react-query'
import { components } from 'api-types'
import { IS_PLATFORM } from 'common'
import { get, handleError } from 'data/fetchers'
-import { useProjectByRefQuery } from 'hooks/misc/useSelectedProject'
+import { useProjectDetailQuery } from 'data/projects/project-detail-query'
import { PROJECT_STATUS } from 'lib/constants/infrastructure'
import type { ResponseError } from 'types'
import { configKeys } from './keys'
@@ -38,7 +38,7 @@ export const useProjectUpgradeEligibilityQuery = <TData = ProjectUpgradeEligibil
...options
}: UseQueryOptions<ProjectUpgradeEligibilityData, ProjectUpgradeEligibilityError, TData> = {}
) => {
- const { data: project } = useProjectByRefQuery(projectRef)
+ const { data: project } = useProjectDetailQuery({ ref: projectRef })
return useQuery<ProjectUpgradeEligibilityData, ProjectUpgradeEligibilityError, TData>(
configKeys.upgradeEligibility(projectRef),
({ signal }) => getProjectUpgradeEligibility({ projectRef }, signal),
diff --git a/apps/studio/hooks/misc/useSelectedOrganization.ts b/apps/studio/hooks/misc/useSelectedOrganization.ts
index 84e47836a98..f7b1c4e7402 100644
--- a/apps/studio/hooks/misc/useSelectedOrganization.ts
+++ b/apps/studio/hooks/misc/useSelectedOrganization.ts
@@ -1,12 +1,12 @@
import { useIsLoggedIn, useParams } from 'common'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
-import { useProjectByRefQuery } from './useSelectedProject'
+import { useProjectDetailQuery } from 'data/projects/project-detail-query'
export function useSelectedOrganizationQuery({ enabled = true } = {}) {
const isLoggedIn = useIsLoggedIn()
const { ref, slug } = useParams()
- const { data: selectedProject } = useProjectByRefQuery(ref)
+ const { data: selectedProject } = useProjectDetailQuery({ ref })
return useOrganizationsQuery({
enabled: isLoggedIn && enabled,
diff --git a/apps/studio/hooks/misc/useSelectedProject.ts b/apps/studio/hooks/misc/useSelectedProject.ts
index 6edab42d9bd..22ffd7df475 100644
--- a/apps/studio/hooks/misc/useSelectedProject.ts
+++ b/apps/studio/hooks/misc/useSelectedProject.ts
@@ -1,6 +1,5 @@
-import { useIsLoggedIn, useParams } from 'common'
+import { useParams } from 'common'
import { useProjectDetailQuery } from 'data/projects/project-detail-query'
-import { useProjectsQuery } from 'data/projects/projects-query'
import { PROVIDERS } from 'lib/constants'
export function useSelectedProjectQuery({ enabled = true } = {}) {
@@ -17,28 +16,6 @@ export function useSelectedProjectQuery({ enabled = true } = {}) {
)
}
-export function useProjectByRefQuery(ref?: string) {
- const isLoggedIn = useIsLoggedIn()
-
- const projectQuery = useProjectDetailQuery({ ref }, { enabled: isLoggedIn })
-
- // [Alaister]: This is here for the purpose of improving performance.
- // Chances are, the user will already have the list of projects in the cache.
- // We can't exclusively rely on this method, as useProjectsQuery does not return branch projects.
- const projectsQuery = useProjectsQuery({
- enabled: isLoggedIn,
- select: (data) => {
- return data.projects.find((project) => project.ref === ref)
- },
- })
-
- if (projectQuery.isSuccess) {
- return projectQuery
- }
-
- return projectsQuery
-}
-
export const useIsAwsCloudProvider = () => {
const { data: project } = useSelectedProjectQuery()
const isAws = project?.cloud_provider === PROVIDERS.AWS.id
diff --git a/apps/studio/pages/project/[ref]/merge.tsx b/apps/studio/pages/project/[ref]/merge.tsx
index 21e946bf6d8..5e3a9751f07 100644
--- a/apps/studio/pages/project/[ref]/merge.tsx
+++ b/apps/studio/pages/project/[ref]/merge.tsx
@@ -22,11 +22,12 @@ import { useBranchMergeMutation } from 'data/branches/branch-merge-mutation'
import { useBranchPushMutation } from 'data/branches/branch-push-mutation'
import { useBranchUpdateMutation } from 'data/branches/branch-update-mutation'
import { useBranchesQuery } from 'data/branches/branches-query'
+import { useProjectDetailQuery } from 'data/projects/project-detail-query'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { useBranchMergeDiff } from 'hooks/branches/useBranchMergeDiff'
import { useWorkflowManagement } from 'hooks/branches/useWorkflowManagement'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
-import { useProjectByRefQuery, useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
+import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import type { NextPageWithLayout } from 'types'
import {
Badge,
@@ -54,7 +55,7 @@ const MergePage: NextPageWithLayout = () => {
const isBranch = project?.parent_project_ref !== undefined
const parentProjectRef = project?.parent_project_ref
- const { data: parentProject } = useProjectByRefQuery(parentProjectRef)
+ const { data: parentProject } = useProjectDetailQuery({ ref: parentProjectRef })
const { data: branches } = useBranchesQuery(
{ projectRef: parentProjectRef },