binary-file.stories.js 3.7 KB

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