Skip to content

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

Chore/projects pagination part 05 (#39350)

Joshen Lim6b7c8116f307
diff --git a/apps/studio/components/interfaces/Billing/NoProjectsOnPaidOrgInfo.tsx b/apps/studio/components/interfaces/Billing/NoProjectsOnPaidOrgInfo.tsx
index 84f685f70bf..372b8257b9e 100644
--- a/apps/studio/components/interfaces/Billing/NoProjectsOnPaidOrgInfo.tsx
+++ b/apps/studio/components/interfaces/Billing/NoProjectsOnPaidOrgInfo.tsx
@@ -1,4 +1,4 @@
-import { useProjectsQuery } from 'data/projects/projects-query'
+import { useOrgProjectsInfiniteQuery } from 'data/projects/org-projects-infinite-query'
import Link from 'next/link'
import type { Organization } from 'types'
import { Admonition } from 'ui-patterns'
@@ -8,10 +8,8 @@ interface NoProjectsOnPaidOrgInfoProps {
}
export const NoProjectsOnPaidOrgInfo = ({ organization }: NoProjectsOnPaidOrgInfoProps) => {
- const { data } = useProjectsQuery({})
- const projectCount =
- (data?.projects ?? []).filter((project) => project.organization_id === organization?.id)
- .length ?? 0
+ const { data } = useOrgProjectsInfiniteQuery({ slug: organization?.slug })
+ const projectCount = data?.pages[0].pagination.count ?? 0
if (
projectCount > 0 ||
diff --git a/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationConnection.tsx b/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationConnection.tsx
index be63d1469d6..f7016dc936b 100644
--- a/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationConnection.tsx
+++ b/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationConnection.tsx
@@ -11,7 +11,7 @@ import {
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { useIntegrationsVercelConnectionSyncEnvsMutation } from 'data/integrations/integrations-vercel-connection-sync-envs-mutation'
import type { IntegrationProjectConnection } from 'data/integrations/integrations.types'
-import { useProjectsQuery } from 'data/projects/projects-query'
+import { useProjectDetailQuery } from 'data/projects/project-detail-query'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import {
Button,
@@ -34,10 +34,7 @@ const IntegrationConnectionItem = forwardRef<HTMLLIElement, IntegrationConnectio
const { data: org } = useSelectedOrganizationQuery()
const { type, connection } = props
- const { data } = useProjectsQuery()
- const project = (data?.projects ?? []).find(
- (project) => project.ref === connection.supabase_project_ref
- )
+ const { data: project } = useProjectDetailQuery({ ref: connection.supabase_project_ref })
const isBranchingEnabled = project?.is_branch_enabled === true
const [isOpen, setIsOpen] = useState(false)
diff --git a/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.tsx b/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.tsx
index f394f3c1ec1..01624ba6092 100644
--- a/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.tsx
+++ b/apps/studio/components/interfaces/Integrations/VercelGithub/IntegrationPanels.tsx
@@ -10,7 +10,7 @@ import type {
Integration,
IntegrationProjectConnection,
} from 'data/integrations/integrations.types'
-import { useProjectsQuery } from 'data/projects/projects-query'
+import { useProjectDetailQuery } from 'data/projects/project-detail-query'
import { BASE_PATH } from 'lib/constants'
import { getIntegrationConfigurationUrl } from 'lib/integration-utils'
import { Badge, Button, cn } from 'ui'
@@ -149,10 +149,7 @@ const IntegrationConnection = forwardRef<HTMLLIElement, IntegrationConnectionPro
{ connection, type, actions, showNode = true, orientation = 'horizontal', className, ...props },
ref
) => {
- const { data } = useProjectsQuery()
- const project = (data?.projects ?? []).find(
- (project) => project.ref === connection.supabase_project_ref
- )
+ const { data: project } = useProjectDetailQuery({ ref: connection.supabase_project_ref })
return (
<li
@@ -238,10 +235,7 @@ const IntegrationConnection = forwardRef<HTMLLIElement, IntegrationConnectionPro
const IntegrationConnectionOption = forwardRef<HTMLLIElement, IntegrationConnectionProps>(
({ connection, type, ...props }, ref) => {
- const { data } = useProjectsQuery()
- const project = (data?.projects ?? []).find(
- (project) => project.ref === connection.supabase_project_ref
- )
+ const { data: project } = useProjectDetailQuery({ ref: connection.supabase_project_ref })
return (
<li
diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/DowngradeModal.tsx b/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/DowngradeModal.tsx
index 91a3e3ceb7c..1f347dbb398 100644
--- a/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/DowngradeModal.tsx
+++ b/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/DowngradeModal.tsx
@@ -1,19 +1,18 @@
import { MinusCircle, PauseCircle } from 'lucide-react'
-import type { ProjectInfo } from 'data/projects/projects-query'
+import { getComputeSize, OrgProject } from 'data/projects/org-projects-infinite-query'
import type { OrgSubscription, ProjectAddon } from 'data/subscriptions/types'
-import { PricingInformation } from 'shared-data'
+import { useMemo } from 'react'
+import { plans as subscriptionsPlans } from 'shared-data/plans'
import { Modal } from 'ui'
import { Admonition } from 'ui-patterns'
-import { plans as subscriptionsPlans } from 'shared-data/plans'
-import { useMemo } from 'react'
export interface DowngradeModalProps {
visible: boolean
subscription?: OrgSubscription
onClose: () => void
onConfirm: () => void
- projects: ProjectInfo[]
+ projects: OrgProject[]
}
const ProjectDowngradeListItem = ({ projectAddon }: { projectAddon: ProjectAddon }) => {
@@ -73,7 +72,10 @@ const DowngradeModal = ({
}
}) || []
- const hasInstancesOnMicro = projects.some((project) => project.infra_compute_size === 'micro')
+ const hasInstancesOnMicro = projects.some((project) => {
+ const computeSize = getComputeSize(project)
+ return computeSize === 'micro'
+ })
return (
<Modal
@@ -102,7 +104,10 @@ const DowngradeModal = ({
))}
{projects
- .filter((it) => it.infra_compute_size === 'micro')
+ .filter((it) => {
+ const computeSize = getComputeSize(it)
+ return computeSize === 'micro'
+ })
.map((project) => (
<li className="list-disc ml-6" key={project.ref}>
{project.name}: Compute will be downgraded. Project will also{' '}
diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/ExitSurveyModal.tsx b/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/ExitSurveyModal.tsx
index d025396fab0..e1c713c0e4d 100644
--- a/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/ExitSurveyModal.tsx
+++ b/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/ExitSurveyModal.tsx
@@ -4,14 +4,14 @@ import { toast } from 'sonner'
import { useFlag, useParams } from 'common'
import { CANCELLATION_REASONS } from 'components/interfaces/Billing/Billing.constants'
import { useSendDowngradeFeedbackMutation } from 'data/feedback/exit-survey-send'
-import { ProjectInfo } from 'data/projects/projects-query'
+import { getComputeSize, OrgProject } from 'data/projects/org-projects-infinite-query'
import { useOrgSubscriptionUpdateMutation } from 'data/subscriptions/org-subscription-update-mutation'
import { Alert, Button, cn, Input, Modal } from 'ui'
import ProjectUpdateDisabledTooltip from '../ProjectUpdateDisabledTooltip'
export interface ExitSurveyModalProps {
visible: boolean
- projects: ProjectInfo[]
+ projects: OrgProject[]
onClose: (success?: boolean) => void
}
@@ -34,9 +34,10 @@ export const ExitSurveyModal = ({ visible, projects, onClose }: ExitSurveyModalP
useSendDowngradeFeedbackMutation()
const isSubmitting = isUpdating || isSubmittingFeedback
- const projectsWithComputeDowngrade = projects.filter(
- (project) => project.infra_compute_size !== 'nano'
- )
+ const projectsWithComputeDowngrade = projects.filter((project) => {
+ const computeSize = getComputeSize(project)
+ return computeSize !== 'nano'
+ })
const hasProjectsWithComputeDowngrade = projectsWithComputeDowngrade.length > 0
diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/PlanUpdateSidePanel.tsx b/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/PlanUpdateSidePanel.tsx
index 5d1f473e0b1..5859e95f9aa 100644
--- a/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/PlanUpdateSidePanel.tsx
+++ b/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/PlanUpdateSidePanel.tsx
@@ -2,7 +2,7 @@ import { PermissionAction } from '@supabase/shared-types/out/constants'
import { isArray } from 'lodash'
import { Check, ExternalLink } from 'lucide-react'
import { useRouter } from 'next/router'
-import { useEffect, useRef, useState } from 'react'
+import { useEffect, useMemo, useRef, useState } from 'react'
import { useParams } from 'common'
import { StudioPricingSidePanelOpenedEvent } from 'common/telemetry-constants'
@@ -13,7 +13,7 @@ import ShimmeringLoader from 'components/ui/ShimmeringLoader'
import { useFreeProjectLimitCheckQuery } from 'data/organizations/free-project-limit-check-query'
import { useOrganizationBillingSubscriptionPreview } from 'data/organizations/organization-billing-subscription-preview'
import { useOrganizationQuery } from 'data/organizations/organization-query'
-import { useProjectsQuery } from 'data/projects/projects-query'
+import { useOrgProjectsInfiniteQuery } from 'data/projects/org-projects-infinite-query'
import { useOrgPlansQuery } from 'data/subscriptions/org-plans-query'
import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query'
import type { OrgPlan } from 'data/subscriptions/types'
@@ -47,7 +47,8 @@ const getPartnerManagedResourceCta = (selectedOrganization: Organization) => {
}
}
}
-const PlanUpdateSidePanel = () => {
+
+export const PlanUpdateSidePanel = () => {
const router = useRouter()
const { slug } = useParams()
const { data: selectedOrganization } = useSelectedOrganizationQuery()
@@ -64,10 +65,13 @@ const PlanUpdateSidePanel = () => {
PermissionAction.BILLING_WRITE,
'stripe.subscriptions'
)
- const { data: projectsData } = useProjectsQuery()
- const orgProjects = (projectsData?.projects ?? []).filter(
- (it) => it.organization_id === selectedOrganization?.id
- )
+
+ const { data: orgProjectsData } = useOrgProjectsInfiniteQuery({ slug })
+ const orgProjects =
+ useMemo(
+ () => orgProjectsData?.pages.flatMap((page) => page.projects),
+ [orgProjectsData?.pages]
+ ) || []
const { data } = useOrganizationQuery({ slug })
const hasOrioleProjects = !!data?.has_oriole_project
@@ -98,6 +102,9 @@ const PlanUpdateSidePanel = () => {
const availablePlans: OrgPlan[] = plans?.plans ?? []
const hasMembersExceedingFreeTierLimit =
(membersExceededLimit || []).length > 0 &&
+ // [Joshen] Note that orgProjects is paginated so there's a chance this may omit certain projects
+ // Although I don't foresee this affecting a majority of users. Ideally perhaps we could return
+ // this data from the organization query
orgProjects.filter((it) => it.status !== 'INACTIVE' && it.status !== 'GOING_DOWN').length > 0
useEffect(() => {
@@ -357,5 +364,3 @@ const PlanUpdateSidePanel = () => {
</>
)
}
-
-export default PlanUpdateSidePanel
diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/Subscription.tsx b/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/Subscription.tsx
index ca0a81d48bb..b6c3173f9e4 100644
--- a/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/Subscription.tsx
+++ b/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/Subscription.tsx
@@ -17,7 +17,7 @@ import { Alert, Button } from 'ui'
import { Admonition } from 'ui-patterns'
import ProjectUpdateDisabledTooltip from '../ProjectUpdateDisabledTooltip'
import { Restriction } from '../Restriction'
-import PlanUpdateSidePanel from './PlanUpdateSidePanel'
+import { PlanUpdateSidePanel } from './PlanUpdateSidePanel'
const Subscription = () => {
const { slug } = useParams()
diff --git a/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/SubscriptionPlanUpdateDialog.tsx b/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/SubscriptionPlanUpdateDialog.tsx
index ebce8bcb1be..778d09c10d2 100644
--- a/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/SubscriptionPlanUpdateDialog.tsx
+++ b/apps/studio/components/interfaces/Organization/BillingSettings/Subscription/SubscriptionPlanUpdateDialog.tsx
@@ -14,7 +14,7 @@ import {
import AlertError from 'components/ui/AlertError'
import ShimmeringLoader from 'components/ui/ShimmeringLoader'
import { OrganizationBillingSubscriptionPreviewResponse } from 'data/organizations/organization-billing-subscription-preview'
-import { ProjectInfo } from 'data/projects/projects-query'
+import { OrgProject } from 'data/projects/org-projects-infinite-query'
import { useConfirmPendingSubscriptionChangeMutation } from 'data/subscriptions/org-subscription-confirm-pending-change'
import { useOrgSubscriptionUpdateMutation } from 'data/subscriptions/org-subscription-update-mutation'
import { SubscriptionTier } from 'data/subscriptions/types'
@@ -64,7 +64,7 @@ interface Props {
subscriptionPreview: OrganizationBillingSubscriptionPreviewResponse | undefined
subscription: any
currentPlanMeta: any
- projects: ProjectInfo[]
+ projects: OrgProject[]
}
export const SubscriptionPlanUpdateDialog = ({
diff --git a/apps/studio/components/interfaces/Support/AIAssistantOption.tsx b/apps/studio/components/interfaces/Support/AIAssistantOption.tsx
index 055ee41a9c6..e2b6db4f268 100644
--- a/apps/studio/components/interfaces/Support/AIAssistantOption.tsx
+++ b/apps/studio/components/interfaces/Support/AIAssistantOption.tsx
@@ -1,9 +1,9 @@
-import { useProjectsQuery } from 'data/projects/projects-query'
-import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { AnimatePresence, motion } from 'framer-motion'
import { MessageSquare } from 'lucide-react'
import Link from 'next/link'
import { useCallback, useEffect, useState } from 'react'
+
+import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { Button } from 'ui'
interface AIAssistantOptionProps {
@@ -17,9 +17,6 @@ export const AIAssistantOption = ({
organizationSlug,
isCondensed = false,
}: AIAssistantOptionProps) => {
- const { data } = useProjectsQuery()
- const projects = data?.projects ?? []
-
const { mutate: sendEvent } = useSendEventMutation()
const [isVisible, setIsVisible] = useState(isCondensed ? true : false)
@@ -42,16 +39,8 @@ export const AIAssistantOption = ({
return null
}
- const getProjectRef = () => {
- if (projectRef !== 'no-project') {
- return projectRef
- }
- // If no specific project selected, use first project from the org
- const orgProjects = projects?.filter((p) => p.organization_slug === organizationSlug)
- return orgProjects?.[0]?.ref || '_'
- }
-
- const aiLink = `/project/${getProjectRef()}?aiAssistantPanelOpen=true`
+ // If no specific project selected, use the wildcard route
+ const aiLink = `/project/${projectRef !== 'no-project' ? projectRef : '_'}?aiAssistantPanelOpen=true&slug=${organizationSlug}`
return (
<AnimatePresence initial={false}>
diff --git a/apps/studio/data/projects/org-projects-infinite-query.ts b/apps/studio/data/projects/org-projects-infinite-query.ts
index 356cf8df0da..69e7e24e592 100644
--- a/apps/studio/data/projects/org-projects-infinite-query.ts
+++ b/apps/studio/data/projects/org-projects-infinite-query.ts
@@ -85,3 +85,8 @@ export const useOrgProjectsInfiniteQuery = <TData = OrgProjectsInfiniteData>(
}
)
}
+
+export const getComputeSize = (project: OrgProject) => {
+ const primaryDatabase = project.databases.find((db) => db.identifier === project.ref)
+ return primaryDatabase?.infra_compute_size
+}
diff --git a/apps/studio/pages/project/_/[[...routeSlug]].tsx b/apps/studio/pages/project/_/[[...routeSlug]].tsx
index 30bdfef0c6e..57ff0d12d1f 100644
--- a/apps/studio/pages/project/_/[[...routeSlug]].tsx
+++ b/apps/studio/pages/project/_/[[...routeSlug]].tsx
@@ -3,7 +3,7 @@ import { NextPage } from 'next'
import { useRouter } from 'next/router'
import { useEffect, useState } from 'react'
-import { IS_PLATFORM, LOCAL_STORAGE_KEYS } from 'common'
+import { IS_PLATFORM, LOCAL_STORAGE_KEYS, useParams } from 'common'
import {
Header,
LoadingCardView,
@@ -33,6 +33,7 @@ import {
const GenericProjectPage: NextPage = () => {
const router = useRouter()
+ const { slug } = useParams()
const { routeSlug, ...queryParams } = router.query
const [lastVisitedOrgSlug] = useLocalStorageQuery(
@@ -40,8 +41,6 @@ const GenericProjectPage: NextPage = () => {
''
)
- const [selectedSlug, setSlug] = useState(lastVisitedOrgSlug)
-
const {
data: organizations = [],
isSuccess: isSuccessOrganizations,
@@ -50,6 +49,10 @@ const GenericProjectPage: NextPage = () => {
} = useOrganizationsQuery({
enabled: IS_PLATFORM,
})
+
+ const [selectedSlug, setSlug] = useState<string>(
+ slug || lastVisitedOrgSlug || organizations[0]?.slug
+ )
const selectedOrganization = organizations.find((x) => x.slug === selectedSlug)
const query = Object.keys(queryParams).length