Merge pull request #29946 from overleaf/dp-reopened-error

Fix go to code location on re-opened errors

GitOrigin-RevId: e7a91ae45ac44453c974c7af8ad938d21c95f410
This commit is contained in:
David
2025-12-03 15:29:09 +00:00
committed by Copybot
parent 76024341f8
commit 2aeb788e3f
2 changed files with 46 additions and 19 deletions

View File

@@ -1,12 +1,12 @@
import { memo, MouseEventHandler, useCallback } from 'react'
import { memo } from 'react'
import PreviewLogEntryHeader from '../../preview/components/preview-log-entry-header'
import PdfLogEntryContent from './pdf-log-entry-content'
import HumanReadableLogsHints from '../../../ide/human-readable-logs/HumanReadableLogsHints'
import getMeta from '@/utils/meta'
import { ErrorLevel, LogEntry, SourceLocation } from '../util/types'
import NewLogEntry from '@/features/ide-redesign/components/error-logs/log-entry'
import { useEditorAnalytics } from '@/shared/hooks/use-editor-analytics'
import { useIsNewEditorEnabled } from '@/features/ide-redesign/utils/new-editor-utils'
import useHandleLogEntryClick from '../hooks/use-handle-log-entry-click'
function PdfLogEntry({
autoExpand,
@@ -46,7 +46,6 @@ function PdfLogEntry({
id?: string
}) {
const showAiErrorAssistant = getMeta('ol-showAiErrorAssistant')
const { sendEvent } = useEditorAnalytics()
if (ruleId && HumanReadableLogsHints[ruleId]) {
const hint = HumanReadableLogsHints[ruleId]
@@ -54,22 +53,12 @@ function PdfLogEntry({
extraInfoURL = hint.extraInfoURL
}
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]
)
const handleLogEntryLinkClick = useHandleLogEntryClick({
level,
ruleId,
sourceLocation,
onSourceLocationClick,
})
const newEditor = useIsNewEditorEnabled()

View File

@@ -0,0 +1,38 @@
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