Skip to content

Commit

Permalink
refactor(e2e): add telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
RitaDias committed Sep 19, 2024
1 parent 68e3a41 commit 0c4014d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
import {ErrorOutlineIcon} from '@sanity/icons'
import {useTelemetry} from '@sanity/telemetry/react'
import {Flex, Text} from '@sanity/ui'
import {useCallback, useEffect, useState} from 'react'
import {isDraftId, useDocumentOperation, useTranslation} from 'sanity'

import {Button} from '../../../../../ui-components'
import {structureLocaleNamespace} from '../../../../i18n'
import {useDocumentPane} from '../../useDocumentPane'
import {
DiscardedLiveEditDraft,
PublishedLiveEditDraft,
} from './__telemetry__/DraftLiveEditBanner.telemetry'
import {Banner} from './Banner'

export function DraftLiveEditBanner(): JSX.Element | null {
const {displayed, documentId} = useDocumentPane()
const {t} = useTranslation(structureLocaleNamespace)
const [isPublishing, setPublishing] = useState(false)
const [isDiscarding, setDiscarding] = useState(false)
const telemetry = useTelemetry()

const {publish, discardChanges} = useDocumentOperation(documentId, displayed?._type || '')

const handlePublish = useCallback(() => {
publish.execute()
setPublishing(true)
}, [publish])
telemetry.log(PublishedLiveEditDraft)
}, [publish, telemetry])

const handleDiscard = useCallback(() => {
discardChanges.execute()
setDiscarding(true)
}, [discardChanges])
telemetry.log(DiscardedLiveEditDraft)
}, [discardChanges, telemetry])

useEffect(() => {
return () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {defineEvent} from '@sanity/telemetry'

/**
* When a draft in a live edit document is published
* @internal
*/
export const PublishedLiveEditDraft = defineEvent({
name: 'Publish a draft (live edit)',
version: 1,
description: 'User published a draft when a draft of a live edit document to continue editing',
})

/*
* When a draft in a live edit document is discarded
* @internal
*/
export const DiscardedLiveEditDraft = defineEvent({
name: 'Create a new draft',
version: 1,
description: 'User discarded a draft when a draft of a live edit document to continue editing',
})

0 comments on commit 0c4014d

Please sign in to comment.