Skip to content

Commit

Permalink
Export files are generated depending on visible columns of data brows…
Browse files Browse the repository at this point in the history
…er and they include _id. (#415)
  • Loading branch information
l0l3r authored Sep 10, 2021
1 parent 1fe9000 commit 3ac8a47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions packages/browser/src/components/DataBrowser/ExportData.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { connect } from 'react-redux';
import { unparse } from 'papaparse';
import { saveAs } from 'file-saver';

import { getIndexTypeMap } from '../../reducers/mappings';
import { getIndexTypeMap, getVisibleColumns } from '../../reducers/mappings';
import { getUrl } from '../../reducers/app';
import { getVersion } from '../../reducers/version';
import { addDataRequest } from '../../actions';
Expand Down Expand Up @@ -54,6 +54,7 @@ type Props = {
indexTypeMap: any,
stats: any,
query: any,
visibleColumns: any,
};

type State = {
Expand Down Expand Up @@ -204,9 +205,14 @@ class ExportData extends Component<Props, State> {
selectedType,
applyCurrentQuery,
} = this.state;
let visibleColumns = this.props.visibleColumns;
visibleColumns.push("_id");
const res = await this.fetchData();
const flattenData = res.map(item => flatten(item));
const newData = unparse(flattenData);
const newData = unparse({
fields: visibleColumns,
data: flattenData
});
const file = new File(
[newData],
`data_${selectedIndex}${
Expand Down Expand Up @@ -470,6 +476,7 @@ const mapStateToProps = state => ({
indexTypeMap: getIndexTypeMap(state),
stats: getStats(state),
query: getQuery(state),
visibleColumns: getVisibleColumns(state),
});

const mapDispatchToProps = {
Expand Down
1 change: 1 addition & 0 deletions packages/browser/src/utils/exportData.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const searchAfter = async (
const lastObject = exportData[exportData.length - 1];
exportData = exportData.map(value => {
const item = Object.assign(value._source);
item['_id'] = value._id;
return item;
});

Expand Down

0 comments on commit 3ac8a47

Please sign in to comment.