binary-file.stories.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import React from 'react'
  2. import { ContextRoot } from '../js/shared/context/root-context'
  3. import BinaryFile from '../js/features/binary-file/components/binary-file'
  4. import useFetchMock from './hooks/use-fetch-mock'
  5. const setupFetchMock = fetchMock => {
  6. fetchMock
  7. .head('express:/project/:project_id/file/:file_id', {
  8. status: 201,
  9. headers: { 'Content-Length': 10000 },
  10. })
  11. .get('express:/project/:project_id/file/:file_id', 'Text file content')
  12. .post('express:/project/:project_id/linked_file/:file_id/refresh', {
  13. status: 204,
  14. })
  15. .post('express:/project/:project_id/references/indexAll', {
  16. status: 204,
  17. })
  18. }
  19. const fileData = {
  20. id: 'file-id',
  21. name: 'file.tex',
  22. created: new Date().toISOString(),
  23. }
  24. export const FileFromUrl = args => {
  25. return <BinaryFile {...args} />
  26. }
  27. FileFromUrl.args = {
  28. file: {
  29. ...fileData,
  30. linkedFileData: {
  31. url: 'https://overleaf.com',
  32. provider: 'url',
  33. },
  34. },
  35. }
  36. export const FileFromProjectWithLinkableProjectId = args => {
  37. return <BinaryFile {...args} />
  38. }
  39. FileFromProjectWithLinkableProjectId.args = {
  40. file: {
  41. ...fileData,
  42. linkedFileData: {
  43. source_project_id: 'source-project-id',
  44. source_entity_path: '/source-entity-path.ext',
  45. provider: 'project_file',
  46. },
  47. },
  48. }
  49. export const FileFromProjectWithoutLinkableProjectId = args => {
  50. return <BinaryFile {...args} />
  51. }
  52. FileFromProjectWithoutLinkableProjectId.args = {
  53. file: {
  54. ...fileData,
  55. linkedFileData: {
  56. v1_source_doc_id: 'v1-source-id',
  57. source_entity_path: '/source-entity-path.ext',
  58. provider: 'project_file',
  59. },
  60. },
  61. }
  62. export const FileFromProjectOutputWithLinkableProject = args => {
  63. return <BinaryFile {...args} />
  64. }
  65. FileFromProjectOutputWithLinkableProject.args = {
  66. file: {
  67. ...fileData,
  68. linkedFileData: {
  69. source_project_id: 'source_project_id',
  70. source_output_file_path: '/source-entity-path.ext',
  71. provider: 'project_output_file',
  72. },
  73. },
  74. }
  75. export const FileFromProjectOutputWithoutLinkableProjectId = args => {
  76. return <BinaryFile {...args} />
  77. }
  78. FileFromProjectOutputWithoutLinkableProjectId.args = {
  79. file: {
  80. ...fileData,
  81. linkedFileData: {
  82. v1_source_doc_id: 'v1-source-id',
  83. source_output_file_path: '/source-entity-path.ext',
  84. provider: 'project_output_file',
  85. },
  86. },
  87. }
  88. export const ImageFile = args => {
  89. return <BinaryFile {...args} />
  90. }
  91. ImageFile.args = {
  92. file: {
  93. ...fileData,
  94. id: '60097ca20454610027c442a8',
  95. name: 'file.jpg',
  96. linkedFileData: {
  97. source_project_id: 'source_project_id',
  98. source_entity_path: '/source-entity-path',
  99. provider: 'project_file',
  100. },
  101. },
  102. }
  103. export const ThirdPartyReferenceFile = args => {
  104. return <BinaryFile {...args} />
  105. }
  106. ThirdPartyReferenceFile.args = {
  107. file: {
  108. ...fileData,
  109. name: 'example.tex',
  110. linkedFileData: {
  111. provider: 'zotero',
  112. },
  113. },
  114. }
  115. export const ThirdPartyReferenceFileWithError = args => {
  116. return <BinaryFile {...args} />
  117. }
  118. ThirdPartyReferenceFileWithError.args = {
  119. file: {
  120. ...fileData,
  121. id: '500500500500500500500500',
  122. name: 'example.tex',
  123. linkedFileData: {
  124. provider: 'zotero',
  125. },
  126. },
  127. }
  128. export const TextFile = args => {
  129. return <BinaryFile {...args} />
  130. }
  131. TextFile.args = {
  132. file: {
  133. ...fileData,
  134. linkedFileData: {
  135. source_project_id: 'source-project-id',
  136. source_entity_path: '/source-entity-path.ext',
  137. provider: 'project_file',
  138. },
  139. name: 'file.txt',
  140. },
  141. }
  142. export const UploadedFile = args => {
  143. return <BinaryFile {...args} />
  144. }
  145. UploadedFile.args = {
  146. file: {
  147. ...fileData,
  148. linkedFileData: null,
  149. name: 'file.jpg',
  150. },
  151. }
  152. export default {
  153. title: 'BinaryFile',
  154. component: BinaryFile,
  155. args: {
  156. storeReferencesKeys: () => {},
  157. },
  158. decorators: [
  159. Story => {
  160. useFetchMock(setupFetchMock)
  161. return <Story />
  162. },
  163. Story => (
  164. <>
  165. <style>{'html, body { height: 100%; }'}</style>
  166. <ContextRoot ide={window._ide} settings={{}}>
  167. <Story />
  168. </ContextRoot>
  169. </>
  170. ),
  171. ],
  172. }