Files
supabase/apps/studio/components/interfaces/ProjectHome/ProjectConnectionHoverCard.tsx
Pamela Chia 01c178e159 chore(studio): graduate homeNew experiment (#43437)
## Summary

The `homeNew` PostHog experiment has concluded. This PR graduates it by
making the new homepage (`ProjectHome`, formerly `HomeV2`) the permanent
default for all users, and removes all dead code from the old
experiment.

## Changes

- Remove `homeNew` PostHog feature flag checks and `home_new` experiment
exposure tracking from 3 files
- Rename `HomeNew/` → `ProjectHome/` directory and `HomeV2` →
`ProjectHome` export
- Delete old `Home/Home.tsx` component (shared components like
`ProjectList/` are kept — still used by org pages)
- Delete `pages/project/[ref]/building.tsx` and add a server-side
redirect from `/project/:ref/building` → `/project/:ref` to prevent 404s
during rollout (old cached JS bundles may still route to `/building`)
- Simplify `ContentWrapper` building-state logic in `ProjectLayout` —
always redirect building projects to home, always suppress building
interstitial on home page
- Always route to `/project/{ref}` after project creation (remove
`/building` path)
- Update all Observability imports from `HomeNew` → `ProjectHome`

## Self-hosted behavior change

Self-hosted Studio previously showed the old `Home` component (client
libraries + example projects) since PostHog flags don't load. This PR
changes self-hosted to show `ProjectHome` (TopSection with service
status + instance diagram, advisor, custom reports). All sections query
backend APIs that exist on self-hosted. E2E tests pass against the
self-hosted build.

## Testing

- [x] `pnpm turbo run build --filter=studio` passes
- [x] No remaining references to `homeNew`, `home_new`, or `HomeNew` in
codebase
- [x] No broken imports to deleted files
- [x] Self-hosted E2E tests pass (145 passed, 1 flaky, 4 skipped)
- [x] `/building` redirect added to both platform and self-hosted config
blocks

**Quick test:**
1. Navigate to any project homepage — should render the ProjectHome
component
2. Create a new project — should redirect to `/project/{ref}` (not
`/building`)
3. Visit a project in `COMING_UP` state on a non-home route — should
redirect to home
4. Visit `/project/{ref}/building` directly — should 302 redirect to
`/project/{ref}`

## Linear

- fixes GROWTH-671
2026-03-10 17:03:58 +09:00

154 lines
5.6 KiB
TypeScript

import { PermissionAction } from '@supabase/shared-types/out/constants'
import { Label } from '@ui/components/shadcn/ui/label'
import { getConnectionStrings } from 'components/interfaces/Connect/DatabaseSettings.utils'
import { getKeys, useAPIKeysQuery } from 'data/api-keys/api-keys-query'
import { useReadReplicasQuery } from 'data/read-replicas/replicas-query'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { pluckObjectFields } from 'lib/helpers'
import { Plug } from 'lucide-react'
import { parseAsBoolean, useQueryState } from 'nuqs'
import { useMemo, useState, type ReactNode } from 'react'
import { Button, HoverCard, HoverCardContent, HoverCardTrigger } from 'ui'
import { ShimmeringLoader } from 'ui-patterns'
import { Input } from 'ui-patterns/DataInputs/Input'
import { useProjectApiUrl } from '@/data/config/project-endpoint-query'
const DB_FIELDS = ['db_host', 'db_name', 'db_port', 'db_user'] as const
const EMPTY_CONNECTION_INFO = {
db_user: '',
db_host: '',
db_port: '',
db_name: '',
}
const DetailRow = ({ label, children }: { label: string; children: ReactNode }) => {
return (
<div className="flex flex-col gap-2">
<Label>{label}</Label>
{children}
</div>
)
}
interface ProjectConnectionHoverCardProps {
projectRef?: string
}
export const ProjectConnectionHoverCard = ({ projectRef }: ProjectConnectionHoverCardProps) => {
const [open, setOpen] = useState(false)
const [, setShowConnect] = useQueryState('showConnect', parseAsBoolean.withDefault(false))
const { isLoading: isLoadingPermissions, can: canReadAPIKeys } = useAsyncCheckPermissions(
PermissionAction.READ,
'service_api_keys'
)
const { data: projectUrl, isPending: isLoadingApiUrl } = useProjectApiUrl({ projectRef })
const { data: apiKeys, isLoading: isLoadingKeys } = useAPIKeysQuery(
{ projectRef },
{ enabled: open && canReadAPIKeys }
)
const { publishableKey } = canReadAPIKeys ? getKeys(apiKeys) : { publishableKey: null }
const { data: databases, isLoading: isLoadingDatabases } = useReadReplicasQuery(
{ projectRef },
{ enabled: open && !!projectRef }
)
const primaryDatabase = databases?.find((db) => db.identifier === projectRef)
const directConnectionString = useMemo(() => {
if (
!primaryDatabase?.db_host ||
!primaryDatabase?.db_name ||
!primaryDatabase?.db_user ||
!primaryDatabase?.db_port
) {
return ''
}
const connectionInfo = pluckObjectFields(primaryDatabase, [...DB_FIELDS])
return getConnectionStrings({
connectionInfo: { ...EMPTY_CONNECTION_INFO, ...connectionInfo },
metadata: { projectRef },
}).direct.uri
}, [primaryDatabase, projectRef])
return (
<HoverCard openDelay={250} closeDelay={100} open={open} onOpenChange={setOpen}>
<HoverCardTrigger asChild>
<button onClick={() => setShowConnect(true)} className="flex items-center gap-4 mt-3 group">
<div className=" transition w-8 h-8 rounded-md bg-surface-75 group-hover:bg-muted border flex items-center justify-center">
<Plug strokeWidth={1.5} size={16} className="text-foreground-light rotate-90" />
</div>
{isLoadingApiUrl ? (
<ShimmeringLoader className="w-32" />
) : (
<span className="transition text-foreground-light group-hover:text-foreground underline decoration-dotted decoration-foreground-muted underline-offset-4 max-w-[320px] text-left">
{projectUrl ?? 'Project URL unavailable'}
</span>
)}
</button>
</HoverCardTrigger>
<HoverCardContent side="bottom" align="start" className="w-[420px] p-0">
<div className="p-4 border-b space-y-4">
<h3 className="heading-meta text-foreground-light">Data API</h3>
<DetailRow label="Project URL">
<Input
copy
readOnly
className="font-mono text-xs"
value={projectUrl ?? ''}
placeholder="Project URL unavailable"
/>
</DetailRow>
<DetailRow label="Publishable Key">
{isLoadingPermissions || isLoadingKeys ? (
<div className="text-xs text-foreground-lighter">Loading publishable key...</div>
) : canReadAPIKeys ? (
<Input
copy
readOnly
className="font-mono text-xs"
value={publishableKey?.api_key ?? ''}
placeholder="Publishable key unavailable"
/>
) : (
<div className="text-xs text-foreground-lighter">
You don't have permission to view API keys.
</div>
)}
</DetailRow>
</div>
<div className="p-4 space-y-4 border-b">
<h3 className="heading-meta text-foreground-light"> Database </h3>
<DetailRow label="Direct connection string">
{isLoadingDatabases ? (
<div className="text-xs text-foreground-lighter">Loading connection string...</div>
) : (
<Input
copy
readOnly
className="font-mono text-xs"
value={directConnectionString}
placeholder="Connection string unavailable"
/>
)}
</DetailRow>
</div>
<div className="p-4">
<Button
icon={<Plug className="rotate-90" />}
type="default"
size="medium"
className="w-full"
onClick={() => setShowConnect(true)}
>
Get connected
</Button>
</div>
</HoverCardContent>
</HoverCard>
)
}