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