mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
The telemetry skill had no rules for mistakes I keep flagging in telemetry PR reviews, two of its sections repeated the rest of the file, and its approved verb list held verbs that no event uses or that another verb already covers. I added the rules, collapsed the repetition, cut four verbs, and renamed the three events whose verb is outside the list. **Changed:** - **New tracking rules**: I added rules for dismiss and abandonment events (a property must be able to differ at the call site), values captured at submit time, `track()` on conditionally rendered elements, debounced sends, events sent just before leaving the page, experiment exposure, and org-level events. I also added a rule for actions that change nothing: a bulk or menu action that changed nothing sends no result event, and a count property reports only the items that changed. The verify step now checks that case too. - **Shorter skill**: I changed "Review Rules" and "Implementing New Tracking" to link to the section that states each rule. I removed the verification checklist because each item duplicated a rule stated above it. - **Approved verbs**: I removed `intended` and `converted` (no event uses them) and `sent` and `moved` (one event each, both covered by another verb), and defined `created` against `added`. The skill now says the list is the authority. It used to say the list was derived from `telemetry-constants.ts`, which still holds older events with other verbs. I also stated when each verb fires: `clicked` and `submitted` in the handler, the rest once the result has happened. I updated the verb list in `.coderabbit.yaml` to match. - **Event renames**: `www_subprocessor_updates_subscribed` is now `www_subprocessor_updates_form_completed` (still sent after the successful response, so it keeps counting completed subscriptions), `realtime_inspector_broadcast_sent` is now `realtime_inspector_broadcast_submitted`, and `home_section_rows_moved` is now `home_section_rows_updated`. Nothing else in this repo references the old names. **Note:** after each app deploys, the renamed event is a new series, so a chart that spans the change needs both names. ## To test Tested on the PR preview: - [ ] On www, open `/legal/customer-resources/subprocessor-list`, submit the updates form with a test email, expect one `telemetry/event` request whose `action` is `www_subprocessor_updates_form_completed`, and no event after a failed submit. - [x] In Studio, open a project's Realtime Inspector, join a channel, send a broadcast message, expect one `telemetry/event` request whose `action` is `realtime_inspector_broadcast_submitted`. Observed: one request with that action and a 201 response, and no event after canceling the modal. - [x] In Studio, on the project home page, drag a section to a new position, expect one `telemetry/event` request whose `action` is `home_section_rows_updated` with `section_moved`, `old_position` and `new_position`. Observed: one request per drag, with `section_moved: "usage"`, `old_position: 1`, `new_position: 2`. I checked the staging analytics project: both new Studio event names showed up with matching counts, and neither old name did. ## Linear - fixes GROWTH-1584
181 lines
7.0 KiB
TypeScript
181 lines
7.0 KiB
TypeScript
import {
|
|
DndContext,
|
|
DragEndEvent,
|
|
KeyboardSensor,
|
|
PointerSensor,
|
|
useSensor,
|
|
useSensors,
|
|
} from '@dnd-kit/core'
|
|
import {
|
|
arrayMove,
|
|
SortableContext,
|
|
sortableKeyboardCoordinates,
|
|
verticalListSortingStrategy,
|
|
} from '@dnd-kit/sortable'
|
|
import { useFlag, useParams } from 'common'
|
|
import dayjs from 'dayjs'
|
|
import { useEffect, useRef } from 'react'
|
|
import { cn } from 'ui'
|
|
import { PageContainer } from 'ui-patterns/PageContainer'
|
|
import { PageSection } from 'ui-patterns/PageSection'
|
|
|
|
import { ConnectSection } from './ConnectSection'
|
|
import { CustomReportSection } from './CustomReportSection'
|
|
import { DEFAULT_SECTION_ORDER, mergeSectionOrder } from './Home.utils'
|
|
import { IssuesSection } from './IssuesSection'
|
|
import { NotebooksSection } from './NotebooksSection'
|
|
import { ProjectUsageSection } from './ProjectUsageSection'
|
|
import { ProjectUsageSectionDeltas } from './ProjectUsageSectionDeltas'
|
|
import { useIsExplorerEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
|
|
import { TopSection } from '@/components/interfaces/ProjectHome/TopSection'
|
|
import { ProjectNeedsSecuring } from '@/components/layouts/ProjectNeedsSecuring/ProjectNeedsSecuring'
|
|
import { SortableSection } from '@/components/ui/SortableSection'
|
|
import { useLocalStorage } from '@/hooks/misc/useLocalStorage'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { IS_PLATFORM, PROJECT_STATUS } from '@/lib/constants'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
|
|
const SORT_GRIP_CLASS = 'absolute -left-10'
|
|
|
|
export const ProjectHome = () => {
|
|
const { enableBranching } = useParams()
|
|
const snap = useAppStateSnapshot()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
const track = useTrack()
|
|
|
|
const showHomepageUsageDeltas = useFlag('newHomepageUsageDeltas')
|
|
const isIssuesInboxEnabled = useFlag('issuesInbox')
|
|
const isExplorerEnabled = useIsExplorerEnabled()
|
|
|
|
const isMatureProject = dayjs(project?.inserted_at).isBefore(dayjs().subtract(10, 'day'))
|
|
|
|
const hasShownEnableBranchingModalRef = useRef(false)
|
|
const isPaused = project?.status === PROJECT_STATUS.INACTIVE
|
|
const isComingUp = project?.status === PROJECT_STATUS.COMING_UP
|
|
|
|
const [sectionOrder, setSectionOrder] = useLocalStorage<string[]>(
|
|
`home-section-order-${project?.ref || 'default'}`,
|
|
DEFAULT_SECTION_ORDER
|
|
)
|
|
|
|
const UsageSection = showHomepageUsageDeltas ? ProjectUsageSectionDeltas : ProjectUsageSection
|
|
|
|
const sensors = useSensors(
|
|
useSensor(PointerSensor, { activationConstraint: { distance: 8 } }),
|
|
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates })
|
|
)
|
|
|
|
const handleDragEnd = (event: DragEndEvent) => {
|
|
const { active, over } = event
|
|
if (!over || active.id === over.id) return
|
|
setSectionOrder((items) => {
|
|
const oldIndex = items.indexOf(String(active.id))
|
|
const newIndex = items.indexOf(String(over.id))
|
|
if (oldIndex === -1 || newIndex === -1) return items
|
|
|
|
track('home_section_rows_updated', {
|
|
section_moved: String(active.id),
|
|
old_position: oldIndex,
|
|
new_position: newIndex,
|
|
})
|
|
|
|
return arrayMove(items, oldIndex, newIndex)
|
|
})
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (enableBranching && !hasShownEnableBranchingModalRef.current) {
|
|
hasShownEnableBranchingModalRef.current = true
|
|
snap.setShowCreateBranchModal(true)
|
|
}
|
|
}, [enableBranching, snap])
|
|
|
|
useEffect(() => {
|
|
setSectionOrder(mergeSectionOrder)
|
|
}, [setSectionOrder])
|
|
|
|
// On self-hosted the project's `inserted_at` is hard-coded to a past date
|
|
// (so it always looks "mature"), and the home page is otherwise sparse —
|
|
// always surface the Get Connected pane there. Platform keeps the
|
|
// maturity gate so long-running projects don't see it forever.
|
|
const showConnectSection = !!project && (!IS_PLATFORM || !isMatureProject)
|
|
|
|
const renderOrder = mergeSectionOrder(sectionOrder).filter((id) => {
|
|
if (id === 'issues') return isIssuesInboxEnabled
|
|
if (id === 'connect') return showConnectSection
|
|
if (id === 'usage' || id === 'custom-report') return IS_PLATFORM
|
|
return true
|
|
})
|
|
|
|
return (
|
|
<ProjectNeedsSecuring>
|
|
<div className="w-full h-full">
|
|
<PageContainer size="large" className={cn(isPaused && 'h-full')}>
|
|
<PageSection
|
|
className={cn(isPaused ? 'h-full justify-center p-0 last:pb-0' : 'last:pb-0')}
|
|
>
|
|
<TopSection />
|
|
</PageSection>
|
|
</PageContainer>
|
|
{!isPaused && (
|
|
<PageContainer size="large">
|
|
<PageSection className="gap-12 last:pb-32">
|
|
<DndContext sensors={sensors} onDragEnd={handleDragEnd}>
|
|
<SortableContext items={renderOrder} strategy={verticalListSortingStrategy}>
|
|
{renderOrder.map((id) => {
|
|
if (IS_PLATFORM && id === 'usage') {
|
|
return (
|
|
<div
|
|
key={id}
|
|
className={cn(isComingUp && 'opacity-60 pointer-events-none')}
|
|
>
|
|
<SortableSection gripClassName={SORT_GRIP_CLASS} id={id}>
|
|
<UsageSection />
|
|
</SortableSection>
|
|
</div>
|
|
)
|
|
}
|
|
if (id === 'connect' && showConnectSection) {
|
|
return (
|
|
<SortableSection gripClassName={SORT_GRIP_CLASS} key={id} id={id}>
|
|
<ConnectSection />
|
|
</SortableSection>
|
|
)
|
|
}
|
|
if (id === 'issues') {
|
|
return (
|
|
<div
|
|
key={id}
|
|
className={cn(isComingUp && 'opacity-60 pointer-events-none')}
|
|
>
|
|
<SortableSection gripClassName={SORT_GRIP_CLASS} id={id}>
|
|
<IssuesSection showEmptyState={isComingUp} />
|
|
</SortableSection>
|
|
</div>
|
|
)
|
|
}
|
|
if (IS_PLATFORM && id === 'custom-report') {
|
|
// Notebooks take over the reports slot (and its saved position) under the Explorer preview
|
|
return (
|
|
<div
|
|
key={id}
|
|
className={cn(isComingUp && 'opacity-60 pointer-events-none')}
|
|
>
|
|
<SortableSection gripClassName={SORT_GRIP_CLASS} id={id}>
|
|
{isExplorerEnabled ? <NotebooksSection /> : <CustomReportSection />}
|
|
</SortableSection>
|
|
</div>
|
|
)
|
|
}
|
|
})}
|
|
</SortableContext>
|
|
</DndContext>
|
|
</PageSection>
|
|
</PageContainer>
|
|
)}
|
|
</div>
|
|
</ProjectNeedsSecuring>
|
|
)
|
|
}
|