You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 24KB

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