-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
started migrating the Flyout component
- Loading branch information
1 parent
b937101
commit ff87632
Showing
14 changed files
with
2,964 additions
and
11 deletions.
There are no files selected for viewing
679 changes: 679 additions & 0 deletions
679
...ugins/so_management/public/management/components/flyout/__snapshots__/flyout.test.js.snap
Large diffs are not rendered by default.
Oops, something went wrong.
570 changes: 570 additions & 0 deletions
570
src/plugins/so_management/public/management/components/flyout/flyout.test.js
Large diffs are not rendered by default.
Oops, something went wrong.
978 changes: 978 additions & 0 deletions
978
src/plugins/so_management/public/management/components/flyout/flyout.tsx
Large diffs are not rendered by default.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
src/plugins/so_management/public/management/components/flyout/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/plugins/so_management/public/management/lib/import_file.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/plugins/so_management/public/management/lib/import_legacy_file.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/plugins/so_management/public/management/lib/log_legacy_import.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} |
89 changes: 89 additions & 0 deletions
89
src/plugins/so_management/public/management/lib/process_import_response.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
Oops, something went wrong.