pdf-file-list.jsx 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { MenuItem as BS3MenuItem } from 'react-bootstrap'
  2. import { useTranslation } from 'react-i18next'
  3. import { memo } from 'react'
  4. import PropTypes from 'prop-types'
  5. import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher'
  6. import {
  7. DropdownDivider,
  8. DropdownHeader,
  9. DropdownItem,
  10. } from '@/features/ui/components/bootstrap-5/dropdown-menu'
  11. function PdfFileList({ fileList }) {
  12. const { t } = useTranslation()
  13. if (!fileList) {
  14. return null
  15. }
  16. function basename(file) {
  17. return file.path.split('/').pop()
  18. }
  19. return (
  20. <BootstrapVersionSwitcher
  21. bs3={
  22. <>
  23. <BS3MenuItem header>{t('other_output_files')}</BS3MenuItem>
  24. {fileList.top.map(file => (
  25. <BS3MenuItem
  26. download={basename(file)}
  27. href={file.url}
  28. key={file.path}
  29. >
  30. <b>{file.path}</b>
  31. </BS3MenuItem>
  32. ))}
  33. {fileList.other.length > 0 && fileList.top.length > 0 && (
  34. <BS3MenuItem divider />
  35. )}
  36. {fileList.other.map(file => (
  37. <BS3MenuItem
  38. download={basename(file)}
  39. href={file.url}
  40. key={file.path}
  41. >
  42. <b>{file.path}</b>
  43. </BS3MenuItem>
  44. ))}
  45. {fileList.archive?.fileCount && fileList.archive?.fileCount > 0 && (
  46. <BS3MenuItem
  47. download={basename(fileList.archive)}
  48. href={fileList.archive.url}
  49. >
  50. <b>
  51. {t('download_all')} ({fileList.archive.fileCount})
  52. </b>
  53. </BS3MenuItem>
  54. )}
  55. </>
  56. }
  57. bs5={
  58. <>
  59. <DropdownHeader>{t('other_output_files')}</DropdownHeader>
  60. {fileList.top.map(file => (
  61. <li key={file.path} role="menuitem">
  62. <DropdownItem
  63. role="link"
  64. download={basename(file)}
  65. href={file.url}
  66. >
  67. {file.path}
  68. </DropdownItem>
  69. </li>
  70. ))}
  71. {fileList.other.length > 0 && fileList.top.length > 0 && (
  72. <DropdownDivider />
  73. )}
  74. {fileList.other.map(file => (
  75. <li key={file.path} role="menuitem">
  76. <DropdownItem
  77. role="link"
  78. download={basename(file)}
  79. href={file.url}
  80. >
  81. {file.path}
  82. </DropdownItem>
  83. </li>
  84. ))}
  85. {fileList.archive?.fileCount > 0 && (
  86. <li role="menuitem">
  87. <DropdownItem
  88. role="link"
  89. download={basename(fileList.archive)}
  90. href={fileList.archive.url}
  91. >
  92. {t('download_all')} ({fileList.archive.fileCount})
  93. </DropdownItem>
  94. </li>
  95. )}
  96. </>
  97. }
  98. />
  99. )
  100. }
  101. const FilesArray = PropTypes.arrayOf(
  102. PropTypes.shape({
  103. path: PropTypes.string.isRequired,
  104. url: PropTypes.string.isRequired,
  105. })
  106. )
  107. PdfFileList.propTypes = {
  108. fileList: PropTypes.shape({
  109. top: FilesArray,
  110. other: FilesArray,
  111. archive: PropTypes.shape({
  112. path: PropTypes.string.isRequired,
  113. url: PropTypes.string.isRequired,
  114. fileCount: PropTypes.number.isRequired,
  115. }),
  116. }),
  117. }
  118. export default memo(PdfFileList)