options.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useCallback } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import CheckboxWithLabel from '../base/checkbox-with-label'
  6. import Field from '../base/field'
  7. import cn from '@/utils/classnames'
  8. import type { CrawlOptions } from '@/models/datasets'
  9. const I18N_PREFIX = 'datasetCreation.stepOne.website'
  10. type Props = {
  11. className?: string
  12. payload: CrawlOptions
  13. onChange: (payload: CrawlOptions) => void
  14. }
  15. const Options: FC<Props> = ({
  16. className = '',
  17. payload,
  18. onChange,
  19. }) => {
  20. const { t } = useTranslation()
  21. const handleChange = useCallback((key: keyof CrawlOptions) => {
  22. return (value: any) => {
  23. onChange({
  24. ...payload,
  25. [key]: value,
  26. })
  27. }
  28. }, [payload, onChange])
  29. return (
  30. <div className={cn(className, ' space-y-2')}>
  31. <CheckboxWithLabel
  32. label={t(`${I18N_PREFIX}.crawlSubPage`)}
  33. isChecked={payload.crawl_sub_pages}
  34. onChange={handleChange('crawl_sub_pages')}
  35. />
  36. <div className='flex justify-between space-x-4'>
  37. <Field
  38. className='grow shrink-0'
  39. label={t(`${I18N_PREFIX}.limit`)}
  40. value={payload.limit}
  41. onChange={handleChange('limit')}
  42. isNumber
  43. isRequired
  44. />
  45. <Field
  46. className='grow shrink-0'
  47. label={t(`${I18N_PREFIX}.maxDepth`)}
  48. value={payload.max_depth}
  49. onChange={handleChange('max_depth')}
  50. isNumber
  51. tooltip={t(`${I18N_PREFIX}.maxDepthTooltip`)!}
  52. />
  53. </div>
  54. <div className='flex justify-between space-x-4'>
  55. <Field
  56. className='grow shrink-0'
  57. label={t(`${I18N_PREFIX}.excludePaths`)}
  58. value={payload.excludes}
  59. onChange={handleChange('excludes')}
  60. placeholder='blog/*, /about/*'
  61. />
  62. <Field
  63. className='grow shrink-0'
  64. label={t(`${I18N_PREFIX}.includeOnlyPaths`)}
  65. value={payload.includes}
  66. onChange={handleChange('includes')}
  67. placeholder='articles/*'
  68. />
  69. </div>
  70. <CheckboxWithLabel
  71. label={t(`${I18N_PREFIX}.extractOnlyMainContent`)}
  72. isChecked={payload.only_main_content}
  73. onChange={handleChange('only_main_content')}
  74. />
  75. </div>
  76. )
  77. }
  78. export default React.memo(Options)