mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
fixes csv export of saved searches that have _source field (#43123)
* fixes csv export of saved searches that have _source field * adding test
This commit is contained in:
parent
d205f1e456
commit
142897fbc5
2 changed files with 16 additions and 2 deletions
|
@ -11,7 +11,16 @@ describe('formatCsvValues', function () {
|
|||
const separator = ',';
|
||||
const fields = ['foo', 'bar'];
|
||||
const mockEscapeValue = val => val;
|
||||
|
||||
describe('with _source as one of the fields', function () {
|
||||
const formatsMap = new Map();
|
||||
const formatCsvValues = createFormatCsvValues(mockEscapeValue, separator, ['foo', '_source'], formatsMap);
|
||||
it('should return full _source for _source field', function () {
|
||||
const values = {
|
||||
foo: 'baz',
|
||||
};
|
||||
expect(formatCsvValues(values)).to.be('baz,{"foo":"baz"}');
|
||||
});
|
||||
});
|
||||
describe('without field formats', function () {
|
||||
const formatsMap = new Map();
|
||||
const formatCsvValues = createFormatCsvValues(mockEscapeValue, separator, fields, formatsMap);
|
||||
|
|
|
@ -10,7 +10,12 @@ export function createFormatCsvValues(escapeValue, separator, fields, formatsMap
|
|||
return function formatCsvValues(values) {
|
||||
return fields
|
||||
.map(field => {
|
||||
const value = values[field];
|
||||
let value;
|
||||
if (field === '_source') {
|
||||
value = values;
|
||||
} else {
|
||||
value = values[field];
|
||||
}
|
||||
if (isNull(value) || isUndefined(value)) {
|
||||
return '';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue