diff --git a/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte b/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte index 740027a8fd..0b63c0bd4d 100644 --- a/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/ExportModal.svelte @@ -18,10 +18,12 @@ let exportFormat = FORMATS[0].key async function exportView() { + const filename = `export.${exportFormat}` download( `/api/views/export?view=${encodeURIComponent( view - )}&format=${exportFormat}` + )}&format=${exportFormat}`, + filename ) } diff --git a/packages/server/src/api/controllers/view/exporters.js b/packages/server/src/api/controllers/view/exporters.js index 830aef1832..e636adb10f 100644 --- a/packages/server/src/api/controllers/view/exporters.js +++ b/packages/server/src/api/controllers/view/exporters.js @@ -3,7 +3,11 @@ exports.csv = function (headers, rows) { for (let row of rows) { csv = `${csv}\n${headers - .map(header => `"${row[header]}"`.trim()) + .map(header => { + let val = row[header] + val = typeof val === "object" ? JSON.stringify(val) : val + return `"${val}"`.trim() + }) .join(",")}` } return csv diff --git a/packages/server/src/middleware/currentapp.js b/packages/server/src/middleware/currentapp.js index 7169a36320..3c469d5874 100644 --- a/packages/server/src/middleware/currentapp.js +++ b/packages/server/src/middleware/currentapp.js @@ -10,7 +10,7 @@ const CouchDB = require("../db") module.exports = async (ctx, next) => { // try to get the appID from the request - const requestAppId = getAppId(ctx) + let requestAppId = getAppId(ctx) // get app cookie if it exists let appCookie = null try { @@ -29,6 +29,8 @@ module.exports = async (ctx, next) => { clearCookie(ctx, Cookies.CurrentApp) return next() } + // if the request app ID wasn't set, update it with the cookie + requestAppId = requestAppId || appId } let appId,