mirror of
https://github.com/overleaf/overleaf.git
synced 2024-10-17 21:05:04 -04:00
Merge pull request #20326 from overleaf/mj-filetree-restore-importtime
[web] Use importedAt timestamp for linked files if present GitOrigin-RevId: 2132dfede83778a018e02fdba3d40180838f37af
This commit is contained in:
parent
9719b3376c
commit
edf2c68c51
2 changed files with 29 additions and 3 deletions
|
@ -2,6 +2,7 @@ import { FileRef } from '../../../../../types/file-ref'
|
||||||
import { BinaryFile } from '@/features/file-view/types/binary-file'
|
import { BinaryFile } from '@/features/file-view/types/binary-file'
|
||||||
|
|
||||||
export function convertFileRefToBinaryFile(fileRef: FileRef): BinaryFile {
|
export function convertFileRefToBinaryFile(fileRef: FileRef): BinaryFile {
|
||||||
|
const timestamp = fileRef.linkedFileData?.importedAt ?? fileRef.created
|
||||||
return {
|
return {
|
||||||
_id: fileRef._id,
|
_id: fileRef._id,
|
||||||
name: fileRef.name,
|
name: fileRef.name,
|
||||||
|
@ -9,7 +10,7 @@ export function convertFileRefToBinaryFile(fileRef: FileRef): BinaryFile {
|
||||||
type: 'file',
|
type: 'file',
|
||||||
selected: true,
|
selected: true,
|
||||||
linkedFileData: fileRef.linkedFileData,
|
linkedFileData: fileRef.linkedFileData,
|
||||||
created: fileRef.created ? new Date(fileRef.created) : new Date(),
|
created: timestamp ? new Date(timestamp) : new Date(),
|
||||||
hash: fileRef.hash,
|
hash: fileRef.hash,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,8 +23,9 @@ export function convertFileRefToBinaryFile(fileRef: FileRef): BinaryFile {
|
||||||
// `FileViewHeader` pass in a string for `created`, so that's what this function
|
// `FileViewHeader` pass in a string for `created`, so that's what this function
|
||||||
// does too.
|
// does too.
|
||||||
export function fileViewFile(fileRef: FileRef) {
|
export function fileViewFile(fileRef: FileRef) {
|
||||||
|
const converted = convertFileRefToBinaryFile(fileRef)
|
||||||
return {
|
return {
|
||||||
...convertFileRefToBinaryFile(fileRef),
|
...converted,
|
||||||
created: fileRef.created,
|
created: converted.created.toISOString(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import fetchMock from 'fetch-mock'
|
||||||
import { renderWithEditorContext } from '../../../helpers/render-with-context'
|
import { renderWithEditorContext } from '../../../helpers/render-with-context'
|
||||||
import FileViewHeader from '../../../../../frontend/js/features/file-view/components/file-view-header'
|
import FileViewHeader from '../../../../../frontend/js/features/file-view/components/file-view-header'
|
||||||
import { USER_ID } from '../../../helpers/editor-providers'
|
import { USER_ID } from '../../../helpers/editor-providers'
|
||||||
|
import { fileViewFile } from '@/features/ide-react/util/file-view'
|
||||||
|
|
||||||
describe('<FileViewHeader/>', function () {
|
describe('<FileViewHeader/>', function () {
|
||||||
const urlFile = {
|
const urlFile = {
|
||||||
|
@ -81,4 +82,27 @@ describe('<FileViewHeader/>', function () {
|
||||||
screen.getByText('Download', { exact: false })
|
screen.getByText('Download', { exact: false })
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should use importedAt as timestamp when present in the linked file data', function () {
|
||||||
|
const fileFromServer = {
|
||||||
|
name: 'example.tex',
|
||||||
|
linkedFileData: {
|
||||||
|
v1_source_doc_id: 'v1-source-id',
|
||||||
|
source_project_id: 'source-project-id',
|
||||||
|
source_entity_path: '/source-entity-path.ext',
|
||||||
|
provider: 'project_file',
|
||||||
|
importer_id: USER_ID,
|
||||||
|
importedAt: new Date(2024, 9, 16, 1, 30).getTime(),
|
||||||
|
},
|
||||||
|
created: new Date(2021, 1, 17, 3, 24).toISOString(),
|
||||||
|
}
|
||||||
|
// FIXME: This should be tested through the <EditorAndPdf /> component instead
|
||||||
|
const fileShown = fileViewFile(fileFromServer)
|
||||||
|
renderWithEditorContext(<FileViewHeader file={fileShown} />)
|
||||||
|
screen.getByText('Imported from', { exact: false })
|
||||||
|
screen.getByText('Another project', { exact: false })
|
||||||
|
screen.getByText('/source-entity-path.ext, at 1:30 am Wed, 16th Oct 24', {
|
||||||
|
exact: false,
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue