Skip to content

Commit

Permalink
Convert saved objects UI to use new import / export API (#33513) (#34802
Browse files Browse the repository at this point in the history
)

* Initial work converting UI to use new server side APIs

* Remove missed file

* Fix jest tests

* Code cleanup pt1

* Fix file casing

* Fix jest tests

* Modify UI to support including nested references

* Fix button layout

* Connect includeReferencesDeep, remove references_missing_references logic

* Fix broken tests

* Cleanup

* Display success notifications and auto close modals on export

* More code cleanup

* Log to server when user imports using legacy .json file

* Final cleanup

* Update test snapshots to match updated text

* Apply PR feedback pt1

* Remove isLoading and wasImportSuccessful state variables, use single status variable instead

* Move business logic out of flyout component

* Apply PR feedback

* Update wordings
  • Loading branch information
mikecote authored Apr 9, 2019
1 parent e0e2e28 commit abe6055
Show file tree
Hide file tree
Showing 38 changed files with 2,416 additions and 633 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { ObjectsTable, INCLUDED_TYPES } from '../objects_table';
import { Flyout } from '../components/flyout/';
import { Relationships } from '../components/relationships/';

jest.mock('ui/kfetch', () => jest.fn());

jest.mock('../components/header', () => ({
Header: () => 'Header',
}));
Expand All @@ -45,12 +47,12 @@ jest.mock('ui/chrome', () => ({
addBasePath: () => ''
}));

jest.mock('../../../lib/retrieve_and_export_docs', () => ({
retrieveAndExportDocs: jest.fn(),
jest.mock('../../../lib/fetch_export_objects', () => ({
fetchExportObjects: jest.fn(),
}));

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

jest.mock('../../../lib/get_saved_object_counts', () => ({
Expand All @@ -64,8 +66,8 @@ jest.mock('../../../lib/get_saved_object_counts', () => ({
})
}));

jest.mock('../../../lib/save_to_file', () => ({
saveToFile: jest.fn(),
jest.mock('@elastic/filesaver', () => ({
saveAs: jest.fn(),
}));

jest.mock('../../../lib/get_relationships', () => ({
Expand Down Expand Up @@ -147,6 +149,7 @@ const defaultProps = {
};

let addDangerMock;
let addSuccessMock;

describe('ObjectsTable', () => {
beforeEach(() => {
Expand All @@ -159,8 +162,10 @@ describe('ObjectsTable', () => {
return debounced;
};
addDangerMock = jest.fn();
addSuccessMock = jest.fn();
require('ui/notify').toastNotifications = {
addDanger: addDangerMock,
addSuccess: addSuccessMock,
};
});

Expand Down Expand Up @@ -222,7 +227,7 @@ describe('ObjectsTable', () => {
}))
};

const { retrieveAndExportDocs } = require('../../../lib/retrieve_and_export_docs');
const { fetchExportObjects } = require('../../../lib/fetch_export_objects');

const component = shallowWithIntl(
<ObjectsTable.WrappedComponent
Expand All @@ -239,10 +244,10 @@ describe('ObjectsTable', () => {
// Set some as selected
component.instance().onSelectionChanged(mockSelectedSavedObjects);

await component.instance().onExport();
await component.instance().onExport(true);

expect(mockSavedObjectsClient.bulkGet).toHaveBeenCalledWith(mockSelectedSavedObjects);
expect(retrieveAndExportDocs).toHaveBeenCalledWith(mockSavedObjects, mockSavedObjectsClient);
expect(fetchExportObjects).toHaveBeenCalledWith(mockSelectedSavedObjects, true);
expect(addSuccessMock).toHaveBeenCalledWith({ title: 'Your file is downloading in the background' });
});

it('should allow the user to choose when exporting all', async () => {
Expand All @@ -260,12 +265,12 @@ describe('ObjectsTable', () => {
component.find('Header').prop('onExportAll')();
component.update();

expect(component.find('EuiConfirmModal')).toMatchSnapshot();
expect(component.find('EuiModal')).toMatchSnapshot();
});

it('should export all', async () => {
const { scanAllTypes } = require('../../../lib/scan_all_types');
const { saveToFile } = require('../../../lib/save_to_file');
const { fetchExportByType } = require('../../../lib/fetch_export_by_type');
const { saveAs } = require('@elastic/filesaver');
const component = shallowWithIntl(
<ObjectsTable.WrappedComponent
{...defaultProps}
Expand All @@ -278,12 +283,14 @@ describe('ObjectsTable', () => {
component.update();

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

await component.instance().onExportAll();

expect(scanAllTypes).toHaveBeenCalledWith(defaultProps.$http, INCLUDED_TYPES);
expect(saveToFile).toHaveBeenCalledWith(JSON.stringify(allSavedObjects, null, 2));
expect(fetchExportByType).toHaveBeenCalledWith(INCLUDED_TYPES, true);
expect(saveAs).toHaveBeenCalledWith(blob, 'export.ndjson');
expect(addSuccessMock).toHaveBeenCalledWith({ title: 'Your file is downloading in the background' });
});
});

Expand Down
Loading

0 comments on commit abe6055

Please sign in to comment.