Skip to content

Commit

Permalink
fix(pte): add telemetry to invalidvalue error (#5809)
Browse files Browse the repository at this point in the history
* fix(pte): add telemetry to invalidvalue error

* fix(core): add id and description to PTE telemetry event
  • Loading branch information
ninaandal authored Feb 22, 2024
1 parent 0794d72 commit f3fd972
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
21 changes: 19 additions & 2 deletions packages/sanity/src/core/form/__telemetry__/form.telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,29 @@ import {defineEvent} from '@sanity/telemetry'

export const PortableTextInputExpanded = defineEvent({
version: 1,
name: 'Portable Text Editor expanded',
name: 'Portable Text Editor Expanded',
description: 'The portable text editor was expanded',
})

export const PortableTextInputCollapsed = defineEvent({
version: 1,
name: 'Portable Text Editor collapsed',
name: 'Portable Text Editor Collapsed',
description: 'The portable text editor was collapsed',
})

export const PortableTextInvalidValueIgnore = defineEvent({
version: 1,
name: 'Portable Text Editor Ignored Invalid Value ',
description:
'The portable text got an invalid value from the form and pressed button to ignore it',
})

export const PortableTextInvalidValueResolve = defineEvent<{
PTEInvalidValueId: string
PTEInvalidValueDescription: string
}>({
version: 1,
name: 'Portable Text Editor Resolved Invalid Value',
description:
'The portable text got an invalid value from the form and pressed button to resolve it.',
})
20 changes: 18 additions & 2 deletions packages/sanity/src/core/form/inputs/PortableText/InvalidValue.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {type InvalidValueResolution} from '@sanity/portable-text-editor'
import {useTelemetry} from '@sanity/telemetry/react'
import {
Box,
// eslint-disable-next-line no-restricted-imports
Expand All @@ -12,6 +13,10 @@ import {
import {useCallback} from 'react'

import {Translate, useTranslation} from '../../../i18n'
import {
PortableTextInvalidValueIgnore,
PortableTextInvalidValueResolve,
} from '../../__telemetry__/form.telemetry'
import {Alert} from '../../components/Alert'

interface InvalidValueProps {
Expand All @@ -23,13 +28,24 @@ interface InvalidValueProps {

export function InvalidValue(props: InvalidValueProps) {
const {onChange, onIgnore, resolution, readOnly} = props
const telemetry = useTelemetry()

const {t} = useTranslation()

const handleAction = useCallback(() => {
if (resolution) {
onChange({type: 'mutation', patches: resolution.patches})
telemetry.log(PortableTextInvalidValueResolve, {
PTEInvalidValueId: resolution.i18n.description,
PTEInvalidValueDescription: resolution.description,
})
}
}, [onChange, resolution])
}, [onChange, resolution, telemetry])

const handleOnIgnore = useCallback(() => {
telemetry.log(PortableTextInvalidValueIgnore)
onIgnore()
}, [onIgnore, telemetry])

if (!resolution) return null

Expand All @@ -42,7 +58,7 @@ export function InvalidValue(props: InvalidValueProps) {
<Grid columns={[1, 2]} gap={1}>
<Button
mode="ghost"
onClick={onIgnore}
onClick={handleOnIgnore}
text={t('inputs.portable-text.invalid-value.ignore-button.text')}
/>
{/* @todo: use plain string */}
Expand Down

0 comments on commit f3fd972

Please sign in to comment.