Commit 677aec94 authored by StyleZhang's avatar StyleZhang

dataset document list add notion icon

parent 92913251
import cn from 'classnames'
import s from './index.module.css'
import type { DataSourceNotionPage } from '@/models/common'
type IconTypes = 'workspace' | 'page'
type NotionIconProps = {
type?: 'workspace' | 'page'
src?: string | null
type?: IconTypes
name?: string | null
className?: string
src?: string | null | Pick<DataSourceNotionPage, 'page_icon'>['page_icon']
}
const NotionIcon = ({
type = 'workspace',
src,
......@@ -15,7 +16,7 @@ const NotionIcon = ({
className,
}: NotionIconProps) => {
if (type === 'workspace') {
if (src) {
if (typeof src === 'string') {
if (src.startsWith('https://') || src.startsWith('http://')) {
return (
<img
......@@ -34,18 +35,18 @@ const NotionIcon = ({
)
}
if (src) {
if (src.startsWith('https://') || src.startsWith('http://')) {
if (typeof src === 'object' && src !== null) {
if (src?.type === 'url') {
return (
<img
alt='page icon'
src={src}
src={src.url || ''}
className={cn('block object-cover w-5 h-5', className)}
/>
)
}
return (
<div className={cn('flex items-center justify-center w-5 h-5', className)}>{src}</div>
<div className={cn('flex items-center justify-center w-5 h-5', className)}>{src?.emoji}</div>
)
}
......
......@@ -83,13 +83,6 @@ const Item = memo(({ index, style, data }: ListChildComponentProps<{
const hasChild = currentWithChildrenAndDescendants.descendants.size > 0
const ancestors = currentWithChildrenAndDescendants.ancestors
const breadCrumbs = ancestors.length ? [...ancestors, current.page_name] : [current.page_name]
let iconSrc
if (current.page_icon && current.page_icon.type === 'url')
iconSrc = current.page_icon.url
if (current.page_icon && current.page_icon.type === 'emoji')
iconSrc = current.page_icon.emoji
const renderArrow = () => {
return hasChild
......@@ -119,7 +112,7 @@ const Item = memo(({ index, style, data }: ListChildComponentProps<{
<NotionIcon
className='shrink-0 mr-1'
type='page'
src={iconSrc}
src={current.page_icon}
/>
<div
className='grow text-sm font-medium text-gray-700 truncate'
......
......@@ -35,16 +35,6 @@ const NotionPagePreview = ({
}
catch {}
}
const getIcon = () => {
let iconSrc
if (currentPage) {
if (currentPage.page_icon && currentPage.page_icon.type === 'url')
iconSrc = currentPage.page_icon.url
if (currentPage.page_icon && currentPage.page_icon.type === 'emoji')
iconSrc = currentPage.page_icon.emoji
}
return iconSrc
}
useEffect(() => {
if (currentPage) {
......@@ -66,7 +56,7 @@ const NotionPagePreview = ({
<NotionIcon
className='shrink-0 mr-1'
type='page'
src={getIcon()}
src={currentPage?.page_icon}
/>
{currentPage?.page_name}
</div>
......
......@@ -326,17 +326,6 @@ const StepTwo = ({
}
}
const getIcon = () => {
let iconSrc
if (notionPages.length > 0) {
if (notionPages[0].page_icon && notionPages[0].page_icon.type === 'url')
iconSrc = notionPages[0].page_icon.url
if (notionPages[0].page_icon && notionPages[0].page_icon.type === 'emoji')
iconSrc = notionPages[0].page_icon.emoji
}
return iconSrc
}
useEffect(() => {
// fetch rules
if (!isSetting) {
......@@ -558,7 +547,7 @@ const StepTwo = ({
<NotionIcon
className='shrink-0 mr-1'
type='page'
src={getIcon()}
src={notionPages[0]?.page_icon}
/>
{notionPages[0]?.page_name}
{notionPages.length > 1 && (
......
......@@ -23,7 +23,8 @@ import Indicator from '@/app/components/header/indicator'
import { asyncRunSafe } from '@/utils'
import { formatNumber } from '@/utils/format'
import { archiveDocument, deleteDocument, disableDocument, enableDocument, syncDocument } from '@/service/datasets'
import type { DocumentDisplayStatus, DocumentListResponse } from '@/models/datasets'
import NotionIcon from '@/app/components/base/notion-icon'
import { DataSourceType, type DocumentDisplayStatus, type DocumentListResponse } from '@/models/datasets'
import type { CommonResponse } from '@/models/common'
export const SettingsIcon: FC<{ className?: string }> = ({ className }) => {
......@@ -311,7 +312,11 @@ const DocumentList: FC<IDocumentListProps> = ({ documents = [], datasetId, onUpd
}}>
<td className='text-left align-middle text-gray-500 text-xs'>{doc.position}</td>
<td className={s.tdValue}>
<div className={cn(s[`${doc?.data_source_info?.upload_file?.extension ?? suffix}Icon`], s.commonIcon, 'mr-1.5')}></div>
{
doc?.data_source_type === DataSourceType.NOTION
? <NotionIcon className='inline-block -mt-[3px] mr-1.5 align-middle' type='page' src={doc.data_source_info.notion_page_icon} />
: <div className={cn(s[`${doc?.data_source_info?.upload_file?.extension ?? suffix}Icon`], s.commonIcon, 'mr-1.5')}></div>
}
<span>{doc?.name?.replace(/\.[^/.]+$/, '')}<span className='text-gray-500'>.{suffix}</span></span>
</td>
<td>{renderCount(doc.word_count)}</td>
......
......@@ -75,6 +75,9 @@
.markdownIcon {
background-image: url(./assets/md.svg);
}
.mdIcon {
background-image: url(./assets/md.svg);
}
.xlsIcon {
background-image: url(./assets/xlsx.svg);
}
......
......@@ -137,7 +137,7 @@ export type InitialDocumentDetail = {
batch: string
position: number
dataset_id: string
data_source_type: 'upload_file'
data_source_type: DataSourceType
data_source_info: DataSourceInfo
dataset_process_rule_id: string
name: string
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment