index.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  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. files: 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. files,
  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. file_ids: files.map(file => file.id),
  197. },
  198. },
  199. indexing_technique: getIndexing_technique(),
  200. process_rule: getProcessRule(),
  201. }
  202. }
  203. if (dataSourceType === DataSourceType.NOTION) {
  204. params = {
  205. info_list: {
  206. data_source_type: dataSourceType,
  207. notion_info_list: getNotionInfo(),
  208. },
  209. indexing_technique: getIndexing_technique(),
  210. process_rule: getProcessRule(),
  211. }
  212. }
  213. return params
  214. }
  215. const getCreationParams = () => {
  216. let params
  217. if (isSetting) {
  218. params = {
  219. original_document_id: documentDetail?.id,
  220. process_rule: getProcessRule(),
  221. } as CreateDocumentReq
  222. }
  223. else {
  224. params = {
  225. data_source: {
  226. type: dataSourceType,
  227. info_list: {
  228. data_source_type: dataSourceType,
  229. },
  230. },
  231. indexing_technique: getIndexing_technique(),
  232. process_rule: getProcessRule(),
  233. } as CreateDocumentReq
  234. if (dataSourceType === DataSourceType.FILE) {
  235. params.data_source.info_list.file_info_list = {
  236. file_ids: files.map(file => 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. if (mutateDatasetRes)
  292. mutateDatasetRes()
  293. onStepChange && onStepChange(+1)
  294. isSetting && onSave && onSave()
  295. }
  296. catch (err) {
  297. Toast.notify({
  298. type: 'error',
  299. message: `${err}`,
  300. })
  301. }
  302. }
  303. useEffect(() => {
  304. // fetch rules
  305. if (!isSetting) {
  306. getRules()
  307. }
  308. else {
  309. getRulesFromDetail()
  310. getDefaultMode()
  311. }
  312. }, [])
  313. useEffect(() => {
  314. scrollRef.current?.addEventListener('scroll', scrollHandle)
  315. return () => {
  316. scrollRef.current?.removeEventListener('scroll', scrollHandle)
  317. }
  318. }, [])
  319. useLayoutEffect(() => {
  320. if (showPreview) {
  321. previewScrollRef.current?.addEventListener('scroll', previewScrollHandle)
  322. return () => {
  323. previewScrollRef.current?.removeEventListener('scroll', previewScrollHandle)
  324. }
  325. }
  326. }, [showPreview])
  327. useEffect(() => {
  328. // get indexing type by props
  329. if (indexingType)
  330. setIndexType(indexingType as IndexingType)
  331. else
  332. setIndexType(hasSetAPIKEY ? IndexingType.QUALIFIED : IndexingType.ECONOMICAL)
  333. }, [hasSetAPIKEY, indexingType, datasetId])
  334. useEffect(() => {
  335. if (segmentationType === SegmentType.AUTO) {
  336. setAutomaticFileIndexingEstimate(null)
  337. setShowPreview()
  338. fetchFileIndexingEstimate()
  339. }
  340. else {
  341. hidePreview()
  342. setCustomFileIndexingEstimate(null)
  343. }
  344. }, [segmentationType, indexType])
  345. return (
  346. <div className='flex w-full h-full'>
  347. <div ref={scrollRef} className='relative h-full w-full overflow-y-scroll'>
  348. <div className={cn(s.pageHeader, scrolled && s.fixed)}>{t('datasetCreation.steps.two')}</div>
  349. <div className={cn(s.form)}>
  350. <div className={s.label}>{t('datasetCreation.stepTwo.segmentation')}</div>
  351. <div className='max-w-[640px]'>
  352. <div
  353. className={cn(
  354. s.radioItem,
  355. s.segmentationItem,
  356. segmentationType === SegmentType.AUTO && s.active,
  357. )}
  358. onClick={() => setSegmentationType(SegmentType.AUTO)}
  359. >
  360. <span className={cn(s.typeIcon, s.auto)} />
  361. <span className={cn(s.radio)} />
  362. <div className={s.typeHeader}>
  363. <div className={s.title}>{t('datasetCreation.stepTwo.auto')}</div>
  364. <div className={s.tip}>{t('datasetCreation.stepTwo.autoDescription')}</div>
  365. </div>
  366. </div>
  367. <div
  368. className={cn(
  369. s.radioItem,
  370. s.segmentationItem,
  371. segmentationType === SegmentType.CUSTOM && s.active,
  372. segmentationType === SegmentType.CUSTOM && s.custom,
  373. )}
  374. onClick={() => setSegmentationType(SegmentType.CUSTOM)}
  375. >
  376. <span className={cn(s.typeIcon, s.customize)} />
  377. <span className={cn(s.radio)} />
  378. <div className={s.typeHeader}>
  379. <div className={s.title}>{t('datasetCreation.stepTwo.custom')}</div>
  380. <div className={s.tip}>{t('datasetCreation.stepTwo.customDescription')}</div>
  381. </div>
  382. {segmentationType === SegmentType.CUSTOM && (
  383. <div className={s.typeFormBody}>
  384. <div className={s.formRow}>
  385. <div className='w-full'>
  386. <div className={s.label}>{t('datasetCreation.stepTwo.separator')}</div>
  387. <input
  388. type="text"
  389. className={s.input}
  390. placeholder={t('datasetCreation.stepTwo.separatorPlaceholder') || ''} value={segmentIdentifier}
  391. onChange={e => setSegmentIdentifier(e.target.value)}
  392. />
  393. </div>
  394. </div>
  395. <div className={s.formRow}>
  396. <div className='w-full'>
  397. <div className={s.label}>{t('datasetCreation.stepTwo.maxLength')}</div>
  398. <input
  399. type="number"
  400. className={s.input}
  401. placeholder={t('datasetCreation.stepTwo.separatorPlaceholder') || ''} value={max}
  402. onChange={e => setMax(Number(e.target.value))}
  403. />
  404. </div>
  405. </div>
  406. <div className={s.formRow}>
  407. <div className='w-full'>
  408. <div className={s.label}>{t('datasetCreation.stepTwo.rules')}</div>
  409. {rules.map(rule => (
  410. <div key={rule.id} className={s.ruleItem}>
  411. <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" />
  412. <label htmlFor={rule.id} className="ml-2 text-sm font-normal cursor-pointer text-gray-800">{getRuleName(rule.id)}</label>
  413. </div>
  414. ))}
  415. </div>
  416. </div>
  417. <div className={s.formFooter}>
  418. <Button type="primary" className={cn(s.button, '!h-8 text-primary-600')} onClick={confirmChangeCustomConfig}>{t('datasetCreation.stepTwo.preview')}</Button>
  419. <Button className={cn(s.button, 'ml-2 !h-8')} onClick={resetRules}>{t('datasetCreation.stepTwo.reset')}</Button>
  420. </div>
  421. </div>
  422. )}
  423. </div>
  424. </div>
  425. <div className={s.label}>{t('datasetCreation.stepTwo.indexMode')}</div>
  426. <div className='max-w-[640px]'>
  427. <div className='flex items-center gap-3'>
  428. {(!hasSetIndexType || (hasSetIndexType && indexingType === IndexingType.QUALIFIED)) && (
  429. <div
  430. className={cn(
  431. s.radioItem,
  432. s.indexItem,
  433. !hasSetAPIKEY && s.disabled,
  434. !hasSetIndexType && indexType === IndexingType.QUALIFIED && s.active,
  435. hasSetIndexType && s.disabled,
  436. hasSetIndexType && '!w-full',
  437. )}
  438. onClick={() => {
  439. if (hasSetAPIKEY)
  440. setIndexType(IndexingType.QUALIFIED)
  441. }}
  442. >
  443. <span className={cn(s.typeIcon, s.qualified)} />
  444. {!hasSetIndexType && <span className={cn(s.radio)} />}
  445. <div className={s.typeHeader}>
  446. <div className={s.title}>
  447. {t('datasetCreation.stepTwo.qualified')}
  448. {!hasSetIndexType && <span className={s.recommendTag}>{t('datasetCreation.stepTwo.recommend')}</span>}
  449. </div>
  450. <div className={s.tip}>{t('datasetCreation.stepTwo.qualifiedTip')}</div>
  451. <div className='pb-0.5 text-xs font-medium text-gray-500'>{t('datasetCreation.stepTwo.emstimateCost')}</div>
  452. {
  453. fileIndexingEstimate
  454. ? (
  455. <div className='text-xs font-medium text-gray-800'>{formatNumber(fileIndexingEstimate.tokens)} tokens(<span className='text-yellow-500'>${formatNumber(fileIndexingEstimate.total_price)}</span>)</div>
  456. )
  457. : (
  458. <div className={s.calculating}>{t('datasetCreation.stepTwo.calculating')}</div>
  459. )
  460. }
  461. </div>
  462. {!hasSetAPIKEY && (
  463. <div className={s.warningTip}>
  464. <span>{t('datasetCreation.stepTwo.warning')}&nbsp;</span>
  465. <span className={s.click} onClick={onSetting}>{t('datasetCreation.stepTwo.click')}</span>
  466. </div>
  467. )}
  468. </div>
  469. )}
  470. {(!hasSetIndexType || (hasSetIndexType && indexingType === IndexingType.ECONOMICAL)) && (
  471. <div
  472. className={cn(
  473. s.radioItem,
  474. s.indexItem,
  475. !hasSetIndexType && indexType === IndexingType.ECONOMICAL && s.active,
  476. hasSetIndexType && s.disabled,
  477. hasSetIndexType && '!w-full',
  478. )}
  479. onClick={() => !hasSetIndexType && setIndexType(IndexingType.ECONOMICAL)}
  480. >
  481. <span className={cn(s.typeIcon, s.economical)} />
  482. {!hasSetIndexType && <span className={cn(s.radio)} />}
  483. <div className={s.typeHeader}>
  484. <div className={s.title}>{t('datasetCreation.stepTwo.economical')}</div>
  485. <div className={s.tip}>{t('datasetCreation.stepTwo.economicalTip')}</div>
  486. <div className='pb-0.5 text-xs font-medium text-gray-500'>{t('datasetCreation.stepTwo.emstimateCost')}</div>
  487. <div className='text-xs font-medium text-gray-800'>0 tokens</div>
  488. </div>
  489. </div>
  490. )}
  491. </div>
  492. {hasSetIndexType && (
  493. <div className='mt-2 text-xs text-gray-500 font-medium'>
  494. {t('datasetCreation.stepTwo.indexSettedTip')}
  495. <Link className='text-[#155EEF]' href={`/datasets/${datasetId}/settings`}>{t('datasetCreation.stepTwo.datasetSettingLink')}</Link>
  496. </div>
  497. )}
  498. <div className={s.source}>
  499. <div className={s.sourceContent}>
  500. {dataSourceType === DataSourceType.FILE && (
  501. <>
  502. <div className='mb-2 text-xs font-medium text-gray-500'>{t('datasetCreation.stepTwo.fileSource')}</div>
  503. <div className='flex items-center text-sm leading-6 font-medium text-gray-800'>
  504. <span className={cn(s.fileIcon, files.length && s[files[0].extension])} />
  505. {getFileName(files[0].name || '')}
  506. {files.length > 1 && (
  507. <span className={s.sourceCount}>
  508. <span>{t('datasetCreation.stepTwo.other')}</span>
  509. <span>{files.length - 1}</span>
  510. <span>{t('datasetCreation.stepTwo.fileUnit')}</span>
  511. </span>
  512. )}
  513. </div>
  514. </>
  515. )}
  516. {dataSourceType === DataSourceType.NOTION && (
  517. <>
  518. <div className='mb-2 text-xs font-medium text-gray-500'>{t('datasetCreation.stepTwo.notionSource')}</div>
  519. <div className='flex items-center text-sm leading-6 font-medium text-gray-800'>
  520. <NotionIcon
  521. className='shrink-0 mr-1'
  522. type='page'
  523. src={notionPages[0]?.page_icon}
  524. />
  525. {notionPages[0]?.page_name}
  526. {notionPages.length > 1 && (
  527. <span className={s.sourceCount}>
  528. <span>{t('datasetCreation.stepTwo.other')}</span>
  529. <span>{notionPages.length - 1}</span>
  530. <span>{t('datasetCreation.stepTwo.notionUnit')}</span>
  531. </span>
  532. )}
  533. </div>
  534. </>
  535. )}
  536. </div>
  537. <div className={s.divider} />
  538. <div className={s.segmentCount}>
  539. <div className='mb-2 text-xs font-medium text-gray-500'>{t('datasetCreation.stepTwo.emstimateSegment')}</div>
  540. <div className='flex items-center text-sm leading-6 font-medium text-gray-800'>
  541. {
  542. fileIndexingEstimate
  543. ? (
  544. <div className='text-xs font-medium text-gray-800'>{formatNumber(fileIndexingEstimate.total_segments)} </div>
  545. )
  546. : (
  547. <div className={s.calculating}>{t('datasetCreation.stepTwo.calculating')}</div>
  548. )
  549. }
  550. </div>
  551. </div>
  552. </div>
  553. {!isSetting
  554. ? (
  555. <div className='flex items-center mt-8 py-2'>
  556. <Button onClick={() => onStepChange && onStepChange(-1)}>{t('datasetCreation.stepTwo.lastStep')}</Button>
  557. <div className={s.divider} />
  558. <Button type='primary' onClick={createHandle}>{t('datasetCreation.stepTwo.nextStep')}</Button>
  559. </div>
  560. )
  561. : (
  562. <div className='flex items-center mt-8 py-2'>
  563. <Button type='primary' onClick={createHandle}>{t('datasetCreation.stepTwo.save')}</Button>
  564. <Button className='ml-2' onClick={onCancel}>{t('datasetCreation.stepTwo.cancel')}</Button>
  565. </div>
  566. )}
  567. </div>
  568. </div>
  569. </div>
  570. {(showPreview)
  571. ? (
  572. <div ref={previewScrollRef} className={cn(s.previewWrap, 'relativeh-full overflow-y-scroll border-l border-[#F2F4F7]')}>
  573. <div className={cn(s.previewHeader, previewScrolled && `${s.fixed} pb-3`, ' flex items-center justify-between px-8')}>
  574. <span>{t('datasetCreation.stepTwo.previewTitle')}</span>
  575. <div className='flex items-center justify-center w-6 h-6 cursor-pointer' onClick={hidePreview}>
  576. <XMarkIcon className='h-4 w-4'></XMarkIcon>
  577. </div>
  578. </div>
  579. <div className='my-4 px-8 space-y-4'>
  580. {fileIndexingEstimate?.preview
  581. ? (
  582. <>
  583. {fileIndexingEstimate?.preview.map((item, index) => (
  584. <PreviewItem key={item} content={item} index={index + 1} />
  585. ))}
  586. </>
  587. )
  588. : <div className='flex items-center justify-center h-[200px]'><Loading type='area'></Loading></div>
  589. }
  590. </div>
  591. </div>
  592. )
  593. : (<div className={cn(s.sideTip)}>
  594. <div className={s.tipCard}>
  595. <span className={s.icon} />
  596. <div className={s.title}>{t('datasetCreation.stepTwo.sideTipTitle')}</div>
  597. <div className={s.content}>
  598. <p className='mb-3'>{t('datasetCreation.stepTwo.sideTipP1')}</p>
  599. <p className='mb-3'>{t('datasetCreation.stepTwo.sideTipP2')}</p>
  600. <p className='mb-3'>{t('datasetCreation.stepTwo.sideTipP3')}</p>
  601. <p>{t('datasetCreation.stepTwo.sideTipP4')}</p>
  602. </div>
  603. </div>
  604. </div>)}
  605. </div>
  606. )
  607. }
  608. export default StepTwo