mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +00:00
## 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>
134 lines
5.2 KiB
TypeScript
134 lines
5.2 KiB
TypeScript
import { useFlag, useParams } from 'common'
|
|
import { Loader2Icon } from 'lucide-react'
|
|
import { useEffect, useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
import { Card, CardContent, Switch, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
|
import {
|
|
PageSection,
|
|
PageSectionContent,
|
|
PageSectionDescription,
|
|
PageSectionMeta,
|
|
PageSectionSummary,
|
|
PageSectionTitle,
|
|
} from 'ui-patterns/PageSection'
|
|
|
|
import { AlertError } from '@/components/ui/AlertError'
|
|
import { DocsButton } from '@/components/ui/DocsButton'
|
|
import { InlineLink } from '@/components/ui/InlineLink'
|
|
import { useComplianceConfigUpdateMutation } from '@/data/config/project-compliance-config-mutation'
|
|
import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query'
|
|
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
|
import { DOCS_URL } from '@/lib/constants'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
|
|
export const ComplianceConfig = () => {
|
|
const { ref } = useParams()
|
|
const track = useTrack()
|
|
const isIssuesInboxEnabled = useFlag('issuesInbox')
|
|
const [isSensitive, setIsSensitive] = useState(false)
|
|
|
|
const { can: canUpdateComplianceConfig } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.PROJECT.ADMIN_WRITE
|
|
)
|
|
|
|
const {
|
|
data: settings,
|
|
error,
|
|
isError,
|
|
isPending: isLoading,
|
|
isSuccess,
|
|
} = useProjectSettingsV2Query({ projectRef: ref })
|
|
const initialIsSensitive = settings?.is_sensitive || false
|
|
|
|
const { mutate: updateComplianceConfig, isPending: isSubmitting } =
|
|
useComplianceConfigUpdateMutation({
|
|
onSuccess: (_data, vars) => {
|
|
track('project_compliance_mode_updated', { isSensitive: vars.isSensitive })
|
|
toast.success('Successfully updated project compliance configuration')
|
|
},
|
|
onError: (error) => {
|
|
setIsSensitive(initialIsSensitive)
|
|
toast.error(`Failed to update project compliance configuration: ${error.message}`)
|
|
},
|
|
})
|
|
|
|
const toggleIsSensitive = async () => {
|
|
if (!ref) return console.error('Project ref is required')
|
|
setIsSensitive(!isSensitive)
|
|
updateComplianceConfig({ projectRef: ref, isSensitive: !isSensitive })
|
|
}
|
|
|
|
useEffect(() => {
|
|
if (!isLoading) setIsSensitive(initialIsSensitive)
|
|
}, [isLoading])
|
|
|
|
return (
|
|
<PageSection id="compliance-configuration">
|
|
<PageSectionMeta>
|
|
<div className="w-full flex flex-col gap-3 @lg:flex-row @lg:items-center @lg:justify-between">
|
|
<PageSectionSummary>
|
|
<PageSectionTitle>High Compliance Configuration</PageSectionTitle>
|
|
<PageSectionDescription>
|
|
For projects storing and processing sensitive data (HIPAA).
|
|
</PageSectionDescription>
|
|
</PageSectionSummary>
|
|
<DocsButton href={`${DOCS_URL}/guides/platform/hipaa-projects`} />
|
|
</div>
|
|
</PageSectionMeta>
|
|
<PageSectionContent>
|
|
<Card>
|
|
<CardContent className="flex flex-col gap-4 @lg:flex-row @lg:items-center @lg:justify-between">
|
|
<div className="space-y-2 max-w-2xl">
|
|
<p className="text-sm">Apply additional compliance controls to project</p>
|
|
<p className="text-sm text-foreground-light">
|
|
<span>
|
|
{isIssuesInboxEnabled ? 'Raise additional ' : 'Enable security warnings in the '}
|
|
</span>
|
|
{isIssuesInboxEnabled ? (
|
|
<InlineLink href={`/project/${ref}/issues?category=security`}>
|
|
security issues
|
|
</InlineLink>
|
|
) : (
|
|
<InlineLink href={`/project/${ref}/advisors/security`}>
|
|
Security Advisor
|
|
</InlineLink>
|
|
)}
|
|
<span> to enforce requirements for managing sensitive data.</span>
|
|
</p>
|
|
</div>
|
|
<div className="flex items-center justify-end space-x-2">
|
|
{(isLoading || isSubmitting) && (
|
|
<Loader2Icon className="animate-spin" strokeWidth={1.5} size={16} />
|
|
)}
|
|
{isError && (
|
|
<AlertError error={error} subject="Failed to retrieve project settings" />
|
|
)}
|
|
{isSuccess && (
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
{/* [Joshen] Added div as tooltip is messing with data state property of toggle */}
|
|
<div>
|
|
<Switch
|
|
size="large"
|
|
checked={isSensitive}
|
|
disabled={isLoading || isSubmitting || !canUpdateComplianceConfig}
|
|
onCheckedChange={toggleIsSensitive}
|
|
/>
|
|
</div>
|
|
</TooltipTrigger>
|
|
{!canUpdateComplianceConfig && (
|
|
<TooltipContent side="bottom" className="w-64 text-center">
|
|
You need additional permissions to update the compliance configuration for
|
|
your project
|
|
</TooltipContent>
|
|
)}
|
|
</Tooltip>
|
|
)}
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
</PageSectionContent>
|
|
</PageSection>
|
|
)
|
|
}
|