Browse Source

[web] convert file-list to typescript (#24354)

* [web] convert file-list to typescript

* [web] add type annotation for clsiServerId without providing default

Co-authored-by: David Powell <david.powell@overleaf.com>

---------

Co-authored-by: David Powell <david.powell@overleaf.com>
GitOrigin-RevId: 5ecb79c2540a3e46e296c6bf7f8573fb65febc3f
Jakob Ackermann 1 năm trước cách đây
mục cha
commit
54f5c3115c

+ 1 - 1
services/clsi/app/js/OutputFileArchiveManager.js

@@ -7,7 +7,7 @@ const { NotFoundError } = require('./Errors')
 const logger = require('@overleaf/logger')
 
 // NOTE: Updating this list requires a corresponding change in
-// * services/web/frontend/js/features/pdf-preview/util/file-list.js
+// * services/web/frontend/js/features/pdf-preview/util/file-list.ts
 const ignoreFiles = ['output.fls', 'output.fdb_latexmk']
 
 function getContentDir(projectId, userId) {

+ 11 - 7
services/web/frontend/js/features/pdf-preview/util/file-list.js → services/web/frontend/js/features/pdf-preview/util/file-list.ts

@@ -1,15 +1,19 @@
+import {
+  CompileOutputFile,
+  CompileResponseData,
+} from '../../../../../types/compile'
+import { PdfFileDataList } from '@/features/pdf-preview/util/types'
+
 const topFileTypes = ['bbl', 'gls', 'ind']
 // NOTE: Updating this list requires a corresponding change in
 // * services/clsi/app/js/OutputFileArchiveManager.js
 const ignoreFiles = ['output.fls', 'output.fdb_latexmk']
 
-export const buildFileList = (
-  outputFiles,
-  clsiServerId,
-  compileGroup,
-  outputFilesArchive
-) => {
-  const files = { top: [], other: [] }
+export function buildFileList(
+  outputFiles: Map<string, CompileOutputFile>,
+  { clsiServerId, compileGroup, outputFilesArchive }: CompileResponseData
+): PdfFileDataList {
+  const files: PdfFileDataList = { top: [], other: [] }
 
   if (outputFiles) {
     const params = new URLSearchParams()

+ 3 - 2
services/web/frontend/js/features/pdf-preview/util/types.ts

@@ -1,4 +1,5 @@
 import React from 'react'
+import { CompileOutputFile } from '../../../../../types/compile'
 
 export type LogEntry = {
   raw: string
@@ -31,8 +32,8 @@ export type SourceLocation = {
   column?: number
 }
 
-export type PdfFileData = { path: string; url: string }
-type PdfFileArchiveData = { path: string; url: string; fileCount: number }
+export type PdfFileData = CompileOutputFile
+type PdfFileArchiveData = CompileOutputFile & { fileCount: number }
 
 export type PdfFileDataList = {
   top: PdfFileData[]

+ 4 - 10
services/web/frontend/js/shared/context/local-compile-context.tsx

@@ -38,6 +38,7 @@ import { useFileTreePathContext } from '@/features/file-tree/contexts/file-tree-
 import { useUserSettingsContext } from '@/shared/context/user-settings-context'
 import { useFeatureFlag } from '@/shared/context/split-test-context'
 import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
+import { CompileResponseData } from '../../../../types/compile'
 import {
   PdfScrollPosition,
   usePdfScrollPosition,
@@ -167,10 +168,10 @@ export const LocalCompileProvider: FC = ({ children }) => {
     useState(false)
 
   // the id of the CLSI server which ran the compile
-  const [clsiServerId, setClsiServerId] = useState()
+  const [clsiServerId, setClsiServerId] = useState<string>()
 
   // data received in response to a compile request
-  const [data, setData] = useState<Record<string, any>>()
+  const [data, setData] = useState<CompileResponseData>()
 
   // the rootDocId used in the most recent compile request, which may not be the
   // same as the project rootDocId. This is used to calculate correct paths when
@@ -392,14 +393,7 @@ export const LocalCompileProvider: FC = ({ children }) => {
           setPdfFile(handleOutputFiles(outputFiles, projectId, data))
         }
 
-        setFileList(
-          buildFileList(
-            outputFiles,
-            data.clsiServerId,
-            data.compileGroup,
-            data.outputFilesArchive
-          )
-        )
+        setFileList(buildFileList(outputFiles, data))
 
         // handle log files
         // asynchronous (TODO: cancel on new compile?)

+ 35 - 0
services/web/types/compile.ts

@@ -0,0 +1,35 @@
+export type CompileOutputFile = {
+  path: string
+  url: string
+  type: string
+  build: string
+  ranges?: {
+    start: number
+    end: number
+    hash: string
+    objectId: string
+  }[]
+  contentId?: string
+  size?: number
+
+  // assigned by buildFileList in frontend
+  main?: boolean
+}
+
+export type CompileResponseData = {
+  fromCache?: boolean
+  status: string
+  outputFiles: CompileOutputFile[]
+  compileGroup?: string
+  clsiServerId?: string
+  pdfDownloadDomain?: string
+  pdfCachingMinChunkSize: number
+  validationProblems: any
+  stats: any
+  timings: any
+  outputFilesArchive?: CompileOutputFile
+
+  // assigned on response body by DocumentCompiler in frontend
+  rootDocId?: string
+  options: any
+}