Просмотр исходного кода

Merge pull request #27303 from overleaf/dp-go-to-code

Hide go to code button in the new editor logs when it does nothing

GitOrigin-RevId: f08c3fc98bae8116a428a7528291edccd6d4f8c0
Alexandre Bourdin 1 год назад
Родитель
Сommit
2cfe2b1e15

+ 10 - 1
services/web/frontend/js/features/ide-redesign/components/error-logs/log-entry-header.tsx

@@ -11,6 +11,8 @@ import useResizeObserver from '@/features/preview/hooks/use-resize-observer'
 import OLIconButton from '@/features/ui/components/ol/ol-icon-button'
 import importOverleafModules from '../../../../../macros/import-overleaf-module.macro'
 import MaterialIcon from '@/shared/components/material-icon'
+import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-path'
+import { useFileTreeOpenContext } from '@/features/ide-react/context/file-tree-open-context'
 
 const actionComponents = importOverleafModules(
   'pdfLogEntryHeaderActionComponents'
@@ -49,6 +51,8 @@ function LogEntryHeader({
   const { t } = useTranslation()
   const logLocationSpanRef = useRef<HTMLSpanElement>(null)
   const [locationSpanOverflown, setLocationSpanOverflown] = useState(false)
+  const { findEntityByPath } = useFileTreePathContext()
+  const { openEntity } = useFileTreeOpenContext()
 
   useResizeObserver(
     logLocationSpanRef,
@@ -95,6 +99,11 @@ function LogEntryHeader({
   ) : null
 
   const headerTitleText = logType ? `${logType} ${headerTitle}` : headerTitle
+  const fileData = file && findEntityByPath(file)
+  const showGoToCodeButton =
+    showSourceLocationLink &&
+    !!fileData &&
+    !(fileData.entity._id === openEntity?.entity._id && !line)
 
   return (
     <header className="log-entry-header-card">
@@ -136,7 +145,7 @@ function LogEntryHeader({
 
       {actionButtonsOverride ?? (
         <div className="log-entry-header-actions">
-          {showSourceLocationLink && (
+          {showGoToCodeButton && (
             <OLTooltip
               id={`go-to-location-${locationText}`}
               description={t('go_to_code_location')}