preview-download-file-list.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import PropTypes from 'prop-types'
  2. import { MenuItem } from 'react-bootstrap'
  3. import { useTranslation } from 'react-i18next'
  4. export const topFileTypes = ['bbl', 'gls', 'ind']
  5. function PreviewDownloadFileList({ fileList = [] }) {
  6. const { t } = useTranslation()
  7. let topFiles = []
  8. let otherFiles = []
  9. if (fileList) {
  10. topFiles = fileList.filter(file => {
  11. return topFileTypes.includes(file.type)
  12. })
  13. otherFiles = fileList.filter(file => {
  14. if (!topFileTypes.includes(file.type)) {
  15. return !(file.type === 'pdf' && file.main === true)
  16. }
  17. return false
  18. })
  19. }
  20. return (
  21. <>
  22. <MenuItem header>{t('other_output_files')}</MenuItem>
  23. <SubFileList subFileList={topFiles} listType="main" />
  24. {otherFiles.length > 0 && topFiles.length > 0 ? (
  25. <>
  26. <MenuItem divider />
  27. </>
  28. ) : (
  29. <></>
  30. )}
  31. {otherFiles.length > 0 ? (
  32. <>
  33. <SubFileList subFileList={otherFiles} listType="other" />
  34. </>
  35. ) : (
  36. <></>
  37. )}
  38. </>
  39. )
  40. }
  41. function SubFileList({ subFileList, listType }) {
  42. return subFileList.map((file, index) => {
  43. return (
  44. <MenuItem download href={file.url} key={`${listType}${index}`}>
  45. <b>{file.fileName}</b>
  46. </MenuItem>
  47. )
  48. })
  49. }
  50. SubFileList.propTypes = {
  51. subFileList: PropTypes.array.isRequired,
  52. listType: PropTypes.string.isRequired,
  53. }
  54. PreviewDownloadFileList.propTypes = {
  55. fileList: PropTypes.array,
  56. }
  57. export default PreviewDownloadFileList