From 2aeb788e3f615f97597cf9bcc6ba96b6f5878885 Mon Sep 17 00:00:00 2001 From: David <33458145+davidmcpowell@users.noreply.github.com> Date: Wed, 3 Dec 2025 15:29:09 +0000 Subject: [PATCH] Merge pull request #29946 from overleaf/dp-reopened-error Fix go to code location on re-opened errors GitOrigin-RevId: e7a91ae45ac44453c974c7af8ad938d21c95f410 --- .../pdf-preview/components/pdf-log-entry.tsx | 27 ++++--------- .../hooks/use-handle-log-entry-click.ts | 38 +++++++++++++++++++ 2 files changed, 46 insertions(+), 19 deletions(-) create mode 100644 services/web/frontend/js/features/pdf-preview/hooks/use-handle-log-entry-click.ts diff --git a/services/web/frontend/js/features/pdf-preview/components/pdf-log-entry.tsx b/services/web/frontend/js/features/pdf-preview/components/pdf-log-entry.tsx index e2e7e5893a..70c08f200d 100644 --- a/services/web/frontend/js/features/pdf-preview/components/pdf-log-entry.tsx +++ b/services/web/frontend/js/features/pdf-preview/components/pdf-log-entry.tsx @@ -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 = - 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() diff --git a/services/web/frontend/js/features/pdf-preview/hooks/use-handle-log-entry-click.ts b/services/web/frontend/js/features/pdf-preview/hooks/use-handle-log-entry-click.ts new file mode 100644 index 0000000000..658fbcab03 --- /dev/null +++ b/services/web/frontend/js/features/pdf-preview/hooks/use-handle-log-entry-click.ts @@ -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 = + 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