Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

csv-downloader.tsx 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React from 'react'
  4. import {
  5. useCSVDownloader,
  6. } from 'react-papaparse'
  7. import { useTranslation } from 'react-i18next'
  8. import { useContext } from 'use-context-selector'
  9. import { Download02 as DownloadIcon } from '@/app/components/base/icons/src/vender/solid/general'
  10. import I18n from '@/context/i18n'
  11. import { LanguagesSupported } from '@/i18n-config/language'
  12. const CSV_TEMPLATE_QA_EN = [
  13. ['question', 'answer'],
  14. ['question1', 'answer1'],
  15. ['question2', 'answer2'],
  16. ]
  17. const CSV_TEMPLATE_QA_CN = [
  18. ['问题', '答案'],
  19. ['问题 1', '答案 1'],
  20. ['问题 2', '答案 2'],
  21. ]
  22. const CSVDownload: FC = () => {
  23. const { t } = useTranslation()
  24. const { locale } = useContext(I18n)
  25. const { CSVDownloader, Type } = useCSVDownloader()
  26. const getTemplate = () => {
  27. return locale !== LanguagesSupported[1] ? CSV_TEMPLATE_QA_EN : CSV_TEMPLATE_QA_CN
  28. }
  29. return (
  30. <div className='mt-6'>
  31. <div className='system-sm-medium text-text-primary'>{t('share.generation.csvStructureTitle')}</div>
  32. <div className='mt-2 max-h-[500px] overflow-auto'>
  33. <table className='w-full table-fixed border-separate border-spacing-0 rounded-lg border border-divider-regular text-xs'>
  34. <thead className='text-text-tertiary'>
  35. <tr>
  36. <td className='h-9 border-b border-divider-regular pl-3 pr-2'>{t('appAnnotation.batchModal.question')}</td>
  37. <td className='h-9 border-b border-divider-regular pl-3 pr-2'>{t('appAnnotation.batchModal.answer')}</td>
  38. </tr>
  39. </thead>
  40. <tbody className='text-text-secondary'>
  41. <tr>
  42. <td className='h-9 border-b border-divider-subtle pl-3 pr-2 text-[13px]'>{t('appAnnotation.batchModal.question')} 1</td>
  43. <td className='h-9 border-b border-divider-subtle pl-3 pr-2 text-[13px]'>{t('appAnnotation.batchModal.answer')} 1</td>
  44. </tr>
  45. <tr>
  46. <td className='h-9 pl-3 pr-2 text-[13px]'>{t('appAnnotation.batchModal.question')} 2</td>
  47. <td className='h-9 pl-3 pr-2 text-[13px]'>{t('appAnnotation.batchModal.answer')} 2</td>
  48. </tr>
  49. </tbody>
  50. </table>
  51. </div>
  52. <CSVDownloader
  53. className="mt-2 block cursor-pointer"
  54. type={Type.Link}
  55. filename={`template-${locale}`}
  56. bom={true}
  57. data={getTemplate()}
  58. >
  59. <div className='system-xs-medium flex h-[18px] items-center space-x-1 text-text-accent'>
  60. <DownloadIcon className='mr-1 h-3 w-3' />
  61. {t('appAnnotation.batchModal.template')}
  62. </div>
  63. </CSVDownloader>
  64. </div>
  65. )
  66. }
  67. export default React.memo(CSVDownload)