Merge pull request #4911 from Budibase/pc/csv-bug-fix
fix button action export for csv
This commit is contained in:
commit
84d28f85ad
|
@ -250,9 +250,9 @@ const exportDataHandler = async action => {
|
||||||
const data = await API.exportRows({
|
const data = await API.exportRows({
|
||||||
tableId: selection.tableId,
|
tableId: selection.tableId,
|
||||||
rows: selection.selectedRows,
|
rows: selection.selectedRows,
|
||||||
|
format: action.parameters.type,
|
||||||
})
|
})
|
||||||
|
download(data, `${selection.tableId}.${action.parameters.type}`)
|
||||||
download(JSON.stringify(data), `export.${action.parameters.type}`)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
notificationStore.actions.error("There was an error exporting the data")
|
notificationStore.actions.error("There was an error exporting the data")
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,12 +66,15 @@ export const buildRowEndpoints = API => ({
|
||||||
* @param tableId the table ID to export the rows from
|
* @param tableId the table ID to export the rows from
|
||||||
* @param rows the array of rows to export
|
* @param rows the array of rows to export
|
||||||
*/
|
*/
|
||||||
exportRows: async ({ tableId, rows }) => {
|
exportRows: async ({ tableId, rows, format }) => {
|
||||||
return await API.post({
|
return await API.post({
|
||||||
url: `/api/${tableId}/rows/exportRows`,
|
url: `/api/${tableId}/rows/exportRows?format=${format}`,
|
||||||
body: {
|
body: {
|
||||||
rows,
|
rows,
|
||||||
},
|
},
|
||||||
|
parseResponse: async response => {
|
||||||
|
return await response.text()
|
||||||
|
},
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -10,6 +10,8 @@ const {
|
||||||
} = require("../../../integrations/utils")
|
} = require("../../../integrations/utils")
|
||||||
const ExternalRequest = require("./ExternalRequest")
|
const ExternalRequest = require("./ExternalRequest")
|
||||||
const { getAppDB } = require("@budibase/backend-core/context")
|
const { getAppDB } = require("@budibase/backend-core/context")
|
||||||
|
const exporters = require("../view/exporters")
|
||||||
|
const { apiFileReturn } = require("../../../utilities/fileSystem")
|
||||||
|
|
||||||
async function handleRequest(operation, tableId, opts = {}) {
|
async function handleRequest(operation, tableId, opts = {}) {
|
||||||
// make sure the filters are cleaned up, no empty strings for equals, fuzzy or string
|
// make sure the filters are cleaned up, no empty strings for equals, fuzzy or string
|
||||||
|
@ -155,6 +157,7 @@ exports.validate = async () => {
|
||||||
exports.exportRows = async ctx => {
|
exports.exportRows = async ctx => {
|
||||||
const { datasourceId, tableName } = breakExternalTableId(ctx.params.tableId)
|
const { datasourceId, tableName } = breakExternalTableId(ctx.params.tableId)
|
||||||
const db = getAppDB()
|
const db = getAppDB()
|
||||||
|
let format = ctx.query.format
|
||||||
const datasource = await db.get(datasourceId)
|
const datasource = await db.get(datasourceId)
|
||||||
if (!datasource || !datasource.entities) {
|
if (!datasource || !datasource.entities) {
|
||||||
ctx.throw(400, "Datasource has not been configured for plus API.")
|
ctx.throw(400, "Datasource has not been configured for plus API.")
|
||||||
|
@ -164,13 +167,22 @@ exports.exportRows = async ctx => {
|
||||||
ctx.request.body = {
|
ctx.request.body = {
|
||||||
query: {
|
query: {
|
||||||
oneOf: {
|
oneOf: {
|
||||||
[table.primaryDisplay]: ctx.request.body.map(
|
[table.primaryDisplay]: ctx.request.body.rows.map(
|
||||||
id => breakRowIdField(id)[0]
|
id => breakRowIdField(id)[0]
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return exports.search(ctx)
|
|
||||||
|
let result = await exports.search(ctx)
|
||||||
|
|
||||||
|
let headers = Object.keys(result.rows[0])
|
||||||
|
const exporter = exporters[format]
|
||||||
|
const filename = `export.${format}`
|
||||||
|
|
||||||
|
// send down the file
|
||||||
|
ctx.attachment(filename)
|
||||||
|
return apiFileReturn(exporter(headers, result.rows))
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.fetchEnrichedRow = async ctx => {
|
exports.fetchEnrichedRow = async ctx => {
|
||||||
|
|
|
@ -27,6 +27,8 @@ const {
|
||||||
const { cloneDeep } = require("lodash/fp")
|
const { cloneDeep } = require("lodash/fp")
|
||||||
const { getAppDB } = require("@budibase/backend-core/context")
|
const { getAppDB } = require("@budibase/backend-core/context")
|
||||||
const { finaliseRow, updateRelatedFormula } = require("./staticFormula")
|
const { finaliseRow, updateRelatedFormula } = require("./staticFormula")
|
||||||
|
const exporters = require("../view/exporters")
|
||||||
|
const { apiFileReturn } = require("../../../utilities/fileSystem")
|
||||||
|
|
||||||
const CALCULATION_TYPES = {
|
const CALCULATION_TYPES = {
|
||||||
SUM: "sum",
|
SUM: "sum",
|
||||||
|
@ -366,6 +368,7 @@ exports.exportRows = async ctx => {
|
||||||
const db = getAppDB()
|
const db = getAppDB()
|
||||||
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 response = (
|
let response = (
|
||||||
await db.allDocs({
|
await db.allDocs({
|
||||||
include_docs: true,
|
include_docs: true,
|
||||||
|
@ -375,7 +378,13 @@ exports.exportRows = async ctx => {
|
||||||
|
|
||||||
let rows = await outputProcessing(table, response)
|
let rows = await outputProcessing(table, response)
|
||||||
|
|
||||||
return rows
|
let headers = Object.keys(rows[0])
|
||||||
|
const exporter = exporters[format]
|
||||||
|
const filename = `export.${format}`
|
||||||
|
|
||||||
|
// send down the file
|
||||||
|
ctx.attachment(filename)
|
||||||
|
return apiFileReturn(exporter(headers, rows))
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.fetchEnrichedRow = async ctx => {
|
exports.fetchEnrichedRow = async ctx => {
|
||||||
|
|
Loading…
Reference in New Issue