Browse Source

Merge pull request #3383 from nocodb/fix/gui-v2-export-csv

fix(gui-v2): include fields, sortArrJson, and filterArrJson when extracting CSV data
pull/3387/head
աɨռɢӄաօռɢ 2 years ago committed by GitHub
parent
commit
b64f77e590
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      packages/nc-gui-v2/components/smartsheet-toolbar/ExportSubActions.vue
  2. 5
      packages/nc-gui-v2/components/smartsheet-toolbar/MoreActions.vue
  3. 2
      packages/nocodb-sdk/package.json
  4. 23
      packages/nocodb/src/lib/meta/api/dataApis/helpers.ts

6
packages/nc-gui-v2/components/smartsheet-toolbar/ExportSubActions.vue

@ -5,6 +5,7 @@ import * as XLSX from 'xlsx'
import { message } from 'ant-design-vue'
const isPublicView = inject(IsPublicInj, ref(false))
const fields = inject(FieldsInj, ref([]))
const { project } = useProject()
@ -15,6 +16,8 @@ const meta = inject(MetaInj)
const selectedView = inject(ActiveViewInj)
const { sorts, nestedFilters } = useSmartsheetStoreOrThrow()
const exportFile = async (exportType: ExportTypes) => {
let offset = 0
let c = 1
@ -36,7 +39,10 @@ const exportFile = async (exportType: ExportTypes) => {
{
responseType,
query: {
fields: fields.value.map((field) => field.title),
offset,
sortArrJson: JSON.stringify(sorts.value),
filterArrJson: JSON.stringify(nestedFilters.value),
},
} as any,
)

5
packages/nc-gui-v2/components/smartsheet-toolbar/MoreActions.vue

@ -33,6 +33,8 @@ const fields = inject(FieldsInj, ref([]))
const selectedView = inject(ActiveViewInj)
const { sorts, nestedFilters } = useSmartsheetStoreOrThrow()
const isLocked = inject(IsLockedInj)
const showWebhookDrawer = ref(false)
@ -62,7 +64,10 @@ const exportFile = async (exportType: ExportTypes) => {
{
responseType,
query: {
fields: fields.value.map((field) => field.title),
offset,
sortArrJson: JSON.stringify(sorts.value),
filterArrJson: JSON.stringify(nestedFilters.value),
},
} as any,
)

2
packages/nocodb-sdk/package.json

@ -9,7 +9,7 @@
"license": "MIT",
"keywords": [],
"scripts": {
"preinstall": "npx npm-force-resolutions",
"preinstall": "npm install --package-lock-only --ignore-scripts && npx npm-force-resolutions",
"build": "npm run generate:sdk && run-p build:*",
"build:main": "tsc -p tsconfig.json",
"build:module": "tsc -p tsconfig.module.json",

23
packages/nocodb/src/lib/meta/api/dataApis/helpers.ts

@ -65,6 +65,7 @@ export async function extractXlsxData(view: View, req: Request) {
export async function extractCsvData(view: View, req: Request) {
const base = await Base.get(view.base_id);
const fields = req.query.fields;
await view.getModelWithInfo();
await view.getColumns();
@ -87,7 +88,17 @@ export async function extractCsvData(view: View, req: Request) {
const data = papaparse.unparse(
{
fields: view.model.columns.map((c) => c.title),
fields: view.model.columns
.sort((c1, c2) =>
Array.isArray(fields)
? fields.indexOf(c1.title as any) - fields.indexOf(c2.title as any)
: 0
)
.filter(
(c) =>
!fields || !Array.isArray(fields) || fields.includes(c.title as any)
)
.map((c) => c.title),
data: dbRows,
},
{
@ -107,6 +118,14 @@ async function getDbRows(baseModel, view: View, req: Request) {
const startTime = process.hrtime();
let elapsed, temp;
const listArgs: any = { ...req.query };
try {
listArgs.filterArr = JSON.parse(listArgs.filterArrJson);
} catch (e) {}
try {
listArgs.sortArr = JSON.parse(listArgs.sortArrJson);
} catch (e) {}
for (
elapsed = 0;
elapsed < timeout;
@ -121,7 +140,7 @@ async function getDbRows(baseModel, view: View, req: Request) {
model: view.model,
view,
}),
await baseModel.list({ ...req.query, offset, limit }),
await baseModel.list({ ...listArgs, offset, limit }),
{},
req.query
);

Loading…
Cancel
Save