mirror of
https://github.com/langgenius/dify.git
synced 2026-05-04 00:18:28 +08:00
feat: use new file icon
This commit is contained in:
parent
e27568f0c7
commit
cc64419c84
40
web/app/components/datasets/common/document-file-icon.tsx
Normal file
40
web/app/components/datasets/common/document-file-icon.tsx
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
'use client'
|
||||||
|
import type { FC } from 'react'
|
||||||
|
import React from 'react'
|
||||||
|
import FileTypeIcon from '../../base/file-uploader/file-type-icon'
|
||||||
|
import type { FileAppearanceType } from '@/app/components/base/file-uploader/types'
|
||||||
|
import { FileAppearanceTypeEnum } from '@/app/components/base/file-uploader/types'
|
||||||
|
|
||||||
|
const extendToFileTypeMap: { [key: string]: FileAppearanceType } = {
|
||||||
|
pdf: FileAppearanceTypeEnum.pdf,
|
||||||
|
json: FileAppearanceTypeEnum.document,
|
||||||
|
html: FileAppearanceTypeEnum.document,
|
||||||
|
txt: FileAppearanceTypeEnum.document,
|
||||||
|
markdown: FileAppearanceTypeEnum.markdown,
|
||||||
|
md: FileAppearanceTypeEnum.markdown,
|
||||||
|
xlsx: FileAppearanceTypeEnum.excel,
|
||||||
|
xls: FileAppearanceTypeEnum.excel,
|
||||||
|
csv: FileAppearanceTypeEnum.excel,
|
||||||
|
doc: FileAppearanceTypeEnum.word,
|
||||||
|
docx: FileAppearanceTypeEnum.word,
|
||||||
|
}
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
extension?: string
|
||||||
|
name?: string
|
||||||
|
size?: 'sm' | 'lg' | 'md'
|
||||||
|
className?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const DocumentFileIcon: FC<Props> = ({
|
||||||
|
extension,
|
||||||
|
name,
|
||||||
|
size = 'md',
|
||||||
|
className,
|
||||||
|
}) => {
|
||||||
|
const localExtension = extension?.toLowerCase() || name?.split('.')?.pop()?.toLowerCase()
|
||||||
|
return (
|
||||||
|
<FileTypeIcon type={extendToFileTypeMap[localExtension!] || FileAppearanceTypeEnum.document} size={size} className={className} />
|
||||||
|
)
|
||||||
|
}
|
||||||
|
export default React.memo(DocumentFileIcon)
|
||||||
@ -3,13 +3,13 @@ import type { FC } from 'react'
|
|||||||
import React, { useState } from 'react'
|
import React, { useState } from 'react'
|
||||||
import { useBoolean } from 'ahooks'
|
import { useBoolean } from 'ahooks'
|
||||||
import { RiArrowDownSLine, RiArrowUpSLine } from '@remixicon/react'
|
import { RiArrowDownSLine, RiArrowUpSLine } from '@remixicon/react'
|
||||||
|
import FileIcon from '../document-file-icon'
|
||||||
import type { ParentMode, ProcessMode, SimpleDocumentDetail } from '@/models/datasets'
|
import type { ParentMode, ProcessMode, SimpleDocumentDetail } from '@/models/datasets'
|
||||||
import {
|
import {
|
||||||
PortalToFollowElem,
|
PortalToFollowElem,
|
||||||
PortalToFollowElemContent,
|
PortalToFollowElemContent,
|
||||||
PortalToFollowElemTrigger,
|
PortalToFollowElemTrigger,
|
||||||
} from '@/app/components/base/portal-to-follow-elem'
|
} from '@/app/components/base/portal-to-follow-elem'
|
||||||
import s from '@/app/components/datasets/documents/style.module.css'
|
|
||||||
import cn from '@/utils/classnames'
|
import cn from '@/utils/classnames'
|
||||||
import SearchInput from '@/app/components/base/search-input'
|
import SearchInput from '@/app/components/base/search-input'
|
||||||
import { GeneralType, ParentChildType } from '@/app/components/base/icons/src/public/knowledge'
|
import { GeneralType, ParentChildType } from '@/app/components/base/icons/src/public/knowledge'
|
||||||
@ -49,7 +49,6 @@ const DocumentPicker: FC<Props> = ({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
const documentsList = data?.data
|
const documentsList = data?.data
|
||||||
const localExtension = extension?.toLowerCase() || name?.split('.')?.pop()?.toLowerCase()
|
|
||||||
const isParentChild = processMode === 'hierarchical'
|
const isParentChild = processMode === 'hierarchical'
|
||||||
const TypeIcon = isParentChild ? ParentChildType : GeneralType
|
const TypeIcon = isParentChild ? ParentChildType : GeneralType
|
||||||
|
|
||||||
@ -67,7 +66,7 @@ const DocumentPicker: FC<Props> = ({
|
|||||||
>
|
>
|
||||||
<PortalToFollowElemTrigger onClick={togglePopup}>
|
<PortalToFollowElemTrigger onClick={togglePopup}>
|
||||||
<div className={cn('flex items-center ml-1 px-2 py-0.5 rounded-lg hover:bg-state-base-hover select-none', open && 'bg-state-base-hover')}>
|
<div className={cn('flex items-center ml-1 px-2 py-0.5 rounded-lg hover:bg-state-base-hover select-none', open && 'bg-state-base-hover')}>
|
||||||
<div className={cn(s[`${localExtension || 'txt'}Icon`], 'w-6 h-6 bg-no-repeat bg-center')}></div>
|
<FileIcon name={name} extension={extension} size='lg' />
|
||||||
<div className='flex flex-col items-start ml-1 mr-0.5'>
|
<div className='flex flex-col items-start ml-1 mr-0.5'>
|
||||||
<div className='flex items-center space-x-0.5'>
|
<div className='flex items-center space-x-0.5'>
|
||||||
<span className={cn('system-md-semibold')}> {name || '--'}</span>
|
<span className={cn('system-md-semibold')}> {name || '--'}</span>
|
||||||
@ -101,7 +100,7 @@ const DocumentPicker: FC<Props> = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<div className={cn(s[`${item.data_source_detail_dict?.upload_file.extension || 'txt'}Icon`], 'shrink-0 w-4 h-4')}></div>
|
<FileIcon name={item.name} extension={item.data_source_detail_dict?.upload_file.extension} size='sm' />
|
||||||
<div className='truncate text-text-secondary text-sm'>{item.name}</div>
|
<div className='truncate text-text-secondary text-sm'>{item.name}</div>
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user