Skip to content

Commit

Permalink
started migrating the Flyout component
Browse files Browse the repository at this point in the history
  • Loading branch information
pgayvallet committed Mar 4, 2020
1 parent b937101 commit ff87632
Show file tree
Hide file tree
Showing 14 changed files with 2,964 additions and 11 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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.
*/

export { Flyout } from './flyout';
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@
export { Header } from './header';
export { Table } from './table';
export { Relationships } from './relationships';
export { Flyout } from './flyout';
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
* under the License.
*/

import { SavedObject } from 'src/core/public';

export function getDefaultTitle(object: SavedObject) {
export function getDefaultTitle(object: { id: string; type: string }) {
return `${object.type} [id=${object.id}]`;
}
42 changes: 42 additions & 0 deletions src/plugins/so_management/public/management/lib/import_file.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 { HttpStart, SavedObjectsImportError } from 'src/core/public';

interface ImportResponse {
success: boolean;
successCount: number;
errors?: SavedObjectsImportError[];
}

export async function importFile(http: HttpStart, file: File, overwriteAll: boolean = false) {
const formData = new FormData();
formData.append('file', file);
return await http.post<ImportResponse>('/api/saved_objects/_import', {
body: formData,
headers: {
// TODO: this was for kfetch. is this also needed here?
// Important to be undefined, it forces proper headers to be set for FormData
'Content-Type': undefined,
},
query: {
overwrite: overwriteAll,
},
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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.
*/

export async function importLegacyFile(
file: File,
fileReader: typeof FileReader = window.FileReader
) {
return new Promise((resolve, reject) => {
const fr = new fileReader();
fr.onload = event => {
const result = event.target!.result as string;
try {
resolve(JSON.parse(result));
} catch (e) {
reject(e);
}
};
fr.readAsText(file);
});
}
5 changes: 5 additions & 0 deletions src/plugins/so_management/public/management/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ export { getDefaultTitle } from './get_default_title';
export { parseQuery } from './parse_query';
export { extractExportDetails, SavedObjectsExportResultDetails } from './extract_export_details';
export { getAllowedTypes } from './get_allowed_types';
export { importFile } from './import_file';
export { importLegacyFile } from './import_legacy_file';
export { logLegacyImport } from './log_legacy_import';
export { processImportResponse, ProcessedImportResponse } from './process_import_response';
export { resolveImportErrors } from './resolve_import_errors';
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 { HttpStart } from 'src/core/public';

export async function logLegacyImport(http: HttpStart) {
return http.post('/api/saved_objects/_log_legacy_import');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* 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 {
SavedObjectsImportResponse,
SavedObjectsImportConflictError,
SavedObjectsImportUnsupportedTypeError,
SavedObjectsImportMissingReferencesError,
SavedObjectsImportUnknownError,
SavedObjectsImportError,
} from 'src/core/public';

export interface ProcessedImportResponse {
failedImports: Array<{
obj: Pick<SavedObjectsImportError, 'id' | 'type' | 'title'>;
error:
| SavedObjectsImportConflictError
| SavedObjectsImportUnsupportedTypeError
| SavedObjectsImportMissingReferencesError
| SavedObjectsImportUnknownError;
}>;
unmatchedReferences: Array<{
existingIndexPatternId: string;
list: Array<Record<string, any>>;
newIndexPatternId: string | undefined;
}>;
status: 'success' | 'idle';
importCount: number;
conflictedSavedObjectsLinkedToSavedSearches: undefined;
conflictedSearchDocs: undefined;
}

export function processImportResponse(
response: SavedObjectsImportResponse
): ProcessedImportResponse {
// Go through the failures and split between unmatchedReferences and failedImports
const failedImports = [];
const unmatchedReferences = new Map();
for (const { error, ...obj } of response.errors || []) {
failedImports.push({ obj, error });
if (error.type !== 'missing_references') {
continue;
}
// Currently only supports resolving references on index patterns
const indexPatternRefs = error.references.filter(ref => ref.type === 'index-pattern');
for (const missingReference of indexPatternRefs) {
const conflict = unmatchedReferences.get(
`${missingReference.type}:${missingReference.id}`
) || {
existingIndexPatternId: missingReference.id,
list: [],
newIndexPatternId: undefined,
};
conflict.list.push(obj);
unmatchedReferences.set(`${missingReference.type}:${missingReference.id}`, conflict);
}
}

return {
failedImports,
unmatchedReferences: Array.from(unmatchedReferences.values()),
// Import won't be successful in the scenario unmatched references exist, import API returned errors of type unknown or import API
// returned errors of type missing_references.
status:
unmatchedReferences.size === 0 &&
!failedImports.some(issue => issue.error.type === 'conflict')
? 'success'
: 'idle',
importCount: response.successCount,
conflictedSavedObjectsLinkedToSavedSearches: undefined,
conflictedSearchDocs: undefined,
};
}
Loading

0 comments on commit ff87632

Please sign in to comment.