|
|
|
|
|
|
|
|
import { DataSourceType } from '@/models/datasets' |
|
|
import { DataSourceType } from '@/models/datasets' |
|
|
import Button from '@/app/components/base/button' |
|
|
import Button from '@/app/components/base/button' |
|
|
import { NotionPageSelector } from '@/app/components/base/notion-page-selector' |
|
|
import { NotionPageSelector } from '@/app/components/base/notion-page-selector' |
|
|
|
|
|
import { useDatasetDetailContext } from '@/context/dataset-detail' |
|
|
|
|
|
|
|
|
type IStepOneProps = { |
|
|
type IStepOneProps = { |
|
|
datasetId?: string |
|
|
datasetId?: string |
|
|
dataSourceType: DataSourceType |
|
|
|
|
|
|
|
|
dataSourceType?: DataSourceType |
|
|
dataSourceTypeDisable: Boolean |
|
|
dataSourceTypeDisable: Boolean |
|
|
hasConnection: boolean |
|
|
hasConnection: boolean |
|
|
onSetting: () => void |
|
|
onSetting: () => void |
|
|
|
|
|
|
|
|
notionPages = [], |
|
|
notionPages = [], |
|
|
updateNotionPages, |
|
|
updateNotionPages, |
|
|
}: IStepOneProps) => { |
|
|
}: IStepOneProps) => { |
|
|
|
|
|
const { dataset } = useDatasetDetailContext() |
|
|
const [showModal, setShowModal] = useState(false) |
|
|
const [showModal, setShowModal] = useState(false) |
|
|
const [showFilePreview, setShowFilePreview] = useState(true) |
|
|
const [showFilePreview, setShowFilePreview] = useState(true) |
|
|
const [currentNotionPage, setCurrentNotionPage] = useState<Page | undefined>() |
|
|
const [currentNotionPage, setCurrentNotionPage] = useState<Page | undefined>() |
|
|
|
|
|
|
|
|
setCurrentNotionPage(undefined) |
|
|
setCurrentNotionPage(undefined) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const shouldShowDataSourceTypeList = !datasetId || (datasetId && !dataset?.data_source_type) |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<div className='flex w-full h-full'> |
|
|
<div className='flex w-full h-full'> |
|
|
<div className='grow overflow-y-auto relative'> |
|
|
<div className='grow overflow-y-auto relative'> |
|
|
<div className={s.stepHeader}>{t('datasetCreation.steps.one')}</div> |
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
shouldShowDataSourceTypeList && ( |
|
|
|
|
|
<div className={s.stepHeader}>{t('datasetCreation.steps.one')}</div> |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
<div className={s.form}> |
|
|
<div className={s.form}> |
|
|
<div className={s.dataSourceTypeList}> |
|
|
|
|
|
<div |
|
|
|
|
|
className={cn( |
|
|
|
|
|
s.dataSourceItem, |
|
|
|
|
|
dataSourceType === DataSourceType.FILE && s.active, |
|
|
|
|
|
dataSourceTypeDisable && dataSourceType !== DataSourceType.FILE && s.disabled, |
|
|
|
|
|
)} |
|
|
|
|
|
onClick={() => { |
|
|
|
|
|
if (dataSourceTypeDisable) |
|
|
|
|
|
return |
|
|
|
|
|
changeType(DataSourceType.FILE) |
|
|
|
|
|
hidePreview() |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
<span className={cn(s.datasetIcon)} /> |
|
|
|
|
|
{t('datasetCreation.stepOne.dataSourceType.file')} |
|
|
|
|
|
</div> |
|
|
|
|
|
<div |
|
|
|
|
|
className={cn( |
|
|
|
|
|
s.dataSourceItem, |
|
|
|
|
|
dataSourceType === DataSourceType.NOTION && s.active, |
|
|
|
|
|
dataSourceTypeDisable && dataSourceType !== DataSourceType.NOTION && s.disabled, |
|
|
|
|
|
)} |
|
|
|
|
|
onClick={() => { |
|
|
|
|
|
if (dataSourceTypeDisable) |
|
|
|
|
|
return |
|
|
|
|
|
changeType(DataSourceType.NOTION) |
|
|
|
|
|
hidePreview() |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
<span className={cn(s.datasetIcon, s.notion)} /> |
|
|
|
|
|
{t('datasetCreation.stepOne.dataSourceType.notion')} |
|
|
|
|
|
</div> |
|
|
|
|
|
<div |
|
|
|
|
|
className={cn(s.dataSourceItem, s.disabled, dataSourceType === DataSourceType.WEB && s.active)} |
|
|
|
|
|
// onClick={() => changeType(DataSourceType.WEB)} |
|
|
|
|
|
> |
|
|
|
|
|
<span className={s.comingTag}>Coming soon</span> |
|
|
|
|
|
<span className={cn(s.datasetIcon, s.web)} /> |
|
|
|
|
|
{t('datasetCreation.stepOne.dataSourceType.web')} |
|
|
|
|
|
</div> |
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
{ |
|
|
|
|
|
shouldShowDataSourceTypeList && ( |
|
|
|
|
|
<div className={s.dataSourceTypeList}> |
|
|
|
|
|
<div |
|
|
|
|
|
className={cn( |
|
|
|
|
|
s.dataSourceItem, |
|
|
|
|
|
dataSourceType === DataSourceType.FILE && s.active, |
|
|
|
|
|
dataSourceTypeDisable && dataSourceType !== DataSourceType.FILE && s.disabled, |
|
|
|
|
|
)} |
|
|
|
|
|
onClick={() => { |
|
|
|
|
|
if (dataSourceTypeDisable) |
|
|
|
|
|
return |
|
|
|
|
|
changeType(DataSourceType.FILE) |
|
|
|
|
|
hidePreview() |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
<span className={cn(s.datasetIcon)} /> |
|
|
|
|
|
{t('datasetCreation.stepOne.dataSourceType.file')} |
|
|
|
|
|
</div> |
|
|
|
|
|
<div |
|
|
|
|
|
className={cn( |
|
|
|
|
|
s.dataSourceItem, |
|
|
|
|
|
dataSourceType === DataSourceType.NOTION && s.active, |
|
|
|
|
|
dataSourceTypeDisable && dataSourceType !== DataSourceType.NOTION && s.disabled, |
|
|
|
|
|
)} |
|
|
|
|
|
onClick={() => { |
|
|
|
|
|
if (dataSourceTypeDisable) |
|
|
|
|
|
return |
|
|
|
|
|
changeType(DataSourceType.NOTION) |
|
|
|
|
|
hidePreview() |
|
|
|
|
|
}} |
|
|
|
|
|
> |
|
|
|
|
|
<span className={cn(s.datasetIcon, s.notion)} /> |
|
|
|
|
|
{t('datasetCreation.stepOne.dataSourceType.notion')} |
|
|
|
|
|
</div> |
|
|
|
|
|
<div |
|
|
|
|
|
className={cn(s.dataSourceItem, s.disabled, dataSourceType === DataSourceType.WEB && s.active)} |
|
|
|
|
|
// onClick={() => changeType(DataSourceType.WEB)} |
|
|
|
|
|
> |
|
|
|
|
|
<span className={s.comingTag}>Coming soon</span> |
|
|
|
|
|
<span className={cn(s.datasetIcon, s.web)} /> |
|
|
|
|
|
{t('datasetCreation.stepOne.dataSourceType.web')} |
|
|
|
|
|
</div> |
|
|
|
|
|
</div> |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
{dataSourceType === DataSourceType.FILE && ( |
|
|
{dataSourceType === DataSourceType.FILE && ( |
|
|
<> |
|
|
<> |
|
|
<FileUploader onFileUpdate={updateFile} file={file} /> |
|
|
|
|
|
|
|
|
<FileUploader onFileUpdate={updateFile} file={file} titleClassName={(!shouldShowDataSourceTypeList) ? 'mt-[30px] !mb-[44px] !text-lg !font-semibold !text-gray-900' : undefined} /> |
|
|
<Button disabled={!file} className={s.submitButton} type='primary' onClick={onStepChange}>{t('datasetCreation.stepOne.button')}</Button> |
|
|
<Button disabled={!file} className={s.submitButton} type='primary' onClick={onStepChange}>{t('datasetCreation.stepOne.button')}</Button> |
|
|
</> |
|
|
</> |
|
|
)} |
|
|
)} |