mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem Project home tracked most interactions, but not which credential people copy from the "Copy" popover, or how often they use the custom report and notebooks beyond adding blocks. Opening the Connect sheet from the popover's "Get Connected" button also reported a stale `connect_sheet_opened` source, because the popover never set one. ## Solution Project home gets three new events: `home_project_credential_copied` (with a `credentialType` enum), `home_custom_report_refresh_clicked`, and `home_notebook_action_clicked` (`action: 'create' | 'analyze'`). "Get Connected" in the popover now sets a new `home_popover` Connect sheet source. The compute and GitHub stats now send `home_activity_stat_clicked` as well, with two new `stat_type` values. Every event fires from its click handler with a typed `track()` call, and none sends the copied value or any user-defined name. This follows the telemetry standards, so no `data-attr` attributes are added. ## How to verify 1. On a project's home page, open the "Copy" popover and copy each item. Each copy sends one `home_project_credential_copied` event, with `credentialType` set to `project_url`, `publishable_key`, `direct_connection_string`, or `cli_setup`. No event contains the copied value. 2. In the same popover, click "Get Connected". The Connect sheet opens and sends `connect_sheet_opened` with `source: 'home_popover'`. Opening it from the header button afterwards still sends `source: 'header_button'`. 3. Click the "Compute size" stat. It sends `home_activity_stat_clicked` with `stat_type: 'compute'` and no `stat_value`. 4. Click the "GitHub" stat. It sends `home_activity_stat_clicked` with `stat_type: 'github'`, and `stat_value` is 1 when a repository is connected and 0 when none is. 5. With the custom report section shown, click "Refresh report". It sends one `home_custom_report_refresh_clicked` event. 6. With the Notebooks section shown, click "New notebook" (or "Create your first notebook" when there are none). It sends `home_notebook_action_clicked` with `action: 'create'`. Click "Analyze" on a notebook with cells: it sends `action: 'analyze'`. ## Checks Ran `tsc --noEmit` in `apps/studio` and `packages/common`, `eslint` and the type-aware `eslint.type-checks.config.cjs` lint on the changed Studio files, `oxfmt --check` on every changed file, and `vitest run` for `ProjectConnectionPopover.platform.test.tsx` and `ActivityStats.test.tsx`. ## Checklist - [x] I have read the [Contributing Guidelines](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md) - [ ] I have checked that the change works in the preview deployment ## Feedback for Tedd To ask Tedd for a change to this PR, reply in Tedd's session on [FE-5026](https://linear.app/supabase/issue/FE-5026/track-usage-on-project-home-gaps-only). Tedd doesn't read comments on this PR. --------- Co-authored-by: supabase-vercel-tedd[bot] <336548405+supabase-vercel-tedd[bot]@users.noreply.github.com> Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
150 lines
4.7 KiB
TypeScript
150 lines
4.7 KiB
TypeScript
import { useParams } from 'common'
|
|
import dayjs from 'dayjs'
|
|
import { NotebookTextIcon, PlusIcon } from 'lucide-react'
|
|
import { AiIconAnimation, Badge, Button } from 'ui'
|
|
import { Row } from 'ui-patterns/Row'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { HomeCard } from './HomeCard'
|
|
import { useAnalyzeNotebook, useCreateNotebook } from '@/components/interfaces/Explorer/hooks'
|
|
import { AlertError } from '@/components/ui/AlertError'
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import {
|
|
useNotebooksInfiniteQuery,
|
|
type NotebookRow,
|
|
} from '@/data/content/notebooks/notebooks-infinite-query'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
|
|
const MAX_HOMEPAGE_NOTEBOOKS = 4
|
|
|
|
export const NotebooksSection = () => {
|
|
const { ref: projectRef } = useParams()
|
|
const { createNotebook } = useCreateNotebook()
|
|
const track = useTrack()
|
|
|
|
const onCreateNotebook = () => {
|
|
track('home_notebook_action_clicked', { action: 'create' })
|
|
createNotebook()
|
|
}
|
|
|
|
const { data, error, isPending, isError, isSuccess, refetch } = useNotebooksInfiniteQuery({
|
|
projectRef,
|
|
limit: MAX_HOMEPAGE_NOTEBOOKS,
|
|
sort: 'inserted_at',
|
|
})
|
|
// The content endpoint can return more rows than `limit`, so cap the row here too
|
|
const notebooks = (data?.pages[0]?.content ?? []).slice(0, MAX_HOMEPAGE_NOTEBOOKS)
|
|
|
|
return (
|
|
<div>
|
|
{isPending && (
|
|
<>
|
|
<ShimmeringLoader className="w-96 mb-6" />
|
|
<div className="flex flex-col gap-2">
|
|
<ShimmeringLoader />
|
|
<ShimmeringLoader className="w-3/4" />
|
|
<ShimmeringLoader className="w-1/2" />
|
|
</div>
|
|
</>
|
|
)}
|
|
|
|
{!isPending && (
|
|
<div className="flex justify-between items-center mb-6">
|
|
<h2>Notebooks</h2>
|
|
<Button icon={<PlusIcon />} onClick={onCreateNotebook}>
|
|
New notebook
|
|
</Button>
|
|
</div>
|
|
)}
|
|
|
|
{isError && (
|
|
<AlertError
|
|
error={error instanceof Error ? error : null}
|
|
subject="Failed to retrieve notebooks"
|
|
projectRef={projectRef}
|
|
additionalActions={
|
|
<Button variant="default" onClick={() => refetch()}>
|
|
Retry
|
|
</Button>
|
|
}
|
|
/>
|
|
)}
|
|
|
|
{isSuccess && notebooks.length === 0 && <EmptyState onCreateNotebook={onCreateNotebook} />}
|
|
|
|
{isSuccess && notebooks.length > 0 && (
|
|
<Row maxColumns={4} minWidth={280}>
|
|
{notebooks.map((notebook) => (
|
|
<NotebookCard key={notebook.id} notebook={notebook} projectRef={projectRef} />
|
|
))}
|
|
</Row>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function NotebookCard({
|
|
notebook,
|
|
projectRef,
|
|
}: {
|
|
notebook: NotebookRow
|
|
projectRef: string | undefined
|
|
}) {
|
|
const { analyzeNotebook, isCreating } = useAnalyzeNotebook()
|
|
const track = useTrack()
|
|
|
|
const cellCount = notebook.content?.cells?.length
|
|
// Treat an unknown cell count as empty so Analyze is never offered on a notebook with no cells
|
|
const isEmpty = !cellCount
|
|
|
|
return (
|
|
<HomeCard
|
|
href={`/project/${projectRef}/explorer/notebook/${notebook.id}`}
|
|
icon={<NotebookTextIcon size={16} strokeWidth={1.5} className="text-foreground-light" />}
|
|
label="NOTEBOOK"
|
|
title={notebook.name}
|
|
description={notebook.description?.trim()}
|
|
meta={`Created ${dayjs(notebook.inserted_at).fromNow()}`}
|
|
actions={
|
|
<>
|
|
{cellCount !== undefined && (
|
|
<Badge className="w-fit">
|
|
{cellCount} {cellCount === 1 ? <span>CELL</span> : <span>CELLS</span>}
|
|
</Badge>
|
|
)}
|
|
<ButtonTooltip
|
|
variant="text"
|
|
className="w-7 h-7 px-1.5"
|
|
icon={<AiIconAnimation size={16} loading={isCreating} />}
|
|
disabled={isEmpty}
|
|
onClick={() => {
|
|
track('home_notebook_action_clicked', { action: 'analyze' })
|
|
analyzeNotebook({ id: notebook.id, name: notebook.name })
|
|
}}
|
|
aria-label="Analyze"
|
|
tooltip={{
|
|
content: {
|
|
text: isEmpty ? 'Add a cell to the notebook to analyze it' : 'Analyze',
|
|
},
|
|
}}
|
|
/>
|
|
</>
|
|
}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function EmptyState({ onCreateNotebook }: { onCreateNotebook: () => void }) {
|
|
return (
|
|
<div className="h-64 flex flex-col items-center justify-center rounded-sm border-2 border-dashed p-16">
|
|
<h4>Create a notebook</h4>
|
|
<p className="text-sm text-foreground-light mb-4">
|
|
Save queries and notes together to revisit and share
|
|
</p>
|
|
<Button iconRight={<PlusIcon size={14} />} onClick={onCreateNotebook}>
|
|
Create your first notebook
|
|
</Button>
|
|
</div>
|
|
)
|
|
}
|