mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
[clsi] migrate convert project to document to compile from history (#33985)
* [clsi] add request flag for isCompileFromHistory * [clsi] derive cacheKey for history snapshot from compile dir * [clsi] migrate convert project to document to compile from history * [clsi] address review feedback * [web] determine root doc at the time of converting the project * [web] wait for flush before starting document conversion * [saas-e2e] add tests for root doc override when converting project GitOrigin-RevId: 71c578030949b89f3a74e7f7ab882dfa9c98c17a
This commit is contained in:
+9
-1
@@ -4,6 +4,8 @@ import { FC } from 'react'
|
||||
import useConvertProject from '../../hooks/use-convert-project'
|
||||
import { useCommandProvider } from '../../hooks/use-command-provider'
|
||||
import OLDropdownMenuItem from '@/shared/components/ol/ol-dropdown-menu-item'
|
||||
import { useRootDoc } from '@/shared/hooks/use-root-doc'
|
||||
import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context'
|
||||
|
||||
type ExportProjectWithConversionProps = {
|
||||
featureFlag?: string
|
||||
@@ -20,7 +22,13 @@ export const ExportProjectWithConversionButton: FC<
|
||||
const enablePandocConversions =
|
||||
getMeta('ol-ExposedSettings')?.enablePandocConversions
|
||||
const anonymous = getMeta('ol-anonymous')
|
||||
const downloadConversion = useConvertProject(conversionType)
|
||||
const getRootDocInfo = useRootDoc()
|
||||
const { openDocs } = useEditorManagerContext()
|
||||
const downloadConversion = useConvertProject(
|
||||
conversionType,
|
||||
openDocs,
|
||||
getRootDocInfo
|
||||
)
|
||||
|
||||
const showExportButton =
|
||||
splitTestEnabledIfNeeded && enablePandocConversions && !anonymous
|
||||
|
||||
@@ -9,13 +9,19 @@ import {
|
||||
showExportDocumentSuccess,
|
||||
showPreparingExportToast,
|
||||
} from '../components/toolbar/export-document-toasts'
|
||||
import { RootDocInfo } from '@/shared/hooks/use-root-doc'
|
||||
import { OpenDocuments } from '../editor/open-documents'
|
||||
|
||||
const SLOW_CONVERSION_THRESHOLD = 2000
|
||||
|
||||
export default function useConvertProject(type: 'docx' | 'markdown') {
|
||||
export default function useConvertProject(
|
||||
type: 'docx' | 'markdown',
|
||||
openDocs: OpenDocuments,
|
||||
getRootDocInfo: () => RootDocInfo
|
||||
) {
|
||||
const { projectId } = useProjectContext()
|
||||
const location = useLocation()
|
||||
const triggerConversion = useCallback(async () => {
|
||||
return useCallback(async () => {
|
||||
let handle: string | undefined
|
||||
const toastTimer = setTimeout(() => {
|
||||
handle = showPreparingExportToast()
|
||||
@@ -24,10 +30,14 @@ export default function useConvertProject(type: 'docx' | 'markdown') {
|
||||
clearTimeout(toastTimer)
|
||||
if (handle) hidePreparingExportToast(handle)
|
||||
}
|
||||
const url = new URL(window.location.origin)
|
||||
url.pathname = `/project/${projectId}/download/conversion/${type}`
|
||||
url.searchParams.set('responseFormat', 'json')
|
||||
const { rootResourcePath } = getRootDocInfo()
|
||||
url.searchParams.set('rootResourcePath', rootResourcePath)
|
||||
try {
|
||||
const response = await getJSON(
|
||||
`/project/${projectId}/download/conversion/${type}?responseFormat=json`
|
||||
)
|
||||
await openDocs.awaitBufferedOps(AbortSignal.timeout(10_000))
|
||||
const response = await getJSON(url.href)
|
||||
hidePreparingToast()
|
||||
const { downloadUrl } = response
|
||||
if (downloadUrl) {
|
||||
@@ -42,7 +52,5 @@ export default function useConvertProject(type: 'docx' | 'markdown') {
|
||||
showExportDocumentError()
|
||||
debugConsole.error(error)
|
||||
}
|
||||
}, [projectId, type, location])
|
||||
|
||||
return triggerConversion
|
||||
}, [projectId, type, getRootDocInfo, openDocs, location])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user