mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem We don't have visibility into how people use the org projects list (`/org/[slug]`) or the organizations list (`/organizations`): whether they search, filter, sort or switch views, and which project card actions they use. Resolves FE-5025. ## Solution Adds four events, defined in `packages/common/telemetry-constants.ts` with org-level groups (no project group): - `org_projects_filter_applied` with `filterType: 'search' | 'status' | 'sort'`. Search sends only the result count, status sends the saved statuses (`active`/`paused`), and sort sends the sort value. - `org_projects_view_mode_updated` with `viewMode`. - `org_project_card_action_clicked` with `action: 'copy_id' | 'settings'` and `viewMode`, from the grid card menu and the table row menu and inline ref button. - `org_list_search_submitted` with `orgCount`. Notes for review: - Every event fires from its handler, not an effect, so restoring filters from local storage doesn't fire anything. - Search events use the same 500ms debounce as the query, skip empty input, and never include the search text. The project search count is read from the list query's cache entry via `fetchInfiniteQuery` on the same key, which reuses the in-flight request. - Status, sort and view events don't fire when the value didn't change. - `HomePageActions` and `ProjectList` also render on the `/project` picker, so `@page` lists both routes. - I didn't add the `data-attr` attributes from the ticket: autocapture is off, so they would send nothing, and the telemetry standards ask for explicit `track()` calls. ## How to test - `pnpm --filter studio exec vitest run components/interfaces/HomePageActions.test.tsx` covers view mode, status filter, search and clearing before the debounce settles. - In the browser network tab on `/org/[slug]`, each action sends one `telemetry/event` request with the properties above. Checking the events in PostHog staging is still to do.
172 lines
7.0 KiB
TypeScript
172 lines
7.0 KiB
TypeScript
import { useNavigate } from '@tanstack/react-router'
|
|
import { CopyIcon, MoreVerticalIcon, SettingsIcon } from 'lucide-react'
|
|
import InlineSVG from 'react-inlinesvg'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Button,
|
|
copyToClipboard,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
GithubIcon,
|
|
} from 'ui'
|
|
|
|
import { inferProjectStatus } from './ProjectCard.utils'
|
|
import { ProjectCardStatus } from './ProjectCardStatus'
|
|
import CardButton from '@/components/ui/CardButton'
|
|
import { ComputeBadgeWrapper } from '@/components/ui/ComputeBadgeWrapper'
|
|
import PartnerIcon from '@/components/ui/PartnerIcon'
|
|
import type { IntegrationProjectConnection } from '@/data/integrations/integrations.types'
|
|
import { getManagedByFromOrganizationPartner } from '@/data/organizations/managed-by-utils'
|
|
import { ProjectIndexPageLink } from '@/data/prefetchers/project.$ref'
|
|
import { getComputeSize, OrgProject } from '@/data/projects/org-projects-infinite-query'
|
|
import type { ResourceWarning } from '@/data/usage/resource-warnings-query'
|
|
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
|
|
import { BASE_PATH } from '@/lib/constants'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
import type { Organization } from '@/types'
|
|
|
|
export interface ProjectCardProps {
|
|
slug?: string
|
|
project: OrgProject
|
|
organization?: Organization
|
|
rewriteHref?: string
|
|
githubIntegration?: IntegrationProjectConnection
|
|
vercelIntegration?: IntegrationProjectConnection
|
|
resourceWarnings?: ResourceWarning
|
|
}
|
|
|
|
export const ProjectCard = ({
|
|
slug,
|
|
project,
|
|
rewriteHref,
|
|
githubIntegration,
|
|
vercelIntegration,
|
|
resourceWarnings,
|
|
}: ProjectCardProps) => {
|
|
const navigate = useNavigate()
|
|
const track = useTrack()
|
|
const { name, ref: projectRef } = project
|
|
|
|
const { projectHomepageShowInstanceSize } = useIsFeatureEnabled([
|
|
'project_homepage:show_instance_size',
|
|
])
|
|
|
|
const isGithubIntegrated = githubIntegration !== undefined
|
|
const isVercelIntegrated = vercelIntegration !== undefined
|
|
const githubRepository = githubIntegration?.metadata.name ?? undefined
|
|
const projectManagedBy = getManagedByFromOrganizationPartner(
|
|
undefined,
|
|
project.integration_source
|
|
)
|
|
const projectStatus = inferProjectStatus(project.status)
|
|
|
|
return (
|
|
<>
|
|
<li className="list-none h-min">
|
|
<CardButton
|
|
tabIndex={0}
|
|
linkHref={rewriteHref ? rewriteHref : `/project/${projectRef}`}
|
|
className="h-44 px-0! group pt-5 pb-0 overflow-hidden relative"
|
|
hideChevron
|
|
title={
|
|
<div className="w-full flex flex-col gap-y-4 justify-between px-5">
|
|
<div className="flex flex-col gap-y-0.5 relative">
|
|
<div className="flex items-center justify-between">
|
|
<h2 className="text-sm shrink truncate pr-5">{name}</h2>
|
|
<div onClick={(e) => e.preventDefault()}>
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
variant="text"
|
|
icon={<MoreVerticalIcon size={14} />}
|
|
className="w-6 h-6 px-0"
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
e.preventDefault()
|
|
}}
|
|
onPointerDown={(e) => e.stopPropagation()}
|
|
aria-label={`Project ${name} actions`}
|
|
/>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end" className="w-48">
|
|
<DropdownMenuItem
|
|
className="gap-x-2"
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
copyToClipboard(projectRef)
|
|
toast.success('Copied project ID to clipboard')
|
|
track('org_project_card_action_clicked', {
|
|
action: 'copy_id',
|
|
viewMode: 'grid',
|
|
})
|
|
}}
|
|
>
|
|
<CopyIcon size={14} />
|
|
<span>Copy project ID</span>
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem
|
|
className="gap-x-2"
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
track('org_project_card_action_clicked', {
|
|
action: 'settings',
|
|
viewMode: 'grid',
|
|
})
|
|
navigate({
|
|
to: '/project/$ref/settings/general',
|
|
params: { ref: projectRef },
|
|
})
|
|
}}
|
|
>
|
|
<SettingsIcon size={14} />
|
|
<span>Settings</span>
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
</div>
|
|
</div>
|
|
<p className="text-sm text-foreground-lighter">{project.region}</p>
|
|
</div>
|
|
<div className="flex items-center gap-x-1.5 relative overflow-hidden">
|
|
{project.status !== 'INACTIVE' && projectHomepageShowInstanceSize && (
|
|
<ComputeBadgeWrapper
|
|
slug={slug}
|
|
projectRef={project.ref}
|
|
cloudProvider={project.cloud_provider}
|
|
computeSize={getComputeSize(project)}
|
|
badgeClassName="text-[10px] leading-none tracking-[0.07em]"
|
|
/>
|
|
)}
|
|
{isVercelIntegrated && (
|
|
<div className="bg-surface-100 w-5 h-5 p-1 border border-strong rounded-md flex items-center justify-center text-black dark:text-white">
|
|
<InlineSVG
|
|
src={`${BASE_PATH}/img/icons/vercel-icon.svg`}
|
|
title="Vercel Icon"
|
|
className="w-3"
|
|
/>
|
|
</div>
|
|
)}
|
|
<PartnerIcon organization={{ managed_by: projectManagedBy }} />
|
|
{isGithubIntegrated && (
|
|
<div className="bg-surface-100 flex items-center gap-x-0.5 h-5 pr-1 border border-strong rounded-md min-w-0">
|
|
<div className="w-5 h-5 p-1 flex items-center justify-center shrink-0">
|
|
<GithubIcon size={12} strokeWidth={1.5} />
|
|
</div>
|
|
<p className="text-xs text-foreground-light truncate">{githubRepository}</p>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</div>
|
|
}
|
|
footer={
|
|
<ProjectCardStatus projectStatus={projectStatus} resourceWarnings={resourceWarnings} />
|
|
}
|
|
containerElement={<ProjectIndexPageLink projectRef={projectRef} />}
|
|
/>
|
|
</li>
|
|
</>
|
|
)
|
|
}
|