Files
supabase/apps/studio/hooks/misc/useSelectedProject.ts
angelico 0880e0e1d0 chore: allow pausing for AWS_NEW projects regardless of pricing tier (#35493)
* chore: gitignore .pnpm-store/*

* chore: allow pausing for aws new projects

* fix: incorrect logic

* chore: clean up logic

* Small refactor

* chore: update conditions for useIsOrioleDbInAwsRevamped

---------

Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
2025-05-16 14:16:53 +08:00

60 lines
2.0 KiB
TypeScript

import { useMemo } from 'react'
import { useIsLoggedIn, useParams } from 'common'
import { useProjectDetailQuery } from 'data/projects/project-detail-query'
import { ProjectInfo, useProjectsQuery } from 'data/projects/projects-query'
import { PROVIDERS } from 'lib/constants'
export function useSelectedProject({ enabled = true } = {}) {
const { ref } = useParams()
const { data } = useProjectDetailQuery({ ref }, { enabled })
return useMemo(
() => data && { ...data, parentRef: data?.parent_project_ref ?? data?.ref },
[data]
)
}
export function useProjectByRef(
ref?: string
): Omit<ProjectInfo, 'organization_slug' | 'preview_branch_refs'> | undefined {
const isLoggedIn = useIsLoggedIn()
const { data: project } = 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 { data: projects } = useProjectsQuery({ enabled: isLoggedIn })
return useMemo(() => {
if (!ref) return undefined
if (project) return project
return projects?.find((project) => project.ref === ref)
}, [project, projects, ref])
}
export const useIsOrioleDb = () => {
const project = useSelectedProject()
const isOrioleDb = project?.dbVersion?.endsWith('orioledb')
return isOrioleDb
}
export const useIsOrioleDbInAws = () => {
const project = useSelectedProject()
const isOrioleDbInAws =
project?.dbVersion?.endsWith('orioledb') && project?.cloud_provider === PROVIDERS.AWS.id
return isOrioleDbInAws
}
export const useIsOrioleDbInAwsRevamped = () => {
const project = useSelectedProject()
const isOrioleDb = project?.dbVersion?.endsWith('orioledb')
const isOrioleDbInAws =
project?.dbVersion?.endsWith('orioledb') && project?.cloud_provider === PROVIDERS.AWS.id
const isOrioleDbInAwsRevamped = isOrioleDb && !isOrioleDbInAws
return isOrioleDbInAwsRevamped
}