options.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. <CheckboxWithLabel
  37. label={t(`${I18N_PREFIX}.useSitemap`)}
  38. isChecked={payload.use_sitemap}
  39. onChange={handleChange('use_sitemap')}
  40. tooltip={t(`${I18N_PREFIX}.useSitemapTooltip`) as string}
  41. />
  42. <div className='flex justify-between space-x-4'>
  43. <Field
  44. className='grow shrink-0'
  45. label={t(`${I18N_PREFIX}.limit`)}
  46. value={payload.limit}
  47. onChange={handleChange('limit')}
  48. isNumber
  49. isRequired
  50. />
  51. </div>
  52. </div>
  53. )
  54. }
  55. export default React.memo(Options)