Files
supabase-vercel-tedd[bot]andIvan Vasilov e3684c034c feat(studio): track usage on Project Settings: General (#54081)
## Problem

Project Settings → General has almost no usage tracking. We can't tell
how often users restart, pause, resume, or transfer projects from here.
We also can't tell how often they copy the project ID or region, use the
custom domain flow, or toggle high compliance mode.

## Solution

Adds six PostHog events to `packages/common/telemetry-constants.ts`:
`project_name_updated`, `project_settings_value_copied`,
`project_lifecycle_action_submitted`, `project_compliance_mode_updated`,
`custom_domain_step_submitted`, and `custom_domain_dns_record_copied`.
Each event fires from the user's submit, confirm, copy, or toggle
handler, never on render. Properties are only enums and booleans. No
project names, domains, DNS record contents, or other typed values are
sent.

`ResumeProjectButton` is shared between settings and the paused-project
home state, so it now takes a required `source` prop. The two call sites
pass `settings_general` and `project_home`. Restart fires from the
confirmation modal, with `restart_project` or `restart_database`
depending on the chosen restart type. `DNSRecord` now types its `type`
prop as `'CNAME' | 'TXT'`, so the copy event sends the record type as an
enum. No `data-attr` attributes are added, because PostHog autocapture
is off and they would not be collected.

## How to verify

1. On Project Settings → General, save a new project name. One
`project_name_updated` event fires.
2. Copy the project ID, then the region. Each copy fires one
`project_settings_value_copied` event, with `field` set to `projectRef`
and then `region`.
3. Open the restart modal, then cancel it. No event fires. Confirm a
restart (project or fast database reboot). One
`project_lifecycle_action_submitted` fires with `action:
restart_project` or `restart_database` and `source: settings_general`.
4. Confirm a pause, a resume, and a transfer. Each fires
`project_lifecycle_action_submitted` with the matching `action`. A
resume from settings sends `source: settings_general`; a resume from the
paused project home page sends `source: project_home`.
5. Toggle high compliance mode. One `project_compliance_mode_updated`
fires, with `isSensitive` set to the new value.
6. In the custom domain flow, Add, Verify, confirm Activate, and confirm
Delete each fire `custom_domain_step_submitted` with `step` set to
`configure`, `verify`, `activate`, and `remove`.
7. In the custom domain verification step, copy a DNS record's name,
then its value. Each copy fires one `custom_domain_dns_record_copied`
event, with `recordType` set to `CNAME` or `TXT` and `field` set to
`name` and then `value`.

## Checks

Ran `tsc --noEmit` in `apps/studio` and `packages/common`. Ran `eslint`
(default config and `eslint.type-checks.config.cjs`) on the changed
Studio files: no errors, only warnings that were already there. Ran
`oxfmt --check` on all changed files. Ran `vitest run` on
`General.test.tsx`, `Project.test.tsx`, `PauseProjectButton.test.tsx`,
and `RestartServerButton.test.tsx`: all pass.

## 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-5029](https://linear.app/supabase/issue/FE-5029/track-usage-on-project-settings-general).
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>
2026-11-30 20:38:20 +01:00

298 lines
10 KiB
TypeScript

import { zodResolver } from '@hookform/resolvers/zod'
import { useQuery } from '@tanstack/react-query'
import { IS_PLATFORM, useParams } from 'common'
import { useForm } from 'react-hook-form'
import { toast } from 'sonner'
import { Button, Card, CardContent, CardFooter, Form, FormControl, FormField, Input } from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import { Input as PasswordInput } from 'ui-patterns/DataInputs/Input'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import {
PageSection,
PageSectionContent,
PageSectionMeta,
PageSectionSummary,
PageSectionTitle,
} from 'ui-patterns/PageSection'
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import * as z from 'zod'
import { AVAILABLE_REPLICA_REGIONS } from '../Infrastructure/InfrastructureConfiguration/InstanceConfiguration.constants'
import { ProjectAccessSection } from './ProjectAccessSection'
import { DocsButton } from '@/components/ui/DocsButton'
import { InlineLink } from '@/components/ui/InlineLink'
import { branchesQueryOptions } from '@/data/branches/branches-query'
import { useProjectUpdateMutation } from '@/data/projects/project-update-mutation'
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
import { useDeploymentMode } from '@/hooks/misc/useDeploymentMode'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { DOCS_URL } from '@/lib/constants'
import { useGrant } from '@/lib/grants'
import { useTrack } from '@/lib/telemetry/track'
export const General = () => {
const { ref } = useParams()
const track = useTrack()
const { data: project } = useSelectedProjectQuery()
const isBranch = Boolean(project?.parent_project_ref)
const entityLabel = isBranch ? 'Branch' : 'Project'
const branchesGrant = useGrant('GET /v1/projects/{ref}/branches', {
projectRef: project?.parent_project_ref,
})
const { data: branches } = useQuery(
branchesQueryOptions(
{
projectRef: project?.parent_project_ref,
grant: branchesGrant.grant,
},
{ enabled: isBranch }
)
)
const branch = branches?.find((x) => x.project_ref === ref)
const projectName = isBranch ? branch?.name : project?.name
const { can: canUpdateProject } = useAsyncCheckPermissionsV2(FGA_PERMISSIONS.PROJECT.ADMIN_WRITE)
const { mutate: updateProject, isPending: isUpdating } = useProjectUpdateMutation()
const formSchema = z.object({
name: z
.string()
.trim()
.min(3, 'Project name must be at least 3 characters long')
.max(256, 'Project name must be no longer than 256 characters'),
})
const defaultValues = { name: projectName ?? '' }
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues,
values: defaultValues,
mode: 'onSubmit',
reValidateMode: 'onBlur',
})
const regionLabel = AVAILABLE_REPLICA_REGIONS.find((region) =>
project?.region?.includes(region.region)
)
const onSubmit = async (values: z.infer<typeof formSchema>) => {
if (!project?.ref) return console.error('Ref is required')
if (values.name.trim() === projectName) return
updateProject(
{ ref: project.ref, name: values.name.trim() },
{
onSuccess: ({ name }) => {
form.reset({ name })
track('project_name_updated')
toast.success('Successfully saved settings')
},
}
)
}
const { isCli, isSelfHosted } = useDeploymentMode()
if (!IS_PLATFORM) {
return (
<PageSection>
<PageSectionMeta>
<PageSectionSummary>
<PageSectionTitle>General settings</PageSectionTitle>
</PageSectionSummary>
</PageSectionMeta>
<PageSectionContent className="space-y-4">
{project === undefined ? (
<Card>
<CardContent>
<GenericSkeletonLoader />
</CardContent>
</Card>
) : (
<Form {...form}>
<Card>
<CardContent>
<FormItemLayout
layout="flex-row-reverse"
label="Project name"
className="[&>div]:md:w-1/2 [&>div>div]:md:w-full"
>
<Input readOnly value={project.name ?? ''} />
</FormItemLayout>
</CardContent>
</Card>
</Form>
)}
{isCli && (
<Admonition
type="default"
title="Local development with the Supabase CLI"
description={
<p>
Project settings are configured in <code>supabase/config.toml</code> — applied on{' '}
<code>supabase start</code>.
</p>
}
actions={<DocsButton href={`${DOCS_URL}/guides/local-development`} />}
/>
)}
{isSelfHosted && (
<Admonition
type="default"
title="Self-hosted Supabase"
description={<p>Project settings are configured via environment variables.</p>}
actions={<DocsButton href={`${DOCS_URL}/guides/self-hosting`} />}
/>
)}
</PageSectionContent>
</PageSection>
)
}
return (
<>
<PageSection>
<PageSectionMeta>
<PageSectionSummary>
<PageSectionTitle>General settings</PageSectionTitle>
</PageSectionSummary>
</PageSectionMeta>
<PageSectionContent>
{isBranch && (
<Admonition
type="default"
className="mb-4"
title="You are currently on a preview branch of your project"
>
Certain settings are not available while you're on a preview branch. To adjust your
project settings, you may return to your{' '}
<InlineLink href={`/project/${project?.parent_project_ref}/settings/general`}>
main branch
</InlineLink>
.
</Admonition>
)}
{project === undefined ? (
<Card>
<CardContent>
<GenericSkeletonLoader />
</CardContent>
</Card>
) : (
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<Card>
<CardContent>
<FormField
control={form.control}
name="name"
render={({ field }) => (
<FormItemLayout
layout="flex-row-reverse"
label={`${entityLabel} name`}
description="Displayed throughout the dashboard."
className="[&>div]:md:w-1/2"
>
<FormControl>
<Input
{...field}
readOnly={isBranch || !canUpdateProject}
autoComplete="off"
/>
</FormControl>
</FormItemLayout>
)}
/>
</CardContent>
{isBranch && (
<CardContent>
<FormItemLayout
layout="flex-row-reverse"
label={`${entityLabel} type`}
description="Preview or persistent"
className="[&>div]:md:w-1/2 [&>div>div]:md:w-full"
>
<FormControl>
<Input readOnly value={branch?.persistent ? 'Persistent' : 'Preview'} />
</FormControl>
</FormItemLayout>
</CardContent>
)}
<CardContent>
<FormItemLayout
layout="flex-row-reverse"
label={`${entityLabel} ID`}
description="Reference used in APIs and URLs."
className="[&>div]:md:w-1/2 [&>div>div]:md:w-full"
>
<FormControl>
<PasswordInput
copy
readOnly
size="small"
value={project.ref}
onCopied={() =>
track('project_settings_value_copied', { field: 'projectRef' })
}
/>
</FormControl>
</FormItemLayout>
</CardContent>
<CardContent>
<FormItemLayout
layout="flex-row-reverse"
label={`${entityLabel} region`}
description={regionLabel?.name}
className="[&>div]:md:w-1/2 [&>div>div]:md:w-full"
>
<FormControl>
<PasswordInput
copy
readOnly
size="small"
value={project.region}
onCopy={() => track('project_settings_value_copied', { field: 'region' })}
/>
</FormControl>
</FormItemLayout>
</CardContent>
<CardFooter className="justify-end space-x-2">
{form.formState.isDirty && (
<Button
type="button"
disabled={isUpdating}
onClick={() => form.reset({ name: project?.name ?? '' })}
>
Cancel
</Button>
)}
<Button
variant="primary"
type="submit"
disabled={
!form.formState.isDirty || isUpdating || !canUpdateProject || isBranch
}
loading={isUpdating}
>
Save changes
</Button>
</CardFooter>
</Card>
</form>
</Form>
)}
</PageSectionContent>
</PageSection>
<ProjectAccessSection />
</>
)
}