Skip to content

Commit

Permalink
Export saved objects based on search criteria (#44723) (#45003)
Browse files Browse the repository at this point in the history
* export all saved objects returned from search, not all saved objects that exist

* remove unused mock
  • Loading branch information
legrego authored Sep 6, 2019
1 parent c2aea56 commit 3f4d6e5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import React from 'react';
import { shallowWithIntl } from 'test_utils/enzyme_helpers';

import { ObjectsTable, POSSIBLE_TYPES } from '../objects_table';
import { ObjectsTable } from '../objects_table';
import { Flyout } from '../components/flyout/';
import { Relationships } from '../components/relationships/';
import { findObjects } from '../../../lib';
Expand Down Expand Up @@ -57,10 +57,6 @@ jest.mock('../../../lib/fetch_export_objects', () => ({
fetchExportObjects: jest.fn(),
}));

jest.mock('../../../lib/fetch_export_by_type', () => ({
fetchExportByType: jest.fn(),
}));

jest.mock('../../../lib/get_saved_object_counts', () => ({
getSavedObjectCounts: jest.fn().mockImplementation(() => {
return {
Expand Down Expand Up @@ -318,7 +314,7 @@ describe('ObjectsTable', () => {
});

it('should export all', async () => {
const { fetchExportByType } = require('../../../lib/fetch_export_by_type');
const { fetchExportObjects } = require('../../../lib/fetch_export_objects');
const { saveAs } = require('@elastic/filesaver');
const component = shallowWithIntl(
<ObjectsTable.WrappedComponent
Expand All @@ -333,11 +329,11 @@ describe('ObjectsTable', () => {

// Set up mocks
const blob = new Blob([JSON.stringify(allSavedObjects)], { type: 'application/ndjson' });
fetchExportByType.mockImplementation(() => blob);
fetchExportObjects.mockImplementation(() => blob);

await component.instance().onExportAll();

expect(fetchExportByType).toHaveBeenCalledWith(POSSIBLE_TYPES, true);
expect(fetchExportObjects).toHaveBeenCalledWith(allSavedObjects.map(so => ({ type: so.type, id: so.id })), true);
expect(saveAs).toHaveBeenCalledWith(blob, 'export.ndjson');
expect(addSuccessMock).toHaveBeenCalledWith({ title: 'Your file is downloading in the background' });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ jest.mock('ui/chrome', () => ({
addBasePath: () => ''
}));

jest.mock('../../../../../lib/fetch_export_by_type', () => ({
fetchExportByType: jest.fn(),
}));

jest.mock('../../../../../lib/fetch_export_objects', () => ({
fetchExportObjects: jest.fn(),
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ import {
getRelationships,
getSavedObjectLabel,
fetchExportObjects,
fetchExportByType,
findObjects,
} from '../../lib';
import { FormattedMessage, injectI18n } from '@kbn/i18n/react';
Expand Down Expand Up @@ -303,20 +302,14 @@ class ObjectsTableUI extends Component {

onExportAll = async () => {
const { intl } = this.props;
const { exportAllSelectedOptions, isIncludeReferencesDeepChecked } = this.state;
const exportTypes = Object.entries(exportAllSelectedOptions).reduce(
(accum, [id, selected]) => {
if (selected) {
accum.push(id);
}
return accum;
},
[]
);

const { exportAllSelectedOptions, isIncludeReferencesDeepChecked, savedObjects } = this.state;

const exportObjects = savedObjects.filter(so => exportAllSelectedOptions[so.type]).map(so => ({ type: so.type, id: so.id }));

let blob;
try {
blob = await fetchExportByType(exportTypes, isIncludeReferencesDeepChecked);
blob = await fetchExportObjects(exportObjects, isIncludeReferencesDeepChecked);
} catch (e) {
toastNotifications.addDanger({
title: intl.formatMessage({
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/

export * from './fetch_export_by_type';
export * from './fetch_export_objects';
export * from './in_app_url';
export * from './get_relationships';
Expand Down

0 comments on commit 3f4d6e5

Please sign in to comment.