From 2ce968178fb345185e78acf199f3943c1b34c3c7 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 25 Feb 2020 15:37:49 -0700 Subject: [PATCH 1/7] Move file upload to np. Some additional mods & removals --- x-pack/index.js | 2 -- x-pack/legacy/plugins/file_upload/index.js | 36 ------------------- .../common/constants/file_import.ts | 0 x-pack/plugins/file_upload/kibana.json | 9 +++++ .../plugins/file_upload/mappings.ts | 0 .../public/components/index_settings.js | 0 .../public/components/json_import_progress.js | 0 .../components/json_index_file_picker.js | 0 .../components/json_upload_and_parse.js | 0 .../plugins/file_upload/public/index.ts | 0 .../file_upload/public/kibana_services.js | 16 ++++----- .../plugins/file_upload/public/plugin.ts | 10 +++--- .../file_upload/public/util/file_parser.js | 0 .../public/util/file_parser.test.js | 0 .../util/geo_json_clean_and_validate.js | 0 .../util/geo_json_clean_and_validate.test.js | 0 .../file_upload/public/util/geo_processing.js | 0 .../public/util/geo_processing.test.js | 0 .../file_upload/public/util/http_service.js | 0 .../public/util/indexing_service.js | 0 .../public/util/indexing_service.test.js | 0 .../file_upload/public/util/pattern_reader.js | 0 .../public/util/size_limited_chunking.js | 0 .../public/util/size_limited_chunking.test.js | 0 .../client/call_with_request_factory.js | 0 .../file_upload/server/client/errors.js | 0 .../file_upload/server/index.js} | 8 ++--- .../server/kibana_server_services.js | 0 .../server/models/import_data/import_data.js | 0 .../server/models/import_data/index.js | 0 .../plugins/file_upload/server/plugin.js | 7 ++-- .../file_upload/server/routes/file_upload.js | 0 .../server/routes/file_upload.test.js | 0 .../telemetry/file_upload_usage_collector.ts | 0 .../file_upload/server/telemetry/index.ts | 0 .../server/telemetry/telemetry.test.ts | 0 .../file_upload/server/telemetry/telemetry.ts | 0 37 files changed, 28 insertions(+), 60 deletions(-) delete mode 100644 x-pack/legacy/plugins/file_upload/index.js rename x-pack/{legacy => }/plugins/file_upload/common/constants/file_import.ts (100%) create mode 100644 x-pack/plugins/file_upload/kibana.json rename x-pack/{legacy => }/plugins/file_upload/mappings.ts (100%) rename x-pack/{legacy => }/plugins/file_upload/public/components/index_settings.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/components/json_import_progress.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/components/json_index_file_picker.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/components/json_upload_and_parse.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/index.ts (100%) rename x-pack/{legacy => }/plugins/file_upload/public/kibana_services.js (53%) rename x-pack/{legacy => }/plugins/file_upload/public/plugin.ts (74%) rename x-pack/{legacy => }/plugins/file_upload/public/util/file_parser.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/util/file_parser.test.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/util/geo_json_clean_and_validate.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/util/geo_json_clean_and_validate.test.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/util/geo_processing.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/util/geo_processing.test.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/util/http_service.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/util/indexing_service.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/util/indexing_service.test.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/util/pattern_reader.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/util/size_limited_chunking.js (100%) rename x-pack/{legacy => }/plugins/file_upload/public/util/size_limited_chunking.test.js (100%) rename x-pack/{legacy => }/plugins/file_upload/server/client/call_with_request_factory.js (100%) rename x-pack/{legacy => }/plugins/file_upload/server/client/errors.js (100%) rename x-pack/{legacy/plugins/file_upload/public/legacy.ts => plugins/file_upload/server/index.js} (60%) rename x-pack/{legacy => }/plugins/file_upload/server/kibana_server_services.js (100%) rename x-pack/{legacy => }/plugins/file_upload/server/models/import_data/import_data.js (100%) rename x-pack/{legacy => }/plugins/file_upload/server/models/import_data/index.js (100%) rename x-pack/{legacy => }/plugins/file_upload/server/plugin.js (95%) rename x-pack/{legacy => }/plugins/file_upload/server/routes/file_upload.js (100%) rename x-pack/{legacy => }/plugins/file_upload/server/routes/file_upload.test.js (100%) rename x-pack/{legacy => }/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts (100%) rename x-pack/{legacy => }/plugins/file_upload/server/telemetry/index.ts (100%) rename x-pack/{legacy => }/plugins/file_upload/server/telemetry/telemetry.test.ts (100%) rename x-pack/{legacy => }/plugins/file_upload/server/telemetry/telemetry.ts (100%) diff --git a/x-pack/index.js b/x-pack/index.js index f3f569e021070..6b84c74690615 100644 --- a/x-pack/index.js +++ b/x-pack/index.js @@ -30,7 +30,6 @@ import { remoteClusters } from './legacy/plugins/remote_clusters'; import { crossClusterReplication } from './legacy/plugins/cross_cluster_replication'; import { upgradeAssistant } from './legacy/plugins/upgrade_assistant'; import { uptime } from './legacy/plugins/uptime'; -import { fileUpload } from './legacy/plugins/file_upload'; import { encryptedSavedObjects } from './legacy/plugins/encrypted_saved_objects'; import { snapshotRestore } from './legacy/plugins/snapshot_restore'; import { transform } from './legacy/plugins/transform'; @@ -69,7 +68,6 @@ module.exports = function(kibana) { crossClusterReplication(kibana), upgradeAssistant(kibana), uptime(kibana), - fileUpload(kibana), encryptedSavedObjects(kibana), lens(kibana), snapshotRestore(kibana), diff --git a/x-pack/legacy/plugins/file_upload/index.js b/x-pack/legacy/plugins/file_upload/index.js deleted file mode 100644 index 23e1e1d98aa7f..0000000000000 --- a/x-pack/legacy/plugins/file_upload/index.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ -import { FileUploadPlugin } from './server/plugin'; -import { mappings } from './mappings'; - -export const fileUpload = kibana => { - return new kibana.Plugin({ - require: ['elasticsearch'], - name: 'file_upload', - id: 'file_upload', - // TODO: uiExports and savedObjectSchemas to be removed on migration - uiExports: { - mappings, - }, - savedObjectSchemas: { - 'file-upload-telemetry': { - isNamespaceAgnostic: true, - }, - }, - - init(server) { - const coreSetup = server.newPlatform.setup.core; - const coreStart = server.newPlatform.start.core; - const { usageCollection } = server.newPlatform.setup.plugins; - const pluginsStart = { - usageCollection, - }; - const fileUploadPlugin = new FileUploadPlugin(); - fileUploadPlugin.setup(coreSetup); - fileUploadPlugin.start(coreStart, pluginsStart); - }, - }); -}; diff --git a/x-pack/legacy/plugins/file_upload/common/constants/file_import.ts b/x-pack/plugins/file_upload/common/constants/file_import.ts similarity index 100% rename from x-pack/legacy/plugins/file_upload/common/constants/file_import.ts rename to x-pack/plugins/file_upload/common/constants/file_import.ts diff --git a/x-pack/plugins/file_upload/kibana.json b/x-pack/plugins/file_upload/kibana.json new file mode 100644 index 0000000000000..3fda32fb6ebe5 --- /dev/null +++ b/x-pack/plugins/file_upload/kibana.json @@ -0,0 +1,9 @@ +{ + "id": "file_upload", + "version": "8.0.0", + "kibanaVersion": "kibana", + "configPath": ["xpack", "file_upload"], + "server": true, + "ui": true, + "requiredPlugins": ["data", "usageCollection"] +} diff --git a/x-pack/legacy/plugins/file_upload/mappings.ts b/x-pack/plugins/file_upload/mappings.ts similarity index 100% rename from x-pack/legacy/plugins/file_upload/mappings.ts rename to x-pack/plugins/file_upload/mappings.ts diff --git a/x-pack/legacy/plugins/file_upload/public/components/index_settings.js b/x-pack/plugins/file_upload/public/components/index_settings.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/components/index_settings.js rename to x-pack/plugins/file_upload/public/components/index_settings.js diff --git a/x-pack/legacy/plugins/file_upload/public/components/json_import_progress.js b/x-pack/plugins/file_upload/public/components/json_import_progress.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/components/json_import_progress.js rename to x-pack/plugins/file_upload/public/components/json_import_progress.js diff --git a/x-pack/legacy/plugins/file_upload/public/components/json_index_file_picker.js b/x-pack/plugins/file_upload/public/components/json_index_file_picker.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/components/json_index_file_picker.js rename to x-pack/plugins/file_upload/public/components/json_index_file_picker.js diff --git a/x-pack/legacy/plugins/file_upload/public/components/json_upload_and_parse.js b/x-pack/plugins/file_upload/public/components/json_upload_and_parse.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/components/json_upload_and_parse.js rename to x-pack/plugins/file_upload/public/components/json_upload_and_parse.js diff --git a/x-pack/legacy/plugins/file_upload/public/index.ts b/x-pack/plugins/file_upload/public/index.ts similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/index.ts rename to x-pack/plugins/file_upload/public/index.ts diff --git a/x-pack/legacy/plugins/file_upload/public/kibana_services.js b/x-pack/plugins/file_upload/public/kibana_services.js similarity index 53% rename from x-pack/legacy/plugins/file_upload/public/kibana_services.js rename to x-pack/plugins/file_upload/public/kibana_services.js index b48b7e49e7912..ae7b7d1287f9e 100644 --- a/x-pack/legacy/plugins/file_upload/public/kibana_services.js +++ b/x-pack/plugins/file_upload/public/kibana_services.js @@ -4,19 +4,17 @@ * you may not use this file except in compliance with the Elastic License. */ -import { npStart } from 'ui/new_platform'; -import { DEFAULT_KBN_VERSION } from '../common/constants/file_import'; - -export const indexPatternService = npStart.plugins.data.indexPatterns; - +export let indexPatternService; export let savedObjectsClient; export let basePath; -export let kbnVersion; export let kbnFetch; -export const initServicesAndConstants = ({ savedObjects, http, injectedMetadata }) => { - savedObjectsClient = savedObjects.client; +export const setupInitServicesAndConstants = ({ http }, { data }) => { + indexPatternService = data.indexPatterns; basePath = http.basePath.basePath; - kbnVersion = injectedMetadata.getKibanaVersion(DEFAULT_KBN_VERSION); kbnFetch = http.fetch; }; + +export const startInitServicesAndConstants = ({ savedObjects }) => { + savedObjectsClient = savedObjects.client; +}; diff --git a/x-pack/legacy/plugins/file_upload/public/plugin.ts b/x-pack/plugins/file_upload/public/plugin.ts similarity index 74% rename from x-pack/legacy/plugins/file_upload/public/plugin.ts rename to x-pack/plugins/file_upload/public/plugin.ts index 53b292b02760f..5f214a83cddcb 100644 --- a/x-pack/legacy/plugins/file_upload/public/plugin.ts +++ b/x-pack/plugins/file_upload/public/plugin.ts @@ -4,11 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ -import { Plugin, CoreStart } from 'src/core/public'; // @ts-ignore +import { CoreSetup, CoreStart } from 'kibana/server'; import { JsonUploadAndParse } from './components/json_upload_and_parse'; // @ts-ignore -import { initServicesAndConstants } from './kibana_services'; +import { setupInitServicesAndConstants, startInitServicesAndConstants } from './kibana_services'; /** * These are the interfaces with your public contracts. You should export these @@ -20,10 +20,12 @@ export type FileUploadPluginStart = ReturnType; /** @internal */ export class FileUploadPlugin implements Plugin { - public setup() {} + public setup(core: CoreSetup, plugins: any) { + setupInitServicesAndConstants(core, plugins); + } public start(core: CoreStart) { - initServicesAndConstants(core); + startInitServicesAndConstants(core); return { JsonUploadAndParse, }; diff --git a/x-pack/legacy/plugins/file_upload/public/util/file_parser.js b/x-pack/plugins/file_upload/public/util/file_parser.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/util/file_parser.js rename to x-pack/plugins/file_upload/public/util/file_parser.js diff --git a/x-pack/legacy/plugins/file_upload/public/util/file_parser.test.js b/x-pack/plugins/file_upload/public/util/file_parser.test.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/util/file_parser.test.js rename to x-pack/plugins/file_upload/public/util/file_parser.test.js diff --git a/x-pack/legacy/plugins/file_upload/public/util/geo_json_clean_and_validate.js b/x-pack/plugins/file_upload/public/util/geo_json_clean_and_validate.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/util/geo_json_clean_and_validate.js rename to x-pack/plugins/file_upload/public/util/geo_json_clean_and_validate.js diff --git a/x-pack/legacy/plugins/file_upload/public/util/geo_json_clean_and_validate.test.js b/x-pack/plugins/file_upload/public/util/geo_json_clean_and_validate.test.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/util/geo_json_clean_and_validate.test.js rename to x-pack/plugins/file_upload/public/util/geo_json_clean_and_validate.test.js diff --git a/x-pack/legacy/plugins/file_upload/public/util/geo_processing.js b/x-pack/plugins/file_upload/public/util/geo_processing.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/util/geo_processing.js rename to x-pack/plugins/file_upload/public/util/geo_processing.js diff --git a/x-pack/legacy/plugins/file_upload/public/util/geo_processing.test.js b/x-pack/plugins/file_upload/public/util/geo_processing.test.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/util/geo_processing.test.js rename to x-pack/plugins/file_upload/public/util/geo_processing.test.js diff --git a/x-pack/legacy/plugins/file_upload/public/util/http_service.js b/x-pack/plugins/file_upload/public/util/http_service.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/util/http_service.js rename to x-pack/plugins/file_upload/public/util/http_service.js diff --git a/x-pack/legacy/plugins/file_upload/public/util/indexing_service.js b/x-pack/plugins/file_upload/public/util/indexing_service.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/util/indexing_service.js rename to x-pack/plugins/file_upload/public/util/indexing_service.js diff --git a/x-pack/legacy/plugins/file_upload/public/util/indexing_service.test.js b/x-pack/plugins/file_upload/public/util/indexing_service.test.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/util/indexing_service.test.js rename to x-pack/plugins/file_upload/public/util/indexing_service.test.js diff --git a/x-pack/legacy/plugins/file_upload/public/util/pattern_reader.js b/x-pack/plugins/file_upload/public/util/pattern_reader.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/util/pattern_reader.js rename to x-pack/plugins/file_upload/public/util/pattern_reader.js diff --git a/x-pack/legacy/plugins/file_upload/public/util/size_limited_chunking.js b/x-pack/plugins/file_upload/public/util/size_limited_chunking.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/util/size_limited_chunking.js rename to x-pack/plugins/file_upload/public/util/size_limited_chunking.js diff --git a/x-pack/legacy/plugins/file_upload/public/util/size_limited_chunking.test.js b/x-pack/plugins/file_upload/public/util/size_limited_chunking.test.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/public/util/size_limited_chunking.test.js rename to x-pack/plugins/file_upload/public/util/size_limited_chunking.test.js diff --git a/x-pack/legacy/plugins/file_upload/server/client/call_with_request_factory.js b/x-pack/plugins/file_upload/server/client/call_with_request_factory.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/server/client/call_with_request_factory.js rename to x-pack/plugins/file_upload/server/client/call_with_request_factory.js diff --git a/x-pack/legacy/plugins/file_upload/server/client/errors.js b/x-pack/plugins/file_upload/server/client/errors.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/server/client/errors.js rename to x-pack/plugins/file_upload/server/client/errors.js diff --git a/x-pack/legacy/plugins/file_upload/public/legacy.ts b/x-pack/plugins/file_upload/server/index.js similarity index 60% rename from x-pack/legacy/plugins/file_upload/public/legacy.ts rename to x-pack/plugins/file_upload/server/index.js index 719599df3ccbe..f894bf788a893 100644 --- a/x-pack/legacy/plugins/file_upload/public/legacy.ts +++ b/x-pack/plugins/file_upload/server/index.js @@ -3,10 +3,8 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ +import { FileUploadPlugin } from './plugin'; -import { npStart } from 'ui/new_platform'; -import { plugin } from '.'; +export * from './plugin'; -const pluginInstance = plugin(); - -export const start = pluginInstance.start(npStart.core); +export const plugin = () => new FileUploadPlugin(); diff --git a/x-pack/legacy/plugins/file_upload/server/kibana_server_services.js b/x-pack/plugins/file_upload/server/kibana_server_services.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/server/kibana_server_services.js rename to x-pack/plugins/file_upload/server/kibana_server_services.js diff --git a/x-pack/legacy/plugins/file_upload/server/models/import_data/import_data.js b/x-pack/plugins/file_upload/server/models/import_data/import_data.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/server/models/import_data/import_data.js rename to x-pack/plugins/file_upload/server/models/import_data/import_data.js diff --git a/x-pack/legacy/plugins/file_upload/server/models/import_data/index.js b/x-pack/plugins/file_upload/server/models/import_data/index.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/server/models/import_data/index.js rename to x-pack/plugins/file_upload/server/models/import_data/index.js diff --git a/x-pack/legacy/plugins/file_upload/server/plugin.js b/x-pack/plugins/file_upload/server/plugin.js similarity index 95% rename from x-pack/legacy/plugins/file_upload/server/plugin.js rename to x-pack/plugins/file_upload/server/plugin.js index c448676f813ea..0b6c7f72cb9ff 100644 --- a/x-pack/legacy/plugins/file_upload/server/plugin.js +++ b/x-pack/plugins/file_upload/server/plugin.js @@ -13,15 +13,14 @@ export class FileUploadPlugin { this.router = null; } - setup(core) { + setup(core, plugins) { setElasticsearchClientServices(core.elasticsearch); this.router = core.http.createRouter(); + registerFileUploadUsageCollector(plugins.usageCollection); } - start(core, plugins) { + start(core) { initRoutes(this.router, core.savedObjects.getSavedObjectsRepository); setInternalRepository(core.savedObjects.createInternalRepository); - - registerFileUploadUsageCollector(plugins.usageCollection); } } diff --git a/x-pack/legacy/plugins/file_upload/server/routes/file_upload.js b/x-pack/plugins/file_upload/server/routes/file_upload.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/server/routes/file_upload.js rename to x-pack/plugins/file_upload/server/routes/file_upload.js diff --git a/x-pack/legacy/plugins/file_upload/server/routes/file_upload.test.js b/x-pack/plugins/file_upload/server/routes/file_upload.test.js similarity index 100% rename from x-pack/legacy/plugins/file_upload/server/routes/file_upload.test.js rename to x-pack/plugins/file_upload/server/routes/file_upload.test.js diff --git a/x-pack/legacy/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts b/x-pack/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts similarity index 100% rename from x-pack/legacy/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts rename to x-pack/plugins/file_upload/server/telemetry/file_upload_usage_collector.ts diff --git a/x-pack/legacy/plugins/file_upload/server/telemetry/index.ts b/x-pack/plugins/file_upload/server/telemetry/index.ts similarity index 100% rename from x-pack/legacy/plugins/file_upload/server/telemetry/index.ts rename to x-pack/plugins/file_upload/server/telemetry/index.ts diff --git a/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.test.ts b/x-pack/plugins/file_upload/server/telemetry/telemetry.test.ts similarity index 100% rename from x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.test.ts rename to x-pack/plugins/file_upload/server/telemetry/telemetry.test.ts diff --git a/x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.ts b/x-pack/plugins/file_upload/server/telemetry/telemetry.ts similarity index 100% rename from x-pack/legacy/plugins/file_upload/server/telemetry/telemetry.ts rename to x-pack/plugins/file_upload/server/telemetry/telemetry.ts From 8256485e0526a20144b1f49a870a870d12cb2745 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 25 Feb 2020 15:39:26 -0700 Subject: [PATCH 2/7] Consume file upload from NP in maps and pass to kibana services --- x-pack/legacy/plugins/maps/public/kibana_services.js | 6 ++++++ .../client_file_source/create_client_file_source_editor.js | 5 +++-- x-pack/legacy/plugins/maps/public/plugin.ts | 3 ++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js index a1b1c9ec1518e..8d883adddddaf 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ b/x-pack/legacy/plugins/maps/public/kibana_services.js @@ -28,6 +28,12 @@ export const getInspector = () => { return inspector; }; +let fileUpload; +export const setFileUpload = fileUploadPlugin => (fileUpload = fileUploadPlugin); +export const getFileUpload = () => { + return fileUpload.JsonUploadAndParse; +}; + export async function fetchSearchSourceAndRecordWithInspector({ searchSource, requestId, diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/client_file_source/create_client_file_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/client_file_source/create_client_file_source_editor.js index 150c7c39fe117..e82a99466baed 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/client_file_source/create_client_file_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/client_file_source/create_client_file_source_editor.js @@ -5,7 +5,7 @@ */ import React from 'react'; -import { start as fileUpload } from '../../../../../file_upload/public/legacy'; +import { getFileUpload } from '../../../kibana_services'; export function ClientFileCreateSourceEditor({ previewGeojsonFile, @@ -14,8 +14,9 @@ export function ClientFileCreateSourceEditor({ onRemove, onIndexReady, }) { + const FileUpload = getFileUpload(); return ( - { public start(core: CoreStart, plugins: any) { setInspector(plugins.np.inspector); + setFileUpload(plugins.np.file_upload); } } From 0ed88f5852d03d5b683d972d9ace098aed3baf6e Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 26 Feb 2020 10:42:32 -0700 Subject: [PATCH 3/7] Register telemetry mappings --- x-pack/plugins/file_upload/server/plugin.js | 3 ++- .../file_upload/server/telemetry/index.ts | 1 + .../file_upload/server/telemetry/mappings.ts | 20 +++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 x-pack/plugins/file_upload/server/telemetry/mappings.ts diff --git a/x-pack/plugins/file_upload/server/plugin.js b/x-pack/plugins/file_upload/server/plugin.js index 0b6c7f72cb9ff..a11516d03f068 100644 --- a/x-pack/plugins/file_upload/server/plugin.js +++ b/x-pack/plugins/file_upload/server/plugin.js @@ -6,7 +6,7 @@ import { initRoutes } from './routes/file_upload'; import { setElasticsearchClientServices, setInternalRepository } from './kibana_server_services'; -import { registerFileUploadUsageCollector } from './telemetry'; +import { registerFileUploadUsageCollector, fileUploadTelemetryMappingsType } from './telemetry'; export class FileUploadPlugin { constructor() { @@ -14,6 +14,7 @@ export class FileUploadPlugin { } setup(core, plugins) { + core.savedObjects.registerType(fileUploadTelemetryMappingsType); setElasticsearchClientServices(core.elasticsearch); this.router = core.http.createRouter(); registerFileUploadUsageCollector(plugins.usageCollection); diff --git a/x-pack/plugins/file_upload/server/telemetry/index.ts b/x-pack/plugins/file_upload/server/telemetry/index.ts index 7969dd04ce31f..8d4f4e72bd28a 100644 --- a/x-pack/plugins/file_upload/server/telemetry/index.ts +++ b/x-pack/plugins/file_upload/server/telemetry/index.ts @@ -5,3 +5,4 @@ */ export { registerFileUploadUsageCollector } from './file_upload_usage_collector'; +export { fileUploadTelemetryMappingsType } from './mappings'; diff --git a/x-pack/plugins/file_upload/server/telemetry/mappings.ts b/x-pack/plugins/file_upload/server/telemetry/mappings.ts new file mode 100644 index 0000000000000..69100295d960d --- /dev/null +++ b/x-pack/plugins/file_upload/server/telemetry/mappings.ts @@ -0,0 +1,20 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import { SavedObjectsType } from 'src/core/server'; +import { TELEMETRY_DOC_ID } from './telemetry'; + +export const fileUploadTelemetryMappingsType: SavedObjectsType = { + name: TELEMETRY_DOC_ID, + namespaceAgnostic: true, + mappings: { + properties: { + filesUploadedTotalCount: { + type: 'long', + }, + }, + }, +}; From 0257d98325c7669215bec3e2f288d58f4fe66986 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 26 Feb 2020 11:07:40 -0700 Subject: [PATCH 4/7] Init indexPatternService in start method --- x-pack/plugins/file_upload/public/kibana_services.js | 6 +++--- x-pack/plugins/file_upload/public/plugin.ts | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/x-pack/plugins/file_upload/public/kibana_services.js b/x-pack/plugins/file_upload/public/kibana_services.js index ae7b7d1287f9e..1269e16266eb5 100644 --- a/x-pack/plugins/file_upload/public/kibana_services.js +++ b/x-pack/plugins/file_upload/public/kibana_services.js @@ -9,12 +9,12 @@ export let savedObjectsClient; export let basePath; export let kbnFetch; -export const setupInitServicesAndConstants = ({ http }, { data }) => { - indexPatternService = data.indexPatterns; +export const setupInitServicesAndConstants = ({ http }) => { basePath = http.basePath.basePath; kbnFetch = http.fetch; }; -export const startInitServicesAndConstants = ({ savedObjects }) => { +export const startInitServicesAndConstants = ({ savedObjects }, { data }) => { + indexPatternService = data.indexPatterns; savedObjectsClient = savedObjects.client; }; diff --git a/x-pack/plugins/file_upload/public/plugin.ts b/x-pack/plugins/file_upload/public/plugin.ts index 5f214a83cddcb..14deba403f072 100644 --- a/x-pack/plugins/file_upload/public/plugin.ts +++ b/x-pack/plugins/file_upload/public/plugin.ts @@ -6,6 +6,7 @@ // @ts-ignore import { CoreSetup, CoreStart } from 'kibana/server'; +// @ts-ignore import { JsonUploadAndParse } from './components/json_upload_and_parse'; // @ts-ignore import { setupInitServicesAndConstants, startInitServicesAndConstants } from './kibana_services'; @@ -20,12 +21,12 @@ export type FileUploadPluginStart = ReturnType; /** @internal */ export class FileUploadPlugin implements Plugin { - public setup(core: CoreSetup, plugins: any) { - setupInitServicesAndConstants(core, plugins); + public setup(core: CoreSetup) { + setupInitServicesAndConstants(core); } - public start(core: CoreStart) { - startInitServicesAndConstants(core); + public start(core: CoreStart, plugins: any) { + startInitServicesAndConstants(core, plugins); return { JsonUploadAndParse, }; From 3fc2bad3b14433d225fb0319974d8df648719bb1 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Wed, 26 Feb 2020 14:45:32 -0700 Subject: [PATCH 5/7] Fix type check issues. Add missing prop to telemetry --- x-pack/plugins/file_upload/public/plugin.ts | 15 +++++++++++---- .../file_upload/server/telemetry/mappings.ts | 1 + 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/file_upload/public/plugin.ts b/x-pack/plugins/file_upload/public/plugin.ts index 14deba403f072..338c61ad141c6 100644 --- a/x-pack/plugins/file_upload/public/plugin.ts +++ b/x-pack/plugins/file_upload/public/plugin.ts @@ -5,27 +5,34 @@ */ // @ts-ignore -import { CoreSetup, CoreStart } from 'kibana/server'; +import { CoreSetup, CoreStart, Plugin } from 'kibana/server'; // @ts-ignore import { JsonUploadAndParse } from './components/json_upload_and_parse'; // @ts-ignore import { setupInitServicesAndConstants, startInitServicesAndConstants } from './kibana_services'; +import { IDataPluginServices } from '../../../../src/plugins/data/public'; /** * These are the interfaces with your public contracts. You should export these * for other plugins to use in _their_ `SetupDeps`/`StartDeps` interfaces. * @public */ + +// eslint-disable-next-line @typescript-eslint/no-empty-interface +export interface FileUploadPluginSetupDependencies {} +export interface FileUploadPluginStartDependencies { + data: IDataPluginServices; +} + export type FileUploadPluginSetup = ReturnType; export type FileUploadPluginStart = ReturnType; -/** @internal */ export class FileUploadPlugin implements Plugin { - public setup(core: CoreSetup) { + public setup(core: CoreSetup, plugins: FileUploadPluginSetupDependencies) { setupInitServicesAndConstants(core); } - public start(core: CoreStart, plugins: any) { + public start(core: CoreStart, plugins: FileUploadPluginStartDependencies) { startInitServicesAndConstants(core, plugins); return { JsonUploadAndParse, diff --git a/x-pack/plugins/file_upload/server/telemetry/mappings.ts b/x-pack/plugins/file_upload/server/telemetry/mappings.ts index 69100295d960d..ca935fea3449a 100644 --- a/x-pack/plugins/file_upload/server/telemetry/mappings.ts +++ b/x-pack/plugins/file_upload/server/telemetry/mappings.ts @@ -9,6 +9,7 @@ import { TELEMETRY_DOC_ID } from './telemetry'; export const fileUploadTelemetryMappingsType: SavedObjectsType = { name: TELEMETRY_DOC_ID, + hidden: false, namespaceAgnostic: true, mappings: { properties: { From 1b9fc1a96a2f9f36ca8ef1e8af4dfae166716763 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Mon, 2 Mar 2020 13:55:46 -0700 Subject: [PATCH 6/7] Update i18n path --- x-pack/.i18nrc.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index 51099815ec938..8e35cd339cdd4 100644 --- a/x-pack/.i18nrc.json +++ b/x-pack/.i18nrc.json @@ -14,7 +14,7 @@ "xpack.drilldowns": "plugins/drilldowns", "xpack.endpoint": "plugins/endpoint", "xpack.features": "plugins/features", - "xpack.fileUpload": "legacy/plugins/file_upload", + "xpack.fileUpload": "plugins/file_upload", "xpack.graph": ["legacy/plugins/graph", "plugins/graph"], "xpack.grokDebugger": "legacy/plugins/grokdebugger", "xpack.idxMgmt": "plugins/index_management", From dc68a58a3eef72a9ba1cc9ef2007b7e7dce2ee13 Mon Sep 17 00:00:00 2001 From: Aaron Caldwell Date: Tue, 3 Mar 2020 16:59:13 -0700 Subject: [PATCH 7/7] Review feedback --- x-pack/legacy/plugins/maps/public/kibana_services.js | 8 ++++---- .../create_client_file_source_editor.js | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/legacy/plugins/maps/public/kibana_services.js b/x-pack/legacy/plugins/maps/public/kibana_services.js index 8d883adddddaf..ef427aa31d01b 100644 --- a/x-pack/legacy/plugins/maps/public/kibana_services.js +++ b/x-pack/legacy/plugins/maps/public/kibana_services.js @@ -28,10 +28,10 @@ export const getInspector = () => { return inspector; }; -let fileUpload; -export const setFileUpload = fileUploadPlugin => (fileUpload = fileUploadPlugin); -export const getFileUpload = () => { - return fileUpload.JsonUploadAndParse; +let fileUploadPlugin; +export const setFileUpload = fileUpload => (fileUploadPlugin = fileUpload); +export const getFileUploadComponent = () => { + return fileUploadPlugin.JsonUploadAndParse; }; export async function fetchSearchSourceAndRecordWithInspector({ diff --git a/x-pack/legacy/plugins/maps/public/layers/sources/client_file_source/create_client_file_source_editor.js b/x-pack/legacy/plugins/maps/public/layers/sources/client_file_source/create_client_file_source_editor.js index e82a99466baed..f9bfc4ddde91b 100644 --- a/x-pack/legacy/plugins/maps/public/layers/sources/client_file_source/create_client_file_source_editor.js +++ b/x-pack/legacy/plugins/maps/public/layers/sources/client_file_source/create_client_file_source_editor.js @@ -5,7 +5,7 @@ */ import React from 'react'; -import { getFileUpload } from '../../../kibana_services'; +import { getFileUploadComponent } from '../../../kibana_services'; export function ClientFileCreateSourceEditor({ previewGeojsonFile, @@ -14,7 +14,7 @@ export function ClientFileCreateSourceEditor({ onRemove, onIndexReady, }) { - const FileUpload = getFileUpload(); + const FileUpload = getFileUploadComponent(); return (