1
0
Fork 0
mirror of synced 2024-09-08 05:31:47 +12:00

Export undefineds as empty values in csv, instead of empty strings

This commit is contained in:
Adria Navarro 2023-04-25 12:34:50 +01:00
parent 5b4b3b6fd1
commit 608a38489f
3 changed files with 9 additions and 4 deletions

View file

@ -37,7 +37,7 @@ import {
Table,
} from "@budibase/types"
const { cleanExportRows } = require("./utils")
import { cleanExportRows } from "./utils"
const CALCULATION_TYPES = {
SUM: "sum",
@ -391,6 +391,9 @@ export async function exportRows(ctx: UserCtx) {
const table = await db.get(ctx.params.tableId)
const rowIds = ctx.request.body.rows
let format = ctx.query.format
if (typeof format !== "string") {
ctx.throw(400, "Format parameter is not valid")
}
const { columns, query } = ctx.request.body
let result

View file

@ -137,8 +137,8 @@ export function cleanExportRows(
delete schema[column]
})
// Intended to avoid 'undefined' in export
if (format === Format.CSV) {
// Intended to append empty values in export
const schemaKeys = Object.keys(schema)
for (let key of schemaKeys) {
if (columns?.length && columns.indexOf(key) > 0) {
@ -146,7 +146,7 @@ export function cleanExportRows(
}
for (let row of cleanRows) {
if (row[key] == null) {
row[key] = ""
row[key] = undefined
}
}
}

View file

@ -10,7 +10,9 @@ export function csv(headers: string[], rows: Row[]) {
val =
typeof val === "object" && !(val instanceof Date)
? `"${JSON.stringify(val).replace(/"/g, "'")}"`
: `"${val}"`
: val !== undefined
? `"${val}"`
: ""
return val.trim()
})
.join(",")}`