file-list-in-log.tsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import React, { useState } from 'react'
  2. import { RiArrowRightSLine } from '@remixicon/react'
  3. import FileImageRender from './file-image-render'
  4. import FileTypeIcon from './file-type-icon'
  5. import FileItem from './file-uploader-in-attachment/file-item'
  6. import type { FileEntity } from './types'
  7. import {
  8. getFileAppearanceType,
  9. } from './utils'
  10. import Tooltip from '@/app/components/base/tooltip'
  11. import { SupportUploadFileTypes } from '@/app/components/workflow/types'
  12. import cn from '@/utils/classnames'
  13. type Props = {
  14. fileList: FileEntity[]
  15. }
  16. const FileListInLog = ({ fileList }: Props) => {
  17. const [expanded, setExpanded] = useState(false)
  18. if (!fileList.length)
  19. return null
  20. return (
  21. <div className={cn('border-t border-divider-subtle px-3 py-2', expanded && 'py-3')}>
  22. <div className='flex justify-between gap-1'>
  23. {expanded && (
  24. <div></div>
  25. )}
  26. {!expanded && (
  27. <div className='flex'>
  28. {fileList.map((file) => {
  29. const { id, name, type, supportFileType, base64Url, url } = file
  30. const isImageFile = supportFileType === SupportUploadFileTypes.image
  31. return (
  32. <>
  33. {isImageFile && (
  34. <Tooltip
  35. popupContent={name}
  36. >
  37. <div key={id}>
  38. <FileImageRender
  39. className='w-8 h-8'
  40. imageUrl={base64Url || url || ''}
  41. />
  42. </div>
  43. </Tooltip>
  44. )}
  45. {!isImageFile && (
  46. <Tooltip
  47. popupContent={name}
  48. >
  49. <div key={id} className='p-1.5 rounded-md bg-components-panel-on-panel-item-bg border-[0.5px] border-components-panel-border shadow-xs'>
  50. <FileTypeIcon
  51. type={getFileAppearanceType(name, type)}
  52. size='md'
  53. />
  54. </div>
  55. </Tooltip>
  56. )}
  57. </>
  58. )
  59. })}
  60. </div>
  61. )}
  62. <div className='flex items-center gap-1 cursor-pointer' onClick={() => setExpanded(!expanded)}>
  63. {!expanded && <div className='text-text-tertiary system-xs-medium-uppercase'>DETAIL</div>}
  64. <RiArrowRightSLine className={cn('w-4 h-4 text-text-tertiary', expanded && 'rotate-90')} />
  65. </div>
  66. </div>
  67. {expanded && (
  68. <div className='flex flex-col gap-1'>
  69. {fileList.map(file => (
  70. <FileItem
  71. key={file.id}
  72. file={file}
  73. showDeleteAction={false}
  74. showDownloadAction
  75. />
  76. ))}
  77. </div>
  78. )}
  79. </div>
  80. )
  81. }
  82. export default FileListInLog