Commit cb6e813b authored by Joel's avatar Joel

feat: csv download

parent 6b941935
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M21 21H3M18 11L12 17M12 17L6 11M12 17V3" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
{
"icon": {
"type": "element",
"isRootNode": true,
"name": "svg",
"attributes": {
"width": "24",
"height": "24",
"viewBox": "0 0 24 24",
"fill": "none",
"xmlns": "http://www.w3.org/2000/svg"
},
"children": [
{
"type": "element",
"name": "path",
"attributes": {
"d": "M21 21H3M18 11L12 17M12 17L6 11M12 17V3",
"stroke": "currentColor",
"stroke-width": "2",
"stroke-linecap": "round",
"stroke-linejoin": "round"
},
"children": []
}
]
},
"name": "Download02"
}
\ No newline at end of file
// GENERATE BY script
// DON NOT EDIT IT MANUALLY
import * as React from 'react'
import data from './Download02.json'
import IconBase from '@/app/components/base/icons/IconBase'
import type { IconBaseProps, IconData } from '@/app/components/base/icons/IconBase'
const Icon = React.forwardRef<React.MutableRefObject<SVGElement>, Omit<IconBaseProps, 'data'>>((
props,
ref,
) => <IconBase {...props} ref={ref} data={data as IconData} />)
export default Icon
export { default as Download02 } from './Download02'
...@@ -342,7 +342,7 @@ const TextGeneration: FC<IMainProps> = ({ ...@@ -342,7 +342,7 @@ const TextGeneration: FC<IMainProps> = ({
)} )}
{currTab === 'batch' && ( {currTab === 'batch' && (
<RunBatch <RunBatch
inputs={inputs} vars={promptConfig.prompt_variables}
onSend={handleRunBatch} onSend={handleRunBatch}
/> />
)} )}
......
'use client'
import type { FC } from 'react'
import React from 'react'
import {
useCSVDownloader,
} from 'react-papaparse'
import { useTranslation } from 'react-i18next'
import { Download02 as DownloadIcon } from '@/app/components/base/icons/src/vender/solid/general'
export type ICSVDownloadProps = {
vars: { name: string }[]
}
const CSVDownload: FC<ICSVDownloadProps> = ({
vars,
}) => {
const { t } = useTranslation()
const { CSVDownloader, Type } = useCSVDownloader()
const template = (() => {
const res: Record<string, string> = {}
vars.forEach((item) => {
res[item.name] = ''
})
console.log(res)
return res
})()
// debugger
return (
<CSVDownloader
className="block mt-2 cursor-pointer"
type={Type.Link}
filename={'template'}
bom={true}
config={{
delimiter: ';',
}}
data={[
template,
]}
>
<div className='flex items-center h-[18px] space-x-1 text-[#155EEF] text-xs font-medium'>
<DownloadIcon className='w-3 h-3' />
<span>{t('share.generation.downloadTemplate')}</span>
</div>
</CSVDownloader>
)
}
export default React.memo(CSVDownload)
...@@ -6,15 +6,16 @@ import { ...@@ -6,15 +6,16 @@ import {
} from '@heroicons/react/24/solid' } from '@heroicons/react/24/solid'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import CSVReader from './csv-reader' import CSVReader from './csv-reader'
import CSVDownload from './csv-download'
import Button from '@/app/components/base/button' import Button from '@/app/components/base/button'
export type IRunBatchProps = { export type IRunBatchProps = {
inputs: Record<string, any> vars: { name: string }[]
onSend: () => void onSend: () => void
} }
const RunBatch: FC<IRunBatchProps> = ({ const RunBatch: FC<IRunBatchProps> = ({
inputs, vars,
onSend, onSend,
}) => { }) => {
const { t } = useTranslation() const { t } = useTranslation()
...@@ -23,11 +24,13 @@ const RunBatch: FC<IRunBatchProps> = ({ ...@@ -23,11 +24,13 @@ const RunBatch: FC<IRunBatchProps> = ({
const [isParsed, setIsParsed] = React.useState(false) const [isParsed, setIsParsed] = React.useState(false)
const handleParsed = (data: string[][]) => { const handleParsed = (data: string[][]) => {
setCsvData(data) setCsvData(data)
console.log(data)
setIsParsed(true) setIsParsed(true)
} }
return ( return (
<div> <div>
<CSVReader onParsed={handleParsed} /> <CSVReader onParsed={handleParsed} />
<CSVDownload vars={vars} />
<Button <Button
type="primary" type="primary"
......
...@@ -46,6 +46,7 @@ const translation = { ...@@ -46,6 +46,7 @@ const translation = {
copy: 'Copy', copy: 'Copy',
resultTitle: 'AI Completion', resultTitle: 'AI Completion',
noData: 'AI will give you what you want here.', noData: 'AI will give you what you want here.',
downloadTemplate: 'Download the template here',
}, },
} }
......
...@@ -42,6 +42,7 @@ const translation = { ...@@ -42,6 +42,7 @@ const translation = {
copy: '拷贝', copy: '拷贝',
resultTitle: 'AI 书写', resultTitle: 'AI 书写',
noData: 'AI 会在这里给你惊喜。', noData: 'AI 会在这里给你惊喜。',
downloadTemplate: '下载模板',
}, },
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment