Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[7.3] Export saved objects based on search criteria (#44723)" #45140

Merged
merged 1 commit into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 } from '../objects_table';
import { ObjectsTable, POSSIBLE_TYPES } from '../objects_table';
import { Flyout } from '../components/flyout/';
import { Relationships } from '../components/relationships/';
import { findObjects } from '../../../lib';
Expand Down Expand Up @@ -57,6 +57,10 @@ 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 @@ -316,7 +320,7 @@ describe('ObjectsTable', () => {
});

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

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

await component.instance().onExportAll();

expect(fetchExportObjects).toHaveBeenCalledWith(allSavedObjects.map(so => ({ type: so.type, id: so.id })), true);
expect(fetchExportByType).toHaveBeenCalledWith(POSSIBLE_TYPES, 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,6 +39,10 @@ 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,6 +58,7 @@ import {
getRelationships,
getSavedObjectLabel,
fetchExportObjects,
fetchExportByType,
findObjects,
} from '../../lib';
import { FormattedMessage, injectI18n } from '@kbn/i18n/react';
Expand Down Expand Up @@ -302,14 +303,20 @@ class ObjectsTableUI extends Component {

onExportAll = async () => {
const { intl } = this.props;

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

const exportObjects = savedObjects.filter(so => exportAllSelectedOptions[so.type]).map(so => ({ type: so.type, id: so.id }));
const { exportAllSelectedOptions, isIncludeReferencesDeepChecked } = this.state;
const exportTypes = Object.entries(exportAllSelectedOptions).reduce(
(accum, [id, selected]) => {
if (selected) {
accum.push(id);
}
return accum;
},
[]
);

let blob;
try {
blob = await fetchExportObjects(exportObjects, isIncludeReferencesDeepChecked);
blob = await fetchExportByType(exportTypes, isIncludeReferencesDeepChecked);
} catch (e) {
toastNotifications.addDanger({
title: intl.formatMessage({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { kfetch } from 'ui/kfetch';

export async function fetchExportByType(types, includeReferencesDeep = false) {
return await kfetch({
method: 'POST',
pathname: '/api/saved_objects/_export',
body: JSON.stringify({
type: types,
includeReferencesDeep,
}),
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* 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