Export undefineds as empty values in csv, instead of empty strings
This commit is contained in:
parent
5b4b3b6fd1
commit
608a38489f
|
@ -37,7 +37,7 @@ import {
|
||||||
Table,
|
Table,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
const { cleanExportRows } = require("./utils")
|
import { cleanExportRows } from "./utils"
|
||||||
|
|
||||||
const CALCULATION_TYPES = {
|
const CALCULATION_TYPES = {
|
||||||
SUM: "sum",
|
SUM: "sum",
|
||||||
|
@ -391,6 +391,9 @@ export async function exportRows(ctx: UserCtx) {
|
||||||
const table = await db.get(ctx.params.tableId)
|
const table = await db.get(ctx.params.tableId)
|
||||||
const rowIds = ctx.request.body.rows
|
const rowIds = ctx.request.body.rows
|
||||||
let format = ctx.query.format
|
let format = ctx.query.format
|
||||||
|
if (typeof format !== "string") {
|
||||||
|
ctx.throw(400, "Format parameter is not valid")
|
||||||
|
}
|
||||||
const { columns, query } = ctx.request.body
|
const { columns, query } = ctx.request.body
|
||||||
|
|
||||||
let result
|
let result
|
||||||
|
|
|
@ -137,8 +137,8 @@ export function cleanExportRows(
|
||||||
delete schema[column]
|
delete schema[column]
|
||||||
})
|
})
|
||||||
|
|
||||||
// Intended to avoid 'undefined' in export
|
|
||||||
if (format === Format.CSV) {
|
if (format === Format.CSV) {
|
||||||
|
// Intended to append empty values in export
|
||||||
const schemaKeys = Object.keys(schema)
|
const schemaKeys = Object.keys(schema)
|
||||||
for (let key of schemaKeys) {
|
for (let key of schemaKeys) {
|
||||||
if (columns?.length && columns.indexOf(key) > 0) {
|
if (columns?.length && columns.indexOf(key) > 0) {
|
||||||
|
@ -146,7 +146,7 @@ export function cleanExportRows(
|
||||||
}
|
}
|
||||||
for (let row of cleanRows) {
|
for (let row of cleanRows) {
|
||||||
if (row[key] == null) {
|
if (row[key] == null) {
|
||||||
row[key] = ""
|
row[key] = undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,9 @@ export function csv(headers: string[], rows: Row[]) {
|
||||||
val =
|
val =
|
||||||
typeof val === "object" && !(val instanceof Date)
|
typeof val === "object" && !(val instanceof Date)
|
||||||
? `"${JSON.stringify(val).replace(/"/g, "'")}"`
|
? `"${JSON.stringify(val).replace(/"/g, "'")}"`
|
||||||
: `"${val}"`
|
: val !== undefined
|
||||||
|
? `"${val}"`
|
||||||
|
: ""
|
||||||
return val.trim()
|
return val.trim()
|
||||||
})
|
})
|
||||||
.join(",")}`
|
.join(",")}`
|
||||||
|
|
Loading…
Reference in New Issue