Skip to content

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

add advisor and stats to home (#35580)

Saxon Fletcher9d36654fbeba
diff --git a/apps/studio/components/interfaces/Home/AdvisorWidget.tsx b/apps/studio/components/interfaces/Home/AdvisorWidget.tsx
new file mode 100644
index 00000000000..9f34cdf006f
--- /dev/null
+++ b/apps/studio/components/interfaces/Home/AdvisorWidget.tsx
@@ -0,0 +1,328 @@
+import { Activity, ExternalLink, Shield } from 'lucide-react'
+import Link from 'next/link'
+import { useMemo, useState } from 'react'
+
+import { useParams } from 'common'
+import { LINTER_LEVELS } from 'components/interfaces/Linter/Linter.constants'
+import { EntityTypeIcon, lintInfoMap } from 'components/interfaces/Linter/Linter.utils'
+import { useQueryPerformanceQuery } from 'components/interfaces/Reports/Reports.queries'
+import { ButtonTooltip } from 'components/ui/ButtonTooltip'
+import { Lint, useProjectLintsQuery } from 'data/lint/lint-query'
+import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
+import {
+ AiIconAnimation,
+ Card,
+ CardContent,
+ CardHeader,
+ CardTitle,
+ Table,
+ TableBody,
+ TableCell,
+ TableHead,
+ TableHeader,
+ TableRow,
+ Tabs_Shadcn_ as Tabs,
+ TabsContent_Shadcn_ as TabsContent,
+ TabsList_Shadcn_ as TabsList,
+ TabsTrigger_Shadcn_ as TabsTrigger,
+} from 'ui'
+import ShimmeringLoader from 'ui-patterns/ShimmeringLoader'
+
+interface SlowQuery {
+ rolname: string
+ mean_time: number
+ calls: number
+ query: string
+}
+
+export const AdvisorWidget = () => {
+ const { ref: projectRef } = useParams()
+ const [selectedTab, setSelectedTab] = useState<'security' | 'performance'>('security')
+ const { data: lints, isLoading: isLoadingLints } = useProjectLintsQuery({ projectRef })
+ const { data: slowestQueriesData, isLoading: isLoadingSlowestQueries } = useQueryPerformanceQuery(
+ {
+ preset: 'slowestExecutionTime',
+ }
+ )
+ const snap = useAiAssistantStateSnapshot()
+
+ const securityLints = useMemo(
+ () => (lints ?? []).filter((lint: Lint) => lint.categories.includes('SECURITY')),
+ [lints]
+ )
+ const performanceLints = useMemo(
+ () => (lints ?? []).filter((lint: Lint) => lint.categories.includes('PERFORMANCE')),
+ [lints]
+ )
+
+ const securityErrorCount = securityLints.filter(
+ (lint: Lint) => lint.level === LINTER_LEVELS.ERROR
+ ).length
+ const securityWarningCount = securityLints.filter(
+ (lint: Lint) => lint.level === LINTER_LEVELS.WARN
+ ).length
+ const performanceErrorCount = performanceLints.filter(
+ (lint: Lint) => lint.level === LINTER_LEVELS.ERROR
+ ).length
+ const performanceWarningCount = performanceLints.filter(
+ (lint: Lint) => lint.level === LINTER_LEVELS.WARN
+ ).length
+
+ const top5SlowestQueries = useMemo(
+ () => ((slowestQueriesData ?? []) as SlowQuery[]).slice(0, 5),
+ [slowestQueriesData]
+ )
+
+ const totalIssues =
+ securityErrorCount + securityWarningCount + performanceErrorCount + performanceWarningCount
+ const hasErrors = securityErrorCount > 0 || performanceErrorCount > 0
+ const hasWarnings = securityWarningCount > 0 || performanceWarningCount > 0
+
+ let titleContent: React.ReactNode
+
+ if (totalIssues === 0) {
+ titleContent = <h2 className="text-xl">No issues available</h2>
+ } else {
+ const issuesText = totalIssues === 1 ? 'issue' : 'issues'
+ const numberDisplay = totalIssues.toString()
+
+ let attentionClassName = ''
+ if (hasErrors) {
+ attentionClassName = 'text-destructive'
+ } else if (hasWarnings) {
+ attentionClassName = 'text-warning'
+ }
+
+ titleContent = (
+ <h2 className="text-xl">
+ {numberDisplay} {issuesText} need
+ {totalIssues === 1 ? 's' : ''} <span className={attentionClassName}>attention</span>
+ </h2>
+ )
+ }
+
+ const renderLintTabContent = (
+ title: string,
+ lints: Lint[],
+ errorCount: number,
+ warningCount: number,
+ isLoading: boolean
+ ) => {
+ const topIssues = lints
+ .filter((lint) => lint.level === LINTER_LEVELS.ERROR || lint.level === LINTER_LEVELS.WARN)
+ .sort((a, b) => (a.level === LINTER_LEVELS.ERROR ? -1 : 1))
+
+ return (
+ <div className="h-full">
+ {isLoading && (
+ <div className="flex flex-col p-4 gap-2">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ </div>
+ )}
+ {!isLoading && (errorCount > 0 || warningCount > 0) && (
+ <ul>
+ {topIssues.map((lint) => {
+ const lintText = lint.detail ? lint.detail : lint.title
+ return (
+ <li
+ key={lint.cache_key}
+ className="text-sm w-full border-b my-0 last:border-b-0 group px-4 "
+ >
+ <div className="flex items-center justify-between w-full group">
+ <Link
+ href={`/project/${projectRef}/advisors/${title.toLowerCase()}?id=${lint.cache_key}&preset=${lint.level}`}
+ className="flex items-center gap-2 transition truncate flex-1 min-w-0 py-3"
+ >
+ <EntityTypeIcon type={lint.metadata?.type} />
+ <p className="flex-1 font-mono text-xs leading-6 text-xs text-foreground-light group-hover:text-foreground truncate">
+ {lintText.replace(/\\`/g, '`')}
+ </p>
+ </Link>
+ <ButtonTooltip
+ type="text"
+ className="px-1 opacity-0 group-hover:opacity-100 w-7"
+ icon={<AiIconAnimation className="w-5 h-5" />}
+ onClick={(e) => {
+ e.stopPropagation()
+ e.preventDefault()
+ snap.newChat({
+ name: 'Summarize lint',
+ open: true,
+ initialInput: `Summarize the issue and suggest fixes for the following lint item:
+ Title: ${lintInfoMap.find((item) => item.name === lint.name)?.title ?? lint.title}
+ Entity: ${(lint.metadata && (lint.metadata.entity || (lint.metadata.schema && lint.metadata.name && `${lint.metadata.schema}.${lint.metadata.name}`))) ?? 'N/A'}
+ Schema: ${lint.metadata?.schema ?? 'N/A'}
+ Issue Details: ${lint.detail ? lint.detail.replace(/\`/g, '`') : 'N/A'}
+ Description: ${lint.description ? lint.description.replace(/\`/g, '`') : 'N/A'}`,
+ })
+ }}
+ tooltip={{
+ content: { side: 'bottom', text: 'What is this issue?' },
+ }}
+ />
+ </div>
+ </li>
+ )
+ })}
+ </ul>
+ )}
+ {!isLoading && errorCount === 0 && warningCount === 0 && (
+ <div className="flex-1 flex flex-col h-full items-center justify-center gap-2">
+ <Shield size={20} strokeWidth={1.5} className="text-foreground-muted" />
+ <p className="text-sm text-foreground-light">No {title.toLowerCase()} issues found</p>
+ </div>
+ )}
+ </div>
+ )
+ }
+
+ return (
+ <div>
+ {isLoadingLints ? (
+ <ShimmeringLoader className="w-96 mb-6" />
+ ) : (
+ <div className="flex justify-between items-center mb-6">{titleContent}</div>
+ )}
+ <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
+ <Card className="h-80">
+ <Tabs value={selectedTab} className="h-full flex flex-col">
+ <CardHeader className="h-10 py-0 pl-4 pr-2 flex flex-row items-center justify-between flex-0">
+ <TabsList className="flex justify-start rounded-none gap-x-4 border-b-0 !mt-0 pt-0">
+ <TabsTrigger
+ value="security"
+ onClick={() => setSelectedTab('security')}
+ className="flex items-center gap-2 text-xs py-3 border-b-[1px] font-mono uppercase"
+ >
+ Security{' '}
+ {securityErrorCount + securityWarningCount > 0 && (
+ <div className="rounded bg-warning text-warning-100 px-1">
+ {securityErrorCount + securityWarningCount}
+ </div>
+ )}
+ </TabsTrigger>
+ <TabsTrigger
+ value="performance"
+ onClick={() => setSelectedTab('performance')}
+ className="flex items-center gap-2 text-xs py-3 border-b-[1px] font-mono uppercase"
+ >
+ Performance{' '}
+ {performanceErrorCount + performanceWarningCount > 0 && (
+ <div className="rounded bg-warning text-warning-100 px-1">
+ {performanceErrorCount + performanceWarningCount}
+ </div>
+ )}
+ </TabsTrigger>
+ </TabsList>
+ <ButtonTooltip
+ asChild
+ type="text"
+ className="!mt-0 w-7"
+ icon={<ExternalLink />}
+ tooltip={{
+ content: {
+ side: 'bottom',
+ text: `Open ${selectedTab} Advisor`,
+ className: 'capitalize',
+ },
+ }}
+ >
+ <Link href={`/project/${projectRef}/advisors/${selectedTab}`} />
+ </ButtonTooltip>
+ </CardHeader>
+ <CardContent className="!p-0 mt-0 flex-1 overflow-y-auto">
+ <TabsContent value="security" className="p-0 mt-0 h-full">
+ {renderLintTabContent(
+ 'Security',
+ securityLints,
+ securityErrorCount,
+ securityWarningCount,
+ isLoadingLints
+ )}
+ </TabsContent>
+ <TabsContent value="performance" className="p-0 mt-0 h-full">
+ {renderLintTabContent(
+ 'Performance',
+ performanceLints,
+ performanceErrorCount,
+ performanceWarningCount,
+ isLoadingLints
+ )}
+ </TabsContent>
+ </CardContent>
+ </Tabs>
+ </Card>
+
+ <Card className="h-80 flex flex-col">
+ <CardHeader className="h-10 flex-row items-center justify-between py-0 pl-4 pr-2">
+ <CardTitle>Slow Queries</CardTitle>
+ <ButtonTooltip
+ asChild
+ type="text"
+ className="!mt-0 w-7"
+ icon={<ExternalLink />}
+ tooltip={{
+ content: {
+ side: 'bottom',
+ text: `Open Query Performance Advisor`,
+ },
+ }}
+ >
+ <Link href={`/project/${projectRef}/advisors/query-performance`} />
+ </ButtonTooltip>
+ </CardHeader>
+ <CardContent className="!p-0 flex-1 overflow-y-auto">
+ {isLoadingSlowestQueries ? (
+ <div className="space-y-2 p-4">
+ <ShimmeringLoader />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ <ShimmeringLoader className="w-3/4" />
+ <ShimmeringLoader className="w-1/2" />
+ </div>
+ ) : top5SlowestQueries.length === 0 ? (
+ <div className="flex-1 flex flex-col h-full items-center justify-center gap-2">
+ <Activity strokeWidth={1.5} size={20} className="text-foreground-muted" />
+ <p className="text-sm text-foreground-light">
+ No slow queries found in the selected period
+ </p>
+ </div>
+ ) : (
+ <Table className="text-xs font-mono max-w-full">
+ <TableHeader>
+ <TableRow>
+ <TableHead className="text-foreground-lighter truncate py-2 h-auto">
+ Query
+ </TableHead>
+ <TableHead className="text-foreground-lighter truncate py-2 h-auto">
+ Avg time
+ </TableHead>
+ <TableHead className="text-foreground-lighter truncate py-2 h-auto">
+ Calls
+ </TableHead>
+ </TableRow>
+ </TableHeader>
+ <TableBody>
+ {/* Added explicit types for map parameters */}
+ {top5SlowestQueries.map((query: SlowQuery, i: number) => (
+ <TableRow key={i} className="py-2">
+ <TableCell className="font-mono truncate max-w-xs">{query.query}</TableCell>
+
+ <TableCell className="font-mono truncate max-w-xs">
+ {typeof query.mean_time === 'number'
+ ? `${(query.mean_time / 1000).toFixed(2)}s`
+ : 'N/A'}
+ </TableCell>
+ <TableCell className="font-mono truncate max-w-xs">{query.calls}</TableCell>
+ </TableRow>
+ ))}
+ </TableBody>
+ </Table>
+ )}
+ </CardContent>
+ </Card>
+ </div>
+ </div>
+ )
+}
diff --git a/apps/studio/components/interfaces/Home/ProjectUsage.tsx b/apps/studio/components/interfaces/Home/ProjectUsage.tsx
index 7ab7d78caa5..911410b65cb 100644
--- a/apps/studio/components/interfaces/Home/ProjectUsage.tsx
+++ b/apps/studio/components/interfaces/Home/ProjectUsage.tsx
@@ -137,7 +137,7 @@ const ProjectUsage = () => {
</span>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 md:gap-4 lg:grid-cols-4">
- <Panel>
+ <Panel className="mb-0 md:mb-0">
<Panel.Content className="space-y-4">
<PanelHeader
icon={
@@ -163,7 +163,7 @@ const ProjectUsage = () => {
</Panel.Content>
</Panel>
{authEnabled && (
- <Panel>
+ <Panel className="mb-0 md:mb-0">
<Panel.Content className="space-y-4">
<PanelHeader
icon={
@@ -189,7 +189,7 @@ const ProjectUsage = () => {
</Panel>
)}
{storageEnabled && (
- <Panel>
+ <Panel className="mb-0 md:mb-0">
<Panel.Content className="space-y-4">
<PanelHeader
icon={
@@ -215,7 +215,7 @@ const ProjectUsage = () => {
</Panel.Content>
</Panel>
)}
- <Panel>
+ <Panel className="mb-0 md:mb-0">
<Panel.Content className="space-y-4">
<PanelHeader
icon={
diff --git a/apps/studio/components/interfaces/Home/ProjectUsageSection.tsx b/apps/studio/components/interfaces/Home/ProjectUsageSection.tsx
index 19f8a375c8f..08f566751f1 100644
--- a/apps/studio/components/interfaces/Home/ProjectUsageSection.tsx
+++ b/apps/studio/components/interfaces/Home/ProjectUsageSection.tsx
@@ -1,7 +1,5 @@
-import dayjs from 'dayjs'
import { AlertCircle } from 'lucide-react'
-import { NewProjectPanel } from 'components/interfaces/Home'
import { ProjectUsageLoadingState } from 'components/layouts/ProjectLayout/LoadingState'
import InformationBox from 'components/ui/InformationBox'
import { useProjectLogRequestsCountQuery } from 'data/analytics/project-log-requests-count-query'
@@ -9,23 +7,21 @@ import { useProjectLogStatsQuery } from 'data/analytics/project-log-stats-query'
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
import ProjectUsage from './ProjectUsage'
-const ProjectUsageSection = () => {
+export const ProjectUsageSection = () => {
const project = useSelectedProject()
+ const { error, isLoading } = useProjectLogRequestsCountQuery({ projectRef: project?.ref })
- const {
- data: usage,
- error: usageError,
- isLoading,
- } = useProjectLogRequestsCountQuery({ projectRef: project?.ref })
-
- // wait for the stats to load before showing the usage section
- // to eliminate multiple spinners
+ // wait for the stats to load before showing the usage section to eliminate multiple spinners
const { isLoading: isLogsStatsLoading } = useProjectLogStatsQuery({
projectRef: project?.ref,
interval: 'minutely',
})
- if (usageError) {
+ if (isLoading || isLogsStatsLoading) {
+ return <ProjectUsageLoadingState />
+ }
+
+ if (error) {
return (
<InformationBox
hideCollapse
@@ -36,23 +32,5 @@ const ProjectUsageSection = () => {
)
}
- // if the project has more than 25 requests, we assume the project has usage
- const hasProjectData =
- usage?.result && usage.result.length > 0 ? (usage.result[0] as any).count > 25 : false
-
- const isNewProject = dayjs(project?.inserted_at).isAfter(dayjs().subtract(2, 'day'))
-
- return (
- <>
- {isLoading || isLogsStatsLoading ? (
- <ProjectUsageLoadingState />
- ) : hasProjectData && !isNewProject ? (
- <ProjectUsage />
- ) : (
- <NewProjectPanel />
- )}
- </>
- )
+ return <ProjectUsage />
}
-
-export default ProjectUsageSection
diff --git a/apps/studio/components/interfaces/Home/SecurityStatus.tsx b/apps/studio/components/interfaces/Home/SecurityStatus.tsx
deleted file mode 100644
index be4dc9b4425..00000000000
--- a/apps/studio/components/interfaces/Home/SecurityStatus.tsx
+++ /dev/null
@@ -1,133 +0,0 @@
-import { CheckCircle2, ChevronRight, Loader2 } from 'lucide-react'
-import Link from 'next/link'
-import { Fragment, useState } from 'react'
-
-import { useParams } from 'common'
-import { useProjectLintsQuery } from 'data/lint/lint-query'
-import {
- Button,
- PopoverContent_Shadcn_,
- PopoverSeparator_Shadcn_,
- PopoverTrigger_Shadcn_,
- Popover_Shadcn_,
- cn,
-} from 'ui'
-import { LINTER_LEVELS, LINT_TABS } from '../Linter/Linter.constants'
-
-export const SecurityStatus = () => {
- const { ref } = useParams()
- const [open, setOpen] = useState(false)
- const { data, isLoading } = useProjectLintsQuery({ projectRef: ref })
-
- const securityLints = (data ?? []).filter((lint) => lint.categories.includes('SECURITY'))
- const errorLints = securityLints.filter((lint) => lint.level === 'ERROR')
- const warnLints = securityLints.filter((lint) => lint.level === 'WARN')
- const infoLints = securityLints.filter((lint) => lint.level === 'INFO')
-
- const totalLints = errorLints.length + warnLints.length + infoLints.length
- const noIssuesFound = totalLints === 0
-
- return (
- <Popover_Shadcn_ modal={false} open={open} onOpenChange={setOpen}>
- <PopoverTrigger_Shadcn_ asChild>
- <Button
- type="default"
- icon={
- isLoading ? (
- <Loader2 className="animate-spin" />
- ) : (
- <div
- className={cn(
- 'w-2 h-2 rounded-full',
- noIssuesFound
- ? 'bg-brand'
- : errorLints.length > 0
- ? 'bg-destructive-600'
- : 'bg-warning-600'
- )}
- />
- )
- }
- >
- Security Issues
- </Button>
- </PopoverTrigger_Shadcn_>
- <PopoverContent_Shadcn_ side="bottom" align="center" className={cn('py-1.5 px-0 w-64')}>
- <div className="text-sm">
- {noIssuesFound ? (
- <div className="flex gap-3 px-4">
- <CheckCircle2 className="text-brand shrink-0" size={18} strokeWidth={1.5} />
- <div className="grid gap-1">
- <p className="">No security issues found</p>
- <p className="text-xs text-foreground-light">
- Keep monitoring Security Advisor for updates as your project grows.
- </p>
- <Button asChild type="default" className="w-min mt-2">
- <Link href={`/project/${ref}/database/security-advisor`}>Security Advisor</Link>
- </Button>
- </div>
- </div>
- ) : (
- <div className="grid">
- <p className="text-xs text-foreground-lighter px-3 pb-1.5">
- {totalLints} issue{totalLints > 1 ? 's' : ''} have been identified
- </p>
- <PopoverSeparator_Shadcn_ />
- {[
- { lints: errorLints, level: LINTER_LEVELS.ERROR },
- { lints: warnLints, level: LINTER_LEVELS.WARN },
- { lints: infoLints, level: LINTER_LEVELS.INFO },
- ].map(({ lints, level }) => {
- const { label, descriptionShort } = LINT_TABS.find((tab) => tab.id === level) ?? {}
- return (
- lints.length > 0 && (
- <Fragment key={level}>
- <Link href={`/project/${ref}/database/security-advisor?preset=${level}`}>
- <div className="group flex items-center justify-between w-full px-3 py-3 transition hover:bg-surface-300">
- <div className="flex gap-x-3">
- <div>
- <StatusDot level={level} />
- </div>
- <div>
- <p className="text-xs">
- {lints.length}{' '}
- {label === 'Info'
- ? 'suggestion'
- : label?.slice(0, label.length - 1).toLowerCase()}
- {lints.length > 1 ? 's' : ''}
- </p>
- <p className="text-xs text-foreground-light">{descriptionShort}</p>
- </div>
- </div>
- <ChevronRight
- size={14}
- className="transition opacity-0 group-hover:opacity-100"
- />
- </div>
- </Link>
- <PopoverSeparator_Shadcn_ />
- </Fragment>
- )
- )
- })}
- <div className="flex items-center justify-end pt-2 pb-0.5 px-3">
- <Button asChild type="default" className="w-min">
- <Link href={`/project/${ref}/database/security-advisor`}>Security Advisor</Link>
- </Button>
- </div>
- </div>
- )}
- </div>
- </PopoverContent_Shadcn_>
- </Popover_Shadcn_>
- )
-}
-
-const StatusDot = ({ level }: { level: LINTER_LEVELS }) => {
- const variants = {
- [LINTER_LEVELS.ERROR]: 'bg-destructive-600',
- [LINTER_LEVELS.WARN]: 'bg-warning-600',
- [LINTER_LEVELS.INFO]: 'bg-foreground-lighter dark:bg-foreground-light',
- }
- return <div className={cn('w-2 h-2 rounded-full mt-1.5', variants[level])} />
-}
diff --git a/apps/studio/components/interfaces/Home/ServiceStatus.tsx b/apps/studio/components/interfaces/Home/ServiceStatus.tsx
index 2d0699bfedc..2c3381b054b 100644
--- a/apps/studio/components/interfaces/Home/ServiceStatus.tsx
+++ b/apps/studio/components/interfaces/Home/ServiceStatus.tsx
@@ -3,6 +3,7 @@ import { AlertTriangle, CheckCircle2, ChevronRight, Loader2 } from 'lucide-react
import Link from 'next/link'
import { useEffect, useState } from 'react'
+import { PopoverSeparator } from '@ui/components/shadcn/ui/popover'
import { useParams } from 'common'
import { useEdgeFunctionServiceStatusQuery } from 'data/service-status/edge-functions-status-query'
import {
@@ -18,7 +19,6 @@ import {
PopoverTrigger_Shadcn_,
Popover_Shadcn_,
} from 'ui'
-import { PopoverSeparator } from '@ui/components/shadcn/ui/popover'
const SERVICE_STATUS_THRESHOLD = 5 // minutes
@@ -70,7 +70,7 @@ const StatusIcon = ({
return <AlertIcon />
}
-const ServiceStatus = () => {
+export const ServiceStatus = () => {
const { ref } = useParams()
const project = useSelectedProject()
const [open, setOpen] = useState(false)
@@ -248,7 +248,7 @@ const ServiceStatus = () => {
{isBranch ? 'Preview Branch' : 'Project'} Status
</Button>
</PopoverTrigger_Shadcn_>
- <PopoverContent_Shadcn_ className="p-0 w-56" side="bottom" align="center">
+ <PopoverContent_Shadcn_ portal className="p-0 w-56" side="bottom" align="center">
{services.map((service) => (
<Link
href={`/project/${ref}${service.logsUrl}`}
@@ -295,5 +295,3 @@ const ServiceStatus = () => {
</Popover_Shadcn_>
)
}
-
-export default ServiceStatus
diff --git a/apps/studio/components/layouts/ProjectLayout/LoadingState.tsx b/apps/studio/components/layouts/ProjectLayout/LoadingState.tsx
index b0dea6fe505..122ff258752 100644
--- a/apps/studio/components/layouts/ProjectLayout/LoadingState.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/LoadingState.tsx
@@ -12,8 +12,8 @@ const LoadingState = () => {
: 'Welcome to your project'
return (
- <div className="w-full mx-auto my-16 space-y-16 max-w-7xl">
- <div className="flex items-center mx-6 space-x-6">
+ <div className="w-full mx-auto">
+ <div className="max-w-7xl mx-auto flex items-center space-x-6 h-[184px]">
{isLoading ? (
<ShimmeringLoader className="h-9 w-40" />
) : (
@@ -21,11 +21,13 @@ const LoadingState = () => {
)}
</div>
- <div className="mx-6">
+ <div className="w-full border-t mb-16" />
+
+ <div className="max-w-7xl mx-auto mb-16">
<ProjectUsageLoadingState />
</div>
- <div className="mx-6 space-y-4">
+ <div className="max-w-7xl mx-auto space-y-4">
<ShimmeringLoader className="w-40 h-7" />
<ShimmeringLoader className="w-full h-32" />
</div>
@@ -37,13 +39,13 @@ export default LoadingState
export const ProjectUsageLoadingState = () => {
return (
- <div className="space-y-4">
+ <div className="space-y-6">
<ShimmeringLoader className="w-40 h-7" />
- <div className="flex flex-col md:flex-row gap-2 md:gap-4 lg:gap-8">
- <ShimmeringLoader className="w-full h-[304px]" />
- <ShimmeringLoader className="w-full h-[304px]" />
- <ShimmeringLoader className="w-full h-[304px]" />
- <ShimmeringLoader className="w-full h-[304px]" />
+ <div className="flex flex-col md:flex-row gap-2 md:gap-4">
+ <ShimmeringLoader className="w-full h-[320px] py-0" />
+ <ShimmeringLoader className="w-full h-[320px] py-0" />
+ <ShimmeringLoader className="w-full h-[320px] py-0" />
+ <ShimmeringLoader className="w-full h-[320px] py-0" />
</div>
</div>
)
diff --git a/apps/studio/components/layouts/ProjectLayout/PausedState/ProjectPausedState.tsx b/apps/studio/components/layouts/ProjectLayout/PausedState/ProjectPausedState.tsx
index c3f7c1bfe94..aff7eee8053 100644
--- a/apps/studio/components/layouts/ProjectLayout/PausedState/ProjectPausedState.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/PausedState/ProjectPausedState.tsx
@@ -140,7 +140,7 @@ export const ProjectPausedState = ({ product }: ProjectPausedStateProps) => {
<>
<div className="space-y-4">
<div className="w-full mx-auto mb-8 md:mb-16 max-w-7xl">
- <div className="mx-6 flex md:h-[500px] items-center justify-center rounded border border-overlay bg-surface-100 p-4 md:p-8">
+ <div className="flex md:h-[500px] items-center justify-center rounded border border-overlay bg-surface-100 p-4 md:p-8">
<div className="grid w-[550px] gap-4">
<div className="mx-auto flex max-w-[300px] items-center justify-center space-x-4 lg:space-x-8">
<PauseCircle className="text-foreground-light" size={50} strokeWidth={1.5} />
diff --git a/apps/studio/pages/project/[ref]/index.tsx b/apps/studio/pages/project/[ref]/index.tsx
index 46af85fcf5b..692f1437dc8 100644
--- a/apps/studio/pages/project/[ref]/index.tsx
+++ b/apps/studio/pages/project/[ref]/index.tsx
@@ -1,17 +1,21 @@
+import dayjs from 'dayjs'
import { useEffect, useRef } from 'react'
import { useParams } from 'common'
-import { ClientLibrary, ExampleProject } from 'components/interfaces/Home'
+import { ClientLibrary, ExampleProject, NewProjectPanel } from 'components/interfaces/Home'
+import { AdvisorWidget } from 'components/interfaces/Home/AdvisorWidget'
import { CLIENT_LIBRARIES, EXAMPLE_PROJECTS } from 'components/interfaces/Home/Home.constants'
-import ProjectUsageSection from 'components/interfaces/Home/ProjectUsageSection'
-import { SecurityStatus } from 'components/interfaces/Home/SecurityStatus'
-import ServiceStatus from 'components/interfaces/Home/ServiceStatus'
+import { ProjectUsageSection } from 'components/interfaces/Home/ProjectUsageSection'
+import { ServiceStatus } from 'components/interfaces/Home/ServiceStatus'
import DefaultLayout from 'components/layouts/DefaultLayout'
import { ProjectPausedState } from 'components/layouts/ProjectLayout/PausedState/ProjectPausedState'
import { ProjectLayoutWithAuth } from 'components/layouts/ProjectLayout/ProjectLayout'
import { ComputeBadgeWrapper } from 'components/ui/ComputeBadgeWrapper'
import { InlineLink } from 'components/ui/InlineLink'
import { ProjectUpgradeFailedBanner } from 'components/ui/ProjectUpgradeFailedBanner'
+import { useEdgeFunctionsQuery } from 'data/edge-functions/edge-functions-query'
+import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
+import { useTablesQuery } from 'data/tables/tables-query'
import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization'
import { useIsOrioleDb, useSelectedProject } from 'hooks/misc/useSelectedProject'
import { IS_PLATFORM, PROJECT_STATUS } from 'lib/constants'
@@ -19,6 +23,7 @@ import { useAppStateSnapshot } from 'state/app-state'
import type { NextPageWithLayout } from 'types'
import {
Badge,
+ cn,
Tabs_Shadcn_,
TabsContent_Shadcn_,
TabsList_Shadcn_,
@@ -27,6 +32,7 @@ import {
TooltipContent,
TooltipTrigger,
} from 'ui'
+import ShimmeringLoader from 'ui-patterns/ShimmeringLoader'
const Home: NextPageWithLayout = () => {
const organization = useSelectedOrganization()
@@ -36,6 +42,9 @@ const Home: NextPageWithLayout = () => {
const { enableBranching } = useParams()
const hasShownEnableBranchingModalRef = useRef(false)
+ const isPaused = project?.status === PROJECT_STATUS.INACTIVE
+ const isNewProject = dayjs(project?.inserted_at).isAfter(dayjs().subtract(2, 'day'))
+
useEffect(() => {
if (enableBranching && !hasShownEnableBranchingModalRef.current) {
hasShownEnableBranchingModalRef.current = true
@@ -49,90 +58,164 @@ const Home: NextPageWithLayout = () => {
? project?.name
: 'Welcome to your project'
+ const { data: tablesData, isLoading: isLoadingTables } = useTablesQuery({
+ projectRef: project?.ref,
+ connectionString: project?.connectionString,
+ schema: 'public',
+ })
+ const { data: functionsData, isLoading: isLoadingFunctions } = useEdgeFunctionsQuery({
+ projectRef: project?.ref,
+ })
+ const { data: replicasData, isLoading: isLoadingReplicas } = useReadReplicasQuery({
+ projectRef: project?.ref,
+ })
+
+ const tablesCount = tablesData?.length ?? 0
+ const functionsCount = functionsData?.length ?? 0
+ const replicasCount = (replicasData?.length ?? 1) - 1
+
return (
- <div className="w-full mx-auto my-12 md:my-16 space-y-12 md:space-y-16 max-w-7xl">
- <div className="flex flex-col md:flex-row md:items-center justify-between mx-6 gap-6">
- <div className="flex flex-col md:flex-row md:items-center gap-3">
- <h1 className="text-3xl">{projectName}</h1>
- {isOrioleDb && (
- <Tooltip>
- <TooltipTrigger>
- <Badge variant="warning">OrioleDB</Badge>
- </TooltipTrigger>
- <TooltipContent side="bottom" align="start" className="max-w-80 text-center">
- This project is using Postgres with OrioleDB which is currently in preview and not
- suitable for production workloads. View our{' '}
- <InlineLink href="https://supabase.com/docs/guides/database/orioledb">
- documentation
- </InlineLink>{' '}
- for all limitations.
- </TooltipContent>
- </Tooltip>
- )}
- <ComputeBadgeWrapper
- project={{
- ref: project?.ref,
- organization_slug: organization?.slug,
- cloud_provider: project?.cloud_provider,
- infra_compute_size: project?.infra_compute_size,
- }}
- />
- </div>
- <div className="flex items-center gap-x-3">
- {project?.status === PROJECT_STATUS.ACTIVE_HEALTHY && <SecurityStatus />}
- {IS_PLATFORM && project?.status === PROJECT_STATUS.ACTIVE_HEALTHY && <ServiceStatus />}
- </div>
- </div>
+ <div className="w-full">
+ <div className={cn('py-16 px-8', !isPaused && 'border-b border-muted ')}>
+ <div className="mx-auto max-w-7xl flex flex-col gap-y-4">
+ <div className="flex flex-col md:flex-row md:items-center gap-6 justify-between w-full">
+ <div className="flex flex-col md:flex-row md:items-center gap-3 w-full">
+ <h1 className="text-3xl">{projectName}</h1>
+ {isOrioleDb && (
+ <Tooltip>
+ <TooltipTrigger>
+ <Badge variant="warning">OrioleDB</Badge>
+ </TooltipTrigger>
+ <TooltipContent side="bottom" align="start" className="max-w-80 text-center">
+ This project is using Postgres with OrioleDB which is currently in preview and
+ not suitable for production workloads. View our{' '}
+ <InlineLink href="https://supabase.com/docs/guides/database/orioledb">
+ documentation
+ </InlineLink>{' '}
+ for all limitations.
+ </TooltipContent>
+ </Tooltip>
+ )}
+ <ComputeBadgeWrapper
+ project={{
+ ref: project?.ref,
+ organization_slug: organization?.slug,
+ cloud_provider: project?.cloud_provider,
+ infra_compute_size: project?.infra_compute_size,
+ }}
+ />
+ </div>
+ <div className="flex items-center">
+ {project?.status === PROJECT_STATUS.ACTIVE_HEALTHY && (
+ <div className="flex items-center gap-x-6">
+ <div>
+ <div className="flex items-center gap-1.5 text-foreground-light text-sm mb-1">
+ Tables
+ </div>
+ <span className="text-2xl tabular-nums">
+ {isLoadingTables ? (
+ <ShimmeringLoader className="w-full h-[32px] w-6 p-0" />
+ ) : (
+ tablesCount
+ )}
+ </span>
+ </div>
- <div className="mx-6">
- <ProjectUpgradeFailedBanner />
- </div>
- {project?.status === PROJECT_STATUS.INACTIVE && <ProjectPausedState />}
- <div className="mx-6">
- {IS_PLATFORM && project?.status !== PROJECT_STATUS.INACTIVE && <ProjectUsageSection />}
+ <div>
+ <div className="flex items-center gap-1.5 text-foreground-light text-sm mb-1">
+ Functions
+ </div>
+ <span className="text-2xl tabular-nums">
+ {isLoadingFunctions ? (
+ <ShimmeringLoader className="w-full h-[32px] w-6 p-0" />
+ ) : (
+ functionsCount
+ )}
+ </span>
+ </div>
+
+ {IS_PLATFORM && (
+ <div>
+ <div className="flex items-center gap-1.5 text-foreground-light text-sm mb-1">
+ Replicas
+ </div>
+ <span className="text-2xl tabular-nums">
+ {isLoadingReplicas ? (
+ <ShimmeringLoader className="w-full h-[32px] w-6 p-0" />
+ ) : (
+ replicasCount
+ )}
+ </span>
+ </div>
+ )}
+ </div>
+ )}
+ {IS_PLATFORM && project?.status === PROJECT_STATUS.ACTIVE_HEALTHY && (
+ <div className="ml-6 border-l flex items-center w-[145px] justify-end">
+ <ServiceStatus />
+ </div>
+ )}
+ </div>
+ </div>
+ <ProjectUpgradeFailedBanner />
+ {isPaused && <ProjectPausedState />}
+ </div>
</div>
- {project?.status !== PROJECT_STATUS.INACTIVE && (
+ {!isPaused && (
<>
- <div className="space-y-8">
- <div className="mx-6">
- <h4 className="text-lg">Client libraries</h4>
- </div>
- <div className="grid grid-cols-2 gap-x-8 gap-y-8 md:gap-12 mx-6 mb-12 md:grid-cols-3">
- {CLIENT_LIBRARIES.map((library) => (
- <ClientLibrary key={library.language} {...library} />
- ))}
+ <div className="py-16 border-b border-muted px-8">
+ <div className="mx-auto max-w-7xl space-y-16">
+ {IS_PLATFORM && project?.status !== PROJECT_STATUS.INACTIVE && (
+ <>{isNewProject ? <NewProjectPanel /> : <ProjectUsageSection />}</>
+ )}
+ {!isNewProject && project?.status !== PROJECT_STATUS.INACTIVE && <AdvisorWidget />}
</div>
</div>
- <div className="space-y-8">
- <div className="mx-6">
- <h4 className="text-lg">Example projects</h4>
- </div>
- <div className="flex justify-center mx-6">
- <Tabs_Shadcn_ defaultValue="app">
- <TabsList_Shadcn_ className="flex gap-4">
- <TabsTrigger_Shadcn_ value="app">App Frameworks</TabsTrigger_Shadcn_>
- <TabsTrigger_Shadcn_ value="mobile">Mobile Framework</TabsTrigger_Shadcn_>
- </TabsList_Shadcn_>
- <TabsContent_Shadcn_ value="app">
- <div className="grid gap-2 md:gap-8 md:grid-cols-2 lg:grid-cols-3">
- {EXAMPLE_PROJECTS.filter((project) => project.type === 'app')
- .sort((a, b) => a.title.localeCompare(b.title))
- .map((project) => (
- <ExampleProject key={project.url} {...project} />
+
+ <div className="bg-surface-100/5 py-16">
+ <div className="mx-auto max-w-7xl space-y-16">
+ {project?.status !== PROJECT_STATUS.INACTIVE && (
+ <>
+ <div className="space-y-8">
+ <h2 className="text-lg">Client libraries</h2>
+ <div className="grid grid-cols-2 gap-x-8 gap-y-8 md:gap-12 mb-12 md:grid-cols-3">
+ {CLIENT_LIBRARIES.map((library) => (
+ <ClientLibrary key={library.language} {...library} />
))}
+ </div>
</div>
- </TabsContent_Shadcn_>
- <TabsContent_Shadcn_ value="mobile">
- <div className="grid gap-2 md:gap-8 md:grid-cols-2 lg:grid-cols-3">
- {EXAMPLE_PROJECTS.filter((project) => project.type === 'mobile')
- .sort((a, b) => a.title.localeCompare(b.title))
- .map((project) => (
- <ExampleProject key={project.url} {...project} />
- ))}
+ <div className="space-y-8">
+ <h4 className="text-lg">Example projects</h4>
+ <div className="flex justify-center">
+ <Tabs_Shadcn_ defaultValue="app">
+ <TabsList_Shadcn_ className="flex gap-4 mb-8">
+ <TabsTrigger_Shadcn_ value="app">App Frameworks</TabsTrigger_Shadcn_>
+ <TabsTrigger_Shadcn_ value="mobile">Mobile Framework</TabsTrigger_Shadcn_>
+ </TabsList_Shadcn_>
+ <TabsContent_Shadcn_ value="app">
+ <div className="grid gap-2 md:gap-8 md:grid-cols-2 lg:grid-cols-3">
+ {EXAMPLE_PROJECTS.filter((project) => project.type === 'app')
+ .sort((a, b) => a.title.localeCompare(b.title))
+ .map((project) => (
+ <ExampleProject key={project.url} {...project} />
+ ))}
+ </div>
+ </TabsContent_Shadcn_>
+ <TabsContent_Shadcn_ value="mobile">
+ <div className="grid gap-2 md:gap-8 md:grid-cols-2 lg:grid-cols-3">
+ {EXAMPLE_PROJECTS.filter((project) => project.type === 'mobile')
+ .sort((a, b) => a.title.localeCompare(b.title))
+ .map((project) => (
+ <ExampleProject key={project.url} {...project} />
+ ))}
+ </div>
+ </TabsContent_Shadcn_>
+ </Tabs_Shadcn_>
+ </div>
</div>
- </TabsContent_Shadcn_>
- </Tabs_Shadcn_>
+ </>
+ )}
</div>
</div>
</>