pdf-file-list.jsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { MenuItem } from 'react-bootstrap'
  2. import { useTranslation } from 'react-i18next'
  3. import { memo } from 'react'
  4. import PropTypes from 'prop-types'
  5. function PdfFileList({ fileList }) {
  6. const { t } = useTranslation()
  7. if (!fileList) {
  8. return null
  9. }
  10. function basename(file) {
  11. return file.path.split('/').pop()
  12. }
  13. return (
  14. <>
  15. <MenuItem header>{t('other_output_files')}</MenuItem>
  16. {fileList.top.map(file => (
  17. <MenuItem download={basename(file)} href={file.url} key={file.path}>
  18. <b>{file.path}</b>
  19. </MenuItem>
  20. ))}
  21. {fileList.other.length > 0 && fileList.top.length > 0 && (
  22. <MenuItem divider />
  23. )}
  24. {fileList.other.map(file => (
  25. <MenuItem download={basename(file)} href={file.url} key={file.path}>
  26. <b>{file.path}</b>
  27. </MenuItem>
  28. ))}
  29. {fileList.archive?.fileCount > 0 && (
  30. <MenuItem
  31. download={basename(fileList.archive)}
  32. href={fileList.archive.url}
  33. key={fileList.archive.path}
  34. >
  35. <b>
  36. {t('download_all')} ({fileList.archive.fileCount})
  37. </b>
  38. </MenuItem>
  39. )}
  40. </>
  41. )
  42. }
  43. const FilesArray = PropTypes.arrayOf(
  44. PropTypes.shape({
  45. path: PropTypes.string.isRequired,
  46. url: PropTypes.string.isRequired,
  47. })
  48. )
  49. PdfFileList.propTypes = {
  50. fileList: PropTypes.shape({
  51. top: FilesArray,
  52. other: FilesArray,
  53. archive: PropTypes.shape({
  54. path: PropTypes.string.isRequired,
  55. url: PropTypes.string.isRequired,
  56. fileCount: PropTypes.number.isRequired,
  57. }),
  58. }),
  59. }
  60. export default memo(PdfFileList)