Browse Source

feat(nc-gui): cover old logic for non streaming import

pull/4135/head
Wing-Kam Wong 2 years ago
parent
commit
bed7495a67
  1. 66
      packages/nc-gui/components/dlg/QuickImport.vue

66
packages/nc-gui/components/dlg/QuickImport.vue

@ -22,6 +22,7 @@ import {
useProject, useProject,
useVModel, useVModel,
} from '#imports' } from '#imports'
import type { importFileList, streamImportFileList } from '~/lib'
interface Props { interface Props {
modelValue: boolean modelValue: boolean
@ -60,9 +61,7 @@ const isParsingData = ref(false)
const useForm = Form.useForm const useForm = Form.useForm
const importState = reactive({ const importState = reactive({
// TODO(import): remove fileList: [] as importFileList | streamImportFileList,
// fileList: [] as (UploadFile & { data: string | ArrayBuffer })[],
fileList: [] as UploadFile[],
url: '', url: '',
jsonEditor: {}, jsonEditor: {},
parserConfig: { parserConfig: {
@ -147,8 +146,11 @@ async function handlePreImport() {
isParsingData.value = true isParsingData.value = true
if (activeKey.value === 'uploadTab') { if (activeKey.value === 'uploadTab') {
// TODO(import): update if (isImportTypeCsv) {
await parseAndExtractData2(importState.fileList) await parseAndExtractStreamData(importState.fileList as streamImportFileList)
} else {
await parseAndExtractData((importState.fileList as importFileList)[0].data)
}
} else if (activeKey.value === 'urlTab') { } else if (activeKey.value === 'urlTab') {
try { try {
await validate() await validate()
@ -183,8 +185,7 @@ async function handleImport() {
dialogShow.value = false dialogShow.value = false
} }
// papaparse experiment async function parseAndExtractStreamData(val: UploadFile[]) {
async function parseAndExtractData2(val: UploadFile[]) {
try { try {
templateData.value = null templateData.value = null
importData.value = null importData.value = null
@ -248,31 +249,32 @@ function rejectDrop(fileList: UploadFile[]) {
function handleChange(info: UploadChangeParam) { function handleChange(info: UploadChangeParam) {
const status = info.file.status const status = info.file.status
if (status && status !== 'uploading' && status !== 'removed') { if (status && status !== 'uploading' && status !== 'removed') {
// const reader = new FileReader() if (isImportTypeCsv) {
// reader.onload = (e: ProgressEvent<FileReader>) => { if (!importState.fileList.find((f) => f.uid === info.file.uid)) {
// const target = importState.fileList.find((f) => f.uid === info.file.uid) ;(importState.fileList as streamImportFileList).push({
// if (e.target && e.target.result) { ...info.file,
// /** if the file was pushed into the list by `<a-upload-dragger>` we just add the data to the file */ status: 'done',
// if (target) { })
// target.data = e.target.result }
// } else if (!target) { } else {
// /** if the file was added programmatically and not with d&d, we create file infos and push it into the list */ const reader = new FileReader()
// importState.fileList.push({ reader.onload = (e: ProgressEvent<FileReader>) => {
// ...info.file, const target = (importState.fileList as importFileList).find((f) => f.uid === info.file.uid)
// status: 'done', if (e.target && e.target.result) {
// data: e.target.result, /** if the file was pushed into the list by `<a-upload-dragger>` we just add the data to the file */
// }) if (target) {
// } target.data = e.target.result
// } } else if (!target) {
// } /** if the file was added programmatically and not with d&d, we create file infos and push it into the list */
// reader.readAsArrayBuffer(info.file.originFileObj!) importState.fileList.push({
...info.file,
if (!importState.fileList.find((f) => f.uid === info.file.uid)) { status: 'done',
/** if the file was added programmatically and not with d&d, we create file infos and push it into the list */ data: e.target.result,
importState.fileList.push({ })
...info.file, }
status: 'done', }
}) }
reader.readAsArrayBuffer(info.file.originFileObj!)
} }
} }

Loading…
Cancel
Save