2021-05-21 07:32:51 -04:00
|
|
|
import { ContextRoot } from '../js/shared/context/root-context'
|
2021-06-10 07:26:04 -04:00
|
|
|
import FileView from '../js/features/file-view/components/file-view'
|
2021-05-11 10:25:22 -04:00
|
|
|
import useFetchMock from './hooks/use-fetch-mock'
|
2021-04-28 07:41:20 -04:00
|
|
|
|
2021-06-25 04:20:33 -04:00
|
|
|
const bodies = {
|
|
|
|
latex: `\\documentclass{article}
|
|
|
|
\\begin{document}
|
|
|
|
First document. This is a simple example, with no
|
|
|
|
extra parameters or packages included.
|
|
|
|
\\end{document}`,
|
|
|
|
bibtex: `@book{latexcompanion,
|
|
|
|
author = "Michel Goossens and Frank Mittelbach and Alexander Samarin",
|
|
|
|
title = "The \\LaTeX\\ Companion",
|
|
|
|
year = "1993",
|
|
|
|
publisher = "Addison-Wesley",
|
|
|
|
address = "Reading, Massachusetts"
|
|
|
|
}`,
|
|
|
|
text: `Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.`,
|
|
|
|
}
|
|
|
|
|
2021-05-11 10:25:22 -04:00
|
|
|
const setupFetchMock = fetchMock => {
|
2021-06-25 04:20:33 -04:00
|
|
|
return fetchMock
|
2021-05-11 10:25:22 -04:00
|
|
|
.head('express:/project/:project_id/file/:file_id', {
|
|
|
|
status: 201,
|
|
|
|
headers: { 'Content-Length': 10000 },
|
|
|
|
})
|
|
|
|
.post('express:/project/:project_id/linked_file/:file_id/refresh', {
|
|
|
|
status: 204,
|
|
|
|
})
|
|
|
|
.post('express:/project/:project_id/references/indexAll', {
|
|
|
|
status: 204,
|
|
|
|
})
|
|
|
|
}
|
2021-04-28 07:41:20 -04:00
|
|
|
|
2021-05-04 07:36:32 -04:00
|
|
|
const fileData = {
|
|
|
|
id: 'file-id',
|
|
|
|
name: 'file.tex',
|
2021-05-21 07:32:51 -04:00
|
|
|
created: new Date().toISOString(),
|
2021-05-04 07:36:32 -04:00
|
|
|
}
|
|
|
|
|
2021-04-28 07:41:20 -04:00
|
|
|
export const FileFromUrl = args => {
|
2021-06-25 04:20:33 -04:00
|
|
|
useFetchMock(fetchMock =>
|
|
|
|
setupFetchMock(fetchMock).get(
|
|
|
|
'express:/project/:project_id/file/:file_id',
|
|
|
|
{ body: bodies.latex }
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-06-10 07:26:04 -04:00
|
|
|
return <FileView {...args} />
|
2021-04-28 07:41:20 -04:00
|
|
|
}
|
|
|
|
FileFromUrl.args = {
|
|
|
|
file: {
|
2021-05-04 07:36:32 -04:00
|
|
|
...fileData,
|
2021-04-28 07:41:20 -04:00
|
|
|
linkedFileData: {
|
2021-06-25 04:20:33 -04:00
|
|
|
url: 'https://example.com/source-file.tex',
|
2021-04-28 07:41:20 -04:00
|
|
|
provider: 'url',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export const FileFromProjectWithLinkableProjectId = args => {
|
2021-06-25 04:20:33 -04:00
|
|
|
useFetchMock(fetchMock =>
|
|
|
|
setupFetchMock(fetchMock).get(
|
|
|
|
'express:/project/:project_id/file/:file_id',
|
|
|
|
{ body: bodies.latex }
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-06-10 07:26:04 -04:00
|
|
|
return <FileView {...args} />
|
2021-04-28 07:41:20 -04:00
|
|
|
}
|
|
|
|
FileFromProjectWithLinkableProjectId.args = {
|
|
|
|
file: {
|
2021-05-04 07:36:32 -04:00
|
|
|
...fileData,
|
2021-04-28 07:41:20 -04:00
|
|
|
linkedFileData: {
|
|
|
|
source_project_id: 'source-project-id',
|
2021-06-25 04:20:33 -04:00
|
|
|
source_entity_path: '/source-file.tex',
|
2021-04-28 07:41:20 -04:00
|
|
|
provider: 'project_file',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export const FileFromProjectWithoutLinkableProjectId = args => {
|
2021-06-25 04:20:33 -04:00
|
|
|
useFetchMock(fetchMock =>
|
|
|
|
setupFetchMock(fetchMock).get(
|
|
|
|
'express:/project/:project_id/file/:file_id',
|
|
|
|
{ body: bodies.latex }
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-06-10 07:26:04 -04:00
|
|
|
return <FileView {...args} />
|
2021-04-28 07:41:20 -04:00
|
|
|
}
|
|
|
|
FileFromProjectWithoutLinkableProjectId.args = {
|
|
|
|
file: {
|
2021-05-04 07:36:32 -04:00
|
|
|
...fileData,
|
2021-04-28 07:41:20 -04:00
|
|
|
linkedFileData: {
|
|
|
|
v1_source_doc_id: 'v1-source-id',
|
2021-06-25 04:20:33 -04:00
|
|
|
source_entity_path: '/source-file.tex',
|
2021-04-28 07:41:20 -04:00
|
|
|
provider: 'project_file',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export const FileFromProjectOutputWithLinkableProject = args => {
|
2021-06-25 04:20:33 -04:00
|
|
|
useFetchMock(fetchMock =>
|
|
|
|
setupFetchMock(fetchMock).get(
|
|
|
|
'express:/project/:project_id/file/:file_id',
|
|
|
|
{ body: bodies.latex }
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-06-10 07:26:04 -04:00
|
|
|
return <FileView {...args} />
|
2021-04-28 07:41:20 -04:00
|
|
|
}
|
|
|
|
FileFromProjectOutputWithLinkableProject.args = {
|
|
|
|
file: {
|
2021-05-04 07:36:32 -04:00
|
|
|
...fileData,
|
2021-04-28 07:41:20 -04:00
|
|
|
linkedFileData: {
|
|
|
|
source_project_id: 'source_project_id',
|
2021-06-25 04:20:33 -04:00
|
|
|
source_output_file_path: '/source-file.tex',
|
2021-04-28 07:41:20 -04:00
|
|
|
provider: 'project_output_file',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export const FileFromProjectOutputWithoutLinkableProjectId = args => {
|
2021-06-25 04:20:33 -04:00
|
|
|
useFetchMock(fetchMock =>
|
|
|
|
setupFetchMock(fetchMock).get(
|
|
|
|
'express:/project/:project_id/file/:file_id',
|
|
|
|
{ body: bodies.latex }
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-06-10 07:26:04 -04:00
|
|
|
return <FileView {...args} />
|
2021-04-28 07:41:20 -04:00
|
|
|
}
|
|
|
|
FileFromProjectOutputWithoutLinkableProjectId.args = {
|
|
|
|
file: {
|
2021-05-04 07:36:32 -04:00
|
|
|
...fileData,
|
2021-04-28 07:41:20 -04:00
|
|
|
linkedFileData: {
|
|
|
|
v1_source_doc_id: 'v1-source-id',
|
2021-06-25 04:20:33 -04:00
|
|
|
source_output_file_path: '/source-file.tex',
|
2021-04-28 07:41:20 -04:00
|
|
|
provider: 'project_output_file',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ImageFile = args => {
|
2021-06-25 04:20:33 -04:00
|
|
|
useFetchMock(setupFetchMock) // NOTE: can't mock img src request
|
|
|
|
|
2021-06-10 07:26:04 -04:00
|
|
|
return <FileView {...args} />
|
2021-04-28 07:41:20 -04:00
|
|
|
}
|
2021-06-25 04:20:33 -04:00
|
|
|
ImageFile.storyName = 'Image File (Error)'
|
2021-04-28 07:41:20 -04:00
|
|
|
ImageFile.args = {
|
|
|
|
file: {
|
2021-05-04 07:36:32 -04:00
|
|
|
...fileData,
|
2021-04-28 07:41:20 -04:00
|
|
|
id: '60097ca20454610027c442a8',
|
|
|
|
name: 'file.jpg',
|
|
|
|
linkedFileData: {
|
|
|
|
source_project_id: 'source_project_id',
|
2021-06-25 04:20:33 -04:00
|
|
|
source_entity_path: '/source-file.jpg',
|
2021-04-28 07:41:20 -04:00
|
|
|
provider: 'project_file',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ThirdPartyReferenceFile = args => {
|
2021-06-25 04:20:33 -04:00
|
|
|
useFetchMock(fetchMock =>
|
|
|
|
setupFetchMock(fetchMock).get(
|
|
|
|
'express:/project/:project_id/file/:file_id',
|
|
|
|
{ body: bodies.bibtex }
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2021-06-10 07:26:04 -04:00
|
|
|
return <FileView {...args} />
|
2021-04-28 07:41:20 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
ThirdPartyReferenceFile.args = {
|
|
|
|
file: {
|
2021-05-04 07:36:32 -04:00
|
|
|
...fileData,
|
2021-06-25 04:20:33 -04:00
|
|
|
name: 'references.bib',
|
2021-04-28 07:41:20 -04:00
|
|
|
linkedFileData: {
|
|
|
|
provider: 'zotero',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ThirdPartyReferenceFileWithError = args => {
|
2021-06-25 04:20:33 -04:00
|
|
|
useFetchMock(fetchMock =>
|
|
|
|
setupFetchMock(fetchMock).head(
|
|
|
|
'express:/project/:project_id/file/:file_id',
|
|
|
|
{ status: 500 },
|
|
|
|
{ overwriteRoutes: true }
|
|
|
|
)
|
|
|
|
)
|
2021-06-10 07:26:04 -04:00
|
|
|
return <FileView {...args} />
|
2021-04-28 07:41:20 -04:00
|
|
|
}
|
2021-06-25 04:20:33 -04:00
|
|
|
ThirdPartyReferenceFileWithError.storyName =
|
|
|
|
'Third Party Reference File (Error)'
|
2021-04-28 07:41:20 -04:00
|
|
|
ThirdPartyReferenceFileWithError.args = {
|
|
|
|
file: {
|
2021-05-04 07:36:32 -04:00
|
|
|
...fileData,
|
2021-04-28 07:41:20 -04:00
|
|
|
id: '500500500500500500500500',
|
2021-06-25 04:20:33 -04:00
|
|
|
name: 'references.bib',
|
2021-04-28 07:41:20 -04:00
|
|
|
linkedFileData: {
|
|
|
|
provider: 'zotero',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export const TextFile = args => {
|
2021-06-25 04:20:33 -04:00
|
|
|
useFetchMock(fetchMock =>
|
|
|
|
setupFetchMock(fetchMock).get(
|
|
|
|
'express:/project/:project_id/file/:file_id',
|
|
|
|
{ body: bodies.text },
|
|
|
|
{ overwriteRoutes: true }
|
|
|
|
)
|
|
|
|
)
|
2021-06-10 07:26:04 -04:00
|
|
|
return <FileView {...args} />
|
2021-04-28 07:41:20 -04:00
|
|
|
}
|
|
|
|
TextFile.args = {
|
|
|
|
file: {
|
2021-05-04 07:36:32 -04:00
|
|
|
...fileData,
|
2021-04-28 07:41:20 -04:00
|
|
|
linkedFileData: {
|
|
|
|
source_project_id: 'source-project-id',
|
2021-06-25 04:20:33 -04:00
|
|
|
source_entity_path: '/source-file.txt',
|
2021-04-28 07:41:20 -04:00
|
|
|
provider: 'project_file',
|
|
|
|
},
|
|
|
|
name: 'file.txt',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export const UploadedFile = args => {
|
2021-06-25 04:20:33 -04:00
|
|
|
useFetchMock(fetchMock =>
|
|
|
|
setupFetchMock(fetchMock).head(
|
|
|
|
'express:/project/:project_id/file/:file_id',
|
|
|
|
{ status: 500 },
|
|
|
|
{ overwriteRoutes: true }
|
|
|
|
)
|
|
|
|
)
|
2021-06-10 07:26:04 -04:00
|
|
|
return <FileView {...args} />
|
2021-04-28 07:41:20 -04:00
|
|
|
}
|
2021-06-25 04:20:33 -04:00
|
|
|
UploadedFile.storyName = 'Uploaded File (Error)'
|
2021-04-28 07:41:20 -04:00
|
|
|
UploadedFile.args = {
|
|
|
|
file: {
|
2021-05-04 07:36:32 -04:00
|
|
|
...fileData,
|
2021-04-28 07:41:20 -04:00
|
|
|
linkedFileData: null,
|
|
|
|
name: 'file.jpg',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
2021-06-10 07:26:04 -04:00
|
|
|
title: 'FileView',
|
|
|
|
component: FileView,
|
2021-06-25 04:20:33 -04:00
|
|
|
argTypes: {
|
|
|
|
storeReferencesKeys: { action: 'store references keys' },
|
2021-04-28 07:41:20 -04:00
|
|
|
},
|
|
|
|
decorators: [
|
2021-05-11 10:25:22 -04:00
|
|
|
Story => (
|
2021-06-25 04:20:33 -04:00
|
|
|
<ContextRoot ide={window._ide} settings={{}}>
|
|
|
|
<Story />
|
|
|
|
</ContextRoot>
|
2021-04-28 07:41:20 -04:00
|
|
|
),
|
|
|
|
],
|
|
|
|
}
|