Commit d658ea8a authored by jyong's avatar jyong

Merge remote-tracking branch 'origin/feat/dataset-notion-import' into feat/dataset-notion-import

parents 4c727d0d a7cf7d6f
...@@ -7,6 +7,7 @@ import SearchInput from './search-input' ...@@ -7,6 +7,7 @@ import SearchInput from './search-input'
import PageSelector from './page-selector' import PageSelector from './page-selector'
import { preImportNotionPages } from '@/service/datasets' import { preImportNotionPages } from '@/service/datasets'
import AccountSetting from '@/app/components/header/account-setting' import AccountSetting from '@/app/components/header/account-setting'
import { NotionConnector } from '@/app/components/datasets/create/step-one'
import type { DataSourceNotionPage, DataSourceNotionPageMap, DataSourceNotionWorkspace } from '@/models/common' import type { DataSourceNotionPage, DataSourceNotionPageMap, DataSourceNotionWorkspace } from '@/models/common'
export type NotionPageSelectorValue = DataSourceNotionPage & { workspace_id: string } export type NotionPageSelectorValue = DataSourceNotionPage & { workspace_id: string }
...@@ -28,7 +29,7 @@ const NotionPageSelector = ({ ...@@ -28,7 +29,7 @@ const NotionPageSelector = ({
onPreview, onPreview,
datasetId = '', datasetId = '',
}: NotionPageSelectorProps) => { }: NotionPageSelectorProps) => {
const { data, mutate } = useSWR({ url: '/notion/pre-import/pages', datasetId }, preImportNotionPages) const { data, error, mutate } = useSWR({ url: '/notion/pre-import/pages', datasetId }, preImportNotionPages)
const [prevData, setPrevData] = useState(data) const [prevData, setPrevData] = useState(data)
const [searchValue, setSearchValue] = useState('') const [searchValue, setSearchValue] = useState('')
const [showDataSourceSetting, setShowDataSourceSetting] = useState(false) const [showDataSourceSetting, setShowDataSourceSetting] = useState(false)
...@@ -86,35 +87,45 @@ const NotionPageSelector = ({ ...@@ -86,35 +87,45 @@ const NotionPageSelector = ({
return ( return (
<div className='bg-gray-25 border border-gray-200 rounded-xl'> <div className='bg-gray-25 border border-gray-200 rounded-xl'>
<div className='flex items-center pl-[10px] pr-2 h-11 bg-white border-b border-b-gray-200 rounded-t-xl'> {
<WorkspaceSelector error?.status === 404
value={currentWorkspaceId} ? (
items={notionWorkspaces} <NotionConnector onSetting={() => setShowDataSourceSetting(true)} />
onSelect={handleSelectWorkspace} )
/> : (
<div className='mx-1 w-[1px] h-3 bg-gray-200' /> <>
<div <div className='flex items-center pl-[10px] pr-2 h-11 bg-white border-b border-b-gray-200 rounded-t-xl'>
className={cn(s['setting-icon'], 'w-6 h-6 cursor-pointer')} <WorkspaceSelector
onClick={() => setShowDataSourceSetting(true)} value={currentWorkspaceId}
/> items={notionWorkspaces}
<div className='grow' /> onSelect={handleSelectWorkspace}
<SearchInput />
value={searchValue} <div className='mx-1 w-[1px] h-3 bg-gray-200' />
onChange={handleSearchValueChange} <div
/> className={cn(s['setting-icon'], 'w-6 h-6 cursor-pointer')}
</div> onClick={() => setShowDataSourceSetting(true)}
<div className='rounded-b-xl overflow-hidden'> />
<PageSelector <div className='grow' />
value={selectedPagesId} <SearchInput
searchValue={searchValue} value={searchValue}
list={currentWorkspace?.pages || []} onChange={handleSearchValueChange}
pagesMap={getPagesMapAndSelectedPagesId[0]} />
onSelect={handleSelecPages} </div>
canPreview={canPreview} <div className='rounded-b-xl overflow-hidden'>
previewPageId={previewPageId} <PageSelector
onPreview={handlePreviewPage} value={selectedPagesId}
/> searchValue={searchValue}
</div> list={currentWorkspace?.pages || []}
pagesMap={getPagesMapAndSelectedPagesId[0]}
onSelect={handleSelecPages}
canPreview={canPreview}
previewPageId={previewPageId}
onPreview={handlePreviewPage}
/>
</div>
</>
)
}
{ {
showDataSourceSetting && ( showDataSourceSetting && (
<AccountSetting activeTab='data-source' onCancel={() => { <AccountSetting activeTab='data-source' onCancel={() => {
......
...@@ -29,6 +29,22 @@ type IStepOneProps = { ...@@ -29,6 +29,22 @@ type IStepOneProps = {
type Page = DataSourceNotionPage & { workspace_id: string } type Page = DataSourceNotionPage & { workspace_id: string }
type NotionConnectorProps = {
onSetting: () => void
}
export const NotionConnector = ({ onSetting }: NotionConnectorProps) => {
const { t } = useTranslation()
return (
<div className={s.notionConnectionTip}>
<span className={s.notionIcon}/>
<div className={s.title}>{t('datasetCreation.stepOne.notionSyncTitle')}</div>
<div className={s.tip}>{t('datasetCreation.stepOne.notionSyncTip')}</div>
<Button className='h-8' type='primary' onClick={onSetting}>{t('datasetCreation.stepOne.connect')}</Button>
</div>
)
}
const StepOne = ({ const StepOne = ({
datasetId, datasetId,
dataSourceType, dataSourceType,
...@@ -116,14 +132,7 @@ const StepOne = ({ ...@@ -116,14 +132,7 @@ const StepOne = ({
)} )}
{dataSourceType === DataSourceType.NOTION && ( {dataSourceType === DataSourceType.NOTION && (
<> <>
{!hasConnection && ( {!hasConnection && <NotionConnector onSetting={onSetting} />}
<div className={s.notionConnectionTip}>
<span className={s.notionIcon}/>
<div className={s.title}>{t('datasetCreation.stepOne.notionSyncTitle')}</div>
<div className={s.tip}>{t('datasetCreation.stepOne.notionSyncTip')}</div>
<Button className='h-8' type='primary' onClick={onSetting}>{t('datasetCreation.stepOne.connect')}</Button>
</div>
)}
{hasConnection && ( {hasConnection && (
<> <>
<div className='mb-8 w-[640px]'> <div className='mb-8 w-[640px]'>
......
...@@ -193,11 +193,6 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => { ...@@ -193,11 +193,6 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
setNotionPageSelectorModalVisible(false) setNotionPageSelectorModalVisible(false)
} }
const handleSync = async () => {
if (dataset?.data_source_type === DataSourceType.NOTION)
mutate()
}
return ( return (
<div className='flex flex-col h-full overflow-y-auto'> <div className='flex flex-col h-full overflow-y-auto'>
<div className='flex flex-col justify-center gap-1 px-6 pt-4'> <div className='flex flex-col justify-center gap-1 px-6 pt-4'>
...@@ -225,7 +220,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => { ...@@ -225,7 +220,7 @@ const Documents: FC<IDocumentsProps> = ({ datasetId }) => {
{isLoading {isLoading
? <Loading type='app' /> ? <Loading type='app' />
: total > 0 : total > 0
? <List documents={documentsWithProgress?.data || []} datasetId={datasetId} onUpdate={mutate} onSync={handleSync} /> ? <List documents={documentsWithProgress?.data || []} datasetId={datasetId} onUpdate={mutate} />
: <EmptyElement onClick={routeToDocCreate} /> : <EmptyElement onClick={routeToDocCreate} />
} }
{/* Show Pagination only if the total is more than the limit */} {/* Show Pagination only if the total is more than the limit */}
......
...@@ -256,7 +256,6 @@ type IDocumentListProps = { ...@@ -256,7 +256,6 @@ type IDocumentListProps = {
documents: (SimpleDocumentDetail & { percent: number })[] documents: (SimpleDocumentDetail & { percent: number })[]
datasetId: string datasetId: string
onUpdate: () => void onUpdate: () => void
onSync: () => void
} }
/** /**
......
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