mirror of
https://github.com/supabase/supabase.git
synced 2026-05-07 17:30:25 -04:00
180ce515f6
* **Chores** * Updated internal module import paths across hook files to use standardized path aliases for improved code consistency and maintainability.
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { useParams } from 'common'
|
|
import type {
|
|
CommandMenuClosedEvent,
|
|
CommandMenuCommandClickedEvent,
|
|
CommandMenuOpenedEvent,
|
|
CommandMenuSearchSubmittedEvent,
|
|
} from 'common/telemetry-constants'
|
|
import { useCallback } from 'react'
|
|
|
|
import { useSendEventMutation } from '@/data/telemetry/send-event-mutation'
|
|
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
|
|
|
|
export function useStudioCommandMenuTelemetry() {
|
|
const { ref: projectRef } = useParams()
|
|
const { data: organization } = useSelectedOrganizationQuery()
|
|
const { mutate: sendEvent } = useSendEventMutation()
|
|
|
|
const onTelemetry = useCallback(
|
|
(
|
|
event:
|
|
| CommandMenuOpenedEvent
|
|
| CommandMenuClosedEvent
|
|
| CommandMenuCommandClickedEvent
|
|
| CommandMenuSearchSubmittedEvent
|
|
) => {
|
|
// Add studio-specific groups (project and organization)
|
|
const eventWithGroups = {
|
|
...event,
|
|
groups: {
|
|
...event.groups,
|
|
...(projectRef && { project: projectRef }),
|
|
...(organization?.slug && { organization: organization.slug }),
|
|
},
|
|
}
|
|
|
|
sendEvent(eventWithGroups)
|
|
},
|
|
[projectRef, organization?.slug, sendEvent]
|
|
)
|
|
|
|
return { onTelemetry }
|
|
}
|