Commit 677aec94 authored by StyleZhang's avatar StyleZhang

dataset document list add notion icon

parent 92913251
import cn from 'classnames' import cn from 'classnames'
import s from './index.module.css' import s from './index.module.css'
import type { DataSourceNotionPage } from '@/models/common'
type IconTypes = 'workspace' | 'page'
type NotionIconProps = { type NotionIconProps = {
type?: 'workspace' | 'page' type?: IconTypes
src?: string | null
name?: string | null name?: string | null
className?: string className?: string
src?: string | null | Pick<DataSourceNotionPage, 'page_icon'>['page_icon']
} }
const NotionIcon = ({ const NotionIcon = ({
type = 'workspace', type = 'workspace',
src, src,
...@@ -15,7 +16,7 @@ const NotionIcon = ({ ...@@ -15,7 +16,7 @@ const NotionIcon = ({
className, className,
}: NotionIconProps) => { }: NotionIconProps) => {
if (type === 'workspace') { if (type === 'workspace') {
if (src) { if (typeof src === 'string') {
if (src.startsWith('https://') || src.startsWith('http://')) { if (src.startsWith('https://') || src.startsWith('http://')) {
return ( return (
<img <img
...@@ -34,18 +35,18 @@ const NotionIcon = ({ ...@@ -34,18 +35,18 @@ const NotionIcon = ({
) )
} }
if (src) { if (typeof src === 'object' && src !== null) {
if (src.startsWith('https://') || src.startsWith('http://')) { if (src?.type === 'url') {
return ( return (
<img <img
alt='page icon' alt='page icon'
src={src} src={src.url || ''}
className={cn('block object-cover w-5 h-5', className)} className={cn('block object-cover w-5 h-5', className)}
/> />
) )
} }
return ( 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<{ ...@@ -83,13 +83,6 @@ const Item = memo(({ index, style, data }: ListChildComponentProps<{
const hasChild = currentWithChildrenAndDescendants.descendants.size > 0 const hasChild = currentWithChildrenAndDescendants.descendants.size > 0
const ancestors = currentWithChildrenAndDescendants.ancestors const ancestors = currentWithChildrenAndDescendants.ancestors
const breadCrumbs = ancestors.length ? [...ancestors, current.page_name] : [current.page_name] 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 = () => { const renderArrow = () => {
return hasChild return hasChild
...@@ -119,7 +112,7 @@ const Item = memo(({ index, style, data }: ListChildComponentProps<{ ...@@ -119,7 +112,7 @@ const Item = memo(({ index, style, data }: ListChildComponentProps<{
<NotionIcon <NotionIcon
className='shrink-0 mr-1' className='shrink-0 mr-1'
type='page' type='page'
src={iconSrc} src={current.page_icon}
/> />
<div <div
className='grow text-sm font-medium text-gray-700 truncate' className='grow text-sm font-medium text-gray-700 truncate'
......
...@@ -35,16 +35,6 @@ const NotionPagePreview = ({ ...@@ -35,16 +35,6 @@ const NotionPagePreview = ({
} }
catch {} 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(() => { useEffect(() => {
if (currentPage) { if (currentPage) {
...@@ -66,7 +56,7 @@ const NotionPagePreview = ({ ...@@ -66,7 +56,7 @@ const NotionPagePreview = ({
<NotionIcon <NotionIcon
className='shrink-0 mr-1' className='shrink-0 mr-1'
type='page' type='page'
src={getIcon()} src={currentPage?.page_icon}
/> />
{currentPage?.page_name} {currentPage?.page_name}
</div> </div>
......
...@@ -326,17 +326,6 @@ const StepTwo = ({ ...@@ -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(() => { useEffect(() => {
// fetch rules // fetch rules
if (!isSetting) { if (!isSetting) {
...@@ -558,7 +547,7 @@ const StepTwo = ({ ...@@ -558,7 +547,7 @@ const StepTwo = ({
<NotionIcon <NotionIcon
className='shrink-0 mr-1' className='shrink-0 mr-1'
type='page' type='page'
src={getIcon()} src={notionPages[0]?.page_icon}
/> />
{notionPages[0]?.page_name} {notionPages[0]?.page_name}
{notionPages.length > 1 && ( {notionPages.length > 1 && (
......
...@@ -23,7 +23,8 @@ import Indicator from '@/app/components/header/indicator' ...@@ -23,7 +23,8 @@ import Indicator from '@/app/components/header/indicator'
import { asyncRunSafe } from '@/utils' import { asyncRunSafe } from '@/utils'
import { formatNumber } from '@/utils/format' import { formatNumber } from '@/utils/format'
import { archiveDocument, deleteDocument, disableDocument, enableDocument, syncDocument } from '@/service/datasets' 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' import type { CommonResponse } from '@/models/common'
export const SettingsIcon: FC<{ className?: string }> = ({ className }) => { export const SettingsIcon: FC<{ className?: string }> = ({ className }) => {
...@@ -311,7 +312,11 @@ const DocumentList: FC<IDocumentListProps> = ({ documents = [], datasetId, onUpd ...@@ -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='text-left align-middle text-gray-500 text-xs'>{doc.position}</td>
<td className={s.tdValue}> <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> <span>{doc?.name?.replace(/\.[^/.]+$/, '')}<span className='text-gray-500'>.{suffix}</span></span>
</td> </td>
<td>{renderCount(doc.word_count)}</td> <td>{renderCount(doc.word_count)}</td>
......
...@@ -75,6 +75,9 @@ ...@@ -75,6 +75,9 @@
.markdownIcon { .markdownIcon {
background-image: url(./assets/md.svg); background-image: url(./assets/md.svg);
} }
.mdIcon {
background-image: url(./assets/md.svg);
}
.xlsIcon { .xlsIcon {
background-image: url(./assets/xlsx.svg); background-image: url(./assets/xlsx.svg);
} }
......
...@@ -137,7 +137,7 @@ export type InitialDocumentDetail = { ...@@ -137,7 +137,7 @@ export type InitialDocumentDetail = {
batch: string batch: string
position: number position: number
dataset_id: string dataset_id: string
data_source_type: 'upload_file' data_source_type: DataSourceType
data_source_info: DataSourceInfo data_source_info: DataSourceInfo
dataset_process_rule_id: string dataset_process_rule_id: string
name: 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