pdf-file-list.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. </>
  30. )
  31. }
  32. const FilesArray = PropTypes.arrayOf(
  33. PropTypes.shape({
  34. path: PropTypes.string.isRequired,
  35. url: PropTypes.string.isRequired,
  36. })
  37. )
  38. PdfFileList.propTypes = {
  39. fileList: PropTypes.shape({
  40. top: FilesArray,
  41. other: FilesArray,
  42. }),
  43. }
  44. export default memo(PdfFileList)