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, meta: Object,
nodes: Object, nodes: Object,
selectedView: Object, selectedView: Object,
publicViewId: String publicViewId: String,
queryParams: Object
}, },
methods: { methods: {
@ -162,6 +163,7 @@ export default {
this.publicViewId ? 'sharedViewExportAsCsv' : 'xcExportAsCsv', this.publicViewId ? 'sharedViewExportAsCsv' : 'xcExportAsCsv',
{ {
query: { offset }, query: { offset },
localQuery: this.queryParams || {},
...(this.publicViewId ...(this.publicViewId
? { ? {
view_id: 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" /> <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> <!-- <v-menu>
<template #activator="{ on, attrs }"> <template #activator="{ on, attrs }">
@ -187,6 +187,7 @@
</template> </template>
<script> <script>
/* eslint-disable camelcase */
import spreadsheet from '../mixins/spreadsheet' import spreadsheet from '../mixins/spreadsheet'
import ApiFactory from '../apis/apiFactory' 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( return this.xcExportAsCsv(
{ {
...sharedViewMeta, ...sharedViewMeta,
args: { ...sharedViewMeta, offset: 0 } args: { ...args.args, ...sharedViewMeta }
}, },
_req, _req,
res res
@ -4019,8 +4019,25 @@ export default class NcMetaMgr {
} }
); );
const localQuery = args.args.localQuery;
const queryParams = JSON.parse(selectedView.query_params); 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( const csvData = await model.extractCsvData(
{ {
@ -4029,12 +4046,12 @@ export default class NcMetaMgr {
.filter(c => queryParams?.showFields?.[c._cn]) .filter(c => queryParams?.showFields?.[c._cn])
.map(c => c._cn) .map(c => c._cn)
.join(','), .join(','),
sort: sort, sort,
where: this.serializeToXwhere(queryParams?.filters), where,
...this.serializeNestedParams(meta, queryParams) ...this.serializeNestedParams(meta, queryParams)
}, },
// filter only visible columns // filter only visible columns
Object.entries(queryParams?.showFields || {}) Object.entries(localQuery?.showFields || queryParams?.showFields || {})
.filter(v => v[1]) .filter(v => v[1])
.map(v => v[0]) .map(v => v[0])
.sort( .sort(
@ -4057,7 +4074,7 @@ export default class NcMetaMgr {
}; };
} }
private serializeSortParam(queryParams) { private serializeSortParam(queryParams, returnArray = false) {
const sort = []; const sort = [];
if (queryParams.sortList) { if (queryParams.sortList) {
sort.push( sort.push(
@ -4068,6 +4085,7 @@ export default class NcMetaMgr {
.filter(Boolean) || []) .filter(Boolean) || [])
); );
} }
if (returnArray) return sort;
return sort.join(','); return sort.join(',');
} }

Loading…
Cancel
Save