Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions apps/studio/components/layouts/Tabs/NewTab.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
import dayjs from 'dayjs'
import { partition } from 'lodash'
import { Table2 } from 'lucide-react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { useEffect, useMemo, useRef, useState } from 'react'
import { useEffect, useState } from 'react'
import { toast } from 'sonner'

import { useParams } from 'common'
import { LOCAL_STORAGE_KEYS, useParams } from 'common'
import { SQL_TEMPLATES } from 'components/interfaces/SQLEditor/SQLEditor.queries'
import { createSqlSnippetSkeletonV2 } from 'components/interfaces/SQLEditor/SQLEditor.utils'
import { QuickstartAIWidget } from 'components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/QuickstartAIWidget'
import { QuickstartTemplatesWidget } from 'components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/QuickstartTemplatesWidget'
import { QuickstartVariant } from 'components/interfaces/TableGridEditor/SidePanelEditor/TableEditor/TableQuickstart/types'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { useAsyncCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { useQuerySchemaState } from 'hooks/misc/useSchemaQueryState'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
Expand Down Expand Up @@ -43,7 +43,6 @@ import { SIDEBAR_KEYS } from '../ProjectLayout/LayoutSidebar/LayoutSidebarProvid
import { ActionCard } from './ActionCard'
import { RecentItems } from './RecentItems'

const NEW_PROJECT_THRESHOLD_DAYS = 7
const TABLE_QUICKSTART_FLAG = 'tableQuickstart'

const ASSISTANT_QUICKSTART_MESSAGES = {
Expand All @@ -70,7 +69,10 @@ export function NewTab() {
const [isCreatingChat, setIsCreatingChat] = useState(false)
const [templates] = partition(SQL_TEMPLATES, { type: 'template' })
const [quickstarts] = partition(SQL_TEMPLATES, { type: 'quickstart' })
const hasTrackedExposure = useRef(false)
const [hasTrackedExposure, setHasTrackedExposure] = useLocalStorageQuery(
LOCAL_STORAGE_KEYS.TABLE_QUICKSTART_EXPOSURE_TRACKED(String(profile?.id ?? 'anonymous')),
false
)

const { mutate: sendEvent } = useSendEventMutation()
const track = useTrack()
Expand All @@ -93,33 +95,33 @@ export function NewTab() {
TABLE_QUICKSTART_FLAG
)

const isNewProject = useMemo(() => {
if (!project?.inserted_at) return false
return dayjs().diff(dayjs(project.inserted_at), 'day') < NEW_PROJECT_THRESHOLD_DAYS
}, [project?.inserted_at])

const activeQuickstartVariant =
editor !== 'sql' &&
isNewProject &&
tableQuickstartVariant &&
tableQuickstartVariant !== QuickstartVariant.CONTROL
? tableQuickstartVariant
: null

const shouldTrackExposure =
editor !== 'sql' &&
isNewProject &&
!!profile?.id &&
tableQuickstartVariant !== false &&
tableQuickstartVariant !== undefined

useEffect(() => {
if (shouldTrackExposure && !hasTrackedExposure.current) {
hasTrackedExposure.current = true
if (shouldTrackExposure && !hasTrackedExposure) {
setHasTrackedExposure(true)
track('table_quickstart_opened', {
variant: tableQuickstartVariant,
})
}
}, [shouldTrackExposure, tableQuickstartVariant, track])
}, [
shouldTrackExposure,
hasTrackedExposure,
setHasTrackedExposure,
tableQuickstartVariant,
track,
])

const handleOpenAssistant = () => {
if (isCreatingChat) return
Expand Down
6 changes: 3 additions & 3 deletions packages/common/constants/local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ export const LOCAL_STORAGE_KEYS = {
*/
BLOG_VIEW: 'supabase-blog-view',

// Used to track if user has dismissed table editor quickstart prompt
TABLE_QUICKSTART_DISMISSED: 'table-quickstart-dismissed',
// Used to track if user has been exposed to table quickstart experiment (prevents duplicate exposure events)
TABLE_QUICKSTART_EXPOSURE_TRACKED: (userId: string) =>
`table-quickstart-exposure-tracked-${userId}`,
} as const

export type LocalStorageKey = (typeof LOCAL_STORAGE_KEYS)[keyof typeof LOCAL_STORAGE_KEYS]
Expand All @@ -140,7 +141,6 @@ const LOCAL_STORAGE_KEYS_ALLOWLIST = [
LOCAL_STORAGE_KEYS.AI_ASSISTANT_MCP_OPT_IN,
LOCAL_STORAGE_KEYS.UI_PREVIEW_BRANCHING_2_0,
LOCAL_STORAGE_KEYS.LINTER_SHOW_FOOTER,
LOCAL_STORAGE_KEYS.TABLE_QUICKSTART_DISMISSED,
]

export function clearLocalStorage() {
Expand Down
Loading