index.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /* eslint-disable no-mixed-operators */
  2. 'use client'
  3. import React, { useEffect, useLayoutEffect, useRef, useState } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import { useBoolean } from 'ahooks'
  6. import { XMarkIcon } from '@heroicons/react/20/solid'
  7. import cn from 'classnames'
  8. import Link from 'next/link'
  9. import { groupBy } from 'lodash-es'
  10. import PreviewItem from './preview-item'
  11. import s from './index.module.css'
  12. import type { CreateDocumentReq, File, FullDocumentDetail, FileIndexingEstimateResponse as IndexingEstimateResponse, NotionInfo, PreProcessingRule, Rules, createDocumentResponse } from '@/models/datasets'
  13. import {
  14. createDocument,
  15. createFirstDocument,
  16. fetchFileIndexingEstimate as didFetchFileIndexingEstimate,
  17. fetchDefaultProcessRule,
  18. } from '@/service/datasets'
  19. import Button from '@/app/components/base/button'
  20. import Loading from '@/app/components/base/loading'
  21. import Toast from '@/app/components/base/toast'
  22. import { formatNumber } from '@/utils/format'
  23. import type { DataSourceNotionPage } from '@/models/common'
  24. import { DataSourceType } from '@/models/datasets'
  25. import NotionIcon from '@/app/components/base/notion-icon'
  26. import { useDatasetDetailContext } from '@/context/dataset-detail'
  27. type Page = DataSourceNotionPage & { workspace_id: string }
  28. type StepTwoProps = {
  29. isSetting?: boolean
  30. documentDetail?: FullDocumentDetail
  31. hasSetAPIKEY: boolean
  32. onSetting: () => void
  33. datasetId?: string
  34. indexingType?: string
  35. dataSourceType: DataSourceType
  36. file?: File
  37. notionPages?: Page[]
  38. onStepChange?: (delta: number) => void
  39. updateIndexingTypeCache?: (type: string) => void
  40. updateResultCache?: (res: createDocumentResponse) => void
  41. onSave?: () => void
  42. onCancel?: () => void
  43. }
  44. enum SegmentType {
  45. AUTO = 'automatic',
  46. CUSTOM = 'custom',
  47. }
  48. enum IndexingType {
  49. QUALIFIED = 'high_quality',
  50. ECONOMICAL = 'economy',
  51. }
  52. const StepTwo = ({
  53. isSetting,
  54. documentDetail,
  55. hasSetAPIKEY,
  56. onSetting,
  57. datasetId,
  58. indexingType,
  59. dataSourceType,
  60. file,
  61. notionPages = [],
  62. onStepChange,
  63. updateIndexingTypeCache,
  64. updateResultCache,
  65. onSave,
  66. onCancel,
  67. }: StepTwoProps) => {
  68. const { t } = useTranslation()
  69. const { mutateDatasetRes } = useDatasetDetailContext()
  70. const scrollRef = useRef<HTMLDivElement>(null)
  71. const [scrolled, setScrolled] = useState(false)
  72. const previewScrollRef = useRef<HTMLDivElement>(null)
  73. const [previewScrolled, setPreviewScrolled] = useState(false)
  74. const [segmentationType, setSegmentationType] = useState<SegmentType>(SegmentType.AUTO)
  75. const [segmentIdentifier, setSegmentIdentifier] = useState('\\n')
  76. const [max, setMax] = useState(1000)
  77. const [rules, setRules] = useState<PreProcessingRule[]>([])
  78. const [defaultConfig, setDefaultConfig] = useState<Rules>()
  79. const hasSetIndexType = !!indexingType
  80. const [indexType, setIndexType] = useState<IndexingType>(
  81. indexingType
  82. || hasSetAPIKEY
  83. ? IndexingType.QUALIFIED
  84. : IndexingType.ECONOMICAL,
  85. )
  86. const [showPreview, { setTrue: setShowPreview, setFalse: hidePreview }] = useBoolean()
  87. const [customFileIndexingEstimate, setCustomFileIndexingEstimate] = useState<IndexingEstimateResponse | null>(null)
  88. const [automaticFileIndexingEstimate, setAutomaticFileIndexingEstimate] = useState<IndexingEstimateResponse | null>(null)
  89. const fileIndexingEstimate = (() => {
  90. return segmentationType === SegmentType.AUTO ? automaticFileIndexingEstimate : customFileIndexingEstimate
  91. })()
  92. const scrollHandle = (e: any) => {
  93. if (e.target.scrollTop > 0)
  94. setScrolled(true)
  95. else
  96. setScrolled(false)
  97. }
  98. const previewScrollHandle = (e: any) => {
  99. if (e.target.scrollTop > 0)
  100. setPreviewScrolled(true)
  101. else
  102. setPreviewScrolled(false)
  103. }
  104. const getFileName = (name: string) => {
  105. const arr = name.split('.')
  106. return arr.slice(0, -1).join('.')
  107. }
  108. const getRuleName = (key: string) => {
  109. if (key === 'remove_extra_spaces')
  110. return t('datasetCreation.stepTwo.removeExtraSpaces')
  111. if (key === 'remove_urls_emails')
  112. return t('datasetCreation.stepTwo.removeUrlEmails')
  113. if (key === 'remove_stopwords')
  114. return t('datasetCreation.stepTwo.removeStopwords')
  115. }
  116. const ruleChangeHandle = (id: string) => {
  117. const newRules = rules.map((rule) => {
  118. if (rule.id === id) {
  119. return {
  120. id: rule.id,
  121. enabled: !rule.enabled,
  122. }
  123. }
  124. return rule
  125. })
  126. setRules(newRules)
  127. }
  128. const resetRules = () => {
  129. if (defaultConfig) {
  130. setSegmentIdentifier(defaultConfig.segmentation.separator === '\n' ? '\\n' : defaultConfig.segmentation.separator || '\\n')
  131. setMax(defaultConfig.segmentation.max_tokens)
  132. setRules(defaultConfig.pre_processing_rules)
  133. }
  134. }
  135. const fetchFileIndexingEstimate = async () => {
  136. // eslint-disable-next-line @typescript-eslint/no-use-before-define
  137. const res = await didFetchFileIndexingEstimate(getFileIndexingEstimateParams())
  138. if (segmentationType === SegmentType.CUSTOM)
  139. setCustomFileIndexingEstimate(res)
  140. else
  141. setAutomaticFileIndexingEstimate(res)
  142. }
  143. const confirmChangeCustomConfig = async () => {
  144. setCustomFileIndexingEstimate(null)
  145. setShowPreview()
  146. await fetchFileIndexingEstimate()
  147. }
  148. const getIndexing_technique = () => indexingType || indexType
  149. const getProcessRule = () => {
  150. const processRule: any = {
  151. rules: {}, // api will check this. It will be removed after api refactored.
  152. mode: segmentationType,
  153. }
  154. if (segmentationType === SegmentType.CUSTOM) {
  155. const ruleObj = {
  156. pre_processing_rules: rules,
  157. segmentation: {
  158. separator: segmentIdentifier === '\\n' ? '\n' : segmentIdentifier,
  159. max_tokens: max,
  160. },
  161. }
  162. processRule.rules = ruleObj
  163. }
  164. return processRule
  165. }
  166. const getNotionInfo = () => {
  167. const workspacesMap = groupBy(notionPages, 'workspace_id')
  168. const workspaces = Object.keys(workspacesMap).map((workspaceId) => {
  169. return {
  170. workspaceId,
  171. pages: workspacesMap[workspaceId],
  172. }
  173. })
  174. return workspaces.map((workspace) => {
  175. return {
  176. workspace_id: workspace.workspaceId,
  177. pages: workspace.pages.map((page) => {
  178. const { page_id, page_name, page_icon, type } = page
  179. return {
  180. page_id,
  181. page_name,
  182. page_icon,
  183. type,
  184. }
  185. }),
  186. }
  187. }) as NotionInfo[]
  188. }
  189. const getFileIndexingEstimateParams = () => {
  190. let params
  191. if (dataSourceType === DataSourceType.FILE) {
  192. params = {
  193. info_list: {
  194. data_source_type: dataSourceType,
  195. file_info_list: {
  196. // TODO multi files
  197. file_ids: [file?.id || ''],
  198. },
  199. },
  200. indexing_technique: getIndexing_technique(),
  201. process_rule: getProcessRule(),
  202. }
  203. }
  204. if (dataSourceType === DataSourceType.NOTION) {
  205. params = {
  206. info_list: {
  207. data_source_type: dataSourceType,
  208. notion_info_list: getNotionInfo(),
  209. },
  210. indexing_technique: getIndexing_technique(),
  211. process_rule: getProcessRule(),
  212. }
  213. }
  214. return params
  215. }
  216. const getCreationParams = () => {
  217. let params
  218. if (isSetting) {
  219. params = {
  220. original_document_id: documentDetail?.id,
  221. process_rule: getProcessRule(),
  222. } as CreateDocumentReq
  223. }
  224. else {
  225. params = {
  226. data_source: {
  227. type: dataSourceType,
  228. info_list: {
  229. data_source_type: dataSourceType,
  230. },
  231. },
  232. indexing_technique: getIndexing_technique(),
  233. process_rule: getProcessRule(),
  234. } as CreateDocumentReq
  235. if (dataSourceType === DataSourceType.FILE) {
  236. params.data_source.info_list.file_info_list = {
  237. // TODO multi files
  238. file_ids: [file?.id || ''],
  239. }
  240. }
  241. if (dataSourceType === DataSourceType.NOTION)
  242. params.data_source.info_list.notion_info_list = getNotionInfo()
  243. }
  244. return params
  245. }
  246. const getRules = async () => {
  247. try {
  248. const res = await fetchDefaultProcessRule({ url: '/datasets/process-rule' })
  249. const separator = res.rules.segmentation.separator
  250. setSegmentIdentifier(separator === '\n' ? '\\n' : separator || '\\n')
  251. setMax(res.rules.segmentation.max_tokens)
  252. setRules(res.rules.pre_processing_rules)
  253. setDefaultConfig(res.rules)
  254. }
  255. catch (err) {
  256. console.log(err)
  257. }
  258. }
  259. const getRulesFromDetail = () => {
  260. if (documentDetail) {
  261. const rules = documentDetail.dataset_process_rule.rules
  262. const separator = rules.segmentation.separator
  263. const max = rules.segmentation.max_tokens
  264. setSegmentIdentifier(separator === '\n' ? '\\n' : separator || '\\n')
  265. setMax(max)
  266. setRules(rules.pre_processing_rules)
  267. setDefaultConfig(rules)
  268. }
  269. }
  270. const getDefaultMode = () => {
  271. if (documentDetail)
  272. setSegmentationType(documentDetail.dataset_process_rule.mode)
  273. }
  274. const createHandle = async () => {
  275. try {
  276. let res
  277. const params = getCreationParams()
  278. if (!datasetId) {
  279. res = await createFirstDocument({
  280. body: params,
  281. })
  282. updateIndexingTypeCache && updateIndexingTypeCache(indexType)
  283. updateResultCache && updateResultCache(res)
  284. }
  285. else {
  286. res = await createDocument({
  287. datasetId,
  288. body: params,
  289. })
  290. updateIndexingTypeCache && updateIndexingTypeCache(indexType)
  291. updateResultCache && updateResultCache(res)
  292. }
  293. if (mutateDatasetRes)
  294. mutateDatasetRes()
  295. onStepChange && onStepChange(+1)
  296. isSetting && onSave && onSave()
  297. }
  298. catch (err) {
  299. Toast.notify({
  300. type: 'error',
  301. message: `${err}`,
  302. })
  303. }
  304. }
  305. useEffect(() => {
  306. // fetch rules
  307. if (!isSetting) {
  308. getRules()
  309. }
  310. else {
  311. getRulesFromDetail()
  312. getDefaultMode()
  313. }
  314. }, [])
  315. useEffect(() => {
  316. scrollRef.current?.addEventListener('scroll', scrollHandle)
  317. return () => {
  318. scrollRef.current?.removeEventListener('scroll', scrollHandle)
  319. }
  320. }, [])
  321. useLayoutEffect(() => {
  322. if (showPreview) {
  323. previewScrollRef.current?.addEventListener('scroll', previewScrollHandle)
  324. return () => {
  325. previewScrollRef.current?.removeEventListener('scroll', previewScrollHandle)
  326. }
  327. }
  328. }, [showPreview])
  329. useEffect(() => {
  330. // get indexing type by props
  331. if (indexingType)
  332. setIndexType(indexingType as IndexingType)
  333. else
  334. setIndexType(hasSetAPIKEY ? IndexingType.QUALIFIED : IndexingType.ECONOMICAL)
  335. }, [hasSetAPIKEY, indexingType, datasetId])
  336. useEffect(() => {
  337. if (segmentationType === SegmentType.AUTO) {
  338. setAutomaticFileIndexingEstimate(null)
  339. setShowPreview()
  340. fetchFileIndexingEstimate()
  341. }
  342. else {
  343. hidePreview()
  344. setCustomFileIndexingEstimate(null)
  345. }
  346. }, [segmentationType, indexType])
  347. return (
  348. <div className='flex w-full h-full'>
  349. <div ref={scrollRef} className='relative h-full w-full overflow-y-scroll'>
  350. <div className={cn(s.pageHeader, scrolled && s.fixed)}>{t('datasetCreation.steps.two')}</div>
  351. <div className={cn(s.form)}>
  352. <div className={s.label}>{t('datasetCreation.stepTwo.segmentation')}</div>
  353. <div className='max-w-[640px]'>
  354. <div
  355. className={cn(
  356. s.radioItem,
  357. s.segmentationItem,
  358. segmentationType === SegmentType.AUTO && s.active,
  359. )}
  360. onClick={() => setSegmentationType(SegmentType.AUTO)}
  361. >
  362. <span className={cn(s.typeIcon, s.auto)} />
  363. <span className={cn(s.radio)} />
  364. <div className={s.typeHeader}>
  365. <div className={s.title}>{t('datasetCreation.stepTwo.auto')}</div>
  366. <div className={s.tip}>{t('datasetCreation.stepTwo.autoDescription')}</div>
  367. </div>
  368. </div>
  369. <div
  370. className={cn(
  371. s.radioItem,
  372. s.segmentationItem,
  373. segmentationType === SegmentType.CUSTOM && s.active,
  374. segmentationType === SegmentType.CUSTOM && s.custom,
  375. )}
  376. onClick={() => setSegmentationType(SegmentType.CUSTOM)}
  377. >
  378. <span className={cn(s.typeIcon, s.customize)} />
  379. <span className={cn(s.radio)} />
  380. <div className={s.typeHeader}>
  381. <div className={s.title}>{t('datasetCreation.stepTwo.custom')}</div>
  382. <div className={s.tip}>{t('datasetCreation.stepTwo.customDescription')}</div>
  383. </div>
  384. {segmentationType === SegmentType.CUSTOM && (
  385. <div className={s.typeFormBody}>
  386. <div className={s.formRow}>
  387. <div className='w-full'>
  388. <div className={s.label}>{t('datasetCreation.stepTwo.separator')}</div>
  389. <input
  390. type="text"
  391. className={s.input}
  392. placeholder={t('datasetCreation.stepTwo.separatorPlaceholder') || ''} value={segmentIdentifier}
  393. onChange={e => setSegmentIdentifier(e.target.value)}
  394. />
  395. </div>
  396. </div>
  397. <div className={s.formRow}>
  398. <div className='w-full'>
  399. <div className={s.label}>{t('datasetCreation.stepTwo.maxLength')}</div>
  400. <input
  401. type="number"
  402. className={s.input}
  403. placeholder={t('datasetCreation.stepTwo.separatorPlaceholder') || ''} value={max}
  404. onChange={e => setMax(Number(e.target.value))}
  405. />
  406. </div>
  407. </div>
  408. <div className={s.formRow}>
  409. <div className='w-full'>
  410. <div className={s.label}>{t('datasetCreation.stepTwo.rules')}</div>
  411. {rules.map(rule => (
  412. <div key={rule.id} className={s.ruleItem}>
  413. <input id={rule.id} type="checkbox" defaultChecked={rule.enabled} onChange={() => ruleChangeHandle(rule.id)} className="w-4 h-4 rounded border-gray-300 text-blue-700 focus:ring-blue-700" />
  414. <label htmlFor={rule.id} className="ml-2 text-sm font-normal cursor-pointer text-gray-800">{getRuleName(rule.id)}</label>
  415. </div>
  416. ))}
  417. </div>
  418. </div>
  419. <div className={s.formFooter}>
  420. <Button type="primary" className={cn(s.button, '!h-8 text-primary-600')} onClick={confirmChangeCustomConfig}>{t('datasetCreation.stepTwo.preview')}</Button>
  421. <Button className={cn(s.button, 'ml-2 !h-8')} onClick={resetRules}>{t('datasetCreation.stepTwo.reset')}</Button>
  422. </div>
  423. </div>
  424. )}
  425. </div>
  426. </div>
  427. <div className={s.label}>{t('datasetCreation.stepTwo.indexMode')}</div>
  428. <div className='max-w-[640px]'>
  429. <div className='flex items-center gap-3'>
  430. {(!hasSetIndexType || (hasSetIndexType && indexingType === IndexingType.QUALIFIED)) && (
  431. <div
  432. className={cn(
  433. s.radioItem,
  434. s.indexItem,
  435. !hasSetAPIKEY && s.disabled,
  436. !hasSetIndexType && indexType === IndexingType.QUALIFIED && s.active,
  437. hasSetIndexType && s.disabled,
  438. hasSetIndexType && '!w-full',
  439. )}
  440. onClick={() => {
  441. if (hasSetAPIKEY)
  442. setIndexType(IndexingType.QUALIFIED)
  443. }}
  444. >
  445. <span className={cn(s.typeIcon, s.qualified)} />
  446. {!hasSetIndexType && <span className={cn(s.radio)} />}
  447. <div className={s.typeHeader}>
  448. <div className={s.title}>
  449. {t('datasetCreation.stepTwo.qualified')}
  450. {!hasSetIndexType && <span className={s.recommendTag}>{t('datasetCreation.stepTwo.recommend')}</span>}
  451. </div>
  452. <div className={s.tip}>{t('datasetCreation.stepTwo.qualifiedTip')}</div>
  453. <div className='pb-0.5 text-xs font-medium text-gray-500'>{t('datasetCreation.stepTwo.emstimateCost')}</div>
  454. {
  455. fileIndexingEstimate
  456. ? (
  457. <div className='text-xs font-medium text-gray-800'>{formatNumber(fileIndexingEstimate.tokens)} tokens(<span className='text-yellow-500'>${formatNumber(fileIndexingEstimate.total_price)}</span>)</div>
  458. )
  459. : (
  460. <div className={s.calculating}>{t('datasetCreation.stepTwo.calculating')}</div>
  461. )
  462. }
  463. </div>
  464. {!hasSetAPIKEY && (
  465. <div className={s.warningTip}>
  466. <span>{t('datasetCreation.stepTwo.warning')}&nbsp;</span>
  467. <span className={s.click} onClick={onSetting}>{t('datasetCreation.stepTwo.click')}</span>
  468. </div>
  469. )}
  470. </div>
  471. )}
  472. {(!hasSetIndexType || (hasSetIndexType && indexingType === IndexingType.ECONOMICAL)) && (
  473. <div
  474. className={cn(
  475. s.radioItem,
  476. s.indexItem,
  477. !hasSetIndexType && indexType === IndexingType.ECONOMICAL && s.active,
  478. hasSetIndexType && s.disabled,
  479. hasSetIndexType && '!w-full',
  480. )}
  481. onClick={() => !hasSetIndexType && setIndexType(IndexingType.ECONOMICAL)}
  482. >
  483. <span className={cn(s.typeIcon, s.economical)} />
  484. {!hasSetIndexType && <span className={cn(s.radio)} />}
  485. <div className={s.typeHeader}>
  486. <div className={s.title}>{t('datasetCreation.stepTwo.economical')}</div>
  487. <div className={s.tip}>{t('datasetCreation.stepTwo.economicalTip')}</div>
  488. <div className='pb-0.5 text-xs font-medium text-gray-500'>{t('datasetCreation.stepTwo.emstimateCost')}</div>
  489. <div className='text-xs font-medium text-gray-800'>0 tokens</div>
  490. </div>
  491. </div>
  492. )}
  493. </div>
  494. {hasSetIndexType && (
  495. <div className='mt-2 text-xs text-gray-500 font-medium'>
  496. {t('datasetCreation.stepTwo.indexSettedTip')}
  497. <Link className='text-[#155EEF]' href={`/datasets/${datasetId}/settings`}>{t('datasetCreation.stepTwo.datasetSettingLink')}</Link>
  498. </div>
  499. )}
  500. {/* TODO multi files */}
  501. <div className={s.source}>
  502. <div className={s.sourceContent}>
  503. {dataSourceType === DataSourceType.FILE && (
  504. <>
  505. <div className='mb-2 text-xs font-medium text-gray-500'>{t('datasetCreation.stepTwo.fileSource')}</div>
  506. <div className='flex items-center text-sm leading-6 font-medium text-gray-800'>
  507. <span className={cn(s.fileIcon, file && s[file.extension])} />
  508. {getFileName(file?.name || '')}
  509. </div>
  510. </>
  511. )}
  512. {dataSourceType === DataSourceType.NOTION && (
  513. <>
  514. <div className='mb-2 text-xs font-medium text-gray-500'>{t('datasetCreation.stepTwo.notionSource')}</div>
  515. <div className='flex items-center text-sm leading-6 font-medium text-gray-800'>
  516. <NotionIcon
  517. className='shrink-0 mr-1'
  518. type='page'
  519. src={notionPages[0]?.page_icon}
  520. />
  521. {notionPages[0]?.page_name}
  522. {notionPages.length > 1 && (
  523. <span className={s.sourceCount}>
  524. <span>{t('datasetCreation.stepTwo.other')}</span>
  525. <span>{notionPages.length - 1}</span>
  526. <span>{t('datasetCreation.stepTwo.notionUnit')}</span>
  527. </span>
  528. )}
  529. </div>
  530. </>
  531. )}
  532. </div>
  533. <div className={s.divider} />
  534. <div className={s.segmentCount}>
  535. <div className='mb-2 text-xs font-medium text-gray-500'>{t('datasetCreation.stepTwo.emstimateSegment')}</div>
  536. <div className='flex items-center text-sm leading-6 font-medium text-gray-800'>
  537. {
  538. fileIndexingEstimate
  539. ? (
  540. <div className='text-xs font-medium text-gray-800'>{formatNumber(fileIndexingEstimate.total_segments)} </div>
  541. )
  542. : (
  543. <div className={s.calculating}>{t('datasetCreation.stepTwo.calculating')}</div>
  544. )
  545. }
  546. </div>
  547. </div>
  548. </div>
  549. {!isSetting
  550. ? (
  551. <div className='flex items-center mt-8 py-2'>
  552. <Button onClick={() => onStepChange && onStepChange(-1)}>{t('datasetCreation.stepTwo.lastStep')}</Button>
  553. <div className={s.divider} />
  554. <Button type='primary' onClick={createHandle}>{t('datasetCreation.stepTwo.nextStep')}</Button>
  555. </div>
  556. )
  557. : (
  558. <div className='flex items-center mt-8 py-2'>
  559. <Button type='primary' onClick={createHandle}>{t('datasetCreation.stepTwo.save')}</Button>
  560. <Button className='ml-2' onClick={onCancel}>{t('datasetCreation.stepTwo.cancel')}</Button>
  561. </div>
  562. )}
  563. </div>
  564. </div>
  565. </div>
  566. {(showPreview)
  567. ? (
  568. <div ref={previewScrollRef} className={cn(s.previewWrap, 'relativeh-full overflow-y-scroll border-l border-[#F2F4F7]')}>
  569. <div className={cn(s.previewHeader, previewScrolled && `${s.fixed} pb-3`, ' flex items-center justify-between px-8')}>
  570. <span>{t('datasetCreation.stepTwo.previewTitle')}</span>
  571. <div className='flex items-center justify-center w-6 h-6 cursor-pointer' onClick={hidePreview}>
  572. <XMarkIcon className='h-4 w-4'></XMarkIcon>
  573. </div>
  574. </div>
  575. <div className='my-4 px-8 space-y-4'>
  576. {fileIndexingEstimate?.preview
  577. ? (
  578. <>
  579. {fileIndexingEstimate?.preview.map((item, index) => (
  580. <PreviewItem key={item} content={item} index={index + 1} />
  581. ))}
  582. </>
  583. )
  584. : <div className='flex items-center justify-center h-[200px]'><Loading type='area'></Loading></div>
  585. }
  586. </div>
  587. </div>
  588. )
  589. : (<div className={cn(s.sideTip)}>
  590. <div className={s.tipCard}>
  591. <span className={s.icon} />
  592. <div className={s.title}>{t('datasetCreation.stepTwo.sideTipTitle')}</div>
  593. <div className={s.content}>
  594. <p className='mb-3'>{t('datasetCreation.stepTwo.sideTipP1')}</p>
  595. <p className='mb-3'>{t('datasetCreation.stepTwo.sideTipP2')}</p>
  596. <p className='mb-3'>{t('datasetCreation.stepTwo.sideTipP3')}</p>
  597. <p>{t('datasetCreation.stepTwo.sideTipP4')}</p>
  598. </div>
  599. </div>
  600. </div>)}
  601. </div>
  602. )
  603. }
  604. export default StepTwo