binary-file.stories.js 3.9 KB

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