Przeglądaj źródła

Merge pull request #29180 from overleaf/mj-linked-files-reindex

[web] Ensure we reindex after refreshing linked file

GitOrigin-RevId: 0c7d561a556525e9db30a8a1cec78b31a4d1d5de
Mathias Jakobsen 1 rok temu
rodzic
commit
d75c5f72fb

+ 17 - 2
services/web/frontend/js/features/file-view/components/file-view-refresh-button.tsx

@@ -15,6 +15,8 @@ import OLButton from '@/shared/components/ol/ol-button'
 import { sendMB } from '@/infrastructure/event-tracking'
 import useIsMounted from '@/shared/hooks/use-is-mounted'
 import clientId from '@/utils/client-id'
+import { useReferencesContext } from '@/features/ide-react/context/references-context'
+import { useFeatureFlag } from '@/shared/context/split-test-context'
 
 type FileViewRefreshButtonProps = {
   setRefreshError: Dispatch<SetStateAction<Nullable<string>>>
@@ -35,14 +37,17 @@ export default function FileViewRefreshButton({
   const { projectId } = useProjectContext()
   const [refreshing, setRefreshing] = useState(false)
   const isMountedRef = useIsMounted()
+  const { indexAllReferences } = useReferencesContext()
+  const clientSideReferences = useFeatureFlag('client-side-references')
 
   const refreshFile = useCallback(
     (isTPR: Nullable<boolean>) => {
       setRefreshing(true)
       // Replacement of the file handled by the file tree
       window.expectingLinkedFileRefreshedSocketFor = file.name
+      const shouldReindexReferences = isTPR || /\.bib$/.test(file.name)
       const body = {
-        shouldReindexReferences: isTPR || /\.bib$/.test(file.name),
+        shouldReindexReferences,
         clientId: clientId.get(),
       }
       postJSON(`/project/${projectId}/linked_file/${file.id}/refresh`, {
@@ -52,6 +57,9 @@ export default function FileViewRefreshButton({
           if (isMountedRef.current) {
             setRefreshing(false)
           }
+          if (clientSideReferences && shouldReindexReferences) {
+            indexAllReferences(false)
+          }
           sendMB('refresh-linked-file', {
             provider: file.linkedFileData?.provider,
           })
@@ -63,7 +71,14 @@ export default function FileViewRefreshButton({
           }
         })
     },
-    [file, projectId, setRefreshError, isMountedRef]
+    [
+      file,
+      projectId,
+      setRefreshError,
+      isMountedRef,
+      indexAllReferences,
+      clientSideReferences,
+    ]
   )
 
   if (tprFileViewRefreshButton.length > 0) {