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:
Mathias Jakobsen 2024-09-18 10:05:31 +01:00 committed by Copybot
parent 9719b3376c
commit edf2c68c51
2 changed files with 29 additions and 3 deletions

View file

@ -2,6 +2,7 @@ import { FileRef } from '../../../../../types/file-ref'
import { BinaryFile } from '@/features/file-view/types/binary-file'
export function convertFileRefToBinaryFile(fileRef: FileRef): BinaryFile {
const timestamp = fileRef.linkedFileData?.importedAt ?? fileRef.created
return {
_id: fileRef._id,
name: fileRef.name,
@ -9,7 +10,7 @@ export function convertFileRefToBinaryFile(fileRef: FileRef): BinaryFile {
type: 'file',
selected: true,
linkedFileData: fileRef.linkedFileData,
created: fileRef.created ? new Date(fileRef.created) : new Date(),
created: timestamp ? new Date(timestamp) : new Date(),
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
// does too.
export function fileViewFile(fileRef: FileRef) {
const converted = convertFileRefToBinaryFile(fileRef)
return {
...convertFileRefToBinaryFile(fileRef),
created: fileRef.created,
...converted,
created: converted.created.toISOString(),
}
}

View file

@ -4,6 +4,7 @@ import fetchMock from 'fetch-mock'
import { renderWithEditorContext } from '../../../helpers/render-with-context'
import FileViewHeader from '../../../../../frontend/js/features/file-view/components/file-view-header'
import { USER_ID } from '../../../helpers/editor-providers'
import { fileViewFile } from '@/features/ide-react/util/file-view'
describe('<FileViewHeader/>', function () {
const urlFile = {
@ -81,4 +82,27 @@ describe('<FileViewHeader/>', function () {
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,
})
})
})