Browse Source

fix: excel import, postgres option add bug

re #326

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/925/head
Pranav C 3 years ago
parent
commit
e43430b148
  1. 24
      packages/nc-gui/components/import/templateParsers/ExcelTemplateAdapter.js
  2. 2
      packages/nc-gui/components/project/spreadsheet/components/cell/setListCell.vue
  3. 27514
      packages/nocodb/package-lock.json
  4. 3
      packages/nocodb/package.json

24
packages/nc-gui/components/import/templateParsers/ExcelTemplateAdapter.js

@ -83,30 +83,28 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
) {
column.uidt = UITypes.LongText
} else {
let vals = rows.slice(columnNameRowExist ? 1 : 0).map(r => r[col])
const vals = rows.slice(columnNameRowExist ? 1 : 0).map(r => r[col]).filter(v => v !== null && v !== undefined && v.toString().trim() !== '')
const checkboxType = isCheckboxType(vals)
if (checkboxType.length === 1) {
column.uidt = UITypes.Checkbox
} else {
// todo: optimize
vals = vals.filter(v => v !== null && v !== undefined).map(v => v.toString().trim())
.filter((v, i, arr) => i === arr.findIndex(v1 => v.toLowerCase() === v1.toLowerCase()))
// check column is multi or single select by comparing unique values
// todo:
if (vals.some(v => v && v.toString().includes(','))) {
const flattenedVals = vals.flatMap(v => v ? v.toString().trim().split(/\s*,\s*/) : [])
const uniqueVals = new Set(flattenedVals)
if (flattenedVals.length > uniqueVals.size && uniqueVals.size <= Math.ceil(flattenedVals.length / 2)) {
let flattenedVals = vals.flatMap(v => v ? v.toString().trim().split(/\s*,\s*/) : [])
const uniqueVals = flattenedVals = flattenedVals
.filter((v, i, arr) => i === arr.findIndex(v1 => v.toLowerCase() === v1.toLowerCase()))
if (flattenedVals.length > uniqueVals.length && uniqueVals.length <= Math.ceil(flattenedVals.length / 2)) {
column.uidt = UITypes.MultiSelect
column.dtxp = `'${[...uniqueVals].join("','")}'`
column.dtxp = `'${uniqueVals.join("','")}'`
}
} else {
const uniqueVals = new Set(vals)
if (vals.length > uniqueVals.size && uniqueVals.size <= Math.ceil(vals.length / 2)) {
const uniqueVals = vals.map(v => v.toString().trim()).filter((v, i, arr) => i === arr.findIndex(v1 => v.toLowerCase() === v1.toLowerCase()))
if (vals.length > uniqueVals.length && uniqueVals.length <= Math.ceil(vals.length / 2)) {
column.uidt = UITypes.SingleSelect
column.dtxp = `'${[...uniqueVals].join("','")}'`
column.dtxp = `'${uniqueVals.join("','")}'`
}
}
}
@ -151,8 +149,6 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
if (table.columns[i].uidt === UITypes.Checkbox) {
rowData[table.columns[i].cn] = getCheckboxValue(row[i])
} else if (table.columns[i].uidt === UITypes.Currency) {
console.log(table.columns[i], table.columns[i].uidt === UITypes.Currency)
const cellId = XLSX.utils.encode_cell({
c: range.s.c + i,
r: rowIndex + columnNameRowExist
@ -160,6 +156,8 @@ export default class ExcelTemplateAdapter extends TemplateGenerator {
const cellObj = ws[cellId]
rowData[table.columns[i].cn] = (cellObj && cellObj.w && cellObj.w.replace(/[^\d.]+/g, '')) || row[i]
} else if (table.columns[i].uidt === UITypes.SingleSelect || table.columns[i].uidt === UITypes.MultiSelect) {
rowData[table.columns[i].cn] = (row[i] || '').toString().trim() || null
} else {
// toto: do parsing if necessary based on type
rowData[table.columns[i].cn] = row[i]

2
packages/nc-gui/components/project/spreadsheet/components/cell/setListCell.vue

@ -2,6 +2,7 @@
<div>
<v-chip
v-for="v in (value || '').split(',')"
v-show="v || setValues.includes(v)"
:key="v"
small
:color="colors[setValues.indexOf(v) % colors.length]"
@ -20,7 +21,6 @@ export default {
mixins: [colors],
props: ['value', 'column'],
computed: {
setValues() {
if (this.column && this.column.dtxp) {
return this.column.dtxp.split(',').map(v => v.replace(/\\'/g, '\'').replace(/^'|'$/g, ''))

27514
packages/nocodb/package-lock.json generated

File diff suppressed because it is too large Load Diff

3
packages/nocodb/package.json

@ -147,7 +147,7 @@
"mysql2": "^2.2.5",
"nanoid": "^3.1.20",
"nc-common": "0.0.6",
"nc-help": "^0.2.18",
"nc-help": "^0.2.22",
"nc-lib-gui": "0.84.1",
"nc-plugin": "^0.1.1",
"ncp": "^2.0.0",
@ -225,7 +225,6 @@
"webpack-node-externals": "^2.5.2",
"webpack-obfuscator": "^1.12.0"
},
"peerDependencies": {},
"ava": {
"failFast": true,
"files": [

Loading…
Cancel
Save