Browse Source

fix: apply shared view fields,filters and sort in csv export

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/743/head
Pranav C 3 years ago
parent
commit
d5814e4c31
  1. 4
      packages/nc-gui/components/project/spreadsheet/components/csvExport.vue
  2. 3
      packages/nc-gui/components/project/spreadsheet/public/xcTable.vue
  3. 30
      packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

4
packages/nc-gui/components/project/spreadsheet/components/csvExport.vue

@ -65,7 +65,8 @@ export default {
meta: Object,
nodes: Object,
selectedView: Object,
publicViewId: String
publicViewId: String,
queryParams: Object
},
methods: {
@ -162,6 +163,7 @@ export default {
this.publicViewId ? 'sharedViewExportAsCsv' : 'xcExportAsCsv',
{
query: { offset },
localQuery: this.queryParams || {},
...(this.publicViewId
? {
view_id: this.publicViewId

3
packages/nc-gui/components/project/spreadsheet/public/xcTable.vue

@ -91,7 +91,7 @@
<column-filter-menu v-model="filters" :field-list="realFieldList" />
<csv-export :public-view-id="$route.params.id" :meta="meta" />
<csv-export :query-params="{...queryParams, showFields}" :public-view-id="$route.params.id" :meta="meta" />
<!-- <v-menu>
<template #activator="{ on, attrs }">
@ -187,6 +187,7 @@
</template>
<script>
/* eslint-disable camelcase */
import spreadsheet from '../mixins/spreadsheet'
import ApiFactory from '../apis/apiFactory'

30
packages/nocodb/src/lib/noco/meta/NcMetaMgr.ts

@ -3870,7 +3870,7 @@ export default class NcMetaMgr {
return this.xcExportAsCsv(
{
...sharedViewMeta,
args: { ...sharedViewMeta, offset: 0 }
args: { ...args.args, ...sharedViewMeta }
},
_req,
res
@ -4019,8 +4019,25 @@ export default class NcMetaMgr {
}
);
const localQuery = args.args.localQuery;
const queryParams = JSON.parse(selectedView.query_params);
const sort = this.serializeSortParam(queryParams);
let sort = this.serializeSortParam(queryParams);
let where = '';
if (localQuery.sort) {
sort = localQuery.sort;
}
if (localQuery.where) {
where += localQuery.where;
}
const privateViewFilter = this.serializeToXwhere(queryParams?.filters);
if (privateViewFilter) {
where += where ? `~and(${privateViewFilter})` : privateViewFilter;
}
const csvData = await model.extractCsvData(
{
@ -4029,12 +4046,12 @@ export default class NcMetaMgr {
.filter(c => queryParams?.showFields?.[c._cn])
.map(c => c._cn)
.join(','),
sort: sort,
where: this.serializeToXwhere(queryParams?.filters),
sort,
where,
...this.serializeNestedParams(meta, queryParams)
},
// filter only visible columns
Object.entries(queryParams?.showFields || {})
Object.entries(localQuery?.showFields || queryParams?.showFields || {})
.filter(v => v[1])
.map(v => v[0])
.sort(
@ -4057,7 +4074,7 @@ export default class NcMetaMgr {
};
}
private serializeSortParam(queryParams) {
private serializeSortParam(queryParams, returnArray = false) {
const sort = [];
if (queryParams.sortList) {
sort.push(
@ -4068,6 +4085,7 @@ export default class NcMetaMgr {
.filter(Boolean) || [])
);
}
if (returnArray) return sort;
return sort.join(',');
}

Loading…
Cancel
Save