The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Small refactors
Joshen Lim7a6f7c7bc396
diff --git a/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx b/studio/components/interfaces/Home/ProjectList/ProjectCard.tsxindex d4306e2b5ea..a3251879130 100644--- a/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx+++ b/studio/components/interfaces/Home/ProjectList/ProjectCard.tsx@@ -1,11 +1,12 @@import { IconGitBranch, IconGitHub } from 'ui'import CardButton from 'components/ui/CardButton'-import { BASE_PATH, PROJECT_STATUS } from 'lib/constants'+import { BASE_PATH } from 'lib/constants'import { Project } from 'types'import { IntegrationProjectConnection } from 'data/integrations/integrations.types'import { ResourceWarning } from 'data/usage/resource-warnings-query'import { ProjectCardStatus } from './ProjectCardStatus'+import { inferProjectStatus } from './ProjectCard.utils'export interface ProjectCardProps {project: Project@@ -15,32 +16,6 @@ export interface ProjectCardProps {resourceWarnings?: ResourceWarning}-const getProjetStatus = (project: Project) => {- let status- switch (project.status) {- case PROJECT_STATUS.ACTIVE_HEALTHY:- status = 'isHealthy'- break- case PROJECT_STATUS.GOING_DOWN:- case PROJECT_STATUS.PAUSING:- status = 'isPausing'- break- case PROJECT_STATUS.INACTIVE:- status = 'isPaused'- break- case PROJECT_STATUS.RESTORING:- status = 'isRestoring'- break- case PROJECT_STATUS.UNKNOWN:- case PROJECT_STATUS.COMING_UP:- status = 'isComingUp'- break- default:- status = ''- }- return status-}-const ProjectCard = ({project,rewriteHref,@@ -55,7 +30,7 @@ const ProjectCard = ({const isGithubIntegrated = githubIntegration !== undefinedconst isVercelIntegrated = vercelIntegration !== undefinedconst githubRepository = githubIntegration?.metadata.name ?? undefined- const projectStatus = getProjetStatus(project)+ const projectStatus = inferProjectStatus(project)return (<li className="col-span-1 list-none">diff --git a/studio/components/interfaces/Home/ProjectList/ProjectCard.utils.ts b/studio/components/interfaces/Home/ProjectList/ProjectCard.utils.tsnew file mode 100644index 00000000000..ea1ab6b0872--- /dev/null+++ b/studio/components/interfaces/Home/ProjectList/ProjectCard.utils.ts@@ -0,0 +1,34 @@+import { PROJECT_STATUS } from 'lib/constants'+import { Project } from 'types'++export const inferProjectStatus = (project: Project) => {+ let status = undefined+ switch (project.status) {+ case PROJECT_STATUS.ACTIVE_HEALTHY:+ status = 'isHealthy'+ break+ case PROJECT_STATUS.GOING_DOWN:+ case PROJECT_STATUS.PAUSING:+ status = 'isPausing'+ break+ case PROJECT_STATUS.INACTIVE:+ status = 'isPaused'+ break+ case PROJECT_STATUS.RESTORING:+ status = 'isRestoring'+ break+ case PROJECT_STATUS.UNKNOWN:+ case PROJECT_STATUS.COMING_UP:+ status = 'isComingUp'+ break+ }+ return status as InferredProjectStatus+}++export type InferredProjectStatus =+ | 'isHealthy'+ | 'isPausing'+ | 'isPaused'+ | 'isRestoring'+ | 'isComingUp'+ | undefineddiff --git a/studio/components/interfaces/Home/ProjectList/ProjectCardStatus.tsx b/studio/components/interfaces/Home/ProjectList/ProjectCardStatus.tsxindex e04a27d4bcb..5a0ec87c02e 100644--- a/studio/components/interfaces/Home/ProjectList/ProjectCardStatus.tsx+++ b/studio/components/interfaces/Home/ProjectList/ProjectCardStatus.tsx@@ -8,10 +8,12 @@ import {IconLoader,IconPauseCircle,} from 'ui'+import { InferredProjectStatus } from './ProjectCard.utils'+import { getWarningContent } from 'components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.utils'export interface ProjectCardWarningsProps {resourceWarnings: ResourceWarning- projectStatus: string+ projectStatus: InferredProjectStatus}export const ProjectCardStatus = ({@@ -31,54 +33,11 @@ export const ProjectCardStatus = ({resourceWarnings[property as keyof typeof resourceWarnings] !== null)- const getContent = (metric: string) => {- if (metric === 'is_readonly_mode_enabled') {- return RESOURCE_WARNING_MESSAGES.is_readonly_mode_enabled.cardContent.warning- }-- const severity = resourceWarnings[metric as keyof typeof resourceWarnings]-- if (typeof severity !== 'string') return undefined-- return RESOURCE_WARNING_MESSAGES[metric as keyof typeof RESOURCE_WARNING_MESSAGES][- 'cardContent'- ][severity as 'warning' | 'critical']- }-const hasCriticalWarning = activeWarnings.some((x) => resourceWarnings[x as keyof typeof resourceWarnings] === 'critical')-const isCritical = activeWarnings.includes('is_readonly_mode_enabled') || hasCriticalWarning- const getWarningType = () => {- let type = 'default'-- switch (true) {- case projectStatus === 'isPaused':- type = 'default'- break- case isCritical:- type = 'destructive'- break- default:- type = 'warning'- break- }-- return type as 'warning' | 'destructive' | 'default'- }-- const AlertIcon = () => {- switch (true) {- case projectStatus === 'isPaused' || projectStatus === 'isPausing':- return <IconPauseCircle strokeWidth={2} />- case projectStatus === 'isRestoring' || projectStatus === 'isComingUp':- return <IconLoader size={14} strokeWidth={2} />- default:- return <IconAlertTriangle strokeWidth={2} />- }- }const getTitle = () => {if (projectStatus === 'isPaused') return 'Project is paused'if (projectStatus === 'isPausing') return 'Project is pausing'@@ -90,7 +49,7 @@ export const ProjectCardStatus = ({? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.cardContent[hasCriticalWarning ? 'critical' : 'warning'].title- : getContent(activeWarnings[0])?.title+ : getWarningContent(resourceWarnings, activeWarnings[0], 'cardContent')?.title}const getDescription = () => {@@ -108,12 +67,16 @@ export const ProjectCardStatus = ({? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.cardContent[hasCriticalWarning ? 'critical' : 'warning'].description- : getContent(activeWarnings[0])?.description+ : getWarningContent(resourceWarnings, activeWarnings[0], 'cardContent')?.description}const alertTitle = getTitle()const alertDescription = getDescription()- const alertType = getWarningType()+ const alertType = isCritical+ ? 'destructive'+ : projectStatus === 'isPaused'+ ? 'default'+ : 'warning'if (activeWarnings.length === 0 && projectStatus === 'isHealthy') return <div className="py-2" />@@ -121,11 +84,15 @@ export const ProjectCardStatus = ({<div><Alert_Shadcn_variant={alertType}- className="border-0 rounded-none rounded-b-md my-2 mb-2.5 [&>svg]:w-[28px]-[&>svg]:h-[28px] [&>svg]:p-1.5 [&>svg]:left-6 pl-6"+ className="border-0 rounded-none rounded-b-md my-2 mb-2.5 [&>svg]:w-[28px] [&>svg]:h-[28px] [&>svg]:p-1.5 [&>svg]:left-6 pl-6">- <AlertIcon />-+ {projectStatus === 'isPaused' || projectStatus === 'isPausing' ? (+ <IconPauseCircle strokeWidth={2} />+ ) : projectStatus === 'isRestoring' || projectStatus === 'isComingUp' ? (+ <IconLoader size={14} strokeWidth={2} className="animate-spin" />+ ) : (+ <IconAlertTriangle strokeWidth={2} />+ )}<AlertTitle_Shadcn_ className="text-xs mb-0.5">{alertTitle}</AlertTitle_Shadcn_><AlertDescription_Shadcn_ className="text-xs">{alertDescription}</AlertDescription_Shadcn_></Alert_Shadcn_>diff --git a/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx b/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsxindex f0fcd6320ee..37df8e4bb7a 100644--- a/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx+++ b/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.tsx@@ -13,6 +13,7 @@ import {import { useResourceWarningsQuery } from 'data/usage/resource-warnings-query'import { useSelectedOrganization } from 'hooks'import { RESOURCE_WARNING_MESSAGES } from './ResourceExhaustionWarningBanner.constants'+import { getWarningContent } from './ResourceExhaustionWarningBanner.utils'const ResourceExhaustionWarningBanner = () => {const { ref } = useParams()@@ -46,34 +47,30 @@ const ResourceExhaustionWarningBanner = () => {: falseconst isCritical = activeWarnings.includes('is_readonly_mode_enabled') || hasCriticalWarning- const getContent = (metric: string) => {- if (projectResourceWarnings === undefined) return undefined- if (metric === 'is_readonly_mode_enabled') {- return RESOURCE_WARNING_MESSAGES.is_readonly_mode_enabled.bannerContent.warning- }- const severity = projectResourceWarnings[metric as keyof typeof projectResourceWarnings]- if (typeof severity !== 'string') return undefined- return RESOURCE_WARNING_MESSAGES[metric as keyof typeof RESOURCE_WARNING_MESSAGES]- .bannerContent[severity as 'warning' | 'critical']- }-const title =activeWarnings.length > 1? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.bannerContent[hasCriticalWarning ? 'critical' : 'warning'].title- : getContent(activeWarnings[0])?.title+ : projectResourceWarnings !== undefined+ ? getWarningContent(projectResourceWarnings, activeWarnings[0], 'bannerContent')?.title+ : null+const description =activeWarnings.length > 1? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.bannerContent[hasCriticalWarning ? 'critical' : 'warning'].description- : getContent(activeWarnings[0])?.description+ : projectResourceWarnings !== undefined+ ? getWarningContent(projectResourceWarnings, activeWarnings[0], 'bannerContent')?.description+ : null+const learnMoreUrl =activeWarnings.length > 1? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.docsUrl: RESOURCE_WARNING_MESSAGES[activeWarnings[0] as keyof typeof RESOURCE_WARNING_MESSAGES]?.docsUrl+const metric =activeWarnings.length > 1? RESOURCE_WARNING_MESSAGES.multiple_resource_warnings.metricdiff --git a/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.utils.ts b/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.utils.tsnew file mode 100644index 00000000000..0b3dd8b77e7--- /dev/null+++ b/studio/components/ui/ResourceExhaustionWarningBanner/ResourceExhaustionWarningBanner.utils.ts@@ -0,0 +1,19 @@+import { ResourceWarning } from 'data/usage/resource-warnings-query'+import { RESOURCE_WARNING_MESSAGES } from './ResourceExhaustionWarningBanner.constants'++export const getWarningContent = (+ resourceWarnings: ResourceWarning,+ metric: string,+ contentType: 'cardContent' | 'bannerContent'+) => {+ if (metric === 'is_readonly_mode_enabled') {+ return RESOURCE_WARNING_MESSAGES.is_readonly_mode_enabled.cardContent.warning+ }++ const severity = resourceWarnings[metric as keyof typeof resourceWarnings]+ if (typeof severity !== 'string') return undefined++ return RESOURCE_WARNING_MESSAGES[metric as keyof typeof RESOURCE_WARNING_MESSAGES][contentType][+ severity as 'warning' | 'critical'+ ]+}