Files
overleaf-cep/services/web/frontend/js/features/ide-react/components/toolbar/project-title.tsx
T
Davinder Singh be5a7b56c8 [WEB + CLSI] Download as docx file feature (#32851)
* using CLSI logic for fetching the project contents and skip the .zip export

* Use unique conversion directory for project-to-docx export to avoid corrupting the shared compile
  directory when a compile runs concurrently

* Remove X-Accel-Buffering header — not needed as CLSI does not run behind nginx

* moving log before sending the data

* Return CLSI stream directly instead of buffering to disk on web

  Previously convertProjectToDocx wrote the CLSI response to a temp file
  on disk, then the controller read it back to stream to the client.
  Now the stream is returned directly and piped to the response,
  avoiding unnecessary disk I/O on the web server.

* Use href redirect for docx export instead of fetching blob into memory

* making functions and files more generic so they can be used in future for other documents exports as well

* adding export-docx split test

* adding unit tests

* adding cypress E2E test

* format:fix

* renaming the route to download from convert

* adding new icon for export docx button

* format:fix

* remove unused showExportDocumentErrorToast export and adding guard against invalid Content-Length header from CLSI

* format:fix

* refactor(clsi): move promisify(parse) into RequestParser

* refactor: generic conversion endpoint with type as route
  param

* refactor: use type→extension map for validated conversion types

* refactor(clsi): remove --standalone flag and fix rejection test

* fixing the href in cypress test

* renaming function

* adding type to Metrics.inc

* fix: rename exportProjectDocument, add WithLock wrapper and metrics type label

* format:fix

* fix: hide docx export from anonymous users and add WithLock wrapper

* format fix

* remove redundant Content-Length validation from DocumentConversionManager

* format:fix

* removing trailing icon

GitOrigin-RevId: e9764fefac2c4b625d23be9e942ea4a8b283c70d
2026-04-24 08:06:10 +00:00

98 lines
3.1 KiB
TypeScript

import {
Dropdown,
DropdownDivider,
DropdownMenu,
DropdownToggle,
} from '@/shared/components/dropdown/dropdown-menu'
import MaterialIcon from '@/shared/components/material-icon'
import { useProjectContext } from '@/shared/context/project-context'
import { useTranslation } from 'react-i18next'
import importOverleafModules from '../../../../../macros/import-overleaf-module.macro'
import { useEditorContext } from '@/shared/context/editor-context'
import { useIdeReactContext } from '@/features/ide-react/context/ide-react-context'
import {
DownloadProjectPDF,
DownloadProjectZip,
ExportProjectDocx,
} from './download-project'
import { useCallback, useState } from 'react'
import OLDropdownMenuItem from '@/shared/components/ol/ol-dropdown-menu-item'
import EditableLabel from './editable-label'
import { DuplicateProject } from './duplicate-project'
const [publishModalModules] = importOverleafModules('publishModal')
const SubmitProjectButton = publishModalModules?.import.NewPublishDropdownButton
export const ToolbarProjectTitle = () => {
const { cobranding } = useEditorContext()
const { t } = useTranslation()
const { renameProject } = useEditorContext()
const { permissionsLevel } = useIdeReactContext()
const { name } = useProjectContext()
const shouldDisplaySubmitButton =
(permissionsLevel === 'owner' || permissionsLevel === 'readAndWrite') &&
SubmitProjectButton
const hasRenamePermissions = permissionsLevel === 'owner'
const [isRenaming, setIsRenaming] = useState(false)
const onRename = useCallback(
(name: string) => {
if (name) {
renameProject(name)
}
setIsRenaming(false)
},
[renameProject]
)
const onCancel = useCallback(() => {
setIsRenaming(false)
}, [])
if (isRenaming) {
return (
<EditableLabel
onChange={onRename}
onCancel={onCancel}
initialText={name}
maxLength={150}
className="ide-redesign-toolbar-editable-project-name"
/>
)
}
return (
<Dropdown align="end" className="ide-redesign-toolbar-project-dropdown">
<DropdownToggle
id="project-title-options"
aria-label={t('project_title_options')}
className="ide-redesign-toolbar-project-dropdown-toggle ide-redesign-toolbar-dropdown-toggle-subdued fw-bold ide-redesign-toolbar-button-subdued"
>
<span className="ide-redesign-toolbar-project-name" translate="no">
{name}
</span>
<MaterialIcon type="keyboard_arrow_down" />
</DropdownToggle>
<DropdownMenu renderOnMount>
{shouldDisplaySubmitButton && !cobranding && (
<>
<SubmitProjectButton />
<DropdownDivider />
</>
)}
<DownloadProjectPDF />
<DownloadProjectZip />
<ExportProjectDocx />
<DropdownDivider />
<DuplicateProject />
<OLDropdownMenuItem
onClick={() => {
setIsRenaming(true)
}}
disabled={!hasRenamePermissions}
>
{t('rename')}
</OLDropdownMenuItem>
</DropdownMenu>
</Dropdown>
)
}