Files
Verso/services/web/frontend/js/features/pdf-preview/hooks/use-handle-log-entry-click.ts
T
David 2aeb788e3f Merge pull request #29946 from overleaf/dp-reopened-error
Fix go to code location on re-opened errors

GitOrigin-RevId: e7a91ae45ac44453c974c7af8ad938d21c95f410
2025-12-04 09:06:38 +00:00

39 lines
1.1 KiB
TypeScript

import { MouseEventHandler, useCallback } from 'react'
import { useEditorAnalytics } from '@/shared/hooks/use-editor-analytics'
import { ErrorLevel, SourceLocation } from '../util/types'
const useHandleLogEntryClick = ({
level,
ruleId,
sourceLocation,
onSourceLocationClick,
}: {
level: ErrorLevel | undefined
ruleId: string | undefined
sourceLocation: SourceLocation | undefined
onSourceLocationClick?: (location: SourceLocation) => void
}) => {
const { sendEvent } = useEditorAnalytics()
const handleLogEntryLinkClick: MouseEventHandler<HTMLButtonElement> =
useCallback(
event => {
event.preventDefault()
if (onSourceLocationClick && sourceLocation) {
onSourceLocationClick(sourceLocation)
const parts = sourceLocation?.file?.split('.')
const extension =
parts?.length && parts?.length > 1 ? parts.pop() : ''
sendEvent('log-entry-link-click', { level, ruleId, extension })
}
},
[level, onSourceLocationClick, ruleId, sourceLocation, sendEvent]
)
return handleLogEntryLinkClick
}
export default useHandleLogEntryClick