mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 09:25:06 +03:00
Cleans up the `tableEditorApiAccessToggle` PostHog flag now that the gated UI is shipping to everyone. Follow-up to #45034 — the new project-creation checkbox makes the management UI a prerequisite, so no reason to keep it behind a flag. **Removed:** - `useDataApiGrantTogglesEnabled` hook - Old schemas-only multi-selector branch in the Data API settings page (the rich per-table / per-function toggles + default-privileges switch become the only UI) - Flag gate around the `<ApiAccessToggle>` section in the table editor side panel - Flag gates around `updateTableApiAccess` calls in the save pipeline (create / duplicate / update) - `tableEditorApiAccessToggleEnabled` telemetry property + stale JSDoc / docs references **Changed:** - `createTableApiAccessHandlerParams` no longer takes an `enabled` param — it was always `true` after removal ## To test - Integrations → Data API settings page: exposed tables, exposed functions, default-privileges toggle all render and save correctly - Table editor: creating, duplicating, and editing a table all run the expected Data API privilege updates - Project creation flow still works end-to-end (unchanged, but the submit telemetry no longer includes `tableEditorApiAccessToggleEnabled`) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Improvements** * API access configuration is now always available in the table editor and PostgreSQL settings, removing previous conditional gating. * Simplified the "Automatically expose new tables and functions" interface by consolidating UI branches. * **Documentation** * Updated telemetry guidance and examples with current feature-flag references. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
56 lines
2.0 KiB
TypeScript
56 lines
2.0 KiB
TypeScript
import { useEffect, useRef } from 'react'
|
|
|
|
import { usePHFlag } from '../ui/useFlag'
|
|
import { IS_TEST_ENV } from '@/lib/constants'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
|
|
/**
|
|
* Controls the default state of the "Automatically expose new tables and functions"
|
|
* checkbox at project creation. When the flag is on, the checkbox defaults
|
|
* to unchecked (i.e. revoke SQL runs). When off/absent, the checkbox defaults
|
|
* to checked (current behaviour — default grants remain).
|
|
*/
|
|
export const useDataApiRevokeOnCreateDefaultEnabled = (): boolean => {
|
|
const flag = usePHFlag<boolean>('dataApiRevokeOnCreateDefault')
|
|
|
|
// Preserve current behaviour (default grants remain) in tests so existing
|
|
// E2E flows don't change silently. Tests that need the revoke-default path
|
|
// should opt in explicitly.
|
|
if (IS_TEST_ENV) {
|
|
return false
|
|
}
|
|
|
|
return !!flag
|
|
}
|
|
|
|
type DefaultPrivilegesExposureOptions =
|
|
| { surface: 'main'; dataApiEnabled: boolean }
|
|
| { surface: 'vercel' }
|
|
|
|
/**
|
|
* Fires `project_creation_default_privileges_exposed` once per mount after the
|
|
* `dataApiRevokeOnCreateDefault` flag resolves. Gating on flag resolution keeps
|
|
* cohort attribution clean — users whose flag never resolves are not counted in
|
|
* either cohort. Deduplicated via ref so re-renders and mid-session flag flips
|
|
* don't re-fire.
|
|
*/
|
|
export const useTrackDefaultPrivilegesExposure = (options: DefaultPrivilegesExposureOptions) => {
|
|
const track = useTrack()
|
|
const flag = usePHFlag<boolean>('dataApiRevokeOnCreateDefault')
|
|
const hasTracked = useRef(false)
|
|
|
|
const { surface } = options
|
|
const dataApiEnabled = options.surface === 'main' ? options.dataApiEnabled : null
|
|
|
|
useEffect(() => {
|
|
if (hasTracked.current) return
|
|
if (flag === undefined) return
|
|
hasTracked.current = true
|
|
track('project_creation_default_privileges_exposed', {
|
|
surface,
|
|
...(dataApiEnabled !== null && { dataApiEnabled }),
|
|
dataApiRevokeOnCreateDefaultEnabled: flag,
|
|
})
|
|
}, [flag, track, surface, dataApiEnabled])
|
|
}
|