From 96c8004d7ba7051fd7d4d2a8c6a32e35b41d3f18 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 18 Dec 2019 17:15:35 +0100 Subject: [PATCH 01/39] Start shimming rollup plugin --- .../rollup/common/{index.js => index.ts} | 0 .../common/{ui_metric.js => ui_metric.ts} | 0 .../plugins/rollup/public/crud_app/index.js | 29 ----- .../{index.js => index.ts} | 12 +- .../public/index_pattern_creation/index.js | 17 --- .../public/index_pattern_creation/register.js | 12 -- .../rollup_index_pattern_creation_config.js | 6 +- .../rollup/public/index_pattern_list/index.js | 16 --- .../public/index_pattern_list/register.js | 12 -- x-pack/legacy/plugins/rollup/public/plugin.ts | 107 ++++++++++++++++++ .../plugins/rollup/public/search/index.js | 17 --- .../plugins/rollup/public/search/register.js | 12 -- .../plugins/rollup/public/services/api.js | 14 --- .../public/visualize/agg_type_field_filter.js | 4 +- .../public/visualize/agg_type_filter.js | 4 +- .../rollup/public/visualize/editor_config.js | 3 +- .../plugins/rollup/public/visualize/index.js | 21 ---- 17 files changed, 116 insertions(+), 170 deletions(-) rename x-pack/legacy/plugins/rollup/common/{index.js => index.ts} (100%) rename x-pack/legacy/plugins/rollup/common/{ui_metric.js => ui_metric.ts} (100%) rename x-pack/legacy/plugins/rollup/public/extend_index_management/{index.js => index.ts} (76%) delete mode 100644 x-pack/legacy/plugins/rollup/public/index_pattern_creation/index.js delete mode 100644 x-pack/legacy/plugins/rollup/public/index_pattern_creation/register.js delete mode 100644 x-pack/legacy/plugins/rollup/public/index_pattern_list/index.js delete mode 100644 x-pack/legacy/plugins/rollup/public/index_pattern_list/register.js create mode 100644 x-pack/legacy/plugins/rollup/public/plugin.ts delete mode 100644 x-pack/legacy/plugins/rollup/public/search/index.js delete mode 100644 x-pack/legacy/plugins/rollup/public/search/register.js delete mode 100644 x-pack/legacy/plugins/rollup/public/services/api.js delete mode 100644 x-pack/legacy/plugins/rollup/public/visualize/index.js diff --git a/x-pack/legacy/plugins/rollup/common/index.js b/x-pack/legacy/plugins/rollup/common/index.ts similarity index 100% rename from x-pack/legacy/plugins/rollup/common/index.js rename to x-pack/legacy/plugins/rollup/common/index.ts diff --git a/x-pack/legacy/plugins/rollup/common/ui_metric.js b/x-pack/legacy/plugins/rollup/common/ui_metric.ts similarity index 100% rename from x-pack/legacy/plugins/rollup/common/ui_metric.js rename to x-pack/legacy/plugins/rollup/common/ui_metric.ts diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/index.js index 82bbb90d2e33c..2dc2af8f59050 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/index.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/index.js @@ -5,15 +5,9 @@ */ import React from 'react'; -import { - FeatureCatalogueRegistryProvider, - FeatureCatalogueCategory, -} from 'ui/registry/feature_catalogue'; import { render, unmountComponentAtNode } from 'react-dom'; import { Provider } from 'react-redux'; -import { i18n } from '@kbn/i18n'; import { I18nContext } from 'ui/i18n'; -import { management } from 'ui/management'; import routes from 'ui/routes'; import { CRUD_APP_BASE_PATH } from './constants'; @@ -22,15 +16,6 @@ import { App } from './app'; import template from './main.html'; import { rollupJobsStore } from './store'; -const esSection = management.getSection('elasticsearch'); - -esSection.register('rollup_jobs', { - visible: true, - display: i18n.translate('xpack.rollupJobs.appTitle', { defaultMessage: 'Rollup Jobs' }), - order: 3, - url: `#${CRUD_APP_BASE_PATH}/job_list`, -}); - const renderReact = async elem => { render( @@ -82,17 +67,3 @@ routes.when(`${CRUD_APP_BASE_PATH}/:view?`, { } }, }); - -FeatureCatalogueRegistryProvider.register(() => { - return { - id: 'rollup_jobs', - title: 'Rollups', - description: i18n.translate('xpack.rollupJobs.featureCatalogueDescription', { - defaultMessage: 'Summarize and store historical data in a smaller index for future analysis.', - }), - icon: 'indexRollupApp', - path: `#${CRUD_APP_BASE_PATH}/job_list`, - showOnHomePage: true, - category: FeatureCatalogueCategory.ADMIN, - }; -}); diff --git a/x-pack/legacy/plugins/rollup/public/extend_index_management/index.js b/x-pack/legacy/plugins/rollup/public/extend_index_management/index.ts similarity index 76% rename from x-pack/legacy/plugins/rollup/public/extend_index_management/index.js rename to x-pack/legacy/plugins/rollup/public/extend_index_management/index.ts index 5e14d3eabc9a6..1a34811901bbe 100644 --- a/x-pack/legacy/plugins/rollup/public/extend_index_management/index.js +++ b/x-pack/legacy/plugins/rollup/public/extend_index_management/index.ts @@ -4,15 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ import { i18n } from '@kbn/i18n'; -import { - addToggleExtension, - addBadgeExtension, -} from '../../../index_management/public/index_management_extensions'; import { get } from 'lodash'; const propertyPath = 'isRollupIndex'; export const rollupToggleExtension = { - matchIndex: index => { + matchIndex: (index: { isRollupIndex: boolean }) => { return get(index, propertyPath); }, label: i18n.translate('xpack.rollupJobs.indexMgmtToggle.toggleLabel', { @@ -20,8 +16,9 @@ export const rollupToggleExtension = { }), name: 'rollupToggle', }; + export const rollupBadgeExtension = { - matchIndex: index => { + matchIndex: (index: { isRollupIndex: boolean }) => { return get(index, propertyPath); }, label: i18n.translate('xpack.rollupJobs.indexMgmtBadge.rollupLabel', { @@ -30,6 +27,3 @@ export const rollupBadgeExtension = { color: 'secondary', filterExpression: 'isRollupIndex:true', }; - -addBadgeExtension(rollupBadgeExtension); -addToggleExtension(rollupToggleExtension); diff --git a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/index.js b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/index.js deleted file mode 100644 index 1add469e073bd..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/index.js +++ /dev/null @@ -1,17 +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 chrome from 'ui/chrome'; - -import { initIndexPatternCreation } from './register'; -import { CONFIG_ROLLUPS } from '../../common'; - -const uiSettings = chrome.getUiSettingsClient(); -const isRollupIndexPatternsEnabled = uiSettings.get(CONFIG_ROLLUPS); - -if (isRollupIndexPatternsEnabled) { - initIndexPatternCreation(); -} diff --git a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/register.js b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/register.js deleted file mode 100644 index 9a3aed548dcc9..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/register.js +++ /dev/null @@ -1,12 +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 { setup as managementSetup } from '../../../../../../src/legacy/core_plugins/management/public/legacy'; -import { RollupIndexPatternCreationConfig } from './rollup_index_pattern_creation_config'; - -export function initIndexPatternCreation() { - managementSetup.indexPattern.creation.add(RollupIndexPatternCreationConfig); -} diff --git a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js index 07f2a674decc5..2540f99821ecf 100644 --- a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js +++ b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js @@ -9,7 +9,6 @@ import { i18n } from '@kbn/i18n'; import { npSetup } from 'ui/new_platform'; import { RollupPrompt } from './components/rollup_prompt'; -import { setHttpClient, getRollupIndices } from '../services/api'; import { IndexPatternCreationConfig } from '../../../../../../src/legacy/core_plugins/management/public'; const rollupIndexPatternTypeName = i18n.translate( @@ -54,7 +53,6 @@ export class RollupIndexPatternCreationConfig extends IndexPatternCreationConfig ...options, }); - setHttpClient(this.httpClient); this.rollupIndex = null; this.rollupJobs = []; this.rollupIndicesCapabilities = {}; @@ -69,7 +67,9 @@ export class RollupIndexPatternCreationConfig extends IndexPatternCreationConfig // request resolves after the logout request resolves, and un-clears the session ID. const isAnonymous = npSetup.core.http.anonymousPaths.isAnonymous(window.location.pathname); if (!isAnonymous) { - this.rollupIndicesCapabilities = await getRollupIndices(); + const response = await this.httpClient.get('/api/rollup/indices'); + return response || {}; + this.rollupIndicesCapabilities = response || {}; } this.rollupIndices = Object.keys(this.rollupIndicesCapabilities); diff --git a/x-pack/legacy/plugins/rollup/public/index_pattern_list/index.js b/x-pack/legacy/plugins/rollup/public/index_pattern_list/index.js deleted file mode 100644 index 63a3149faaadb..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/index_pattern_list/index.js +++ /dev/null @@ -1,16 +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 chrome from 'ui/chrome'; -import { initIndexPatternList } from './register'; -import { CONFIG_ROLLUPS } from '../../common'; - -const uiSettings = chrome.getUiSettingsClient(); -const isRollupIndexPatternsEnabled = uiSettings.get(CONFIG_ROLLUPS); - -if (isRollupIndexPatternsEnabled) { - initIndexPatternList(); -} diff --git a/x-pack/legacy/plugins/rollup/public/index_pattern_list/register.js b/x-pack/legacy/plugins/rollup/public/index_pattern_list/register.js deleted file mode 100644 index 173c28826436b..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/index_pattern_list/register.js +++ /dev/null @@ -1,12 +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 { setup as managementSetup } from '../../../../../../src/legacy/core_plugins/management/public/legacy'; -import { RollupIndexPatternListConfig } from './rollup_index_pattern_list_config'; - -export function initIndexPatternList() { - managementSetup.indexPattern.list.add(RollupIndexPatternListConfig); -} diff --git a/x-pack/legacy/plugins/rollup/public/plugin.ts b/x-pack/legacy/plugins/rollup/public/plugin.ts new file mode 100644 index 0000000000000..d0ef98fb650fe --- /dev/null +++ b/x-pack/legacy/plugins/rollup/public/plugin.ts @@ -0,0 +1,107 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; +import { EditorConfigProviderRegistry } from 'ui/vis/editors/config/editor_config_providers'; +import { SearchStrategyProvider } from 'ui/courier/search_strategy/types'; +import { ManagementSetup } from '../../../../../src/legacy/core_plugins/management/public/np_ready'; +import { rollupBadgeExtension, rollupToggleExtension } from './extend_index_management'; +// @ts-ignore +import { RollupIndexPatternCreationConfig } from './index_pattern_creation/rollup_index_pattern_creation_config'; +// @ts-ignore +import { RollupIndexPatternListConfig } from './index_pattern_list/rollup_index_pattern_list_config'; +// @ts-ignore +import { rollupSearchStrategy } from './search/rollup_search_strategy'; +// @ts-ignore +import { initAggTypeFilter } from './visualize/agg_type_filter'; +// @ts-ignore +import { initAggTypeFieldFilter } from './visualize/agg_type_field_filter'; +// @ts-ignore +import { initEditorConfig } from './visualize/editor_config'; +import { CONFIG_ROLLUPS } from '../common'; +import { + FeatureCatalogueCategory, + HomePublicPluginSetup, +} from '../../../../../src/plugins/home/public'; +// @ts-ignore +import { CRUD_APP_BASE_PATH } from './crud_app/constants'; +import { ManagementStart } from '../../../../../src/plugins/management/public'; + +export interface RollupPluginSetupDependencies { + __LEGACY: { + aggTypeFilters: any; + aggTypeFieldFilters: any; + editorConfigProviders: EditorConfigProviderRegistry; + addSearchStrategy: (searchStrategy: SearchStrategyProvider) => void; + management: ManagementSetup; + addBadgeExtension: (badgeExtension: any) => void; + addToggleExtension: (toggleExtension: any) => void; + }; + home?: HomePublicPluginSetup; +} + +export interface RollupPluginStartDependencies { + management: ManagementStart; +} + +export class RollupPlugin implements Plugin { + setup( + core: CoreSetup, + { + __LEGACY: { + aggTypeFilters, + aggTypeFieldFilters, + editorConfigProviders, + addSearchStrategy, + management, + addBadgeExtension, + addToggleExtension, + }, + home, + }: RollupPluginSetupDependencies + ) { + addBadgeExtension(rollupBadgeExtension); + addToggleExtension(rollupToggleExtension); + + const isRollupIndexPatternsEnabled = core.uiSettings.get(CONFIG_ROLLUPS); + + if (isRollupIndexPatternsEnabled) { + management.indexPattern.creation.add(RollupIndexPatternCreationConfig); + management.indexPattern.list.add(RollupIndexPatternListConfig); + addSearchStrategy(rollupSearchStrategy); + initAggTypeFilter(aggTypeFilters); + initAggTypeFieldFilter(aggTypeFieldFilters); + initEditorConfig(editorConfigProviders); + } + + if (home) { + home.featureCatalogue.register({ + id: 'rollup_jobs', + title: 'Rollups', + description: i18n.translate('xpack.rollupJobs.featureCatalogueDescription', { + defaultMessage: + 'Summarize and store historical data in a smaller index for future analysis.', + }), + icon: 'indexRollupApp', + path: `#${CRUD_APP_BASE_PATH}/job_list`, + showOnHomePage: true, + category: FeatureCatalogueCategory.ADMIN, + }); + } + } + + start(core: CoreStart, { management }: RollupPluginStartDependencies) { + const esSection = management.legacy.getSection('elasticsearch'); + + esSection.register('rollup_jobs', { + visible: true, + display: i18n.translate('xpack.rollupJobs.appTitle', { defaultMessage: 'Rollup Jobs' }), + order: 3, + url: `#${CRUD_APP_BASE_PATH}/job_list`, + }); + } +} diff --git a/x-pack/legacy/plugins/rollup/public/search/index.js b/x-pack/legacy/plugins/rollup/public/search/index.js deleted file mode 100644 index e76ba4817d72c..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/search/index.js +++ /dev/null @@ -1,17 +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 chrome from 'ui/chrome'; - -import { initSearch } from './register'; -import { CONFIG_ROLLUPS } from '../../common'; - -const uiSettings = chrome.getUiSettingsClient(); -const isRollupIndexPatternsEnabled = uiSettings.get(CONFIG_ROLLUPS); - -if (isRollupIndexPatternsEnabled) { - initSearch(); -} diff --git a/x-pack/legacy/plugins/rollup/public/search/register.js b/x-pack/legacy/plugins/rollup/public/search/register.js deleted file mode 100644 index f7f1c681b63ca..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/search/register.js +++ /dev/null @@ -1,12 +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 { addSearchStrategy } from '../../../../../../src/legacy/ui/public/courier'; -import { rollupSearchStrategy } from './rollup_search_strategy'; - -export function initSearch() { - addSearchStrategy(rollupSearchStrategy); -} diff --git a/x-pack/legacy/plugins/rollup/public/services/api.js b/x-pack/legacy/plugins/rollup/public/services/api.js deleted file mode 100644 index ae9e8756c7efc..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/services/api.js +++ /dev/null @@ -1,14 +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. - */ -let httpClient; -export const setHttpClient = client => { - httpClient = client; -}; - -export async function getRollupIndices() { - const response = await httpClient.get('/api/rollup/indices'); - return response || {}; -} diff --git a/x-pack/legacy/plugins/rollup/public/visualize/agg_type_field_filter.js b/x-pack/legacy/plugins/rollup/public/visualize/agg_type_field_filter.js index 9d19dff648667..6f44e0ef90efd 100644 --- a/x-pack/legacy/plugins/rollup/public/visualize/agg_type_field_filter.js +++ b/x-pack/legacy/plugins/rollup/public/visualize/agg_type_field_filter.js @@ -4,9 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { aggTypeFieldFilters } from 'ui/agg_types/param_types/filter'; - -export function initAggTypeFieldFilter() { +export function initAggTypeFieldFilter(aggTypeFieldFilters) { /** * If rollup index pattern, check its capabilities * and limit available fields for a given aggType based on that. diff --git a/x-pack/legacy/plugins/rollup/public/visualize/agg_type_filter.js b/x-pack/legacy/plugins/rollup/public/visualize/agg_type_filter.js index 75b11dac06cf5..5f9fab3061a19 100644 --- a/x-pack/legacy/plugins/rollup/public/visualize/agg_type_filter.js +++ b/x-pack/legacy/plugins/rollup/public/visualize/agg_type_filter.js @@ -4,9 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { aggTypeFilters } from 'ui/agg_types/filter'; - -export function initAggTypeFilter() { +export function initAggTypeFilter(aggTypeFilters) { /** * If rollup index pattern, check its capabilities * and limit available aggregations based on that. diff --git a/x-pack/legacy/plugins/rollup/public/visualize/editor_config.js b/x-pack/legacy/plugins/rollup/public/visualize/editor_config.js index 590f3dc85740e..5087ac3d64e84 100644 --- a/x-pack/legacy/plugins/rollup/public/visualize/editor_config.js +++ b/x-pack/legacy/plugins/rollup/public/visualize/editor_config.js @@ -5,9 +5,8 @@ */ import { i18n } from '@kbn/i18n'; -import { editorConfigProviders } from 'ui/vis/editors/config/editor_config_providers'; -export function initEditorConfig() { +export function initEditorConfig(editorConfigProviders) { // Limit agg params based on rollup capabilities editorConfigProviders.register((aggType, indexPattern, aggConfig) => { if (indexPattern.type !== 'rollup') { diff --git a/x-pack/legacy/plugins/rollup/public/visualize/index.js b/x-pack/legacy/plugins/rollup/public/visualize/index.js deleted file mode 100644 index e5a9c63c91a92..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/visualize/index.js +++ /dev/null @@ -1,21 +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 chrome from 'ui/chrome'; - -import { initAggTypeFilter } from './agg_type_filter'; -import { initAggTypeFieldFilter } from './agg_type_field_filter'; -import { initEditorConfig } from './editor_config'; -import { CONFIG_ROLLUPS } from '../../common'; - -const uiSettings = chrome.getUiSettingsClient(); -const isRollupIndexPatternsEnabled = uiSettings.get(CONFIG_ROLLUPS); - -if (isRollupIndexPatternsEnabled) { - initAggTypeFilter(); - initAggTypeFieldFilter(); - initEditorConfig(); -} From ce83531ca03c815d7d883ad69aac8b6fef91ffc1 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Fri, 20 Dec 2019 17:49:24 +0100 Subject: [PATCH 02/39] continued shimming rollup ui --- x-pack/legacy/plugins/rollup/index.js | 12 ++-- .../plugins/rollup/public/angular/index.js | 54 +++++++++++++++ .../public/{crud_app => angular}/main.html | 0 .../plugins/rollup/public/crud_app/index.js | 69 ------------------- x-pack/legacy/plugins/rollup/public/legacy.ts | 37 ++++++++++ .../rollup/public/{plugin.ts => plugin.tsx} | 43 +++++++++++- 6 files changed, 137 insertions(+), 78 deletions(-) create mode 100644 x-pack/legacy/plugins/rollup/public/angular/index.js rename x-pack/legacy/plugins/rollup/public/{crud_app => angular}/main.html (100%) delete mode 100644 x-pack/legacy/plugins/rollup/public/crud_app/index.js create mode 100644 x-pack/legacy/plugins/rollup/public/legacy.ts rename x-pack/legacy/plugins/rollup/public/{plugin.ts => plugin.tsx} (75%) diff --git a/x-pack/legacy/plugins/rollup/index.js b/x-pack/legacy/plugins/rollup/index.js index f4210435abc09..a10407b19fa93 100644 --- a/x-pack/legacy/plugins/rollup/index.js +++ b/x-pack/legacy/plugins/rollup/index.js @@ -26,7 +26,7 @@ export function rollup(kibana) { require: ['kibana', 'elasticsearch', 'xpack_main'], uiExports: { styleSheetPaths: resolve(__dirname, 'public/index.scss'), - managementSections: ['plugins/rollup/crud_app'], + managementSections: ['plugins/rollup/legacy'], uiSettingDefaults: { [CONFIG_ROLLUPS]: { name: i18n.translate('xpack.rollupJobs.rollupIndexPatternsTitle', { @@ -41,13 +41,9 @@ export function rollup(kibana) { category: ['rollups'], }, }, - indexManagement: [ - 'plugins/rollup/index_pattern_creation', - 'plugins/rollup/index_pattern_list', - 'plugins/rollup/extend_index_management', - ], - visualize: ['plugins/rollup/visualize'], - search: ['plugins/rollup/search'], + indexManagement: ['plugins/rollup/legacy'], + visualize: ['plugins/rollup/legacy'], + search: ['plugins/rollup/legacy'], }, init: function(server) { const { usageCollection } = server.newPlatform.setup.plugins; diff --git a/x-pack/legacy/plugins/rollup/public/angular/index.js b/x-pack/legacy/plugins/rollup/public/angular/index.js new file mode 100644 index 0000000000000..ed76e3140bb98 --- /dev/null +++ b/x-pack/legacy/plugins/rollup/public/angular/index.js @@ -0,0 +1,54 @@ +/* + * 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 routes from 'ui/routes'; + +import { CRUD_APP_BASE_PATH } from '../crud_app/constants'; +import { setHttp, setUserHasLeftApp } from '../crud_app/services'; +import template from './main.html'; + +export function registerRollupApp(renderFn) { + routes.when(`${CRUD_APP_BASE_PATH}/:view?`, { + template: template, + controllerAs: 'rollupJobs', + controller: class IndexRollupJobsController { + constructor($scope, $route, $injector) { + // NOTE: We depend upon Angular's $http service because it's decorated with interceptors, + // e.g. to check license status per request. + setHttp($injector.get('$http')); + + // If returning to the app, we'll need to reset this state. + setUserHasLeftApp(false); + + $scope.$$postDigest(() => { + const appElement = document.getElementById('rollupJobsReactRoot'); + const onUnmount = renderFn(appElement); + + const appRoute = $route.current; + const stopListeningForLocationChange = $scope.$on('$locationChangeSuccess', () => { + const currentRoute = $route.current; + + const isNavigationInApp = currentRoute.$$route.template === appRoute.$$route.template; + + // When we navigate within rollups, prevent Angular from re-matching the route and + // rebuilding the app. + if (isNavigationInApp) { + $route.current = appRoute; + } else { + // Set internal flag so we can prevent reacting to the route change internally. + setUserHasLeftApp(true); + } + }); + + $scope.$on('$destroy', () => { + stopListeningForLocationChange(); + onUnmount(); + }); + }); + } + }, + }); +} diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/main.html b/x-pack/legacy/plugins/rollup/public/angular/main.html similarity index 100% rename from x-pack/legacy/plugins/rollup/public/crud_app/main.html rename to x-pack/legacy/plugins/rollup/public/angular/main.html diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/index.js deleted file mode 100644 index 2dc2af8f59050..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/crud_app/index.js +++ /dev/null @@ -1,69 +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 React from 'react'; -import { render, unmountComponentAtNode } from 'react-dom'; -import { Provider } from 'react-redux'; -import { I18nContext } from 'ui/i18n'; -import routes from 'ui/routes'; - -import { CRUD_APP_BASE_PATH } from './constants'; -import { setHttp, setUserHasLeftApp } from './services'; -import { App } from './app'; -import template from './main.html'; -import { rollupJobsStore } from './store'; - -const renderReact = async elem => { - render( - - - - - , - elem - ); -}; - -routes.when(`${CRUD_APP_BASE_PATH}/:view?`, { - template: template, - controllerAs: 'rollupJobs', - controller: class IndexRollupJobsController { - constructor($scope, $route, $injector) { - // NOTE: We depend upon Angular's $http service because it's decorated with interceptors, - // e.g. to check license status per request. - setHttp($injector.get('$http')); - - // If returning to the app, we'll need to reset this state. - setUserHasLeftApp(false); - - $scope.$$postDigest(() => { - const appElement = document.getElementById('rollupJobsReactRoot'); - renderReact(appElement); - - const appRoute = $route.current; - const stopListeningForLocationChange = $scope.$on('$locationChangeSuccess', () => { - const currentRoute = $route.current; - - const isNavigationInApp = currentRoute.$$route.template === appRoute.$$route.template; - - // When we navigate within rollups, prevent Angular from re-matching the route and - // rebuilding the app. - if (isNavigationInApp) { - $route.current = appRoute; - } else { - // Set internal flag so we can prevent reacting to the route change internally. - setUserHasLeftApp(true); - } - }); - - $scope.$on('$destroy', () => { - stopListeningForLocationChange(); - unmountComponentAtNode(appElement); - }); - }); - } - }, -}); diff --git a/x-pack/legacy/plugins/rollup/public/legacy.ts b/x-pack/legacy/plugins/rollup/public/legacy.ts new file mode 100644 index 0000000000000..a9c45c850bd5d --- /dev/null +++ b/x-pack/legacy/plugins/rollup/public/legacy.ts @@ -0,0 +1,37 @@ +/* + * 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 { npSetup, npStart } from 'ui/new_platform'; +import { aggTypeFilters } from 'ui/agg_types/filter'; +import { aggTypeFieldFilters } from 'ui/agg_types/param_types/filter'; +import { editorConfigProviders } from 'ui/vis/editors/config/editor_config_providers'; +import { addSearchStrategy } from 'ui/courier'; +import { RollupPlugin } from './plugin'; +import { setup as management } from '../../../../../src/legacy/core_plugins/management/public/legacy'; +import { addBadgeExtension, addToggleExtension } from '../../index_management/public'; +// @ts-ignore +import { registerRollupApp } from './angular'; + +const plugin = new RollupPlugin(); + +export const setup = plugin.setup(npSetup.core, { + ...npSetup.plugins, + __LEGACY: { + aggTypeFilters, + aggTypeFieldFilters, + editorConfigProviders, + addSearchStrategy, + addBadgeExtension, + addToggleExtension, + management, + }, +}); +export const start = plugin.start(npStart.core, { + ...npStart.plugins, + __LEGACY: { + registerRollupApp, + }, +}); diff --git a/x-pack/legacy/plugins/rollup/public/plugin.ts b/x-pack/legacy/plugins/rollup/public/plugin.tsx similarity index 75% rename from x-pack/legacy/plugins/rollup/public/plugin.ts rename to x-pack/legacy/plugins/rollup/public/plugin.tsx index d0ef98fb650fe..1c53c7f5f82a1 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.ts +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -4,6 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ +import { render, unmountComponentAtNode } from 'react-dom'; +import { Provider } from 'react-redux'; +import React from 'react'; import { i18n } from '@kbn/i18n'; import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; import { EditorConfigProviderRegistry } from 'ui/vis/editors/config/editor_config_providers'; @@ -29,7 +32,12 @@ import { } from '../../../../../src/plugins/home/public'; // @ts-ignore import { CRUD_APP_BASE_PATH } from './crud_app/constants'; +// @ts-ignore +import { App } from './crud_app/app'; import { ManagementStart } from '../../../../../src/plugins/management/public'; +// @ts-ignore +import { rollupJobsStore } from './crud_app/store'; +import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; export interface RollupPluginSetupDependencies { __LEGACY: { @@ -46,6 +54,11 @@ export interface RollupPluginSetupDependencies { export interface RollupPluginStartDependencies { management: ManagementStart; + __LEGACY: { + // TODO this becomes part of the management section register function as soon as + // the API is ready + registerRollupApp: (renderFunction: (element: HTMLElement) => void) => () => void; + }; } export class RollupPlugin implements Plugin { @@ -94,7 +107,10 @@ export class RollupPlugin implements Plugin { } } - start(core: CoreStart, { management }: RollupPluginStartDependencies) { + start( + core: CoreStart, + { management, __LEGACY: { registerRollupApp } }: RollupPluginStartDependencies + ) { const esSection = management.legacy.getSection('elasticsearch'); esSection.register('rollup_jobs', { @@ -103,5 +119,30 @@ export class RollupPlugin implements Plugin { order: 3, url: `#${CRUD_APP_BASE_PATH}/job_list`, }); + + const I18nContext = core.i18n.Context; + + registerRollupApp(elem => { + render( + + + + + + + , + elem + ); + + return () => { + unmountComponentAtNode(elem); + }; + }); } } From 6dba8d49cc11ac89c34dfa3372ae0f6b97f88eea Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Thu, 9 Jan 2020 09:49:04 +0300 Subject: [PATCH 03/39] Remove unnecessarily return --- .../rollup_index_pattern_creation_config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js index 2540f99821ecf..c506475b71842 100644 --- a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js +++ b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js @@ -68,7 +68,6 @@ export class RollupIndexPatternCreationConfig extends IndexPatternCreationConfig const isAnonymous = npSetup.core.http.anonymousPaths.isAnonymous(window.location.pathname); if (!isAnonymous) { const response = await this.httpClient.get('/api/rollup/indices'); - return response || {}; this.rollupIndicesCapabilities = response || {}; } From 937297c5112c50b507ff18a1e96af0598a39c2e3 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Thu, 9 Jan 2020 11:45:30 +0300 Subject: [PATCH 04/39] Register management section --- .../sections/job_create/job_create.js | 2 +- .../rollup/public/crud_app/services/api.js | 12 ++- .../crud_app/store/actions/create_job.js | 2 +- .../legacy/plugins/rollup/public/plugin.tsx | 79 +++++++++++-------- 4 files changed, 51 insertions(+), 44 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js index a8e921973efc0..12fd5f41cc23b 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js @@ -181,7 +181,7 @@ export class JobCreateUi extends Component { dateFields: indexPatternDateFields, numericFields, keywordFields, - } = response.data; + } = response; let indexPatternAsyncErrors; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js index e712415f9568d..22c992f17680b 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js @@ -20,36 +20,34 @@ import { trackUserRequest } from './track_ui_metric'; const apiPrefix = chrome.addBasePath('/api/rollup'); export async function loadJobs() { - const { - data: { jobs }, - } = await getHttp().get(`${apiPrefix}/jobs`); + const { jobs } = await getHttp().get(`${apiPrefix}/jobs`); return jobs; } export async function startJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${apiPrefix}/start`, body); + const request = getHttp().post(`${apiPrefix}/start`, { body: JSON.stringify(body) }); const actionType = jobIds.length > 1 ? UIM_JOB_START_MANY : UIM_JOB_START; return await trackUserRequest(request, actionType); } export async function stopJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${apiPrefix}/stop`, body); + const request = getHttp().post(`${apiPrefix}/stop`, { body: JSON.stringify(body) }); const actionType = jobIds.length > 1 ? UIM_JOB_STOP_MANY : UIM_JOB_STOP; return await trackUserRequest(request, actionType); } export async function deleteJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${apiPrefix}/delete`, body); + const request = getHttp().post(`${apiPrefix}/delete`, { body: JSON.stringify(body) }); const actionType = jobIds.length > 1 ? UIM_JOB_DELETE_MANY : UIM_JOB_DELETE; return await trackUserRequest(request, actionType); } export async function createJob(job) { const body = { job }; - const request = getHttp().put(`${apiPrefix}/create`, body); + const request = getHttp().put(`${apiPrefix}/create`, { body: JSON.stringify(body) }); return await trackUserRequest(request, UIM_JOB_CREATE); } diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js index 163860b7f24c6..753c8e78f00b2 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js @@ -86,7 +86,7 @@ export const createJob = jobConfig => async dispatch => { ); } - const deserializedJob = deserializeJob(newJob.data); + const deserializedJob = deserializeJob(newJob); dispatch({ type: CREATE_JOB_SUCCESS, diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.tsx index 1c53c7f5f82a1..3326e0d9adfe4 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -5,6 +5,7 @@ */ import { render, unmountComponentAtNode } from 'react-dom'; +import { HashRouter as Router } from 'react-router-dom'; import { Provider } from 'react-redux'; import React from 'react'; import { i18n } from '@kbn/i18n'; @@ -38,6 +39,8 @@ import { ManagementStart } from '../../../../../src/plugins/management/public'; // @ts-ignore import { rollupJobsStore } from './crud_app/store'; import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; +// @ts-ignore +import { setHttp } from './crud_app/services'; export interface RollupPluginSetupDependencies { __LEGACY: { @@ -70,7 +73,7 @@ export class RollupPlugin implements Plugin { aggTypeFieldFilters, editorConfigProviders, addSearchStrategy, - management, + management: managementLegacy, addBadgeExtension, addToggleExtension, }, @@ -83,8 +86,8 @@ export class RollupPlugin implements Plugin { const isRollupIndexPatternsEnabled = core.uiSettings.get(CONFIG_ROLLUPS); if (isRollupIndexPatternsEnabled) { - management.indexPattern.creation.add(RollupIndexPatternCreationConfig); - management.indexPattern.list.add(RollupIndexPatternListConfig); + managementLegacy.indexPattern.creation.add(RollupIndexPatternCreationConfig); + managementLegacy.indexPattern.list.add(RollupIndexPatternListConfig); addSearchStrategy(rollupSearchStrategy); initAggTypeFilter(aggTypeFilters); initAggTypeFieldFilter(aggTypeFieldFilters); @@ -107,42 +110,48 @@ export class RollupPlugin implements Plugin { } } - start( - core: CoreStart, - { management, __LEGACY: { registerRollupApp } }: RollupPluginStartDependencies - ) { - const esSection = management.legacy.getSection('elasticsearch'); - - esSection.register('rollup_jobs', { - visible: true, - display: i18n.translate('xpack.rollupJobs.appTitle', { defaultMessage: 'Rollup Jobs' }), - order: 3, - url: `#${CRUD_APP_BASE_PATH}/job_list`, - }); + start(core: CoreStart, { management }: RollupPluginStartDependencies) { + setHttp(core.http); + const esSection = management.sections.getSection('elasticsearch'); const I18nContext = core.i18n.Context; - registerRollupApp(elem => { - render( - - - - - - - , - elem - ); + esSection!.registerApp({ + id: 'rollup_jobs', + title: i18n.translate('xpack.rollupJobs.appTitle', { defaultMessage: 'Rollup Jobs' }), + order: 3, + mount(params) { + params.setBreadcrumbs([ + { + text: i18n.translate('xpack.rollupJobs.breadcrumbsTitle', { + defaultMessage: 'Rollup Jobs', + }), + }, + ]); + + render( + + + + + + + + + , + params.element + ); - return () => { - unmountComponentAtNode(elem); - }; + return () => { + unmountComponentAtNode(params.element); + }; + }, }); } } From bd7df05ca35dcf05cdab86579ac42a3a2147c6c0 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Fri, 10 Jan 2020 10:19:27 +0300 Subject: [PATCH 05/39] Replace ui/chrome --- .../plugins/rollup/public/angular/index.js | 54 ------------------- .../plugins/rollup/public/angular/main.html | 3 -- .../rollup/public/crud_app/_crud_app.scss | 4 -- .../plugins/rollup/public/crud_app/app.js | 7 +-- .../sections/job_create/job_create.js | 10 ++-- .../crud_app/sections/job_list/job_list.js | 19 +++---- .../rollup/public/crud_app/services/api.js | 22 +++++--- .../public/crud_app/services/http_provider.js | 2 - .../rollup/public/crud_app/services/index.js | 18 ++++--- .../public/crud_app/services/routing.js | 10 ---- .../crud_app/store/middleware/clone_job.js | 10 ++-- .../crud_app/store/middleware/detail_panel.js | 14 +++-- .../legacy/plugins/rollup/public/plugin.tsx | 4 +- 13 files changed, 51 insertions(+), 126 deletions(-) delete mode 100644 x-pack/legacy/plugins/rollup/public/angular/index.js delete mode 100644 x-pack/legacy/plugins/rollup/public/angular/main.html diff --git a/x-pack/legacy/plugins/rollup/public/angular/index.js b/x-pack/legacy/plugins/rollup/public/angular/index.js deleted file mode 100644 index ed76e3140bb98..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/angular/index.js +++ /dev/null @@ -1,54 +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 routes from 'ui/routes'; - -import { CRUD_APP_BASE_PATH } from '../crud_app/constants'; -import { setHttp, setUserHasLeftApp } from '../crud_app/services'; -import template from './main.html'; - -export function registerRollupApp(renderFn) { - routes.when(`${CRUD_APP_BASE_PATH}/:view?`, { - template: template, - controllerAs: 'rollupJobs', - controller: class IndexRollupJobsController { - constructor($scope, $route, $injector) { - // NOTE: We depend upon Angular's $http service because it's decorated with interceptors, - // e.g. to check license status per request. - setHttp($injector.get('$http')); - - // If returning to the app, we'll need to reset this state. - setUserHasLeftApp(false); - - $scope.$$postDigest(() => { - const appElement = document.getElementById('rollupJobsReactRoot'); - const onUnmount = renderFn(appElement); - - const appRoute = $route.current; - const stopListeningForLocationChange = $scope.$on('$locationChangeSuccess', () => { - const currentRoute = $route.current; - - const isNavigationInApp = currentRoute.$$route.template === appRoute.$$route.template; - - // When we navigate within rollups, prevent Angular from re-matching the route and - // rebuilding the app. - if (isNavigationInApp) { - $route.current = appRoute; - } else { - // Set internal flag so we can prevent reacting to the route change internally. - setUserHasLeftApp(true); - } - }); - - $scope.$on('$destroy', () => { - stopListeningForLocationChange(); - onUnmount(); - }); - }); - } - }, - }); -} diff --git a/x-pack/legacy/plugins/rollup/public/angular/main.html b/x-pack/legacy/plugins/rollup/public/angular/main.html deleted file mode 100644 index 2956d157e784c..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/angular/main.html +++ /dev/null @@ -1,3 +0,0 @@ - -
-
diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/_crud_app.scss b/x-pack/legacy/plugins/rollup/public/crud_app/_crud_app.scss index e1166d0942a5c..9e3bd491115ce 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/_crud_app.scss +++ b/x-pack/legacy/plugins/rollup/public/crud_app/_crud_app.scss @@ -5,10 +5,6 @@ align-items: flex-end; /* 1 */ } -.rollupJobsRoot { - display: flex; -} - /** * 1. Ensure panel fills width of parent when search input yields no matching rollup jobs. */ diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/app.js b/x-pack/legacy/plugins/rollup/public/crud_app/app.js index da35c8a56f2d2..f28398ca58963 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/app.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/app.js @@ -10,7 +10,7 @@ import { HashRouter, Switch, Route, Redirect, withRouter } from 'react-router-do import { UIM_APP_LOAD } from '../../common'; import { CRUD_APP_BASE_PATH } from './constants'; -import { registerRouter, setUserHasLeftApp, trackUiMetric, METRIC_TYPE } from './services'; +import { registerRouter, trackUiMetric, METRIC_TYPE } from './services'; import { JobList, JobCreate } from './sections'; class ShareRouterComponent extends Component { @@ -45,11 +45,6 @@ export class App extends Component { trackUiMetric(METRIC_TYPE.LOADED, UIM_APP_LOAD); } - componentWillUnmount() { - // Set internal flag so we can prevent reacting to route changes internally. - setUserHasLeftApp(true); - } - render() { return ( diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js index 12fd5f41cc23b..5b8622dcf8f51 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js @@ -12,9 +12,9 @@ import debounce from 'lodash/function/debounce'; import first from 'lodash/array/first'; import { i18n } from '@kbn/i18n'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; -import chrome from 'ui/chrome'; -import { MANAGEMENT_BREADCRUMB } from 'ui/management'; +import { FormattedMessage } from '@kbn/i18n/react'; + +import { withKibana } from '../../../../../../../../src/plugins/kibana_react/public/'; import { EuiCallOut, @@ -92,7 +92,7 @@ export class JobCreateUi extends Component { constructor(props) { super(props); - chrome.breadcrumbs.set([MANAGEMENT_BREADCRUMB, listBreadcrumb, createBreadcrumb]); + props.kibana.services.setBreadcrumbs([listBreadcrumb, createBreadcrumb]); const { jobToClone: stepDefaultOverrides } = props; const stepsFields = mapValues(stepIdToStepConfigMap, step => cloneDeep(step.getDefaultFields(stepDefaultOverrides)) @@ -689,4 +689,4 @@ export class JobCreateUi extends Component { } } -export const JobCreate = injectI18n(JobCreateUi); +export const JobCreate = withKibana(JobCreateUi); diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.js index 035a53206c71d..bf73d93c1b73b 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.js @@ -6,9 +6,8 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; -import chrome from 'ui/chrome'; -import { MANAGEMENT_BREADCRUMB } from 'ui/management'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; import { EuiButton, @@ -26,6 +25,8 @@ import { EuiCallOut, } from '@elastic/eui'; +import { withKibana } from '../../../../../../../../src/plugins/kibana_react/public/'; + import { CRUD_APP_BASE_PATH } from '../../constants'; import { getRouterLinkProps, extractQueryParams, listBreadcrumb } from '../../services'; @@ -67,7 +68,7 @@ export class JobListUi extends Component { props.loadJobs(); - chrome.breadcrumbs.set([MANAGEMENT_BREADCRUMB, listBreadcrumb]); + props.kibana.services.setBreadcrumbs([listBreadcrumb]); this.state = {}; } @@ -97,9 +98,7 @@ export class JobListUi extends Component { } renderNoPermission() { - const { intl } = this.props; - const title = intl.formatMessage({ - id: 'xpack.rollupJobs.jobList.noPermissionTitle', + const title = i18n.translate('xpack.rollupJobs.jobList.noPermissionTitle', { defaultMessage: 'Permission error', }); return ( @@ -126,9 +125,7 @@ export class JobListUi extends Component { // handle unexpected error shapes in the API action. const { statusCode, error: errorString } = error.data; - const { intl } = this.props; - const title = intl.formatMessage({ - id: 'xpack.rollupJobs.jobList.loadingErrorTitle', + const title = i18n.translate('xpack.rollupJobs.jobList.loadingErrorTitle', { defaultMessage: 'Error loading rollup jobs', }); return ( @@ -254,4 +251,4 @@ export class JobListUi extends Component { } } -export const JobList = injectI18n(JobListUi); +export const JobList = withKibana(JobListUi); diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js index 22c992f17680b..be377b576b3fb 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import chrome from 'ui/chrome'; import { UIM_JOB_CREATE, UIM_JOB_DELETE, @@ -17,40 +16,47 @@ import { import { getHttp } from './http_provider'; import { trackUserRequest } from './track_ui_metric'; -const apiPrefix = chrome.addBasePath('/api/rollup'); +let apiPrefix; +export function setApiPrefix(prefix) { + apiPrefix = prefix; +} + +export function getApiPrefix() { + return apiPrefix; +} export async function loadJobs() { - const { jobs } = await getHttp().get(`${apiPrefix}/jobs`); + const { jobs } = await getHttp().get(`${getApiPrefix()}/jobs`); return jobs; } export async function startJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${apiPrefix}/start`, { body: JSON.stringify(body) }); + const request = getHttp().post(`${getApiPrefix()}/start`, { body: JSON.stringify(body) }); const actionType = jobIds.length > 1 ? UIM_JOB_START_MANY : UIM_JOB_START; return await trackUserRequest(request, actionType); } export async function stopJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${apiPrefix}/stop`, { body: JSON.stringify(body) }); + const request = getHttp().post(`${getApiPrefix()}/stop`, { body: JSON.stringify(body) }); const actionType = jobIds.length > 1 ? UIM_JOB_STOP_MANY : UIM_JOB_STOP; return await trackUserRequest(request, actionType); } export async function deleteJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${apiPrefix}/delete`, { body: JSON.stringify(body) }); + const request = getHttp().post(`${getApiPrefix()}/delete`, { body: JSON.stringify(body) }); const actionType = jobIds.length > 1 ? UIM_JOB_DELETE_MANY : UIM_JOB_DELETE; return await trackUserRequest(request, actionType); } export async function createJob(job) { const body = { job }; - const request = getHttp().put(`${apiPrefix}/create`, { body: JSON.stringify(body) }); + const request = getHttp().put(`${getApiPrefix()}/create`, { body: JSON.stringify(body) }); return await trackUserRequest(request, UIM_JOB_CREATE); } export async function validateIndexPattern(indexPattern) { - return await getHttp().get(`${apiPrefix}/index_pattern_validity/${indexPattern}`); + return await getHttp().get(`${getApiPrefix()}/index_pattern_validity/${indexPattern}`); } diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.js index 835a7bdc09d86..0d202a2c9a0ed 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.js @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -// This is an Angular service, which is why we use this provider pattern to access it within -// our React app. let _http; export function setHttp(http) { diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js index 74ed8d8c325c0..d2f1465b60519 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js @@ -4,7 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -export { createJob, deleteJobs, loadJobs, startJobs, stopJobs, validateIndexPattern } from './api'; +export { + createJob, + deleteJobs, + loadJobs, + startJobs, + stopJobs, + validateIndexPattern, + setApiPrefix, +} from './api'; export { showApiError, showApiWarning } from './api_errors'; @@ -34,13 +42,7 @@ export { createNoticeableDelay } from './noticeable_delay'; export { extractQueryParams } from './query_params'; -export { - setUserHasLeftApp, - getUserHasLeftApp, - registerRouter, - getRouter, - getRouterLinkProps, -} from './routing'; +export { registerRouter, getRouter, getRouterLinkProps } from './routing'; export { sortTable } from './sort_table'; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/routing.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/routing.js index 3b78e73c6b3af..a21ed780a748a 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/routing.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/routing.js @@ -10,16 +10,6 @@ import { createLocation } from 'history'; -let _userHasLeftApp = false; - -export function setUserHasLeftApp(userHasLeftApp) { - _userHasLeftApp = userHasLeftApp; -} - -export function getUserHasLeftApp() { - return _userHasLeftApp; -} - const isModifiedEvent = event => !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey); diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/clone_job.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/clone_job.js index e424232cce0a1..433934b0b9c38 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/clone_job.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/clone_job.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getRouter, getUserHasLeftApp } from '../../services'; +import { getRouter } from '../../services'; import { CLONE_JOB_START } from '../action_types'; import { CRUD_APP_BASE_PATH } from '../../constants'; @@ -12,11 +12,9 @@ export const cloneJob = () => next => action => { const { type } = action; if (type === CLONE_JOB_START) { - if (!getUserHasLeftApp()) { - getRouter().history.push({ - pathname: `${CRUD_APP_BASE_PATH}/create`, - }); - } + getRouter().history.push({ + pathname: `${CRUD_APP_BASE_PATH}/create`, + }); } return next(action); diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/detail_panel.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/detail_panel.js index cbe86fb7065b6..062b44b51a9b1 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/detail_panel.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/detail_panel.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getRouter, getUserHasLeftApp } from '../../services'; +import { getRouter } from '../../services'; import { CLOSE_DETAIL_PANEL } from '../action_types'; export const detailPanel = () => next => action => { @@ -12,14 +12,12 @@ export const detailPanel = () => next => action => { switch (type) { case CLOSE_DETAIL_PANEL: - if (!getUserHasLeftApp()) { - const { history } = getRouter(); + const { history } = getRouter(); - // Persist state to query params by removing deep link. - history.replace({ - search: '', - }); - } + // Persist state to query params by removing deep link. + history.replace({ + search: '', + }); break; } diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.tsx index 3326e0d9adfe4..8b71650858676 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -40,7 +40,7 @@ import { ManagementStart } from '../../../../../src/plugins/management/public'; import { rollupJobsStore } from './crud_app/store'; import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; // @ts-ignore -import { setHttp } from './crud_app/services'; +import { setHttp, setApiPrefix } from './crud_app/services'; export interface RollupPluginSetupDependencies { __LEGACY: { @@ -112,6 +112,7 @@ export class RollupPlugin implements Plugin { start(core: CoreStart, { management }: RollupPluginStartDependencies) { setHttp(core.http); + setApiPrefix(core.http.basePath.prepend('/api/rollup')); const esSection = management.sections.getSection('elasticsearch'); const I18nContext = core.i18n.Context; @@ -137,6 +138,7 @@ export class RollupPlugin implements Plugin { http: core.http, notifications: core.notifications, chrome: core.chrome, + setBreadcrumbs: params.setBreadcrumbs, }} > From f698766a068ec775481a45a734e47027447795b5 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Mon, 13 Jan 2020 14:04:11 +0300 Subject: [PATCH 06/39] Replace ui/documentation_links --- .../job_create/steps/step_date_histogram.js | 6 ++--- .../job_create/steps/step_histogram.js | 4 +-- .../job_create/steps/step_logistics.js | 6 ++--- .../sections/job_create/steps/step_metrics.js | 4 +-- .../sections/job_create/steps/step_terms.js | 4 +-- .../crud_app/services/documentation_links.js | 25 +++++++++++-------- .../rollup/public/crud_app/services/index.js | 15 +++++------ x-pack/legacy/plugins/rollup/public/legacy.ts | 9 +------ .../legacy/plugins/rollup/public/plugin.tsx | 10 +++----- 9 files changed, 40 insertions(+), 43 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js index c4ff37efa4490..433d4c39e07ea 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js @@ -26,7 +26,7 @@ import { import { parseEsInterval } from '../../../../../../../../../src/legacy/core_plugins/data/public'; -import { dateHistogramDetailsUrl, dateHistogramAggregationUrl } from '../../../services'; +import { getDateHistogramDetailsUrl, getDateHistogramAggregationUrl } from '../../../services'; import { StepError } from './components'; @@ -192,7 +192,7 @@ export class StepDateHistogramUi extends Component { + - + `${esBase}/rollup-job-config.html#_logistical_details`; +export const getDateHistogramDetailsUrl = () => + `${esBase}/rollup-job-config.html#_date_histogram_2`; +export const getTermsDetailsUrl = () => `${esBase}/rollup-job-config.html#_terms_2`; +export const getHistogramDetailsUrl = () => `${esBase}/rollup-job-config.html#_histogram_2`; +export const getMetricsDetailsUrl = () => `${esBase}/rollup-job-config.html#rollup-metrics-config`; -export const dateHistogramAggregationUrl = `${esBase}/search-aggregations-bucket-datehistogram-aggregation.html`; -export const cronUrl = `${xPackBase}/trigger-schedule.html#_cron_expressions`; +export const getDateHistogramAggregationUrl = () => + `${esBase}/search-aggregations-bucket-datehistogram-aggregation.html`; +export const getCronUrl = () => `${xPackBase}/trigger-schedule.html#_cron_expressions`; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js index d2f1465b60519..fb481b90c5dc1 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js @@ -19,13 +19,14 @@ export { showApiError, showApiWarning } from './api_errors'; export { listBreadcrumb, createBreadcrumb } from './breadcrumbs'; export { - logisticalDetailsUrl, - dateHistogramDetailsUrl, - dateHistogramAggregationUrl, - termsDetailsUrl, - histogramDetailsUrl, - metricsDetailsUrl, - cronUrl, + setEsBaseAndXPackBase, + getLogisticalDetailsUrl, + getDateHistogramDetailsUrl, + getDateHistogramAggregationUrl, + getTermsDetailsUrl, + getHistogramDetailsUrl, + getMetricsDetailsUrl, + getCronUrl, } from './documentation_links'; export { filterItems } from './filter_items'; diff --git a/x-pack/legacy/plugins/rollup/public/legacy.ts b/x-pack/legacy/plugins/rollup/public/legacy.ts index a9c45c850bd5d..aa2de21a58317 100644 --- a/x-pack/legacy/plugins/rollup/public/legacy.ts +++ b/x-pack/legacy/plugins/rollup/public/legacy.ts @@ -12,8 +12,6 @@ import { addSearchStrategy } from 'ui/courier'; import { RollupPlugin } from './plugin'; import { setup as management } from '../../../../../src/legacy/core_plugins/management/public/legacy'; import { addBadgeExtension, addToggleExtension } from '../../index_management/public'; -// @ts-ignore -import { registerRollupApp } from './angular'; const plugin = new RollupPlugin(); @@ -29,9 +27,4 @@ export const setup = plugin.setup(npSetup.core, { management, }, }); -export const start = plugin.start(npStart.core, { - ...npStart.plugins, - __LEGACY: { - registerRollupApp, - }, -}); +export const start = plugin.start(npStart.core, npStart.plugins); diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.tsx index 8b71650858676..6303740d4cdde 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -11,6 +11,7 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; import { EditorConfigProviderRegistry } from 'ui/vis/editors/config/editor_config_providers'; +// @ts-ignore import { SearchStrategyProvider } from 'ui/courier/search_strategy/types'; import { ManagementSetup } from '../../../../../src/legacy/core_plugins/management/public/np_ready'; import { rollupBadgeExtension, rollupToggleExtension } from './extend_index_management'; @@ -40,7 +41,7 @@ import { ManagementStart } from '../../../../../src/plugins/management/public'; import { rollupJobsStore } from './crud_app/store'; import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; // @ts-ignore -import { setHttp, setApiPrefix } from './crud_app/services'; +import { setHttp, setApiPrefix, setEsBaseAndXPackBase } from './crud_app/services'; export interface RollupPluginSetupDependencies { __LEGACY: { @@ -57,11 +58,6 @@ export interface RollupPluginSetupDependencies { export interface RollupPluginStartDependencies { management: ManagementStart; - __LEGACY: { - // TODO this becomes part of the management section register function as soon as - // the API is ready - registerRollupApp: (renderFunction: (element: HTMLElement) => void) => () => void; - }; } export class RollupPlugin implements Plugin { @@ -113,6 +109,8 @@ export class RollupPlugin implements Plugin { start(core: CoreStart, { management }: RollupPluginStartDependencies) { setHttp(core.http); setApiPrefix(core.http.basePath.prepend('/api/rollup')); + setEsBaseAndXPackBase(core.docLinks.ELASTIC_WEBSITE_URL, core.docLinks.DOC_LINK_VERSION); + const esSection = management.sections.getSection('elasticsearch'); const I18nContext = core.i18n.Context; From 9612ec79358de9b18bdaae48b8260d98f03b3556 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Wed, 15 Jan 2020 11:27:49 +0300 Subject: [PATCH 07/39] Replace ui/kfetch and ui/courier --- src/legacy/ui/public/courier/index.ts | 1 - x-pack/legacy/plugins/rollup/public/legacy.ts | 2 +- .../legacy/plugins/rollup/public/plugin.tsx | 8 ++--- ..._strategy.js => rollup_search_strategy.ts} | 30 ++++++++++--------- 4 files changed, 20 insertions(+), 21 deletions(-) rename x-pack/legacy/plugins/rollup/public/search/{rollup_search_strategy.js => rollup_search_strategy.ts} (77%) diff --git a/src/legacy/ui/public/courier/index.ts b/src/legacy/ui/public/courier/index.ts index 709ff1c11e901..51e418be4bde6 100644 --- a/src/legacy/ui/public/courier/index.ts +++ b/src/legacy/ui/public/courier/index.ts @@ -54,7 +54,6 @@ export { /* eslint-disable @kbn/eslint/no-restricted-paths */ export { addSearchStrategy, // used externally by Rollups - getSearchErrorType, // used externally by Rollups hasSearchStategyForIndexPattern, // used externally by Discover isDefaultTypeIndexPattern, // used externally by Discover SearchError, // used externally by Visualizations & Rollups diff --git a/x-pack/legacy/plugins/rollup/public/legacy.ts b/x-pack/legacy/plugins/rollup/public/legacy.ts index aa2de21a58317..29b58d20e1690 100644 --- a/x-pack/legacy/plugins/rollup/public/legacy.ts +++ b/x-pack/legacy/plugins/rollup/public/legacy.ts @@ -8,7 +8,7 @@ import { npSetup, npStart } from 'ui/new_platform'; import { aggTypeFilters } from 'ui/agg_types/filter'; import { aggTypeFieldFilters } from 'ui/agg_types/param_types/filter'; import { editorConfigProviders } from 'ui/vis/editors/config/editor_config_providers'; -import { addSearchStrategy } from 'ui/courier'; +import { addSearchStrategy } from '../../../../../src/legacy/core_plugins/data/public/search/search_strategy'; import { RollupPlugin } from './plugin'; import { setup as management } from '../../../../../src/legacy/core_plugins/management/public/legacy'; import { addBadgeExtension, addToggleExtension } from '../../index_management/public'; diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.tsx index 6303740d4cdde..14f916a5e9dd4 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -11,16 +11,14 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; import { EditorConfigProviderRegistry } from 'ui/vis/editors/config/editor_config_providers'; -// @ts-ignore -import { SearchStrategyProvider } from 'ui/courier/search_strategy/types'; +import { SearchStrategyProvider } from '../../../../../src/legacy/core_plugins/data/public/search/search_strategy/types'; import { ManagementSetup } from '../../../../../src/legacy/core_plugins/management/public/np_ready'; import { rollupBadgeExtension, rollupToggleExtension } from './extend_index_management'; // @ts-ignore import { RollupIndexPatternCreationConfig } from './index_pattern_creation/rollup_index_pattern_creation_config'; // @ts-ignore import { RollupIndexPatternListConfig } from './index_pattern_list/rollup_index_pattern_list_config'; -// @ts-ignore -import { rollupSearchStrategy } from './search/rollup_search_strategy'; +import { getRollupSearchStrategy } from './search/rollup_search_strategy'; // @ts-ignore import { initAggTypeFilter } from './visualize/agg_type_filter'; // @ts-ignore @@ -84,7 +82,7 @@ export class RollupPlugin implements Plugin { if (isRollupIndexPatternsEnabled) { managementLegacy.indexPattern.creation.add(RollupIndexPatternCreationConfig); managementLegacy.indexPattern.list.add(RollupIndexPatternListConfig); - addSearchStrategy(rollupSearchStrategy); + addSearchStrategy(getRollupSearchStrategy(core.http.fetch)); initAggTypeFilter(aggTypeFilters); initAggTypeFieldFilter(aggTypeFieldFilters); initEditorConfig(editorConfigProviders); diff --git a/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.js b/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts similarity index 77% rename from x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.js rename to x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts index becaf6dd338c8..2ddc86a9ad1f0 100644 --- a/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.js +++ b/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts @@ -4,12 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -import { kfetch } from 'ui/kfetch'; -import { SearchError, getSearchErrorType } from '../../../../../../src/legacy/ui/public/courier'; +import { HttpSetup } from 'src/core/public'; +import { + SearchError, + getSearchErrorType, +} from '../../../../../../src/legacy/core_plugins/data/public/search/search_strategy'; -function serializeFetchParams(searchRequests) { +function serializeFetchParams(searchRequests: any) { return JSON.stringify( - searchRequests.map(searchRequestWithFetchParams => { + searchRequests.map((searchRequestWithFetchParams: any) => { const indexPattern = searchRequestWithFetchParams.index.title || searchRequestWithFetchParams.index; const { @@ -17,7 +20,7 @@ function serializeFetchParams(searchRequests) { } = searchRequestWithFetchParams; const query = { - size: size, + size, aggregations: aggs, query: _query, }; @@ -30,8 +33,8 @@ function serializeFetchParams(searchRequests) { // Rollup search always returns 0 hits, but visualizations expect search responses // to return hits > 0, otherwise they do not render. We fake the number of hits here // by counting the number of aggregation buckets/values returned by rollup search. -function shimHitsInFetchResponse(response) { - return response.map(result => { +function shimHitsInFetchResponse(response: any) { + return response.map((result: any) => { const buckets = result.aggregations ? Object.keys(result.aggregations).reduce((allBuckets, agg) => { return allBuckets.concat( @@ -51,17 +54,16 @@ function shimHitsInFetchResponse(response) { }); } -export const rollupSearchStrategy = { +export const getRollupSearchStrategy = (fetch: HttpSetup['fetch']) => ({ id: 'rollup', - search: ({ searchRequests, Promise }) => { + search: ({ searchRequests }: any) => { // Serialize the fetch params into a format suitable for the body of an ES query. const serializedFetchParams = serializeFetchParams(searchRequests); const controller = new AbortController(); - const promise = kfetch({ + const promise = fetch('../api/rollup/search', { signal: controller.signal, - pathname: '../api/rollup/search', method: 'POST', body: serializedFetchParams, }); @@ -79,7 +81,7 @@ export const rollupSearchStrategy = { title, message: `Rollup search error: ${message}`, path: url, - type: getSearchErrorType({ message }), + type: getSearchErrorType({ message }) || '', }); return Promise.reject(searchError); @@ -88,11 +90,11 @@ export const rollupSearchStrategy = { }; }, - isViable: indexPattern => { + isViable: (indexPattern: any) => { if (!indexPattern) { return false; } return indexPattern.type === 'rollup'; }, -}; +}); From 4336dceb718ff081b8c8523d05ef203901dc2402 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Wed, 18 Dec 2019 17:15:35 +0100 Subject: [PATCH 08/39] Start shimming rollup plugin --- .../rollup/common/{index.js => index.ts} | 0 .../common/{ui_metric.js => ui_metric.ts} | 0 .../plugins/rollup/public/crud_app/index.js | 29 ----- .../{index.js => index.ts} | 12 +- .../public/index_pattern_creation/index.js | 17 --- .../public/index_pattern_creation/register.js | 12 -- .../rollup_index_pattern_creation_config.js | 6 +- .../rollup/public/index_pattern_list/index.js | 16 --- .../public/index_pattern_list/register.js | 12 -- x-pack/legacy/plugins/rollup/public/plugin.ts | 107 ++++++++++++++++++ .../plugins/rollup/public/search/index.js | 17 --- .../plugins/rollup/public/search/register.js | 12 -- .../plugins/rollup/public/services/api.js | 14 --- .../public/visualize/agg_type_field_filter.js | 4 +- .../public/visualize/agg_type_filter.js | 4 +- .../rollup/public/visualize/editor_config.js | 3 +- .../plugins/rollup/public/visualize/index.js | 21 ---- 17 files changed, 116 insertions(+), 170 deletions(-) rename x-pack/legacy/plugins/rollup/common/{index.js => index.ts} (100%) rename x-pack/legacy/plugins/rollup/common/{ui_metric.js => ui_metric.ts} (100%) rename x-pack/legacy/plugins/rollup/public/extend_index_management/{index.js => index.ts} (76%) delete mode 100644 x-pack/legacy/plugins/rollup/public/index_pattern_creation/index.js delete mode 100644 x-pack/legacy/plugins/rollup/public/index_pattern_creation/register.js delete mode 100644 x-pack/legacy/plugins/rollup/public/index_pattern_list/index.js delete mode 100644 x-pack/legacy/plugins/rollup/public/index_pattern_list/register.js create mode 100644 x-pack/legacy/plugins/rollup/public/plugin.ts delete mode 100644 x-pack/legacy/plugins/rollup/public/search/index.js delete mode 100644 x-pack/legacy/plugins/rollup/public/search/register.js delete mode 100644 x-pack/legacy/plugins/rollup/public/services/api.js delete mode 100644 x-pack/legacy/plugins/rollup/public/visualize/index.js diff --git a/x-pack/legacy/plugins/rollup/common/index.js b/x-pack/legacy/plugins/rollup/common/index.ts similarity index 100% rename from x-pack/legacy/plugins/rollup/common/index.js rename to x-pack/legacy/plugins/rollup/common/index.ts diff --git a/x-pack/legacy/plugins/rollup/common/ui_metric.js b/x-pack/legacy/plugins/rollup/common/ui_metric.ts similarity index 100% rename from x-pack/legacy/plugins/rollup/common/ui_metric.js rename to x-pack/legacy/plugins/rollup/common/ui_metric.ts diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/index.js index 82bbb90d2e33c..2dc2af8f59050 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/index.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/index.js @@ -5,15 +5,9 @@ */ import React from 'react'; -import { - FeatureCatalogueRegistryProvider, - FeatureCatalogueCategory, -} from 'ui/registry/feature_catalogue'; import { render, unmountComponentAtNode } from 'react-dom'; import { Provider } from 'react-redux'; -import { i18n } from '@kbn/i18n'; import { I18nContext } from 'ui/i18n'; -import { management } from 'ui/management'; import routes from 'ui/routes'; import { CRUD_APP_BASE_PATH } from './constants'; @@ -22,15 +16,6 @@ import { App } from './app'; import template from './main.html'; import { rollupJobsStore } from './store'; -const esSection = management.getSection('elasticsearch'); - -esSection.register('rollup_jobs', { - visible: true, - display: i18n.translate('xpack.rollupJobs.appTitle', { defaultMessage: 'Rollup Jobs' }), - order: 3, - url: `#${CRUD_APP_BASE_PATH}/job_list`, -}); - const renderReact = async elem => { render( @@ -82,17 +67,3 @@ routes.when(`${CRUD_APP_BASE_PATH}/:view?`, { } }, }); - -FeatureCatalogueRegistryProvider.register(() => { - return { - id: 'rollup_jobs', - title: 'Rollups', - description: i18n.translate('xpack.rollupJobs.featureCatalogueDescription', { - defaultMessage: 'Summarize and store historical data in a smaller index for future analysis.', - }), - icon: 'indexRollupApp', - path: `#${CRUD_APP_BASE_PATH}/job_list`, - showOnHomePage: true, - category: FeatureCatalogueCategory.ADMIN, - }; -}); diff --git a/x-pack/legacy/plugins/rollup/public/extend_index_management/index.js b/x-pack/legacy/plugins/rollup/public/extend_index_management/index.ts similarity index 76% rename from x-pack/legacy/plugins/rollup/public/extend_index_management/index.js rename to x-pack/legacy/plugins/rollup/public/extend_index_management/index.ts index 5e14d3eabc9a6..1a34811901bbe 100644 --- a/x-pack/legacy/plugins/rollup/public/extend_index_management/index.js +++ b/x-pack/legacy/plugins/rollup/public/extend_index_management/index.ts @@ -4,15 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ import { i18n } from '@kbn/i18n'; -import { - addToggleExtension, - addBadgeExtension, -} from '../../../index_management/public/index_management_extensions'; import { get } from 'lodash'; const propertyPath = 'isRollupIndex'; export const rollupToggleExtension = { - matchIndex: index => { + matchIndex: (index: { isRollupIndex: boolean }) => { return get(index, propertyPath); }, label: i18n.translate('xpack.rollupJobs.indexMgmtToggle.toggleLabel', { @@ -20,8 +16,9 @@ export const rollupToggleExtension = { }), name: 'rollupToggle', }; + export const rollupBadgeExtension = { - matchIndex: index => { + matchIndex: (index: { isRollupIndex: boolean }) => { return get(index, propertyPath); }, label: i18n.translate('xpack.rollupJobs.indexMgmtBadge.rollupLabel', { @@ -30,6 +27,3 @@ export const rollupBadgeExtension = { color: 'secondary', filterExpression: 'isRollupIndex:true', }; - -addBadgeExtension(rollupBadgeExtension); -addToggleExtension(rollupToggleExtension); diff --git a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/index.js b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/index.js deleted file mode 100644 index 1add469e073bd..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/index.js +++ /dev/null @@ -1,17 +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 chrome from 'ui/chrome'; - -import { initIndexPatternCreation } from './register'; -import { CONFIG_ROLLUPS } from '../../common'; - -const uiSettings = chrome.getUiSettingsClient(); -const isRollupIndexPatternsEnabled = uiSettings.get(CONFIG_ROLLUPS); - -if (isRollupIndexPatternsEnabled) { - initIndexPatternCreation(); -} diff --git a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/register.js b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/register.js deleted file mode 100644 index 9a3aed548dcc9..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/register.js +++ /dev/null @@ -1,12 +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 { setup as managementSetup } from '../../../../../../src/legacy/core_plugins/management/public/legacy'; -import { RollupIndexPatternCreationConfig } from './rollup_index_pattern_creation_config'; - -export function initIndexPatternCreation() { - managementSetup.indexPattern.creation.add(RollupIndexPatternCreationConfig); -} diff --git a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js index 07f2a674decc5..2540f99821ecf 100644 --- a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js +++ b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js @@ -9,7 +9,6 @@ import { i18n } from '@kbn/i18n'; import { npSetup } from 'ui/new_platform'; import { RollupPrompt } from './components/rollup_prompt'; -import { setHttpClient, getRollupIndices } from '../services/api'; import { IndexPatternCreationConfig } from '../../../../../../src/legacy/core_plugins/management/public'; const rollupIndexPatternTypeName = i18n.translate( @@ -54,7 +53,6 @@ export class RollupIndexPatternCreationConfig extends IndexPatternCreationConfig ...options, }); - setHttpClient(this.httpClient); this.rollupIndex = null; this.rollupJobs = []; this.rollupIndicesCapabilities = {}; @@ -69,7 +67,9 @@ export class RollupIndexPatternCreationConfig extends IndexPatternCreationConfig // request resolves after the logout request resolves, and un-clears the session ID. const isAnonymous = npSetup.core.http.anonymousPaths.isAnonymous(window.location.pathname); if (!isAnonymous) { - this.rollupIndicesCapabilities = await getRollupIndices(); + const response = await this.httpClient.get('/api/rollup/indices'); + return response || {}; + this.rollupIndicesCapabilities = response || {}; } this.rollupIndices = Object.keys(this.rollupIndicesCapabilities); diff --git a/x-pack/legacy/plugins/rollup/public/index_pattern_list/index.js b/x-pack/legacy/plugins/rollup/public/index_pattern_list/index.js deleted file mode 100644 index 63a3149faaadb..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/index_pattern_list/index.js +++ /dev/null @@ -1,16 +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 chrome from 'ui/chrome'; -import { initIndexPatternList } from './register'; -import { CONFIG_ROLLUPS } from '../../common'; - -const uiSettings = chrome.getUiSettingsClient(); -const isRollupIndexPatternsEnabled = uiSettings.get(CONFIG_ROLLUPS); - -if (isRollupIndexPatternsEnabled) { - initIndexPatternList(); -} diff --git a/x-pack/legacy/plugins/rollup/public/index_pattern_list/register.js b/x-pack/legacy/plugins/rollup/public/index_pattern_list/register.js deleted file mode 100644 index 173c28826436b..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/index_pattern_list/register.js +++ /dev/null @@ -1,12 +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 { setup as managementSetup } from '../../../../../../src/legacy/core_plugins/management/public/legacy'; -import { RollupIndexPatternListConfig } from './rollup_index_pattern_list_config'; - -export function initIndexPatternList() { - managementSetup.indexPattern.list.add(RollupIndexPatternListConfig); -} diff --git a/x-pack/legacy/plugins/rollup/public/plugin.ts b/x-pack/legacy/plugins/rollup/public/plugin.ts new file mode 100644 index 0000000000000..d0ef98fb650fe --- /dev/null +++ b/x-pack/legacy/plugins/rollup/public/plugin.ts @@ -0,0 +1,107 @@ +/* + * 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 { i18n } from '@kbn/i18n'; +import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; +import { EditorConfigProviderRegistry } from 'ui/vis/editors/config/editor_config_providers'; +import { SearchStrategyProvider } from 'ui/courier/search_strategy/types'; +import { ManagementSetup } from '../../../../../src/legacy/core_plugins/management/public/np_ready'; +import { rollupBadgeExtension, rollupToggleExtension } from './extend_index_management'; +// @ts-ignore +import { RollupIndexPatternCreationConfig } from './index_pattern_creation/rollup_index_pattern_creation_config'; +// @ts-ignore +import { RollupIndexPatternListConfig } from './index_pattern_list/rollup_index_pattern_list_config'; +// @ts-ignore +import { rollupSearchStrategy } from './search/rollup_search_strategy'; +// @ts-ignore +import { initAggTypeFilter } from './visualize/agg_type_filter'; +// @ts-ignore +import { initAggTypeFieldFilter } from './visualize/agg_type_field_filter'; +// @ts-ignore +import { initEditorConfig } from './visualize/editor_config'; +import { CONFIG_ROLLUPS } from '../common'; +import { + FeatureCatalogueCategory, + HomePublicPluginSetup, +} from '../../../../../src/plugins/home/public'; +// @ts-ignore +import { CRUD_APP_BASE_PATH } from './crud_app/constants'; +import { ManagementStart } from '../../../../../src/plugins/management/public'; + +export interface RollupPluginSetupDependencies { + __LEGACY: { + aggTypeFilters: any; + aggTypeFieldFilters: any; + editorConfigProviders: EditorConfigProviderRegistry; + addSearchStrategy: (searchStrategy: SearchStrategyProvider) => void; + management: ManagementSetup; + addBadgeExtension: (badgeExtension: any) => void; + addToggleExtension: (toggleExtension: any) => void; + }; + home?: HomePublicPluginSetup; +} + +export interface RollupPluginStartDependencies { + management: ManagementStart; +} + +export class RollupPlugin implements Plugin { + setup( + core: CoreSetup, + { + __LEGACY: { + aggTypeFilters, + aggTypeFieldFilters, + editorConfigProviders, + addSearchStrategy, + management, + addBadgeExtension, + addToggleExtension, + }, + home, + }: RollupPluginSetupDependencies + ) { + addBadgeExtension(rollupBadgeExtension); + addToggleExtension(rollupToggleExtension); + + const isRollupIndexPatternsEnabled = core.uiSettings.get(CONFIG_ROLLUPS); + + if (isRollupIndexPatternsEnabled) { + management.indexPattern.creation.add(RollupIndexPatternCreationConfig); + management.indexPattern.list.add(RollupIndexPatternListConfig); + addSearchStrategy(rollupSearchStrategy); + initAggTypeFilter(aggTypeFilters); + initAggTypeFieldFilter(aggTypeFieldFilters); + initEditorConfig(editorConfigProviders); + } + + if (home) { + home.featureCatalogue.register({ + id: 'rollup_jobs', + title: 'Rollups', + description: i18n.translate('xpack.rollupJobs.featureCatalogueDescription', { + defaultMessage: + 'Summarize and store historical data in a smaller index for future analysis.', + }), + icon: 'indexRollupApp', + path: `#${CRUD_APP_BASE_PATH}/job_list`, + showOnHomePage: true, + category: FeatureCatalogueCategory.ADMIN, + }); + } + } + + start(core: CoreStart, { management }: RollupPluginStartDependencies) { + const esSection = management.legacy.getSection('elasticsearch'); + + esSection.register('rollup_jobs', { + visible: true, + display: i18n.translate('xpack.rollupJobs.appTitle', { defaultMessage: 'Rollup Jobs' }), + order: 3, + url: `#${CRUD_APP_BASE_PATH}/job_list`, + }); + } +} diff --git a/x-pack/legacy/plugins/rollup/public/search/index.js b/x-pack/legacy/plugins/rollup/public/search/index.js deleted file mode 100644 index e76ba4817d72c..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/search/index.js +++ /dev/null @@ -1,17 +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 chrome from 'ui/chrome'; - -import { initSearch } from './register'; -import { CONFIG_ROLLUPS } from '../../common'; - -const uiSettings = chrome.getUiSettingsClient(); -const isRollupIndexPatternsEnabled = uiSettings.get(CONFIG_ROLLUPS); - -if (isRollupIndexPatternsEnabled) { - initSearch(); -} diff --git a/x-pack/legacy/plugins/rollup/public/search/register.js b/x-pack/legacy/plugins/rollup/public/search/register.js deleted file mode 100644 index f7f1c681b63ca..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/search/register.js +++ /dev/null @@ -1,12 +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 { addSearchStrategy } from '../../../../../../src/legacy/ui/public/courier'; -import { rollupSearchStrategy } from './rollup_search_strategy'; - -export function initSearch() { - addSearchStrategy(rollupSearchStrategy); -} diff --git a/x-pack/legacy/plugins/rollup/public/services/api.js b/x-pack/legacy/plugins/rollup/public/services/api.js deleted file mode 100644 index ae9e8756c7efc..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/services/api.js +++ /dev/null @@ -1,14 +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. - */ -let httpClient; -export const setHttpClient = client => { - httpClient = client; -}; - -export async function getRollupIndices() { - const response = await httpClient.get('/api/rollup/indices'); - return response || {}; -} diff --git a/x-pack/legacy/plugins/rollup/public/visualize/agg_type_field_filter.js b/x-pack/legacy/plugins/rollup/public/visualize/agg_type_field_filter.js index 9d19dff648667..6f44e0ef90efd 100644 --- a/x-pack/legacy/plugins/rollup/public/visualize/agg_type_field_filter.js +++ b/x-pack/legacy/plugins/rollup/public/visualize/agg_type_field_filter.js @@ -4,9 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { aggTypeFieldFilters } from 'ui/agg_types/param_types/filter'; - -export function initAggTypeFieldFilter() { +export function initAggTypeFieldFilter(aggTypeFieldFilters) { /** * If rollup index pattern, check its capabilities * and limit available fields for a given aggType based on that. diff --git a/x-pack/legacy/plugins/rollup/public/visualize/agg_type_filter.js b/x-pack/legacy/plugins/rollup/public/visualize/agg_type_filter.js index 75b11dac06cf5..5f9fab3061a19 100644 --- a/x-pack/legacy/plugins/rollup/public/visualize/agg_type_filter.js +++ b/x-pack/legacy/plugins/rollup/public/visualize/agg_type_filter.js @@ -4,9 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { aggTypeFilters } from 'ui/agg_types/filter'; - -export function initAggTypeFilter() { +export function initAggTypeFilter(aggTypeFilters) { /** * If rollup index pattern, check its capabilities * and limit available aggregations based on that. diff --git a/x-pack/legacy/plugins/rollup/public/visualize/editor_config.js b/x-pack/legacy/plugins/rollup/public/visualize/editor_config.js index 590f3dc85740e..5087ac3d64e84 100644 --- a/x-pack/legacy/plugins/rollup/public/visualize/editor_config.js +++ b/x-pack/legacy/plugins/rollup/public/visualize/editor_config.js @@ -5,9 +5,8 @@ */ import { i18n } from '@kbn/i18n'; -import { editorConfigProviders } from 'ui/vis/editors/config/editor_config_providers'; -export function initEditorConfig() { +export function initEditorConfig(editorConfigProviders) { // Limit agg params based on rollup capabilities editorConfigProviders.register((aggType, indexPattern, aggConfig) => { if (indexPattern.type !== 'rollup') { diff --git a/x-pack/legacy/plugins/rollup/public/visualize/index.js b/x-pack/legacy/plugins/rollup/public/visualize/index.js deleted file mode 100644 index e5a9c63c91a92..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/visualize/index.js +++ /dev/null @@ -1,21 +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 chrome from 'ui/chrome'; - -import { initAggTypeFilter } from './agg_type_filter'; -import { initAggTypeFieldFilter } from './agg_type_field_filter'; -import { initEditorConfig } from './editor_config'; -import { CONFIG_ROLLUPS } from '../../common'; - -const uiSettings = chrome.getUiSettingsClient(); -const isRollupIndexPatternsEnabled = uiSettings.get(CONFIG_ROLLUPS); - -if (isRollupIndexPatternsEnabled) { - initAggTypeFilter(); - initAggTypeFieldFilter(); - initEditorConfig(); -} From ec8730a0607b33e87bbb446026fe388ce46e0957 Mon Sep 17 00:00:00 2001 From: Joe Reuter Date: Fri, 20 Dec 2019 17:49:24 +0100 Subject: [PATCH 09/39] continued shimming rollup ui --- x-pack/legacy/plugins/rollup/index.js | 12 ++-- .../plugins/rollup/public/angular/index.js | 54 +++++++++++++++ .../public/{crud_app => angular}/main.html | 0 .../plugins/rollup/public/crud_app/index.js | 69 ------------------- x-pack/legacy/plugins/rollup/public/legacy.ts | 37 ++++++++++ .../rollup/public/{plugin.ts => plugin.tsx} | 43 +++++++++++- 6 files changed, 137 insertions(+), 78 deletions(-) create mode 100644 x-pack/legacy/plugins/rollup/public/angular/index.js rename x-pack/legacy/plugins/rollup/public/{crud_app => angular}/main.html (100%) delete mode 100644 x-pack/legacy/plugins/rollup/public/crud_app/index.js create mode 100644 x-pack/legacy/plugins/rollup/public/legacy.ts rename x-pack/legacy/plugins/rollup/public/{plugin.ts => plugin.tsx} (75%) diff --git a/x-pack/legacy/plugins/rollup/index.js b/x-pack/legacy/plugins/rollup/index.js index f4210435abc09..a10407b19fa93 100644 --- a/x-pack/legacy/plugins/rollup/index.js +++ b/x-pack/legacy/plugins/rollup/index.js @@ -26,7 +26,7 @@ export function rollup(kibana) { require: ['kibana', 'elasticsearch', 'xpack_main'], uiExports: { styleSheetPaths: resolve(__dirname, 'public/index.scss'), - managementSections: ['plugins/rollup/crud_app'], + managementSections: ['plugins/rollup/legacy'], uiSettingDefaults: { [CONFIG_ROLLUPS]: { name: i18n.translate('xpack.rollupJobs.rollupIndexPatternsTitle', { @@ -41,13 +41,9 @@ export function rollup(kibana) { category: ['rollups'], }, }, - indexManagement: [ - 'plugins/rollup/index_pattern_creation', - 'plugins/rollup/index_pattern_list', - 'plugins/rollup/extend_index_management', - ], - visualize: ['plugins/rollup/visualize'], - search: ['plugins/rollup/search'], + indexManagement: ['plugins/rollup/legacy'], + visualize: ['plugins/rollup/legacy'], + search: ['plugins/rollup/legacy'], }, init: function(server) { const { usageCollection } = server.newPlatform.setup.plugins; diff --git a/x-pack/legacy/plugins/rollup/public/angular/index.js b/x-pack/legacy/plugins/rollup/public/angular/index.js new file mode 100644 index 0000000000000..ed76e3140bb98 --- /dev/null +++ b/x-pack/legacy/plugins/rollup/public/angular/index.js @@ -0,0 +1,54 @@ +/* + * 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 routes from 'ui/routes'; + +import { CRUD_APP_BASE_PATH } from '../crud_app/constants'; +import { setHttp, setUserHasLeftApp } from '../crud_app/services'; +import template from './main.html'; + +export function registerRollupApp(renderFn) { + routes.when(`${CRUD_APP_BASE_PATH}/:view?`, { + template: template, + controllerAs: 'rollupJobs', + controller: class IndexRollupJobsController { + constructor($scope, $route, $injector) { + // NOTE: We depend upon Angular's $http service because it's decorated with interceptors, + // e.g. to check license status per request. + setHttp($injector.get('$http')); + + // If returning to the app, we'll need to reset this state. + setUserHasLeftApp(false); + + $scope.$$postDigest(() => { + const appElement = document.getElementById('rollupJobsReactRoot'); + const onUnmount = renderFn(appElement); + + const appRoute = $route.current; + const stopListeningForLocationChange = $scope.$on('$locationChangeSuccess', () => { + const currentRoute = $route.current; + + const isNavigationInApp = currentRoute.$$route.template === appRoute.$$route.template; + + // When we navigate within rollups, prevent Angular from re-matching the route and + // rebuilding the app. + if (isNavigationInApp) { + $route.current = appRoute; + } else { + // Set internal flag so we can prevent reacting to the route change internally. + setUserHasLeftApp(true); + } + }); + + $scope.$on('$destroy', () => { + stopListeningForLocationChange(); + onUnmount(); + }); + }); + } + }, + }); +} diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/main.html b/x-pack/legacy/plugins/rollup/public/angular/main.html similarity index 100% rename from x-pack/legacy/plugins/rollup/public/crud_app/main.html rename to x-pack/legacy/plugins/rollup/public/angular/main.html diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/index.js deleted file mode 100644 index 2dc2af8f59050..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/crud_app/index.js +++ /dev/null @@ -1,69 +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 React from 'react'; -import { render, unmountComponentAtNode } from 'react-dom'; -import { Provider } from 'react-redux'; -import { I18nContext } from 'ui/i18n'; -import routes from 'ui/routes'; - -import { CRUD_APP_BASE_PATH } from './constants'; -import { setHttp, setUserHasLeftApp } from './services'; -import { App } from './app'; -import template from './main.html'; -import { rollupJobsStore } from './store'; - -const renderReact = async elem => { - render( - - - - - , - elem - ); -}; - -routes.when(`${CRUD_APP_BASE_PATH}/:view?`, { - template: template, - controllerAs: 'rollupJobs', - controller: class IndexRollupJobsController { - constructor($scope, $route, $injector) { - // NOTE: We depend upon Angular's $http service because it's decorated with interceptors, - // e.g. to check license status per request. - setHttp($injector.get('$http')); - - // If returning to the app, we'll need to reset this state. - setUserHasLeftApp(false); - - $scope.$$postDigest(() => { - const appElement = document.getElementById('rollupJobsReactRoot'); - renderReact(appElement); - - const appRoute = $route.current; - const stopListeningForLocationChange = $scope.$on('$locationChangeSuccess', () => { - const currentRoute = $route.current; - - const isNavigationInApp = currentRoute.$$route.template === appRoute.$$route.template; - - // When we navigate within rollups, prevent Angular from re-matching the route and - // rebuilding the app. - if (isNavigationInApp) { - $route.current = appRoute; - } else { - // Set internal flag so we can prevent reacting to the route change internally. - setUserHasLeftApp(true); - } - }); - - $scope.$on('$destroy', () => { - stopListeningForLocationChange(); - unmountComponentAtNode(appElement); - }); - }); - } - }, -}); diff --git a/x-pack/legacy/plugins/rollup/public/legacy.ts b/x-pack/legacy/plugins/rollup/public/legacy.ts new file mode 100644 index 0000000000000..a9c45c850bd5d --- /dev/null +++ b/x-pack/legacy/plugins/rollup/public/legacy.ts @@ -0,0 +1,37 @@ +/* + * 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 { npSetup, npStart } from 'ui/new_platform'; +import { aggTypeFilters } from 'ui/agg_types/filter'; +import { aggTypeFieldFilters } from 'ui/agg_types/param_types/filter'; +import { editorConfigProviders } from 'ui/vis/editors/config/editor_config_providers'; +import { addSearchStrategy } from 'ui/courier'; +import { RollupPlugin } from './plugin'; +import { setup as management } from '../../../../../src/legacy/core_plugins/management/public/legacy'; +import { addBadgeExtension, addToggleExtension } from '../../index_management/public'; +// @ts-ignore +import { registerRollupApp } from './angular'; + +const plugin = new RollupPlugin(); + +export const setup = plugin.setup(npSetup.core, { + ...npSetup.plugins, + __LEGACY: { + aggTypeFilters, + aggTypeFieldFilters, + editorConfigProviders, + addSearchStrategy, + addBadgeExtension, + addToggleExtension, + management, + }, +}); +export const start = plugin.start(npStart.core, { + ...npStart.plugins, + __LEGACY: { + registerRollupApp, + }, +}); diff --git a/x-pack/legacy/plugins/rollup/public/plugin.ts b/x-pack/legacy/plugins/rollup/public/plugin.tsx similarity index 75% rename from x-pack/legacy/plugins/rollup/public/plugin.ts rename to x-pack/legacy/plugins/rollup/public/plugin.tsx index d0ef98fb650fe..1c53c7f5f82a1 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.ts +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -4,6 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ +import { render, unmountComponentAtNode } from 'react-dom'; +import { Provider } from 'react-redux'; +import React from 'react'; import { i18n } from '@kbn/i18n'; import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; import { EditorConfigProviderRegistry } from 'ui/vis/editors/config/editor_config_providers'; @@ -29,7 +32,12 @@ import { } from '../../../../../src/plugins/home/public'; // @ts-ignore import { CRUD_APP_BASE_PATH } from './crud_app/constants'; +// @ts-ignore +import { App } from './crud_app/app'; import { ManagementStart } from '../../../../../src/plugins/management/public'; +// @ts-ignore +import { rollupJobsStore } from './crud_app/store'; +import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; export interface RollupPluginSetupDependencies { __LEGACY: { @@ -46,6 +54,11 @@ export interface RollupPluginSetupDependencies { export interface RollupPluginStartDependencies { management: ManagementStart; + __LEGACY: { + // TODO this becomes part of the management section register function as soon as + // the API is ready + registerRollupApp: (renderFunction: (element: HTMLElement) => void) => () => void; + }; } export class RollupPlugin implements Plugin { @@ -94,7 +107,10 @@ export class RollupPlugin implements Plugin { } } - start(core: CoreStart, { management }: RollupPluginStartDependencies) { + start( + core: CoreStart, + { management, __LEGACY: { registerRollupApp } }: RollupPluginStartDependencies + ) { const esSection = management.legacy.getSection('elasticsearch'); esSection.register('rollup_jobs', { @@ -103,5 +119,30 @@ export class RollupPlugin implements Plugin { order: 3, url: `#${CRUD_APP_BASE_PATH}/job_list`, }); + + const I18nContext = core.i18n.Context; + + registerRollupApp(elem => { + render( + + + + + + + , + elem + ); + + return () => { + unmountComponentAtNode(elem); + }; + }); } } From 339d013c4366838433d45c95fc3af610ffda8447 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Thu, 9 Jan 2020 09:49:04 +0300 Subject: [PATCH 10/39] Remove unnecessarily return --- .../rollup_index_pattern_creation_config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js index 2540f99821ecf..c506475b71842 100644 --- a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js +++ b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js @@ -68,7 +68,6 @@ export class RollupIndexPatternCreationConfig extends IndexPatternCreationConfig const isAnonymous = npSetup.core.http.anonymousPaths.isAnonymous(window.location.pathname); if (!isAnonymous) { const response = await this.httpClient.get('/api/rollup/indices'); - return response || {}; this.rollupIndicesCapabilities = response || {}; } From c0dfed83d48cd46682e7a12b390ce8d428d53d32 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Thu, 9 Jan 2020 11:45:30 +0300 Subject: [PATCH 11/39] Register management section --- .../sections/job_create/job_create.js | 2 +- .../rollup/public/crud_app/services/api.js | 12 ++- .../crud_app/store/actions/create_job.js | 2 +- .../legacy/plugins/rollup/public/plugin.tsx | 79 +++++++++++-------- 4 files changed, 51 insertions(+), 44 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js index a8e921973efc0..12fd5f41cc23b 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js @@ -181,7 +181,7 @@ export class JobCreateUi extends Component { dateFields: indexPatternDateFields, numericFields, keywordFields, - } = response.data; + } = response; let indexPatternAsyncErrors; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js index e712415f9568d..22c992f17680b 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js @@ -20,36 +20,34 @@ import { trackUserRequest } from './track_ui_metric'; const apiPrefix = chrome.addBasePath('/api/rollup'); export async function loadJobs() { - const { - data: { jobs }, - } = await getHttp().get(`${apiPrefix}/jobs`); + const { jobs } = await getHttp().get(`${apiPrefix}/jobs`); return jobs; } export async function startJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${apiPrefix}/start`, body); + const request = getHttp().post(`${apiPrefix}/start`, { body: JSON.stringify(body) }); const actionType = jobIds.length > 1 ? UIM_JOB_START_MANY : UIM_JOB_START; return await trackUserRequest(request, actionType); } export async function stopJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${apiPrefix}/stop`, body); + const request = getHttp().post(`${apiPrefix}/stop`, { body: JSON.stringify(body) }); const actionType = jobIds.length > 1 ? UIM_JOB_STOP_MANY : UIM_JOB_STOP; return await trackUserRequest(request, actionType); } export async function deleteJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${apiPrefix}/delete`, body); + const request = getHttp().post(`${apiPrefix}/delete`, { body: JSON.stringify(body) }); const actionType = jobIds.length > 1 ? UIM_JOB_DELETE_MANY : UIM_JOB_DELETE; return await trackUserRequest(request, actionType); } export async function createJob(job) { const body = { job }; - const request = getHttp().put(`${apiPrefix}/create`, body); + const request = getHttp().put(`${apiPrefix}/create`, { body: JSON.stringify(body) }); return await trackUserRequest(request, UIM_JOB_CREATE); } diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js index 163860b7f24c6..753c8e78f00b2 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js @@ -86,7 +86,7 @@ export const createJob = jobConfig => async dispatch => { ); } - const deserializedJob = deserializeJob(newJob.data); + const deserializedJob = deserializeJob(newJob); dispatch({ type: CREATE_JOB_SUCCESS, diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.tsx index 1c53c7f5f82a1..3326e0d9adfe4 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -5,6 +5,7 @@ */ import { render, unmountComponentAtNode } from 'react-dom'; +import { HashRouter as Router } from 'react-router-dom'; import { Provider } from 'react-redux'; import React from 'react'; import { i18n } from '@kbn/i18n'; @@ -38,6 +39,8 @@ import { ManagementStart } from '../../../../../src/plugins/management/public'; // @ts-ignore import { rollupJobsStore } from './crud_app/store'; import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; +// @ts-ignore +import { setHttp } from './crud_app/services'; export interface RollupPluginSetupDependencies { __LEGACY: { @@ -70,7 +73,7 @@ export class RollupPlugin implements Plugin { aggTypeFieldFilters, editorConfigProviders, addSearchStrategy, - management, + management: managementLegacy, addBadgeExtension, addToggleExtension, }, @@ -83,8 +86,8 @@ export class RollupPlugin implements Plugin { const isRollupIndexPatternsEnabled = core.uiSettings.get(CONFIG_ROLLUPS); if (isRollupIndexPatternsEnabled) { - management.indexPattern.creation.add(RollupIndexPatternCreationConfig); - management.indexPattern.list.add(RollupIndexPatternListConfig); + managementLegacy.indexPattern.creation.add(RollupIndexPatternCreationConfig); + managementLegacy.indexPattern.list.add(RollupIndexPatternListConfig); addSearchStrategy(rollupSearchStrategy); initAggTypeFilter(aggTypeFilters); initAggTypeFieldFilter(aggTypeFieldFilters); @@ -107,42 +110,48 @@ export class RollupPlugin implements Plugin { } } - start( - core: CoreStart, - { management, __LEGACY: { registerRollupApp } }: RollupPluginStartDependencies - ) { - const esSection = management.legacy.getSection('elasticsearch'); - - esSection.register('rollup_jobs', { - visible: true, - display: i18n.translate('xpack.rollupJobs.appTitle', { defaultMessage: 'Rollup Jobs' }), - order: 3, - url: `#${CRUD_APP_BASE_PATH}/job_list`, - }); + start(core: CoreStart, { management }: RollupPluginStartDependencies) { + setHttp(core.http); + const esSection = management.sections.getSection('elasticsearch'); const I18nContext = core.i18n.Context; - registerRollupApp(elem => { - render( - - - - - - - , - elem - ); + esSection!.registerApp({ + id: 'rollup_jobs', + title: i18n.translate('xpack.rollupJobs.appTitle', { defaultMessage: 'Rollup Jobs' }), + order: 3, + mount(params) { + params.setBreadcrumbs([ + { + text: i18n.translate('xpack.rollupJobs.breadcrumbsTitle', { + defaultMessage: 'Rollup Jobs', + }), + }, + ]); + + render( + + + + + + + + + , + params.element + ); - return () => { - unmountComponentAtNode(elem); - }; + return () => { + unmountComponentAtNode(params.element); + }; + }, }); } } From 518d580ee2ce8c835f586109a8746a7d8eb17b26 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Fri, 10 Jan 2020 10:19:27 +0300 Subject: [PATCH 12/39] Replace ui/chrome --- .../plugins/rollup/public/angular/index.js | 54 ------------------- .../plugins/rollup/public/angular/main.html | 3 -- .../rollup/public/crud_app/_crud_app.scss | 4 -- .../plugins/rollup/public/crud_app/app.js | 7 +-- .../sections/job_create/job_create.js | 10 ++-- .../crud_app/sections/job_list/job_list.js | 19 +++---- .../rollup/public/crud_app/services/api.js | 22 +++++--- .../public/crud_app/services/http_provider.js | 2 - .../rollup/public/crud_app/services/index.js | 18 ++++--- .../public/crud_app/services/routing.js | 10 ---- .../crud_app/store/middleware/clone_job.js | 10 ++-- .../crud_app/store/middleware/detail_panel.js | 14 +++-- .../legacy/plugins/rollup/public/plugin.tsx | 4 +- 13 files changed, 51 insertions(+), 126 deletions(-) delete mode 100644 x-pack/legacy/plugins/rollup/public/angular/index.js delete mode 100644 x-pack/legacy/plugins/rollup/public/angular/main.html diff --git a/x-pack/legacy/plugins/rollup/public/angular/index.js b/x-pack/legacy/plugins/rollup/public/angular/index.js deleted file mode 100644 index ed76e3140bb98..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/angular/index.js +++ /dev/null @@ -1,54 +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 routes from 'ui/routes'; - -import { CRUD_APP_BASE_PATH } from '../crud_app/constants'; -import { setHttp, setUserHasLeftApp } from '../crud_app/services'; -import template from './main.html'; - -export function registerRollupApp(renderFn) { - routes.when(`${CRUD_APP_BASE_PATH}/:view?`, { - template: template, - controllerAs: 'rollupJobs', - controller: class IndexRollupJobsController { - constructor($scope, $route, $injector) { - // NOTE: We depend upon Angular's $http service because it's decorated with interceptors, - // e.g. to check license status per request. - setHttp($injector.get('$http')); - - // If returning to the app, we'll need to reset this state. - setUserHasLeftApp(false); - - $scope.$$postDigest(() => { - const appElement = document.getElementById('rollupJobsReactRoot'); - const onUnmount = renderFn(appElement); - - const appRoute = $route.current; - const stopListeningForLocationChange = $scope.$on('$locationChangeSuccess', () => { - const currentRoute = $route.current; - - const isNavigationInApp = currentRoute.$$route.template === appRoute.$$route.template; - - // When we navigate within rollups, prevent Angular from re-matching the route and - // rebuilding the app. - if (isNavigationInApp) { - $route.current = appRoute; - } else { - // Set internal flag so we can prevent reacting to the route change internally. - setUserHasLeftApp(true); - } - }); - - $scope.$on('$destroy', () => { - stopListeningForLocationChange(); - onUnmount(); - }); - }); - } - }, - }); -} diff --git a/x-pack/legacy/plugins/rollup/public/angular/main.html b/x-pack/legacy/plugins/rollup/public/angular/main.html deleted file mode 100644 index 2956d157e784c..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/angular/main.html +++ /dev/null @@ -1,3 +0,0 @@ - -
-
diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/_crud_app.scss b/x-pack/legacy/plugins/rollup/public/crud_app/_crud_app.scss index e1166d0942a5c..9e3bd491115ce 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/_crud_app.scss +++ b/x-pack/legacy/plugins/rollup/public/crud_app/_crud_app.scss @@ -5,10 +5,6 @@ align-items: flex-end; /* 1 */ } -.rollupJobsRoot { - display: flex; -} - /** * 1. Ensure panel fills width of parent when search input yields no matching rollup jobs. */ diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/app.js b/x-pack/legacy/plugins/rollup/public/crud_app/app.js index da35c8a56f2d2..f28398ca58963 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/app.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/app.js @@ -10,7 +10,7 @@ import { HashRouter, Switch, Route, Redirect, withRouter } from 'react-router-do import { UIM_APP_LOAD } from '../../common'; import { CRUD_APP_BASE_PATH } from './constants'; -import { registerRouter, setUserHasLeftApp, trackUiMetric, METRIC_TYPE } from './services'; +import { registerRouter, trackUiMetric, METRIC_TYPE } from './services'; import { JobList, JobCreate } from './sections'; class ShareRouterComponent extends Component { @@ -45,11 +45,6 @@ export class App extends Component { trackUiMetric(METRIC_TYPE.LOADED, UIM_APP_LOAD); } - componentWillUnmount() { - // Set internal flag so we can prevent reacting to route changes internally. - setUserHasLeftApp(true); - } - render() { return ( diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js index 12fd5f41cc23b..5b8622dcf8f51 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js @@ -12,9 +12,9 @@ import debounce from 'lodash/function/debounce'; import first from 'lodash/array/first'; import { i18n } from '@kbn/i18n'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; -import chrome from 'ui/chrome'; -import { MANAGEMENT_BREADCRUMB } from 'ui/management'; +import { FormattedMessage } from '@kbn/i18n/react'; + +import { withKibana } from '../../../../../../../../src/plugins/kibana_react/public/'; import { EuiCallOut, @@ -92,7 +92,7 @@ export class JobCreateUi extends Component { constructor(props) { super(props); - chrome.breadcrumbs.set([MANAGEMENT_BREADCRUMB, listBreadcrumb, createBreadcrumb]); + props.kibana.services.setBreadcrumbs([listBreadcrumb, createBreadcrumb]); const { jobToClone: stepDefaultOverrides } = props; const stepsFields = mapValues(stepIdToStepConfigMap, step => cloneDeep(step.getDefaultFields(stepDefaultOverrides)) @@ -689,4 +689,4 @@ export class JobCreateUi extends Component { } } -export const JobCreate = injectI18n(JobCreateUi); +export const JobCreate = withKibana(JobCreateUi); diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.js index 035a53206c71d..bf73d93c1b73b 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.js @@ -6,9 +6,8 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; -import chrome from 'ui/chrome'; -import { MANAGEMENT_BREADCRUMB } from 'ui/management'; +import { FormattedMessage } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; import { EuiButton, @@ -26,6 +25,8 @@ import { EuiCallOut, } from '@elastic/eui'; +import { withKibana } from '../../../../../../../../src/plugins/kibana_react/public/'; + import { CRUD_APP_BASE_PATH } from '../../constants'; import { getRouterLinkProps, extractQueryParams, listBreadcrumb } from '../../services'; @@ -67,7 +68,7 @@ export class JobListUi extends Component { props.loadJobs(); - chrome.breadcrumbs.set([MANAGEMENT_BREADCRUMB, listBreadcrumb]); + props.kibana.services.setBreadcrumbs([listBreadcrumb]); this.state = {}; } @@ -97,9 +98,7 @@ export class JobListUi extends Component { } renderNoPermission() { - const { intl } = this.props; - const title = intl.formatMessage({ - id: 'xpack.rollupJobs.jobList.noPermissionTitle', + const title = i18n.translate('xpack.rollupJobs.jobList.noPermissionTitle', { defaultMessage: 'Permission error', }); return ( @@ -126,9 +125,7 @@ export class JobListUi extends Component { // handle unexpected error shapes in the API action. const { statusCode, error: errorString } = error.data; - const { intl } = this.props; - const title = intl.formatMessage({ - id: 'xpack.rollupJobs.jobList.loadingErrorTitle', + const title = i18n.translate('xpack.rollupJobs.jobList.loadingErrorTitle', { defaultMessage: 'Error loading rollup jobs', }); return ( @@ -254,4 +251,4 @@ export class JobListUi extends Component { } } -export const JobList = injectI18n(JobListUi); +export const JobList = withKibana(JobListUi); diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js index 22c992f17680b..be377b576b3fb 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js @@ -4,7 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import chrome from 'ui/chrome'; import { UIM_JOB_CREATE, UIM_JOB_DELETE, @@ -17,40 +16,47 @@ import { import { getHttp } from './http_provider'; import { trackUserRequest } from './track_ui_metric'; -const apiPrefix = chrome.addBasePath('/api/rollup'); +let apiPrefix; +export function setApiPrefix(prefix) { + apiPrefix = prefix; +} + +export function getApiPrefix() { + return apiPrefix; +} export async function loadJobs() { - const { jobs } = await getHttp().get(`${apiPrefix}/jobs`); + const { jobs } = await getHttp().get(`${getApiPrefix()}/jobs`); return jobs; } export async function startJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${apiPrefix}/start`, { body: JSON.stringify(body) }); + const request = getHttp().post(`${getApiPrefix()}/start`, { body: JSON.stringify(body) }); const actionType = jobIds.length > 1 ? UIM_JOB_START_MANY : UIM_JOB_START; return await trackUserRequest(request, actionType); } export async function stopJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${apiPrefix}/stop`, { body: JSON.stringify(body) }); + const request = getHttp().post(`${getApiPrefix()}/stop`, { body: JSON.stringify(body) }); const actionType = jobIds.length > 1 ? UIM_JOB_STOP_MANY : UIM_JOB_STOP; return await trackUserRequest(request, actionType); } export async function deleteJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${apiPrefix}/delete`, { body: JSON.stringify(body) }); + const request = getHttp().post(`${getApiPrefix()}/delete`, { body: JSON.stringify(body) }); const actionType = jobIds.length > 1 ? UIM_JOB_DELETE_MANY : UIM_JOB_DELETE; return await trackUserRequest(request, actionType); } export async function createJob(job) { const body = { job }; - const request = getHttp().put(`${apiPrefix}/create`, { body: JSON.stringify(body) }); + const request = getHttp().put(`${getApiPrefix()}/create`, { body: JSON.stringify(body) }); return await trackUserRequest(request, UIM_JOB_CREATE); } export async function validateIndexPattern(indexPattern) { - return await getHttp().get(`${apiPrefix}/index_pattern_validity/${indexPattern}`); + return await getHttp().get(`${getApiPrefix()}/index_pattern_validity/${indexPattern}`); } diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.js index 835a7bdc09d86..0d202a2c9a0ed 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.js @@ -4,8 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -// This is an Angular service, which is why we use this provider pattern to access it within -// our React app. let _http; export function setHttp(http) { diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js index 74ed8d8c325c0..d2f1465b60519 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js @@ -4,7 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -export { createJob, deleteJobs, loadJobs, startJobs, stopJobs, validateIndexPattern } from './api'; +export { + createJob, + deleteJobs, + loadJobs, + startJobs, + stopJobs, + validateIndexPattern, + setApiPrefix, +} from './api'; export { showApiError, showApiWarning } from './api_errors'; @@ -34,13 +42,7 @@ export { createNoticeableDelay } from './noticeable_delay'; export { extractQueryParams } from './query_params'; -export { - setUserHasLeftApp, - getUserHasLeftApp, - registerRouter, - getRouter, - getRouterLinkProps, -} from './routing'; +export { registerRouter, getRouter, getRouterLinkProps } from './routing'; export { sortTable } from './sort_table'; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/routing.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/routing.js index 3b78e73c6b3af..a21ed780a748a 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/routing.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/routing.js @@ -10,16 +10,6 @@ import { createLocation } from 'history'; -let _userHasLeftApp = false; - -export function setUserHasLeftApp(userHasLeftApp) { - _userHasLeftApp = userHasLeftApp; -} - -export function getUserHasLeftApp() { - return _userHasLeftApp; -} - const isModifiedEvent = event => !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey); diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/clone_job.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/clone_job.js index e424232cce0a1..433934b0b9c38 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/clone_job.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/clone_job.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getRouter, getUserHasLeftApp } from '../../services'; +import { getRouter } from '../../services'; import { CLONE_JOB_START } from '../action_types'; import { CRUD_APP_BASE_PATH } from '../../constants'; @@ -12,11 +12,9 @@ export const cloneJob = () => next => action => { const { type } = action; if (type === CLONE_JOB_START) { - if (!getUserHasLeftApp()) { - getRouter().history.push({ - pathname: `${CRUD_APP_BASE_PATH}/create`, - }); - } + getRouter().history.push({ + pathname: `${CRUD_APP_BASE_PATH}/create`, + }); } return next(action); diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/detail_panel.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/detail_panel.js index cbe86fb7065b6..062b44b51a9b1 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/detail_panel.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/detail_panel.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getRouter, getUserHasLeftApp } from '../../services'; +import { getRouter } from '../../services'; import { CLOSE_DETAIL_PANEL } from '../action_types'; export const detailPanel = () => next => action => { @@ -12,14 +12,12 @@ export const detailPanel = () => next => action => { switch (type) { case CLOSE_DETAIL_PANEL: - if (!getUserHasLeftApp()) { - const { history } = getRouter(); + const { history } = getRouter(); - // Persist state to query params by removing deep link. - history.replace({ - search: '', - }); - } + // Persist state to query params by removing deep link. + history.replace({ + search: '', + }); break; } diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.tsx index 3326e0d9adfe4..8b71650858676 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -40,7 +40,7 @@ import { ManagementStart } from '../../../../../src/plugins/management/public'; import { rollupJobsStore } from './crud_app/store'; import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; // @ts-ignore -import { setHttp } from './crud_app/services'; +import { setHttp, setApiPrefix } from './crud_app/services'; export interface RollupPluginSetupDependencies { __LEGACY: { @@ -112,6 +112,7 @@ export class RollupPlugin implements Plugin { start(core: CoreStart, { management }: RollupPluginStartDependencies) { setHttp(core.http); + setApiPrefix(core.http.basePath.prepend('/api/rollup')); const esSection = management.sections.getSection('elasticsearch'); const I18nContext = core.i18n.Context; @@ -137,6 +138,7 @@ export class RollupPlugin implements Plugin { http: core.http, notifications: core.notifications, chrome: core.chrome, + setBreadcrumbs: params.setBreadcrumbs, }} > From d1233b4dc9424a5489b7e16c0156be4e73c8dc08 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Mon, 13 Jan 2020 14:04:11 +0300 Subject: [PATCH 13/39] Replace ui/documentation_links --- .../job_create/steps/step_date_histogram.js | 6 ++--- .../job_create/steps/step_histogram.js | 4 +-- .../job_create/steps/step_logistics.js | 6 ++--- .../sections/job_create/steps/step_metrics.js | 4 +-- .../sections/job_create/steps/step_terms.js | 4 +-- .../crud_app/services/documentation_links.js | 25 +++++++++++-------- .../rollup/public/crud_app/services/index.js | 15 +++++------ x-pack/legacy/plugins/rollup/public/legacy.ts | 9 +------ .../legacy/plugins/rollup/public/plugin.tsx | 10 +++----- 9 files changed, 40 insertions(+), 43 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js index c4ff37efa4490..433d4c39e07ea 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js @@ -26,7 +26,7 @@ import { import { parseEsInterval } from '../../../../../../../../../src/legacy/core_plugins/data/public'; -import { dateHistogramDetailsUrl, dateHistogramAggregationUrl } from '../../../services'; +import { getDateHistogramDetailsUrl, getDateHistogramAggregationUrl } from '../../../services'; import { StepError } from './components'; @@ -192,7 +192,7 @@ export class StepDateHistogramUi extends Component { + - + `${esBase}/rollup-job-config.html#_logistical_details`; +export const getDateHistogramDetailsUrl = () => + `${esBase}/rollup-job-config.html#_date_histogram_2`; +export const getTermsDetailsUrl = () => `${esBase}/rollup-job-config.html#_terms_2`; +export const getHistogramDetailsUrl = () => `${esBase}/rollup-job-config.html#_histogram_2`; +export const getMetricsDetailsUrl = () => `${esBase}/rollup-job-config.html#rollup-metrics-config`; -export const dateHistogramAggregationUrl = `${esBase}/search-aggregations-bucket-datehistogram-aggregation.html`; -export const cronUrl = `${xPackBase}/trigger-schedule.html#_cron_expressions`; +export const getDateHistogramAggregationUrl = () => + `${esBase}/search-aggregations-bucket-datehistogram-aggregation.html`; +export const getCronUrl = () => `${xPackBase}/trigger-schedule.html#_cron_expressions`; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js index d2f1465b60519..fb481b90c5dc1 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js @@ -19,13 +19,14 @@ export { showApiError, showApiWarning } from './api_errors'; export { listBreadcrumb, createBreadcrumb } from './breadcrumbs'; export { - logisticalDetailsUrl, - dateHistogramDetailsUrl, - dateHistogramAggregationUrl, - termsDetailsUrl, - histogramDetailsUrl, - metricsDetailsUrl, - cronUrl, + setEsBaseAndXPackBase, + getLogisticalDetailsUrl, + getDateHistogramDetailsUrl, + getDateHistogramAggregationUrl, + getTermsDetailsUrl, + getHistogramDetailsUrl, + getMetricsDetailsUrl, + getCronUrl, } from './documentation_links'; export { filterItems } from './filter_items'; diff --git a/x-pack/legacy/plugins/rollup/public/legacy.ts b/x-pack/legacy/plugins/rollup/public/legacy.ts index a9c45c850bd5d..aa2de21a58317 100644 --- a/x-pack/legacy/plugins/rollup/public/legacy.ts +++ b/x-pack/legacy/plugins/rollup/public/legacy.ts @@ -12,8 +12,6 @@ import { addSearchStrategy } from 'ui/courier'; import { RollupPlugin } from './plugin'; import { setup as management } from '../../../../../src/legacy/core_plugins/management/public/legacy'; import { addBadgeExtension, addToggleExtension } from '../../index_management/public'; -// @ts-ignore -import { registerRollupApp } from './angular'; const plugin = new RollupPlugin(); @@ -29,9 +27,4 @@ export const setup = plugin.setup(npSetup.core, { management, }, }); -export const start = plugin.start(npStart.core, { - ...npStart.plugins, - __LEGACY: { - registerRollupApp, - }, -}); +export const start = plugin.start(npStart.core, npStart.plugins); diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.tsx index 8b71650858676..6303740d4cdde 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -11,6 +11,7 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; import { EditorConfigProviderRegistry } from 'ui/vis/editors/config/editor_config_providers'; +// @ts-ignore import { SearchStrategyProvider } from 'ui/courier/search_strategy/types'; import { ManagementSetup } from '../../../../../src/legacy/core_plugins/management/public/np_ready'; import { rollupBadgeExtension, rollupToggleExtension } from './extend_index_management'; @@ -40,7 +41,7 @@ import { ManagementStart } from '../../../../../src/plugins/management/public'; import { rollupJobsStore } from './crud_app/store'; import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; // @ts-ignore -import { setHttp, setApiPrefix } from './crud_app/services'; +import { setHttp, setApiPrefix, setEsBaseAndXPackBase } from './crud_app/services'; export interface RollupPluginSetupDependencies { __LEGACY: { @@ -57,11 +58,6 @@ export interface RollupPluginSetupDependencies { export interface RollupPluginStartDependencies { management: ManagementStart; - __LEGACY: { - // TODO this becomes part of the management section register function as soon as - // the API is ready - registerRollupApp: (renderFunction: (element: HTMLElement) => void) => () => void; - }; } export class RollupPlugin implements Plugin { @@ -113,6 +109,8 @@ export class RollupPlugin implements Plugin { start(core: CoreStart, { management }: RollupPluginStartDependencies) { setHttp(core.http); setApiPrefix(core.http.basePath.prepend('/api/rollup')); + setEsBaseAndXPackBase(core.docLinks.ELASTIC_WEBSITE_URL, core.docLinks.DOC_LINK_VERSION); + const esSection = management.sections.getSection('elasticsearch'); const I18nContext = core.i18n.Context; From 1e77e22e29d1dee4f46aa6eebceca56b556e0f29 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Wed, 15 Jan 2020 11:27:49 +0300 Subject: [PATCH 14/39] Replace ui/kfetch and ui/courier --- src/legacy/ui/public/courier/index.ts | 1 - x-pack/legacy/plugins/rollup/public/legacy.ts | 2 +- .../legacy/plugins/rollup/public/plugin.tsx | 8 ++--- ..._strategy.js => rollup_search_strategy.ts} | 30 ++++++++++--------- 4 files changed, 20 insertions(+), 21 deletions(-) rename x-pack/legacy/plugins/rollup/public/search/{rollup_search_strategy.js => rollup_search_strategy.ts} (77%) diff --git a/src/legacy/ui/public/courier/index.ts b/src/legacy/ui/public/courier/index.ts index 709ff1c11e901..51e418be4bde6 100644 --- a/src/legacy/ui/public/courier/index.ts +++ b/src/legacy/ui/public/courier/index.ts @@ -54,7 +54,6 @@ export { /* eslint-disable @kbn/eslint/no-restricted-paths */ export { addSearchStrategy, // used externally by Rollups - getSearchErrorType, // used externally by Rollups hasSearchStategyForIndexPattern, // used externally by Discover isDefaultTypeIndexPattern, // used externally by Discover SearchError, // used externally by Visualizations & Rollups diff --git a/x-pack/legacy/plugins/rollup/public/legacy.ts b/x-pack/legacy/plugins/rollup/public/legacy.ts index aa2de21a58317..29b58d20e1690 100644 --- a/x-pack/legacy/plugins/rollup/public/legacy.ts +++ b/x-pack/legacy/plugins/rollup/public/legacy.ts @@ -8,7 +8,7 @@ import { npSetup, npStart } from 'ui/new_platform'; import { aggTypeFilters } from 'ui/agg_types/filter'; import { aggTypeFieldFilters } from 'ui/agg_types/param_types/filter'; import { editorConfigProviders } from 'ui/vis/editors/config/editor_config_providers'; -import { addSearchStrategy } from 'ui/courier'; +import { addSearchStrategy } from '../../../../../src/legacy/core_plugins/data/public/search/search_strategy'; import { RollupPlugin } from './plugin'; import { setup as management } from '../../../../../src/legacy/core_plugins/management/public/legacy'; import { addBadgeExtension, addToggleExtension } from '../../index_management/public'; diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.tsx index 6303740d4cdde..14f916a5e9dd4 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -11,16 +11,14 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; import { EditorConfigProviderRegistry } from 'ui/vis/editors/config/editor_config_providers'; -// @ts-ignore -import { SearchStrategyProvider } from 'ui/courier/search_strategy/types'; +import { SearchStrategyProvider } from '../../../../../src/legacy/core_plugins/data/public/search/search_strategy/types'; import { ManagementSetup } from '../../../../../src/legacy/core_plugins/management/public/np_ready'; import { rollupBadgeExtension, rollupToggleExtension } from './extend_index_management'; // @ts-ignore import { RollupIndexPatternCreationConfig } from './index_pattern_creation/rollup_index_pattern_creation_config'; // @ts-ignore import { RollupIndexPatternListConfig } from './index_pattern_list/rollup_index_pattern_list_config'; -// @ts-ignore -import { rollupSearchStrategy } from './search/rollup_search_strategy'; +import { getRollupSearchStrategy } from './search/rollup_search_strategy'; // @ts-ignore import { initAggTypeFilter } from './visualize/agg_type_filter'; // @ts-ignore @@ -84,7 +82,7 @@ export class RollupPlugin implements Plugin { if (isRollupIndexPatternsEnabled) { managementLegacy.indexPattern.creation.add(RollupIndexPatternCreationConfig); managementLegacy.indexPattern.list.add(RollupIndexPatternListConfig); - addSearchStrategy(rollupSearchStrategy); + addSearchStrategy(getRollupSearchStrategy(core.http.fetch)); initAggTypeFilter(aggTypeFilters); initAggTypeFieldFilter(aggTypeFieldFilters); initEditorConfig(editorConfigProviders); diff --git a/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.js b/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts similarity index 77% rename from x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.js rename to x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts index becaf6dd338c8..2ddc86a9ad1f0 100644 --- a/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.js +++ b/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts @@ -4,12 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -import { kfetch } from 'ui/kfetch'; -import { SearchError, getSearchErrorType } from '../../../../../../src/legacy/ui/public/courier'; +import { HttpSetup } from 'src/core/public'; +import { + SearchError, + getSearchErrorType, +} from '../../../../../../src/legacy/core_plugins/data/public/search/search_strategy'; -function serializeFetchParams(searchRequests) { +function serializeFetchParams(searchRequests: any) { return JSON.stringify( - searchRequests.map(searchRequestWithFetchParams => { + searchRequests.map((searchRequestWithFetchParams: any) => { const indexPattern = searchRequestWithFetchParams.index.title || searchRequestWithFetchParams.index; const { @@ -17,7 +20,7 @@ function serializeFetchParams(searchRequests) { } = searchRequestWithFetchParams; const query = { - size: size, + size, aggregations: aggs, query: _query, }; @@ -30,8 +33,8 @@ function serializeFetchParams(searchRequests) { // Rollup search always returns 0 hits, but visualizations expect search responses // to return hits > 0, otherwise they do not render. We fake the number of hits here // by counting the number of aggregation buckets/values returned by rollup search. -function shimHitsInFetchResponse(response) { - return response.map(result => { +function shimHitsInFetchResponse(response: any) { + return response.map((result: any) => { const buckets = result.aggregations ? Object.keys(result.aggregations).reduce((allBuckets, agg) => { return allBuckets.concat( @@ -51,17 +54,16 @@ function shimHitsInFetchResponse(response) { }); } -export const rollupSearchStrategy = { +export const getRollupSearchStrategy = (fetch: HttpSetup['fetch']) => ({ id: 'rollup', - search: ({ searchRequests, Promise }) => { + search: ({ searchRequests }: any) => { // Serialize the fetch params into a format suitable for the body of an ES query. const serializedFetchParams = serializeFetchParams(searchRequests); const controller = new AbortController(); - const promise = kfetch({ + const promise = fetch('../api/rollup/search', { signal: controller.signal, - pathname: '../api/rollup/search', method: 'POST', body: serializedFetchParams, }); @@ -79,7 +81,7 @@ export const rollupSearchStrategy = { title, message: `Rollup search error: ${message}`, path: url, - type: getSearchErrorType({ message }), + type: getSearchErrorType({ message }) || '', }); return Promise.reject(searchError); @@ -88,11 +90,11 @@ export const rollupSearchStrategy = { }; }, - isViable: indexPattern => { + isViable: (indexPattern: any) => { if (!indexPattern) { return false; } return indexPattern.type === 'rollup'; }, -}; +}); From 79ee7c6b215123092557ea94be19b76277174df1 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Thu, 16 Jan 2020 12:58:35 +0300 Subject: [PATCH 15/39] Replace ui/notify --- .../crud_app/sections/job_create/job_create.js | 6 +++--- .../services/{api_errors.js => api_errors.ts} | 16 ++++++++-------- .../public/crud_app/store/actions/create_job.js | 4 ++-- .../public/crud_app/store/actions/delete_jobs.js | 6 +++--- 4 files changed, 16 insertions(+), 16 deletions(-) rename x-pack/legacy/plugins/rollup/public/crud_app/services/{api_errors.js => api_errors.ts} (65%) diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js index 5b8622dcf8f51..aa315a6be33fb 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js @@ -14,6 +14,8 @@ import first from 'lodash/array/first'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; +import { npSetup } from 'ui/new_platform'; + import { withKibana } from '../../../../../../../../src/plugins/kibana_react/public/'; import { @@ -27,8 +29,6 @@ import { EuiTitle, } from '@elastic/eui'; -import { fatalError } from 'ui/notify'; - import { validateIndexPattern, formatFields, @@ -324,7 +324,7 @@ export class JobCreateUi extends Component { // This error isn't an HTTP error, so let the fatal error screen tell the user something // unexpected happened. - fatalError( + npSetup.core.fatalErrors.add( error, i18n.translate('xpack.rollupJobs.create.errors.indexPatternValidationFatalErrorTitle', { defaultMessage: 'Rollup Job Wizard index pattern validation', diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/api_errors.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/api_errors.ts similarity index 65% rename from x-pack/legacy/plugins/rollup/public/crud_app/services/api_errors.js rename to x-pack/legacy/plugins/rollup/public/crud_app/services/api_errors.ts index bacaf13405898..0db4e68bdf5d4 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/api_errors.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/api_errors.ts @@ -4,9 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import { fatalError, toastNotifications } from 'ui/notify'; +import { npStart, npSetup } from 'ui/new_platform'; -function createToastConfig(error, errorTitle) { +function createToastConfig(error: any, errorTitle: string) { // Expect an error in the shape provided by Angular's $http service. if (error && error.data) { const { error: errorString, statusCode, message } = error.data; @@ -17,26 +17,26 @@ function createToastConfig(error, errorTitle) { } } -export function showApiWarning(error, errorTitle) { +export function showApiWarning(error: any, errorTitle: string) { const toastConfig = createToastConfig(error, errorTitle); if (toastConfig) { - return toastNotifications.addWarning(toastConfig); + return npStart.core.notifications.toasts.addWarning(toastConfig); } // This error isn't an HTTP error, so let the fatal error screen tell the user something // unexpected happened. - return fatalError(error, errorTitle); + return npSetup.core.fatalErrors.add(error, errorTitle); } -export function showApiError(error, errorTitle) { +export function showApiError(error: any, errorTitle: string) { const toastConfig = createToastConfig(error, errorTitle); if (toastConfig) { - return toastNotifications.addDanger(toastConfig); + return npStart.core.notifications.toasts.addDanger(toastConfig); } // This error isn't an HTTP error, so let the fatal error screen tell the user something // unexpected happened. - fatalError(error, errorTitle); + npSetup.core.fatalErrors.add(error, errorTitle); } diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js index 753c8e78f00b2..129f846f9ff94 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js @@ -5,7 +5,7 @@ */ import { i18n } from '@kbn/i18n'; -import { fatalError } from 'ui/notify'; +import { npSetup } from 'ui/new_platform'; import { CRUD_APP_BASE_PATH } from '../../constants'; import { @@ -78,7 +78,7 @@ export const createJob = jobConfig => async dispatch => { // This error isn't an HTTP error, so let the fatal error screen tell the user something // unexpected happened. - return fatalError( + return npSetup.core.fatalErrors.add( error, i18n.translate('xpack.rollupJobs.createAction.errorTitle', { defaultMessage: 'Error creating rollup job', diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/delete_jobs.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/delete_jobs.js index d700ec69839be..2fd380246f3d7 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/delete_jobs.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/delete_jobs.js @@ -5,7 +5,7 @@ */ import { i18n } from '@kbn/i18n'; -import { toastNotifications } from 'ui/notify'; +import { npStart } from 'ui/new_platform'; import { deleteJobs as sendDeleteJobsRequest, @@ -40,14 +40,14 @@ export const deleteJobs = jobIds => async (dispatch, getState) => { } if (jobIds.length === 1) { - toastNotifications.addSuccess( + npStart.core.notifications.toasts.addSuccess( i18n.translate('xpack.rollupJobs.deleteAction.successSingleNotificationTitle', { defaultMessage: `Rollup job '{jobId}' was deleted`, values: { jobId: jobIds[0] }, }) ); } else { - toastNotifications.addSuccess( + npStart.core.notifications.toasts.addSuccess( i18n.translate('xpack.rollupJobs.deleteAction.successMultipleNotificationTitle', { defaultMessage: '{count} rollup jobs were deleted', values: { count: jobIds.length }, From b8c8dad3141c10a87645c0d6e5bde29a0cefbf5b Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Thu, 16 Jan 2020 13:56:46 +0300 Subject: [PATCH 16/39] Move ui/ imports to legacy_imports.ts --- src/legacy/ui/public/agg_types/filter/index.ts | 2 +- .../public/agg_types/param_types/filter/index.ts | 2 +- .../crud_app/sections/job_create/job_create.js | 2 +- .../sections/job_create/steps/step_logistics.js | 2 +- .../steps_config/validate_rollup_index.js | 2 +- .../rollup/public/crud_app/services/api_errors.ts | 2 +- .../public/crud_app/store/actions/create_job.js | 2 +- .../public/crud_app/store/actions/delete_jobs.js | 2 +- .../rollup_index_pattern_creation_config.js | 2 +- x-pack/legacy/plugins/rollup/public/legacy.ts | 11 +++++++---- .../plugins/rollup/public/legacy_imports.ts | 15 +++++++++++++++ x-pack/legacy/plugins/rollup/public/plugin.tsx | 10 +++++++--- 12 files changed, 38 insertions(+), 16 deletions(-) create mode 100644 x-pack/legacy/plugins/rollup/public/legacy_imports.ts diff --git a/src/legacy/ui/public/agg_types/filter/index.ts b/src/legacy/ui/public/agg_types/filter/index.ts index 3fc577e7e9a23..35d06807d0ec2 100644 --- a/src/legacy/ui/public/agg_types/filter/index.ts +++ b/src/legacy/ui/public/agg_types/filter/index.ts @@ -17,5 +17,5 @@ * under the License. */ -export { aggTypeFilters } from './agg_type_filters'; +export { aggTypeFilters, AggTypeFilters } from './agg_type_filters'; export { propFilter } from './prop_filter'; diff --git a/src/legacy/ui/public/agg_types/param_types/filter/index.ts b/src/legacy/ui/public/agg_types/param_types/filter/index.ts index ce5c7c4f9fea5..2e0039c96a192 100644 --- a/src/legacy/ui/public/agg_types/param_types/filter/index.ts +++ b/src/legacy/ui/public/agg_types/param_types/filter/index.ts @@ -17,4 +17,4 @@ * under the License. */ -export { aggTypeFieldFilters } from './field_filters'; +export { aggTypeFieldFilters, AggTypeFieldFilters } from './field_filters'; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js index aa315a6be33fb..4c4d03f3c39de 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js @@ -14,7 +14,7 @@ import first from 'lodash/array/first'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { npSetup } from 'ui/new_platform'; +import { npSetup } from '../../../legacy_imports'; import { withKibana } from '../../../../../../../../src/plugins/kibana_react/public/'; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js index a9b5915399f1b..532de51314c02 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js @@ -26,7 +26,7 @@ import { // eslint-disable-next-line @kbn/eslint/no-restricted-paths import { CronEditor } from '../../../../../../../../../src/plugins/es_ui_shared/public/components/cron_editor'; -import { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from 'ui/indices'; +import { INDEX_ILLEGAL_CHARACTERS_VISIBLE } from '../../../../legacy_imports'; import { getLogisticalDetailsUrl, getCronUrl } from '../../../services'; import { StepError } from './components'; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps_config/validate_rollup_index.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps_config/validate_rollup_index.js index c1a4af34d0e4e..637caa2199c42 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps_config/validate_rollup_index.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps_config/validate_rollup_index.js @@ -6,7 +6,7 @@ import React from 'react'; import { FormattedMessage } from '@kbn/i18n/react'; -import { findIllegalCharactersInIndexName } from 'ui/indices'; +import { findIllegalCharactersInIndexName } from '../../../../legacy_imports'; export function validateRollupIndex(rollupIndex, indexPattern) { if (!rollupIndex || !rollupIndex.trim()) { diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/api_errors.ts b/x-pack/legacy/plugins/rollup/public/crud_app/services/api_errors.ts index 0db4e68bdf5d4..6701b66784b13 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/api_errors.ts +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/api_errors.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { npStart, npSetup } from 'ui/new_platform'; +import { npStart, npSetup } from '../../legacy_imports'; function createToastConfig(error: any, errorTitle: string) { // Expect an error in the shape provided by Angular's $http service. diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js index 129f846f9ff94..b33325db5cf8e 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js @@ -5,7 +5,7 @@ */ import { i18n } from '@kbn/i18n'; -import { npSetup } from 'ui/new_platform'; +import { npSetup } from '../../../legacy_imports'; import { CRUD_APP_BASE_PATH } from '../../constants'; import { diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/delete_jobs.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/delete_jobs.js index 2fd380246f3d7..db127b20f6175 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/delete_jobs.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/delete_jobs.js @@ -5,7 +5,7 @@ */ import { i18n } from '@kbn/i18n'; -import { npStart } from 'ui/new_platform'; +import { npStart } from '../../../legacy_imports'; import { deleteJobs as sendDeleteJobsRequest, diff --git a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js index c506475b71842..ee172cf2e90a5 100644 --- a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js +++ b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js @@ -6,7 +6,7 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; -import { npSetup } from 'ui/new_platform'; +import { npSetup } from '../legacy_imports'; import { RollupPrompt } from './components/rollup_prompt'; import { IndexPatternCreationConfig } from '../../../../../../src/legacy/core_plugins/management/public'; diff --git a/x-pack/legacy/plugins/rollup/public/legacy.ts b/x-pack/legacy/plugins/rollup/public/legacy.ts index 29b58d20e1690..9a0a5d49c9eda 100644 --- a/x-pack/legacy/plugins/rollup/public/legacy.ts +++ b/x-pack/legacy/plugins/rollup/public/legacy.ts @@ -4,10 +4,13 @@ * you may not use this file except in compliance with the Elastic License. */ -import { npSetup, npStart } from 'ui/new_platform'; -import { aggTypeFilters } from 'ui/agg_types/filter'; -import { aggTypeFieldFilters } from 'ui/agg_types/param_types/filter'; -import { editorConfigProviders } from 'ui/vis/editors/config/editor_config_providers'; +import { + npSetup, + npStart, + aggTypeFilters, + aggTypeFieldFilters, + editorConfigProviders, +} from './legacy_imports'; import { addSearchStrategy } from '../../../../../src/legacy/core_plugins/data/public/search/search_strategy'; import { RollupPlugin } from './plugin'; import { setup as management } from '../../../../../src/legacy/core_plugins/management/public/legacy'; diff --git a/x-pack/legacy/plugins/rollup/public/legacy_imports.ts b/x-pack/legacy/plugins/rollup/public/legacy_imports.ts new file mode 100644 index 0000000000000..884e6102a4503 --- /dev/null +++ b/x-pack/legacy/plugins/rollup/public/legacy_imports.ts @@ -0,0 +1,15 @@ +/* + * 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. + */ + +// @ts-ignore +export { findIllegalCharactersInIndexName, INDEX_ILLEGAL_CHARACTERS_VISIBLE } from 'ui/indices'; + +export { npSetup, npStart } from 'ui/new_platform'; + +export { aggTypeFilters, AggTypeFilters } from 'ui/agg_types/filter'; +export { aggTypeFieldFilters, AggTypeFieldFilters } from 'ui/agg_types/param_types/filter'; +export { editorConfigProviders } from 'ui/vis/editors/config/editor_config_providers'; +export { EditorConfigProviderRegistry } from 'ui/vis/editors/config/editor_config_providers'; diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.tsx index 14f916a5e9dd4..fa7364778229e 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -10,7 +10,11 @@ import { Provider } from 'react-redux'; import React from 'react'; import { i18n } from '@kbn/i18n'; import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; -import { EditorConfigProviderRegistry } from 'ui/vis/editors/config/editor_config_providers'; +import { + EditorConfigProviderRegistry, + AggTypeFilters, + AggTypeFieldFilters, +} from './legacy_imports'; import { SearchStrategyProvider } from '../../../../../src/legacy/core_plugins/data/public/search/search_strategy/types'; import { ManagementSetup } from '../../../../../src/legacy/core_plugins/management/public/np_ready'; import { rollupBadgeExtension, rollupToggleExtension } from './extend_index_management'; @@ -43,8 +47,8 @@ import { setHttp, setApiPrefix, setEsBaseAndXPackBase } from './crud_app/service export interface RollupPluginSetupDependencies { __LEGACY: { - aggTypeFilters: any; - aggTypeFieldFilters: any; + aggTypeFilters: AggTypeFilters; + aggTypeFieldFilters: AggTypeFieldFilters; editorConfigProviders: EditorConfigProviderRegistry; addSearchStrategy: (searchStrategy: SearchStrategyProvider) => void; management: ManagementSetup; From b6f1f9e65f9f4ed823d89c5b86debea1a7235e07 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Thu, 16 Jan 2020 15:47:35 +0300 Subject: [PATCH 17/39] Update NP mock for management --- .../public/new_platform/new_platform.karma_mock.js | 5 +++++ .../crud_app/sections/job_list/job_list.test.js | 13 ------------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js index d3f74a540b960..8340d7c56ffe3 100644 --- a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js +++ b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js @@ -155,6 +155,11 @@ export const npStart = { hasItem: sinon.fake(), }), }, + sections: { + getSection: () => ({ + registerApp: sinon.fake(), + }), + }, }, embeddable: { getEmbeddableFactory: sinon.fake(), diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js index 5c7d53efbd62c..dd9ca3f2afe07 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js @@ -9,19 +9,6 @@ import { rollupJobsStore } from '../../store'; import { JobList } from './job_list'; jest.mock('ui/new_platform'); -jest.mock('ui/chrome', () => ({ - addBasePath: () => {}, - breadcrumbs: { set: () => {} }, - getInjected: key => { - if (key === 'uiCapabilities') { - return { - navLinks: {}, - management: {}, - catalogue: {}, - }; - } - }, -})); jest.mock('../../services', () => { const services = require.requireActual('../../services'); From 522ebffa30bded0a59b6f8e9535d25cf54bf8d0c Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Thu, 16 Jan 2020 16:49:55 +0300 Subject: [PATCH 18/39] Refactoring --- .../rollup/public/crud_app/services/api.js | 34 +++++++++++-------- .../public/crud_app/services/http_provider.js | 15 -------- .../rollup/public/crud_app/services/index.js | 12 +------ .../legacy/plugins/rollup/public/plugin.tsx | 4 +-- 4 files changed, 21 insertions(+), 44 deletions(-) delete mode 100644 x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.js diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js index be377b576b3fb..8ad5d5f8a3552 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js @@ -13,50 +13,54 @@ import { UIM_JOB_STOP, UIM_JOB_STOP_MANY, } from '../../../common'; -import { getHttp } from './http_provider'; +import { npStart } from '../../legacy_imports'; import { trackUserRequest } from './track_ui_metric'; -let apiPrefix; -export function setApiPrefix(prefix) { - apiPrefix = prefix; -} - -export function getApiPrefix() { - return apiPrefix; -} +const apiPrefix = '/api/rollup'; +const { prepend } = npStart.core.http.basePath; export async function loadJobs() { - const { jobs } = await getHttp().get(`${getApiPrefix()}/jobs`); + const { jobs } = await npStart.core.http.get(`${prepend(apiPrefix)}/jobs`); return jobs; } export async function startJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${getApiPrefix()}/start`, { body: JSON.stringify(body) }); + const request = npStart.core.http.post(`${prepend(apiPrefix)}/start`, { + body: JSON.stringify(body), + }); const actionType = jobIds.length > 1 ? UIM_JOB_START_MANY : UIM_JOB_START; return await trackUserRequest(request, actionType); } export async function stopJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${getApiPrefix()}/stop`, { body: JSON.stringify(body) }); + const request = npStart.core.http.post(`${prepend(apiPrefix)}/stop`, { + body: JSON.stringify(body), + }); const actionType = jobIds.length > 1 ? UIM_JOB_STOP_MANY : UIM_JOB_STOP; return await trackUserRequest(request, actionType); } export async function deleteJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${getApiPrefix()}/delete`, { body: JSON.stringify(body) }); + const request = npStart.core.http.post(`${prepend(apiPrefix)}/delete`, { + body: JSON.stringify(body), + }); const actionType = jobIds.length > 1 ? UIM_JOB_DELETE_MANY : UIM_JOB_DELETE; return await trackUserRequest(request, actionType); } export async function createJob(job) { const body = { job }; - const request = getHttp().put(`${getApiPrefix()}/create`, { body: JSON.stringify(body) }); + const request = npStart.core.http.put(`${prepend(apiPrefix)}/create`, { + body: JSON.stringify(body), + }); return await trackUserRequest(request, UIM_JOB_CREATE); } export async function validateIndexPattern(indexPattern) { - return await getHttp().get(`${getApiPrefix()}/index_pattern_validity/${indexPattern}`); + return await npStart.core.http.get( + `${prepend(apiPrefix)}/index_pattern_validity/${indexPattern}` + ); } diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.js deleted file mode 100644 index 0d202a2c9a0ed..0000000000000 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.js +++ /dev/null @@ -1,15 +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. - */ - -let _http; - -export function setHttp(http) { - _http = http; -} - -export function getHttp() { - return _http; -} diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js index fb481b90c5dc1..ae0d3dee0885e 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js @@ -4,15 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -export { - createJob, - deleteJobs, - loadJobs, - startJobs, - stopJobs, - validateIndexPattern, - setApiPrefix, -} from './api'; +export { createJob, deleteJobs, loadJobs, startJobs, stopJobs, validateIndexPattern } from './api'; export { showApiError, showApiWarning } from './api_errors'; @@ -35,8 +27,6 @@ export { flattenPanelTree } from './flatten_panel_tree'; export { formatFields } from './format_fields'; -export { setHttp, getHttp } from './http_provider'; - export { serializeJob, deserializeJob, deserializeJobs } from './jobs'; export { createNoticeableDelay } from './noticeable_delay'; diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.tsx index fa7364778229e..dd00e5fc5172a 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -43,7 +43,7 @@ import { ManagementStart } from '../../../../../src/plugins/management/public'; import { rollupJobsStore } from './crud_app/store'; import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; // @ts-ignore -import { setHttp, setApiPrefix, setEsBaseAndXPackBase } from './crud_app/services'; +import { setEsBaseAndXPackBase } from './crud_app/services'; export interface RollupPluginSetupDependencies { __LEGACY: { @@ -109,8 +109,6 @@ export class RollupPlugin implements Plugin { } start(core: CoreStart, { management }: RollupPluginStartDependencies) { - setHttp(core.http); - setApiPrefix(core.http.basePath.prepend('/api/rollup')); setEsBaseAndXPackBase(core.docLinks.ELASTIC_WEBSITE_URL, core.docLinks.DOC_LINK_VERSION); const esSection = management.sections.getSection('elasticsearch'); From 50ccb07a82a6f969b479ebd9d86cd8f9b04e6cd1 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Thu, 16 Jan 2020 17:52:39 +0300 Subject: [PATCH 19/39] Read body from error object --- .../crud_app/sections/job_create/job_create.js | 6 +++--- .../public/crud_app/sections/job_list/job_list.js | 4 ++-- .../rollup/public/crud_app/services/api_errors.ts | 6 +++--- .../public/crud_app/store/actions/create_job.js | 12 ++++++------ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js index 4c4d03f3c39de..933daf0491df9 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js @@ -298,9 +298,9 @@ export class JobCreateUi extends Component { return; } - // Expect an error in the shape provided by Angular's $http service. - if (error && error.data) { - const { error: errorString, statusCode } = error.data; + // Expect an error in the shape provided by http service. + if (error && error.body) { + const { error: errorString, statusCode } = error.body; const indexPatternAsyncErrors = [ async dispatch => { ]); } catch (error) { if (error) { - const { statusCode, data } = error; + const { statusCode, body } = error; - // Expect an error in the shape provided by Angular's $http service. - if (data) { + // Expect an error in the shape provided by http service. + if (body) { // Some errors have statusCode directly available but some are under a data property. - if ((statusCode || (data && data.statusCode)) === 409) { + if ((statusCode || (body && body.statusCode)) === 409) { return dispatch({ type: CREATE_JOB_FAILURE, payload: { @@ -67,9 +67,9 @@ export const createJob = jobConfig => async dispatch => { error: { message: i18n.translate('xpack.rollupJobs.createAction.failedDefaultErrorMessage', { defaultMessage: 'Request failed with a {statusCode} error. {message}', - values: { statusCode, message: data.message }, + values: { statusCode: body.statusCode, message: body.message }, }), - cause: data.cause, + cause: body.error, }, }, }); From 3f400ec33b37d31e9b21a562fa2f3ea3ba8af6f5 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Fri, 17 Jan 2020 09:26:46 +0300 Subject: [PATCH 20/39] Update setup_environment.js --- .../client_integration/helpers/setup_environment.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.js index 71e7f050786b5..c091622f20b31 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.js @@ -4,16 +4,9 @@ * you may not use this file except in compliance with the Elastic License. */ -import axios from 'axios'; -import axiosXhrAdapter from 'axios/lib/adapters/xhr'; - -import { setHttp } from '../../../public/crud_app/services'; import { init as initHttpRequests } from './http_requests'; export const setupEnvironment = () => { - // axios has a $http like interface so using it to simulate $http - setHttp(axios.create({ adapter: axiosXhrAdapter })); - const { server, httpRequestsMockHelpers } = initHttpRequests(); return { From c05f7234817eb69489157971f55e3d216cd5cfbe Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Mon, 20 Jan 2020 17:51:18 +0300 Subject: [PATCH 21/39] Update unit tests --- .../helpers/http_requests.js | 70 ------------------- .../client_integration/helpers/index.js | 4 +- .../helpers/job_clone.helpers.js | 4 +- .../helpers/job_create.helpers.js | 4 +- .../helpers/job_list.helpers.js | 4 +- .../helpers/setup_context.tsx | 26 +++++++ .../helpers/setup_environment.js | 16 ----- .../helpers/setup_environment.ts | 47 +++++++++++++ .../job_create_clone.test.js | 15 ++-- .../job_create_date_histogram.test.js | 24 +++---- .../job_create_histogram.test.js | 27 +++---- .../job_create_logistics.test.js | 27 +++---- .../job_create_metrics.test.js | 26 +++---- .../job_create_review.test.js | 52 ++++++++------ .../job_create_terms.test.js | 39 +++++++---- .../client_integration/job_list.test.js | 17 +++-- .../client_integration/job_list_clone.test.js | 21 +++--- .../sections/job_list/job_list.test.js | 18 ++++- 18 files changed, 237 insertions(+), 204 deletions(-) delete mode 100644 x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/http_requests.js create mode 100644 x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_context.tsx delete mode 100644 x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.js create mode 100644 x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/http_requests.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/http_requests.js deleted file mode 100644 index 4552e62c371a1..0000000000000 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/http_requests.js +++ /dev/null @@ -1,70 +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 sinon from 'sinon'; - -// Register helpers to mock HTTP Requests -const registerHttpRequestMockHelpers = server => { - const setIndexPatternValidityResponse = response => { - const defaultResponse = { - doesMatchIndices: true, - doesMatchRollupIndices: false, - dateFields: ['foo', 'bar'], - numericFields: [], - keywordFields: [], - }; - server.respondWith(/\/api\/rollup\/index_pattern_validity\/.*/, [ - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ ...defaultResponse, ...response }), - ]); - }; - - const setCreateJobResponse = (responsePayload = {}) => { - server.respondWith(/\/api\/rollup\/create/, [ - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(responsePayload), - ]); - }; - - const setStartJobResponse = () => { - server.respondWith(/\/api\/rollup\/start/, [ - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({}), - ]); - }; - - const setLoadJobsResponse = response => { - server.respondWith('GET', '/api/rollup/jobs', [ - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(response), - ]); - }; - - return { - setIndexPatternValidityResponse, - setCreateJobResponse, - setLoadJobsResponse, - setStartJobResponse, - }; -}; - -export const init = () => { - const server = sinon.fakeServer.create(); - server.respondImmediately = true; - - // We make requests to APIs which don't impact the UX, e.g. UI metric telemetry, - // and we can mock them all with a 200 instead of mocking each one individually. - server.respondWith([200, {}, '']); - - return { - server, - httpRequestsMockHelpers: registerHttpRequestMockHelpers(server), - }; -}; diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/index.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/index.js index 9573e2f405b84..4a5b67e687d85 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/index.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/index.js @@ -10,7 +10,9 @@ import { setup as jobCloneSetup } from './job_clone.helpers'; export { nextTick, getRandomString, findTestSubject } from '../../../../../../test_utils'; -export { setupEnvironment } from './setup_environment'; +export { mockHttpRequest } from './setup_environment'; + +export { wrapComponent } from './setup_context'; export const pageHelpers = { jobCreate: { setup: jobCreateSetup }, diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/job_clone.helpers.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/job_clone.helpers.js index db0bb49289b60..a8376bb31b23f 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/job_clone.helpers.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/job_clone.helpers.js @@ -10,8 +10,10 @@ import { JobCreate } from '../../../public/crud_app/sections'; import { JOB_TO_CLONE } from './constants'; import { deserializeJob } from '../../../public/crud_app/services'; +import { wrapComponent } from './setup_context'; + export const setup = props => { - const initTestBed = registerTestBed(JobCreate, { + const initTestBed = registerTestBed(wrapComponent(JobCreate), { store: createRollupJobsStore({ cloneJob: { job: deserializeJob(JOB_TO_CLONE.jobs[0]) }, }), diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/job_create.helpers.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/job_create.helpers.js index 5de5d02dadd83..2395fd014dd1e 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/job_create.helpers.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/job_create.helpers.js @@ -10,7 +10,9 @@ import { JobCreate } from '../../../public/crud_app/sections'; import { JOB_TO_CREATE } from './constants'; -const initTestBed = registerTestBed(JobCreate, { store: rollupJobsStore }); +import { wrapComponent } from './setup_context'; + +const initTestBed = registerTestBed(wrapComponent(JobCreate), { store: rollupJobsStore }); export const setup = props => { const testBed = initTestBed(props); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/job_list.helpers.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/job_list.helpers.js index 10fa79f775fdc..bcad8c29c87c0 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/job_list.helpers.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/job_list.helpers.js @@ -9,6 +9,8 @@ import { registerRouter } from '../../../public/crud_app/services'; import { createRollupJobsStore } from '../../../public/crud_app/store'; import { JobList } from '../../../public/crud_app/sections/job_list'; +import { wrapComponent } from './setup_context'; + const testBedConfig = { store: createRollupJobsStore, memoryRouter: { @@ -19,4 +21,4 @@ const testBedConfig = { }, }; -export const setup = registerTestBed(JobList, testBedConfig); +export const setup = registerTestBed(wrapComponent(JobList), testBedConfig); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_context.tsx b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_context.tsx new file mode 100644 index 0000000000000..521903eaec045 --- /dev/null +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_context.tsx @@ -0,0 +1,26 @@ +/* + * 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 React, { FunctionComponent } from 'react'; + +import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public'; +import { coreMock } from '../../../../../../../src/core/public/mocks'; +const startMock = coreMock.createStart(); + +const services = { + setBreadcrumbs: startMock.chrome.setBreadcrumbs, + http: startMock.http, + notifications: startMock.notifications, + chrome: startMock.chrome, +}; + +const wrapComponent = (Component: FunctionComponent) => (props: any) => ( + + + +); + +export { wrapComponent }; diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.js deleted file mode 100644 index c091622f20b31..0000000000000 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.js +++ /dev/null @@ -1,16 +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 { init as initHttpRequests } from './http_requests'; - -export const setupEnvironment = () => { - const { server, httpRequestsMockHelpers } = initHttpRequests(); - - return { - server, - httpRequestsMockHelpers, - }; -}; diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts new file mode 100644 index 0000000000000..b5248458d04f8 --- /dev/null +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts @@ -0,0 +1,47 @@ +/* + * 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. + */ + +interface RequestMocks { + jobs: object; + createdJob: object; + indxPatternVldtResp: object; +} + +const mockHttpRequest = ( + http: any, + { + jobs = {}, + createdJob = {}, + indxPatternVldtResp = {}, + }: RequestMocks | { [key: string]: any } = {} +) => { + http.get.mockImplementation(async (url: string) => { + if (url === '/api/rollup/jobs') { + return jobs; + } + + if (url.startsWith('/api/rollup/index_pattern_validity')) { + return { + doesMatchIndices: true, + doesMatchRollupIndices: false, + dateFields: ['foo', 'bar'], + numericFields: [], + keywordFields: [], + ...indxPatternVldtResp, + }; + } + + return {}; + }); + + // mock '/api/rollup/start' + http.post.mockImplementation(async (url: string) => ({})); + + // mock '/api/rollup/create + http.put.mockImplementation(async (url: string) => createdJob); +}; + +export { mockHttpRequest }; diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_clone.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_clone.test.js index 4ffffd7574bd8..55552ac075d6c 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_clone.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_clone.test.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { setupEnvironment, pageHelpers, nextTick } from './helpers'; +import { mockHttpRequest, pageHelpers, nextTick } from './helpers'; import { JOB_TO_CLONE, JOB_CLONE_INDEX_PATTERN_CHECK } from './helpers/constants'; jest.mock('ui/new_platform'); @@ -17,26 +17,27 @@ const { } = JOB_TO_CLONE; describe('Cloning a rollup job through create job wizard', () => { - let httpRequestsMockHelpers; - let server; let find; let exists; let form; let table; let actions; + let npStart; beforeAll(() => { - ({ server, httpRequestsMockHelpers } = setupEnvironment()); + npStart = require('ui/new_platform').npStart; // eslint-disable-line }); beforeEach(() => { - httpRequestsMockHelpers.setIndexPatternValidityResponse(JOB_CLONE_INDEX_PATTERN_CHECK); + mockHttpRequest(npStart.core.http, { indxPatternVldtResp: JOB_CLONE_INDEX_PATTERN_CHECK }); ({ exists, find, form, actions, table } = setup()); }); - afterAll(() => { - server.restore(); + afterEach(() => { + npStart.core.http.get.mockClear(); + npStart.core.http.post.mockClear(); + npStart.core.http.put.mockClear(); }); it('should have fields correctly pre-populated', async () => { diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_date_histogram.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_date_histogram.test.js index c4336c535a0ee..b5b102e5e4e8a 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_date_histogram.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_date_histogram.test.js @@ -6,7 +6,7 @@ import moment from 'moment-timezone'; -import { setupEnvironment, pageHelpers } from './helpers'; +import { mockHttpRequest, pageHelpers } from './helpers'; jest.mock('ui/new_platform'); @@ -15,30 +15,30 @@ jest.mock('lodash/function/debounce', () => fn => fn); const { setup } = pageHelpers.jobCreate; describe('Create Rollup Job, step 2: Date histogram', () => { - let server; - let httpRequestsMockHelpers; let find; let exists; let actions; let goToStep; let form; let getEuiStepsHorizontalActive; + let npStart; beforeAll(() => { - ({ server, httpRequestsMockHelpers } = setupEnvironment()); + npStart = require('ui/new_platform').npStart; // eslint-disable-line }); - - afterAll(() => { - server.restore(); - }); - beforeEach(() => { // Set "default" mock responses by not providing any arguments - httpRequestsMockHelpers.setIndexPatternValidityResponse(); + mockHttpRequest(npStart.core.http); ({ find, exists, actions, form, getEuiStepsHorizontalActive, goToStep } = setup()); }); + afterEach(() => { + npStart.core.http.get.mockClear(); + npStart.core.http.post.mockClear(); + npStart.core.http.put.mockClear(); + }); + describe('layout', () => { beforeEach(async () => { await goToStep(2); @@ -71,7 +71,7 @@ describe('Create Rollup Job, step 2: Date histogram', () => { describe('Date field select', () => { it('should set the options value from the index pattern', async () => { const dateFields = ['field1', 'field2', 'field3']; - httpRequestsMockHelpers.setIndexPatternValidityResponse({ dateFields }); + mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { dateFields } }); await goToStep(2); @@ -83,7 +83,7 @@ describe('Create Rollup Job, step 2: Date histogram', () => { it('should sort the options in ascending order', async () => { const dateFields = ['field3', 'field2', 'field1']; - httpRequestsMockHelpers.setIndexPatternValidityResponse({ dateFields }); + mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { dateFields } }); await goToStep(2); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_histogram.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_histogram.test.js index f91c4582ba247..18f000d3222eb 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_histogram.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_histogram.test.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { setupEnvironment, pageHelpers } from './helpers'; +import { mockHttpRequest, pageHelpers } from './helpers'; jest.mock('ui/new_platform'); @@ -13,8 +13,6 @@ jest.mock('lodash/function/debounce', () => fn => fn); const { setup } = pageHelpers.jobCreate; describe('Create Rollup Job, step 4: Histogram', () => { - let server; - let httpRequestsMockHelpers; let find; let exists; let actions; @@ -22,22 +20,25 @@ describe('Create Rollup Job, step 4: Histogram', () => { let goToStep; let table; let form; + let npStart; beforeAll(() => { - ({ server, httpRequestsMockHelpers } = setupEnvironment()); - }); - - afterAll(() => { - server.restore(); + npStart = require('ui/new_platform').npStart; // eslint-disable-line }); beforeEach(() => { // Set "default" mock responses by not providing any arguments - httpRequestsMockHelpers.setIndexPatternValidityResponse(); + mockHttpRequest(npStart.core.http); ({ find, exists, actions, getEuiStepsHorizontalActive, goToStep, table, form } = setup()); }); + afterEach(() => { + npStart.core.http.get.mockClear(); + npStart.core.http.post.mockClear(); + npStart.core.http.put.mockClear(); + }); + const numericFields = ['a-numericField', 'b-numericField']; const goToStepAndOpenFieldChooser = async () => { @@ -108,7 +109,7 @@ describe('Create Rollup Job, step 4: Histogram', () => { describe('when no histogram fields are availalbe', () => { it('should indicate it to the user', async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse({ numericFields: [] }); + mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { numericFields: [] } }); await goToStepAndOpenFieldChooser(); const { tableCellsValues } = table.getMetaData('rollupJobHistogramFieldChooser-table'); @@ -119,7 +120,7 @@ describe('Create Rollup Job, step 4: Histogram', () => { describe('when histogram fields are available', () => { beforeEach(async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse({ numericFields }); + mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { numericFields } }); await goToStepAndOpenFieldChooser(); }); @@ -153,7 +154,7 @@ describe('Create Rollup Job, step 4: Histogram', () => { it('should have a delete button on each row to remove an histogram field', async () => { // First let's add a term to the list - httpRequestsMockHelpers.setIndexPatternValidityResponse({ numericFields }); + mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { numericFields } }); await goToStepAndOpenFieldChooser(); const { rows: fieldChooserRows } = table.getMetaData('rollupJobHistogramFieldChooser-table'); fieldChooserRows[0].reactWrapper.simulate('click'); @@ -180,7 +181,7 @@ describe('Create Rollup Job, step 4: Histogram', () => { }; beforeEach(async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse({ numericFields }); + mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { numericFields } }); await goToStep(4); addHistogramFieldToList(); }); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js index c960eabb37dcb..5d6795f86a059 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js @@ -13,7 +13,7 @@ import { YEAR, } from '../../../../../../src/plugins/es_ui_shared/public/components/cron_editor'; import { indexPatterns } from '../../../../../../src/plugins/data/public'; -import { setupEnvironment, pageHelpers } from './helpers'; +import { mockHttpRequest, pageHelpers } from './helpers'; jest.mock('ui/new_platform'); @@ -22,29 +22,30 @@ jest.mock('lodash/function/debounce', () => fn => fn); const { setup } = pageHelpers.jobCreate; describe('Create Rollup Job, step 1: Logistics', () => { - let server; - let httpRequestsMockHelpers; let find; let exists; let actions; let form; let getEuiStepsHorizontalActive; + let npStart; beforeAll(() => { - ({ server, httpRequestsMockHelpers } = setupEnvironment()); - }); - - afterAll(() => { - server.restore(); + npStart = require('ui/new_platform').npStart; // eslint-disable-line }); beforeEach(() => { // Set "default" mock responses by not providing any arguments - httpRequestsMockHelpers.setIndexPatternValidityResponse(); + mockHttpRequest(npStart.core.http); ({ find, exists, actions, form, getEuiStepsHorizontalActive } = setup()); }); + afterEach(() => { + npStart.core.http.get.mockClear(); + npStart.core.http.post.mockClear(); + npStart.core.http.put.mockClear(); + }); + it('should have the horizontal step active on "Logistics"', () => { expect(getEuiStepsHorizontalActive()).toContain('Logistics'); }); @@ -94,14 +95,14 @@ describe('Create Rollup Job, step 1: Logistics', () => { }); it('should not allow an unknown index pattern', async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse({ doesMatchIndices: false }); + mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { doesMatchIndices: false } }); await form.setInputValue('rollupIndexPattern', 'unknown', true); actions.clickNextStep(); expect(form.getErrorsMessages()).toContain("Index pattern doesn't match any indices."); }); it('should not allow an index pattern without time fields', async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse({ dateFields: [] }); + mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { dateFields: [] } }); await form.setInputValue('rollupIndexPattern', 'abc', true); actions.clickNextStep(); expect(form.getErrorsMessages()).toContain( @@ -110,7 +111,9 @@ describe('Create Rollup Job, step 1: Logistics', () => { }); it('should not allow an index pattern that matches a rollup index', async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse({ doesMatchRollupIndices: true }); + mockHttpRequest(npStart.core.http, { + indxPatternVldtResp: { doesMatchRollupIndices: true }, + }); await form.setInputValue('rollupIndexPattern', 'abc', true); actions.clickNextStep(); expect(form.getErrorsMessages()).toContain('Index pattern must not match rollup indices.'); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_metrics.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_metrics.test.js index bbbd2974c56db..0ce816f39820a 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_metrics.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_metrics.test.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { setupEnvironment, pageHelpers } from './helpers'; +import { mockHttpRequest, pageHelpers } from './helpers'; jest.mock('ui/new_platform'); @@ -13,8 +13,6 @@ jest.mock('lodash/function/debounce', () => fn => fn); const { setup } = pageHelpers.jobCreate; describe('Create Rollup Job, step 5: Metrics', () => { - let server; - let httpRequestsMockHelpers; let find; let exists; let actions; @@ -22,22 +20,25 @@ describe('Create Rollup Job, step 5: Metrics', () => { let goToStep; let table; let metrics; + let npStart; beforeAll(() => { - ({ server, httpRequestsMockHelpers } = setupEnvironment()); - }); - - afterAll(() => { - server.restore(); + npStart = require('ui/new_platform').npStart; // eslint-disable-line }); beforeEach(() => { // Set "default" mock responses by not providing any arguments - httpRequestsMockHelpers.setIndexPatternValidityResponse(); + mockHttpRequest(npStart.core.http); ({ find, exists, actions, getEuiStepsHorizontalActive, goToStep, table, metrics } = setup()); }); + afterEach(() => { + npStart.core.http.get.mockClear(); + npStart.core.http.post.mockClear(); + npStart.core.http.put.mockClear(); + }); + const numericFields = ['a-numericField', 'c-numericField']; const dateFields = ['b-dateField', 'd-dateField']; @@ -109,7 +110,7 @@ describe('Create Rollup Job, step 5: Metrics', () => { describe('table', () => { beforeEach(async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse({ numericFields, dateFields }); + mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { numericFields, dateFields } }); await goToStepAndOpenFieldChooser(); }); @@ -166,7 +167,7 @@ describe('Create Rollup Job, step 5: Metrics', () => { describe('when fields are added', () => { beforeEach(async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse({ numericFields, dateFields }); + mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { numericFields, dateFields } }); await goToStepAndOpenFieldChooser(); }); @@ -257,7 +258,8 @@ describe('Create Rollup Job, step 5: Metrics', () => { let getFieldListTableRows; beforeEach(async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse({ numericFields, dateFields }); + mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { numericFields, dateFields } }); + await goToStep(5); await addFieldToList('numeric'); await addFieldToList('date'); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js index d7bc5416263fe..680d9229f82b9 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { setupEnvironment, pageHelpers } from './helpers'; +import { pageHelpers, mockHttpRequest } from './helpers'; import { first } from 'lodash'; import { JOBS } from './helpers/constants'; @@ -15,8 +15,6 @@ jest.mock('lodash/function/debounce', () => fn => fn); const { setup } = pageHelpers.jobCreate; describe('Create Rollup Job, step 6: Review', () => { - let server; - let httpRequestsMockHelpers; let find; let exists; let actions; @@ -24,21 +22,24 @@ describe('Create Rollup Job, step 6: Review', () => { let goToStep; let table; let form; + let npStart; beforeAll(() => { - ({ server, httpRequestsMockHelpers } = setupEnvironment()); - }); - - afterAll(() => { - server.restore(); + npStart = require('ui/new_platform').npStart; // eslint-disable-line }); beforeEach(() => { // Set "default" mock responses by not providing any arguments - httpRequestsMockHelpers.setIndexPatternValidityResponse(); + mockHttpRequest(npStart.core.http); ({ find, exists, actions, getEuiStepsHorizontalActive, goToStep, table, form } = setup()); }); + afterEach(() => { + npStart.core.http.get.mockClear(); + npStart.core.http.post.mockClear(); + npStart.core.http.put.mockClear(); + }); + describe('layout', () => { beforeEach(async () => { await goToStep(6); @@ -81,7 +82,7 @@ describe('Create Rollup Job, step 6: Review', () => { }); it('should have a "Summary", "Terms" & "Request" tab if a term aggregation was added', async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse({ numericFields: ['my-field'] }); + mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { numericFields: ['my-field'] } }); await goToStep(3); selectFirstField('Terms'); @@ -93,7 +94,7 @@ describe('Create Rollup Job, step 6: Review', () => { }); it('should have a "Summary", "Histogram" & "Request" tab if a histogram field was added', async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse({ numericFields: ['a-field'] }); + mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { numericFields: ['a-field'] } }); await goToStep(4); selectFirstField('Histogram'); form.setInputValue('rollupJobCreateHistogramInterval', 3); // set an interval @@ -105,9 +106,11 @@ describe('Create Rollup Job, step 6: Review', () => { }); it('should have a "Summary", "Metrics" & "Request" tab if a histogram field was added', async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse({ - numericFields: ['a-field'], - dateFields: ['b-field'], + mockHttpRequest(npStart.core.http, { + indxPatternVldtResp: { + numericFields: ['a-field'], + dateFields: ['b-field'], + }, }); await goToStep(5); selectFirstField('Metrics'); @@ -125,27 +128,30 @@ describe('Create Rollup Job, step 6: Review', () => { describe('without starting job after creation', () => { it('should call the "create" Api server endpoint', async () => { - httpRequestsMockHelpers.setCreateJobResponse(first(JOBS.jobs)); + mockHttpRequest(npStart.core.http, { + createdJob: first(JOBS.jobs), + }); await goToStep(6); - expect(server.requests.find(r => r.url === jobCreateApiPath)).toBe(undefined); // make sure it hasn't been called - expect(server.requests.find(r => r.url === jobStartApiPath)).toBe(undefined); // make sure it hasn't been called + expect(npStart.core.http.put).not.toHaveBeenCalledWith(jobCreateApiPath); // make sure it hasn't been called + expect(npStart.core.http.get).not.toHaveBeenCalledWith(jobStartApiPath); // make sure it hasn't been called actions.clickSave(); // Given the following anti-jitter sleep x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js // we add a longer sleep here :( await new Promise(res => setTimeout(res, 750)); - expect(server.requests.find(r => r.url === jobCreateApiPath)).not.toBe(undefined); // It has been called! - expect(server.requests.find(r => r.url === jobStartApiPath)).toBe(undefined); // It has still not been called! + expect(npStart.core.http.put).toHaveBeenCalledWith(jobCreateApiPath, expect.anything()); // It has been called! + expect(npStart.core.http.get).not.toHaveBeenCalledWith(jobStartApiPath); // It has still not been called! }); }); describe('with starting job after creation', () => { it('should call the "create" and "start" Api server endpoints', async () => { - httpRequestsMockHelpers.setCreateJobResponse(first(JOBS.jobs)); - httpRequestsMockHelpers.setStartJobResponse(); + mockHttpRequest(npStart.core.http, { + createdJob: first(JOBS.jobs), + }); await goToStep(6); @@ -153,14 +159,14 @@ describe('Create Rollup Job, step 6: Review', () => { target: { checked: true }, }); - expect(server.requests.find(r => r.url === jobStartApiPath)).toBe(undefined); // make sure it hasn't been called + expect(npStart.core.http.post).not.toHaveBeenCalledWith(jobStartApiPath); // make sure it hasn't been called actions.clickSave(); // Given the following anti-jitter sleep x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js // we add a longer sleep here :( await new Promise(res => setTimeout(res, 750)); - expect(server.requests.find(r => r.url === jobStartApiPath)).not.toBe(undefined); // It has been called! + expect(npStart.core.http.post).toHaveBeenCalledWith(jobStartApiPath, expect.anything()); // It has been called! }); }); }); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_terms.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_terms.test.js index d3a0aaa08e148..28cc96590f61c 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_terms.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_terms.test.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { setupEnvironment, pageHelpers } from './helpers'; +import { pageHelpers, mockHttpRequest } from './helpers'; jest.mock('ui/new_platform'); @@ -13,30 +13,29 @@ jest.mock('lodash/function/debounce', () => fn => fn); const { setup } = pageHelpers.jobCreate; describe('Create Rollup Job, step 3: Terms', () => { - let server; - let httpRequestsMockHelpers; let find; let exists; let actions; let getEuiStepsHorizontalActive; let goToStep; let table; + let npStart; beforeAll(() => { - ({ server, httpRequestsMockHelpers } = setupEnvironment()); - }); - - afterAll(() => { - server.restore(); + npStart = require('ui/new_platform').npStart; // eslint-disable-line }); beforeEach(() => { // Set "default" mock responses by not providing any arguments - httpRequestsMockHelpers.setIndexPatternValidityResponse(); + mockHttpRequest(npStart.core.http); ({ find, exists, actions, getEuiStepsHorizontalActive, goToStep, table } = setup()); }); + afterEach(() => { + npStart.core.http.get.mockClear(); + }); + const numericFields = ['a-numericField', 'c-numericField']; const keywordFields = ['b-keywordField', 'd-keywordField']; @@ -108,9 +107,11 @@ describe('Create Rollup Job, step 3: Terms', () => { describe('when no terms are available', () => { it('should indicate it to the user', async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse({ - numericFields: [], - keywordFields: [], + mockHttpRequest(npStart.core.http, { + indxPatternVldtResp: { + numericFields: [], + keywordFields: [], + }, }); await goToStepAndOpenFieldChooser(); @@ -122,7 +123,12 @@ describe('Create Rollup Job, step 3: Terms', () => { describe('when terms are available', () => { beforeEach(async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse({ numericFields, keywordFields }); + mockHttpRequest(npStart.core.http, { + indxPatternVldtResp: { + numericFields, + keywordFields, + }, + }); await goToStepAndOpenFieldChooser(); }); @@ -163,7 +169,12 @@ describe('Create Rollup Job, step 3: Terms', () => { it('should have a delete button on each row to remove a term', async () => { // First let's add a term to the list - httpRequestsMockHelpers.setIndexPatternValidityResponse({ numericFields, keywordFields }); + mockHttpRequest(npStart.core.http, { + indxPatternVldtResp: { + numericFields, + keywordFields, + }, + }); await goToStepAndOpenFieldChooser(); const { rows: fieldChooserRows } = table.getMetaData('rollupJobTermsFieldChooser-table'); fieldChooserRows[0].reactWrapper.simulate('click'); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list.test.js index 16cb41bc76677..b857905966e8f 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list.test.js @@ -5,7 +5,7 @@ */ import { getRouter } from '../../public/crud_app/services'; -import { setupEnvironment, pageHelpers, nextTick } from './helpers'; +import { mockHttpRequest, pageHelpers, nextTick } from './helpers'; import { JOBS } from './helpers/constants'; jest.mock('ui/new_platform'); @@ -22,22 +22,17 @@ const { setup } = pageHelpers.jobList; describe('', () => { describe('detail panel', () => { - let server; - let httpRequestsMockHelpers; let component; let table; let exists; + let npStart; beforeAll(() => { - ({ server, httpRequestsMockHelpers } = setupEnvironment()); - }); - - afterAll(() => { - server.restore(); + npStart = require('ui/new_platform').npStart; // eslint-disable-line }); beforeEach(async () => { - httpRequestsMockHelpers.setLoadJobsResponse(JOBS); + mockHttpRequest(npStart.core.http, { jobs: JOBS }); ({ component, exists, table } = setup()); @@ -45,6 +40,10 @@ describe('', () => { component.update(); }); + afterEach(() => { + npStart.core.http.get.mockClear(); + }); + test('should open the detail panel when clicking on a job in the table', () => { const { rows } = table.getMetaData('rollupJobsListTable'); const button = rows[0].columns[1].reactWrapper.find('button'); diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list_clone.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list_clone.test.js index 6feabe7f772ee..0fad35eddfa31 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list_clone.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list_clone.test.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { setupEnvironment, pageHelpers, nextTick } from './helpers'; +import { mockHttpRequest, pageHelpers, nextTick } from './helpers'; import { JOB_TO_CLONE, JOB_CLONE_INDEX_PATTERN_CHECK } from './helpers/constants'; import { getRouter } from '../../public/crud_app/services/routing'; import { CRUD_APP_BASE_PATH } from '../../public/crud_app/constants'; @@ -16,24 +16,21 @@ jest.mock('lodash/function/debounce', () => fn => fn); const { setup } = pageHelpers.jobList; describe('Smoke test cloning an existing rollup job from job list', () => { - let server; - let httpRequestsMockHelpers; let table; let find; let component; let exists; + let npStart; beforeAll(() => { - ({ server, httpRequestsMockHelpers } = setupEnvironment()); - }); - - afterAll(() => { - server.restore(); + npStart = require('ui/new_platform').npStart; // eslint-disable-line }); beforeEach(async () => { - httpRequestsMockHelpers.setIndexPatternValidityResponse(JOB_CLONE_INDEX_PATTERN_CHECK); - httpRequestsMockHelpers.setLoadJobsResponse(JOB_TO_CLONE); + mockHttpRequest(npStart.core.http, { + jobs: JOB_TO_CLONE, + indxPatternVldtResp: JOB_CLONE_INDEX_PATTERN_CHECK, + }); ({ find, exists, table, component } = setup()); @@ -41,6 +38,10 @@ describe('Smoke test cloning an existing rollup job from job list', () => { component.update(); }); + afterEach(() => { + npStart.core.http.get.mockClear(); + }); + it('should navigate to create view with default values set', async () => { const router = getRouter(); const { rows } = table.getMetaData('rollupJobsListTable'); diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js index dd9ca3f2afe07..842b7a93d85b4 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js @@ -4,10 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ +import React from 'react'; import { registerTestBed } from '../../../../../../../test_utils'; import { rollupJobsStore } from '../../store'; import { JobList } from './job_list'; +import { KibanaContextProvider } from '../../../../../../../../src/plugins/kibana_react/public'; +import { coreMock } from '../../../../../../../../src/core/public/mocks'; +const startMock = coreMock.createStart(); + jest.mock('ui/new_platform'); jest.mock('../../services', () => { @@ -27,7 +32,16 @@ const defaultProps = { isLoading: false, }; -const initTestBed = registerTestBed(JobList, { defaultProps, store: rollupJobsStore }); +const services = { + setBreadcrumbs: startMock.chrome.setBreadcrumbs, +}; +const Component = props => ( + + + +); + +const initTestBed = registerTestBed(Component, { defaultProps, store: rollupJobsStore }); describe('', () => { it('should render empty prompt when loading is complete and there are no jobs', () => { @@ -54,7 +68,7 @@ describe('', () => { const { exists, find } = initTestBed({ jobLoadError: { status: 400, - data: { statusCode: 400, error: 'Houston we got a problem.' }, + body: { statusCode: 400, error: 'Houston we got a problem.' }, }, }); From 9136fb768c36c46612dac23cd169e9357d4dd773 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Mon, 20 Jan 2020 18:27:04 +0300 Subject: [PATCH 22/39] Get rid of injectI18n --- .../confirm_delete_modal.js | 19 +++++++++++-------- .../job_create/navigation/navigation.js | 8 ++++---- .../job_create/steps/step_date_histogram.js | 6 +++--- .../job_create/steps/step_histogram.js | 6 +++--- .../job_create/steps/step_logistics.js | 6 +++--- .../sections/job_create/steps/step_metrics.js | 10 +++++----- .../sections/job_create/steps/step_review.js | 6 +++--- .../sections/job_create/steps/step_terms.js | 6 +++--- .../job_list/detail_panel/detail_panel.js | 12 ++++++------ .../detail_panel/detail_panel.test.js | 4 ++-- .../sections/job_list/job_list.test.js | 4 ++-- .../sections/job_list/job_table/job_table.js | 11 +++++------ 12 files changed, 50 insertions(+), 48 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_action_menu/confirm_delete_modal/confirm_delete_modal.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_action_menu/confirm_delete_modal/confirm_delete_modal.js index 183a3765e1fd9..8b1b93b424603 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_action_menu/confirm_delete_modal/confirm_delete_modal.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_action_menu/confirm_delete_modal/confirm_delete_modal.js @@ -6,11 +6,12 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; import { EuiConfirmModal, EuiOverlayMask } from '@elastic/eui'; -class ConfirmDeleteModalUi extends Component { +class ConfirmDeleteModal extends Component { static propTypes = { isSingleSelection: PropTypes.bool.isRequired, jobs: PropTypes.array.isRequired, @@ -19,12 +20,14 @@ class ConfirmDeleteModalUi extends Component { }; renderJobs() { - const { jobs, intl } = this.props; + const { jobs } = this.props; const jobItems = jobs.map(({ id, status }) => { - const startedMessage = intl.formatMessage({ - id: 'xpack.rollupJobs.jobActionMenu.deleteJob.confirmModal.startedMessage', - defaultMessage: 'started', - }); + const startedMessage = i18n.translate( + 'xpack.rollupJobs.jobActionMenu.deleteJob.confirmModal.startedMessage', + { + defaultMessage: 'started', + } + ); const statusText = status === 'started' ? ` (${startedMessage})` : null; return (
  • @@ -109,4 +112,4 @@ class ConfirmDeleteModalUi extends Component { } } -export const ConfirmDeleteModal = injectI18n(ConfirmDeleteModalUi); +export { ConfirmDeleteModal }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/navigation/navigation.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/navigation/navigation.js index 5f4d528cf14f2..000a74ead0eb2 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/navigation/navigation.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/navigation/navigation.js @@ -6,7 +6,7 @@ import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { FormattedMessage } from '@kbn/i18n/react'; import { EuiButton, @@ -18,7 +18,7 @@ import { EuiCheckbox, } from '@elastic/eui'; -const NavigationUi = ({ +const Navigation = ({ isSaving, hasNextStep, hasPreviousStep, @@ -120,7 +120,7 @@ const NavigationUi = ({ ); }; -NavigationUi.propTypes = { +Navigation.propTypes = { hasNextStep: PropTypes.bool.isRequired, hasPreviousStep: PropTypes.bool.isRequired, isSaving: PropTypes.bool.isRequired, @@ -130,4 +130,4 @@ NavigationUi.propTypes = { canGoToNextStep: PropTypes.bool.isRequired, }; -export const Navigation = injectI18n(NavigationUi); +export { Navigation }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js index 433d4c39e07ea..6ebccfc861e70 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js @@ -6,7 +6,7 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { FormattedMessage } from '@kbn/i18n/react'; import moment from 'moment-timezone'; import { @@ -35,7 +35,7 @@ const timeZoneOptions = moment.tz.names().map(name => ({ text: name, })); -export class StepDateHistogramUi extends Component { +class StepDateHistogram extends Component { static propTypes = { fields: PropTypes.object.isRequired, onFieldsChange: PropTypes.func.isRequired, @@ -319,4 +319,4 @@ export class StepDateHistogramUi extends Component { }; } -export const StepDateHistogram = injectI18n(StepDateHistogramUi); +export { StepDateHistogram }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_histogram.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_histogram.js index 8b34cb743303c..d87245ac4fac6 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_histogram.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_histogram.js @@ -6,7 +6,7 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { FormattedMessage } from '@kbn/i18n/react'; import { EuiButtonEmpty, @@ -26,7 +26,7 @@ import { FieldList } from '../../components'; import { FieldChooser, StepError } from './components'; -export class StepHistogramUi extends Component { +class StepHistogram extends Component { static propTypes = { fields: PropTypes.object.isRequired, onFieldsChange: PropTypes.func.isRequired, @@ -213,4 +213,4 @@ export class StepHistogramUi extends Component { }; } -export const StepHistogram = injectI18n(StepHistogramUi); +export { StepHistogram }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js index 532de51314c02..b1f5d475461c6 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js @@ -6,7 +6,7 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { FormattedMessage } from '@kbn/i18n/react'; import { EuiButtonEmpty, @@ -35,7 +35,7 @@ import { indexPatterns } from '../../../../../../../../../src/plugins/data/publi const indexPatternIllegalCharacters = indexPatterns.ILLEGAL_CHARACTERS_VISIBLE.join(' '); const indexIllegalCharacters = INDEX_ILLEGAL_CHARACTERS_VISIBLE.join(' '); -export class StepLogisticsUi extends Component { +class StepLogistics extends Component { static propTypes = { fields: PropTypes.object.isRequired, onFieldsChange: PropTypes.func.isRequired, @@ -523,4 +523,4 @@ export class StepLogisticsUi extends Component { }; } -export const StepLogistics = injectI18n(StepLogisticsUi); +export { StepLogistics }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_metrics.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_metrics.js index ff321099de784..989ef128ec1ac 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_metrics.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_metrics.js @@ -6,7 +6,7 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { FormattedMessage } from '@kbn/i18n/react'; import { i18n } from '@kbn/i18n'; import get from 'lodash/object/get'; @@ -64,7 +64,7 @@ const metricTypesConfig = (function() { }); })(); -export class StepMetricsUi extends Component { +class StepMetrics extends Component { static propTypes = { fields: PropTypes.object.isRequired, onFieldsChange: PropTypes.func.isRequired, @@ -247,7 +247,7 @@ export class StepMetricsUi extends Component { } getListColumns() { - return StepMetricsUi.chooserColumns.concat({ + return StepMetrics.chooserColumns.concat({ type: 'metrics', name: i18n.translate('xpack.rollupJobs.create.stepMetrics.metricsColumnHeader', { defaultMessage: 'Metrics', @@ -421,7 +421,7 @@ export class StepMetricsUi extends Component { defaultMessage="Add metrics fields" /> } - columns={StepMetricsUi.chooserColumns} + columns={StepMetrics.chooserColumns} fields={metricsFields} selectedFields={metrics} onSelectField={this.onSelectField} @@ -473,4 +473,4 @@ export class StepMetricsUi extends Component { ]; } -export const StepMetrics = injectI18n(StepMetricsUi); +export { StepMetrics }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_review.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_review.js index 19937732275a2..b0876458f5929 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_review.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_review.js @@ -6,7 +6,7 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { FormattedMessage } from '@kbn/i18n/react'; import { EuiErrorBoundary, EuiSpacer, EuiTab, EuiTabs, EuiTitle } from '@elastic/eui'; @@ -30,7 +30,7 @@ const JOB_DETAILS_TABS = [ JOB_DETAILS_TAB_REQUEST, ]; -export class StepReviewUi extends Component { +class StepReview extends Component { static propTypes = { job: PropTypes.object.isRequired, }; @@ -122,4 +122,4 @@ export class StepReviewUi extends Component { } } -export const StepReview = injectI18n(StepReviewUi); +export { StepReview }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_terms.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_terms.js index 5ebe6de07c9ff..502a6665c3656 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_terms.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_terms.js @@ -6,7 +6,7 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { FormattedMessage } from '@kbn/i18n/react'; import { EuiButtonEmpty, @@ -23,7 +23,7 @@ import { FieldList } from '../../components'; import { FieldChooser } from './components'; -export class StepTermsUi extends Component { +class StepTerms extends Component { static propTypes = { fields: PropTypes.object.isRequired, onFieldsChange: PropTypes.func.isRequired, @@ -141,4 +141,4 @@ export class StepTermsUi extends Component { } } -export const StepTerms = injectI18n(StepTermsUi); +export { StepTerms }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/detail_panel/detail_panel.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/detail_panel/detail_panel.js index 30b245e693f24..04ce5fc85a622 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/detail_panel/detail_panel.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/detail_panel/detail_panel.js @@ -6,7 +6,8 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n/react'; import { EuiErrorBoundary, @@ -62,7 +63,7 @@ const tabToUiMetricMap = { [JOB_DETAILS_TAB_JSON]: UIM_DETAIL_PANEL_JSON_TAB_CLICK, }; -export class DetailPanelUi extends Component { +class DetailPanel extends Component { static propTypes = { isOpen: PropTypes.bool.isRequired, isLoading: PropTypes.bool, @@ -130,7 +131,7 @@ export class DetailPanelUi extends Component { } renderJob() { - const { panelType, job, intl } = this.props; + const { panelType, job } = this.props; const { status, documentsProcessed, pagesProcessed, rollupsIndexed, triggerCount, json } = job; @@ -159,8 +160,7 @@ export class DetailPanelUi extends Component { anchorPosition="upRight" detailPanel={true} iconType="arrowUp" - label={intl.formatMessage({ - id: 'xpack.rollupJobs.detailPanel.jobActionMenu.buttonLabel', + label={i18n.translate('xpack.rollupJobs.detailPanel.jobActionMenu.buttonLabel', { defaultMessage: 'Manage', })} /> @@ -252,4 +252,4 @@ export class DetailPanelUi extends Component { } } -export const DetailPanel = injectI18n(DetailPanelUi); +export { DetailPanel }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/detail_panel/detail_panel.test.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/detail_panel/detail_panel.test.js index 39153cda1f99d..9ac8e6075e4cf 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/detail_panel/detail_panel.test.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/detail_panel/detail_panel.test.js @@ -58,12 +58,12 @@ describe('', () => { }); it("should have children if it's open", () => { - expect(component.find('DetailPanelUi').children().length).toBeTruthy(); + expect(component.find('DetailPanel').children().length).toBeTruthy(); }); it('should *not* have children if its closed', () => { ({ component } = initTestBed({ isOpen: false })); - expect(component.find('DetailPanelUi').children().length).toBeFalsy(); + expect(component.find('DetailPanel').children().length).toBeFalsy(); }); it('should show a loading when the job is loading', () => { diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js index 842b7a93d85b4..725789fc584de 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_list.test.js @@ -54,14 +54,14 @@ describe('', () => { const { component, exists } = initTestBed({ isLoading: true }); expect(exists('jobListLoading')).toBeTruthy(); - expect(component.find('JobTableUi').length).toBeFalsy(); + expect(component.find('JobTable').length).toBeFalsy(); }); it('should display the when there are jobs', () => { const { component, exists } = initTestBed({ hasJobs: true }); expect(exists('jobListLoading')).toBeFalsy(); - expect(component.find('JobTableUi').length).toBeTruthy(); + expect(component.find('JobTable').length).toBeTruthy(); }); describe('when there is an API error', () => { diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_table/job_table.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_table/job_table.js index 42d48702a3385..cd1616afb09a5 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_table/job_table.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_table/job_table.js @@ -7,7 +7,7 @@ import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import { i18n } from '@kbn/i18n'; -import { injectI18n, FormattedMessage } from '@kbn/i18n/react'; +import { FormattedMessage } from '@kbn/i18n/react'; import { EuiCheckbox, @@ -120,7 +120,7 @@ const COLUMNS = [ }, ]; -export class JobTableUi extends Component { +class JobTable extends Component { static propTypes = { jobs: PropTypes.array, pager: PropTypes.object.isRequired, @@ -333,7 +333,7 @@ export class JobTableUi extends Component { } render() { - const { filterChanged, filter, jobs, intl, closeDetailPanel } = this.props; + const { filterChanged, filter, jobs, closeDetailPanel } = this.props; const { idToSelectedJobMap } = this.state; @@ -360,8 +360,7 @@ export class JobTableUi extends Component { filterChanged(event.target.value); }} data-test-subj="jobTableFilterInput" - placeholder={intl.formatMessage({ - id: 'xpack.rollupJobs.jobTable.searchInputPlaceholder', + placeholder={i18n.translate('xpack.rollupJobs.jobTable.searchInputPlaceholder', { defaultMessage: 'Search', })} aria-label="Search jobs" @@ -406,4 +405,4 @@ export class JobTableUi extends Component { } } -export const JobTable = injectI18n(JobTableUi); +export { JobTable }; From e815a97b8f8ed9eed19a253f20cbc17dd5d5b192 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Wed, 22 Jan 2020 12:48:05 +0300 Subject: [PATCH 23/39] Replace npStart and npSetup usage to services --- .../confirm_delete_modal.js | 38 ++++++++++--------- .../sections/job_create/job_create.js | 6 +-- .../rollup/public/crud_app/services/api.js | 27 +++++++------ .../public/crud_app/services/api_errors.ts | 10 ++--- .../public/crud_app/services/http_provider.ts | 20 ++++++++++ .../rollup/public/crud_app/services/index.js | 12 +++++- .../crud_app/store/actions/create_job.js | 5 ++- .../crud_app/store/actions/delete_jobs.js | 7 ++-- .../rollup_index_pattern_creation_config.js | 3 +- .../plugins/rollup/public/kibana_services.ts | 30 +++++++++++++++ x-pack/legacy/plugins/rollup/public/legacy.ts | 9 +---- .../plugins/rollup/public/legacy_imports.ts | 2 - .../legacy/plugins/rollup/public/plugin.tsx | 10 +++-- 13 files changed, 122 insertions(+), 57 deletions(-) create mode 100644 x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.ts create mode 100644 x-pack/legacy/plugins/rollup/public/kibana_services.ts diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_action_menu/confirm_delete_modal/confirm_delete_modal.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_action_menu/confirm_delete_modal/confirm_delete_modal.js index 8b1b93b424603..cbf648044f9fc 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_action_menu/confirm_delete_modal/confirm_delete_modal.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_action_menu/confirm_delete_modal/confirm_delete_modal.js @@ -41,19 +41,19 @@ class ConfirmDeleteModal extends Component { } render() { - const { isSingleSelection, jobs, onCancel, onConfirm, intl } = this.props; + const { isSingleSelection, jobs, onCancel, onConfirm } = this.props; let title; let content; if (isSingleSelection) { const { id, status } = jobs[0]; - title = intl.formatMessage( + title = i18n.translate( + 'xpack.rollupJobs.jobActionMenu.deleteJob.confirmModal.deleteSingleJobTitle', { - id: 'xpack.rollupJobs.jobActionMenu.deleteJob.confirmModal.deleteSingleJobTitle', defaultMessage: "Delete rollup job '{id}'?", - }, - { id } + values: { id }, + } ); if (status === 'started') { @@ -67,12 +67,12 @@ class ConfirmDeleteModal extends Component { ); } } else { - title = intl.formatMessage( + title = i18n.translate( + 'xpack.rollupJobs.jobActionMenu.deleteJob.confirmModal.multipleDeletionTitle', { - id: 'xpack.rollupJobs.jobActionMenu.deleteJob.confirmModal.multipleDeletionTitle', defaultMessage: 'Delete {count} rollup jobs?', - }, - { count: jobs.length } + values: { count: jobs.length }, + } ); content = ( @@ -95,15 +95,19 @@ class ConfirmDeleteModal extends Component { title={title} onCancel={onCancel} onConfirm={onConfirm} - cancelButtonText={intl.formatMessage({ - id: 'xpack.rollupJobs.jobActionMenu.deleteJob.confirmModal.cancelButtonText', - defaultMessage: 'Cancel', - })} + cancelButtonText={i18n.translate( + 'xpack.rollupJobs.jobActionMenu.deleteJob.confirmModal.cancelButtonText', + { + defaultMessage: 'Cancel', + } + )} buttonColor="danger" - confirmButtonText={intl.formatMessage({ - id: 'xpack.rollupJobs.jobActionMenu.deleteJob.confirmModal.confirmButtonText', - defaultMessage: 'Delete', - })} + confirmButtonText={i18n.translate( + 'xpack.rollupJobs.jobActionMenu.deleteJob.confirmModal.confirmButtonText', + { + defaultMessage: 'Delete', + } + )} > {content} diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js index 933daf0491df9..5379778c77e2f 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/job_create.js @@ -14,8 +14,6 @@ import first from 'lodash/array/first'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; -import { npSetup } from '../../../legacy_imports'; - import { withKibana } from '../../../../../../../../src/plugins/kibana_react/public/'; import { @@ -59,6 +57,8 @@ import { hasErrors, } from './steps_config'; +import { getFatalErrors } from '../../../kibana_services'; + const stepIdToTitleMap = { [STEP_LOGISTICS]: i18n.translate('xpack.rollupJobs.create.steps.stepLogisticsTitle', { defaultMessage: 'Logistics', @@ -324,7 +324,7 @@ export class JobCreateUi extends Component { // This error isn't an HTTP error, so let the fatal error screen tell the user something // unexpected happened. - npSetup.core.fatalErrors.add( + getFatalErrors().add( error, i18n.translate('xpack.rollupJobs.create.errors.indexPatternValidationFatalErrorTitle', { defaultMessage: 'Rollup Job Wizard index pattern validation', diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js index 8ad5d5f8a3552..13983d207346c 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js @@ -13,20 +13,27 @@ import { UIM_JOB_STOP, UIM_JOB_STOP_MANY, } from '../../../common'; -import { npStart } from '../../legacy_imports'; +import { getHttp } from './http_provider'; import { trackUserRequest } from './track_ui_metric'; -const apiPrefix = '/api/rollup'; -const { prepend } = npStart.core.http.basePath; +let apiPrefix = ''; + +export async function setApiPrefix(url) { + apiPrefix = url; +} + +export function getApiPrefix() { + return apiPrefix; +} export async function loadJobs() { - const { jobs } = await npStart.core.http.get(`${prepend(apiPrefix)}/jobs`); + const { jobs } = await getHttp().get(`${getApiPrefix()}/jobs`); return jobs; } export async function startJobs(jobIds) { const body = { jobIds }; - const request = npStart.core.http.post(`${prepend(apiPrefix)}/start`, { + const request = getHttp().post(`${getApiPrefix()}/start`, { body: JSON.stringify(body), }); const actionType = jobIds.length > 1 ? UIM_JOB_START_MANY : UIM_JOB_START; @@ -35,7 +42,7 @@ export async function startJobs(jobIds) { export async function stopJobs(jobIds) { const body = { jobIds }; - const request = npStart.core.http.post(`${prepend(apiPrefix)}/stop`, { + const request = getHttp().post(`${getApiPrefix()}/stop`, { body: JSON.stringify(body), }); const actionType = jobIds.length > 1 ? UIM_JOB_STOP_MANY : UIM_JOB_STOP; @@ -44,7 +51,7 @@ export async function stopJobs(jobIds) { export async function deleteJobs(jobIds) { const body = { jobIds }; - const request = npStart.core.http.post(`${prepend(apiPrefix)}/delete`, { + const request = getHttp().post(`${getApiPrefix()}/delete`, { body: JSON.stringify(body), }); const actionType = jobIds.length > 1 ? UIM_JOB_DELETE_MANY : UIM_JOB_DELETE; @@ -53,14 +60,12 @@ export async function deleteJobs(jobIds) { export async function createJob(job) { const body = { job }; - const request = npStart.core.http.put(`${prepend(apiPrefix)}/create`, { + const request = getHttp().put(`${getApiPrefix()}/create`, { body: JSON.stringify(body), }); return await trackUserRequest(request, UIM_JOB_CREATE); } export async function validateIndexPattern(indexPattern) { - return await npStart.core.http.get( - `${prepend(apiPrefix)}/index_pattern_validity/${indexPattern}` - ); + return await getHttp().get(`${getApiPrefix()}/index_pattern_validity/${indexPattern}`); } diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/api_errors.ts b/x-pack/legacy/plugins/rollup/public/crud_app/services/api_errors.ts index 563f5b7441ef2..af9e1a16e4cc5 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/api_errors.ts +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/api_errors.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { npStart, npSetup } from '../../legacy_imports'; +import { getNotifications, getFatalErrors } from '../../kibana_services'; function createToastConfig(error: any, errorTitle: string) { // Expect an error in the shape provided by http service. @@ -21,22 +21,22 @@ export function showApiWarning(error: any, errorTitle: string) { const toastConfig = createToastConfig(error, errorTitle); if (toastConfig) { - return npStart.core.notifications.toasts.addWarning(toastConfig); + return getNotifications().toasts.addWarning(toastConfig); } // This error isn't an HTTP error, so let the fatal error screen tell the user something // unexpected happened. - return npSetup.core.fatalErrors.add(error, errorTitle); + return getFatalErrors().add(error, errorTitle); } export function showApiError(error: any, errorTitle: string) { const toastConfig = createToastConfig(error, errorTitle); if (toastConfig) { - return npStart.core.notifications.toasts.addDanger(toastConfig); + return getNotifications().toasts.addDanger(toastConfig); } // This error isn't an HTTP error, so let the fatal error screen tell the user something // unexpected happened. - npSetup.core.fatalErrors.add(error, errorTitle); + getFatalErrors().add(error, errorTitle); } diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.ts b/x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.ts new file mode 100644 index 0000000000000..dd84328084d05 --- /dev/null +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/http_provider.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 { HttpStart } from 'src/core/public'; + +let _http: HttpStart | null = null; + +export function setHttp(http: HttpStart) { + _http = http; +} + +export function getHttp() { + if (!_http) { + throw new Error('Rollup http is not defined'); + } + return _http; +} diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js index ae0d3dee0885e..fb481b90c5dc1 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js @@ -4,7 +4,15 @@ * you may not use this file except in compliance with the Elastic License. */ -export { createJob, deleteJobs, loadJobs, startJobs, stopJobs, validateIndexPattern } from './api'; +export { + createJob, + deleteJobs, + loadJobs, + startJobs, + stopJobs, + validateIndexPattern, + setApiPrefix, +} from './api'; export { showApiError, showApiWarning } from './api_errors'; @@ -27,6 +35,8 @@ export { flattenPanelTree } from './flatten_panel_tree'; export { formatFields } from './format_fields'; +export { setHttp, getHttp } from './http_provider'; + export { serializeJob, deserializeJob, deserializeJobs } from './jobs'; export { createNoticeableDelay } from './noticeable_delay'; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js index 503f3c8893393..c6e72e3081769 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js @@ -5,7 +5,6 @@ */ import { i18n } from '@kbn/i18n'; -import { npSetup } from '../../../legacy_imports'; import { CRUD_APP_BASE_PATH } from '../../constants'; import { @@ -24,6 +23,8 @@ import { CLEAR_CREATE_JOB_ERRORS, } from '../action_types'; +import { getFatalErrors } from '../../../kibana_services'; + export const createJob = jobConfig => async dispatch => { dispatch({ type: CREATE_JOB_START, @@ -78,7 +79,7 @@ export const createJob = jobConfig => async dispatch => { // This error isn't an HTTP error, so let the fatal error screen tell the user something // unexpected happened. - return npSetup.core.fatalErrors.add( + return getFatalErrors().add( error, i18n.translate('xpack.rollupJobs.createAction.errorTitle', { defaultMessage: 'Error creating rollup job', diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/delete_jobs.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/delete_jobs.js index db127b20f6175..0cfc8c24d46e9 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/delete_jobs.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/delete_jobs.js @@ -5,7 +5,6 @@ */ import { i18n } from '@kbn/i18n'; -import { npStart } from '../../../legacy_imports'; import { deleteJobs as sendDeleteJobsRequest, @@ -19,6 +18,8 @@ import { UPDATE_JOB_START, UPDATE_JOB_SUCCESS, UPDATE_JOB_FAILURE } from '../act import { refreshJobs } from './refresh_jobs'; import { closeDetailPanel } from './detail_panel'; +import { getNotifications } from '../../../kibana_services'; + export const deleteJobs = jobIds => async (dispatch, getState) => { dispatch({ type: UPDATE_JOB_START, @@ -40,14 +41,14 @@ export const deleteJobs = jobIds => async (dispatch, getState) => { } if (jobIds.length === 1) { - npStart.core.notifications.toasts.addSuccess( + getNotifications().toasts.addSuccess( i18n.translate('xpack.rollupJobs.deleteAction.successSingleNotificationTitle', { defaultMessage: `Rollup job '{jobId}' was deleted`, values: { jobId: jobIds[0] }, }) ); } else { - npStart.core.notifications.toasts.addSuccess( + getNotifications().toasts.addSuccess( i18n.translate('xpack.rollupJobs.deleteAction.successMultipleNotificationTitle', { defaultMessage: '{count} rollup jobs were deleted', values: { count: jobIds.length }, diff --git a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js index ee172cf2e90a5..82a4c5a888594 100644 --- a/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js +++ b/x-pack/legacy/plugins/rollup/public/index_pattern_creation/rollup_index_pattern_creation_config.js @@ -6,7 +6,6 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; -import { npSetup } from '../legacy_imports'; import { RollupPrompt } from './components/rollup_prompt'; import { IndexPatternCreationConfig } from '../../../../../../src/legacy/core_plugins/management/public'; @@ -65,7 +64,7 @@ export class RollupIndexPatternCreationConfig extends IndexPatternCreationConfig // This is a hack intended to prevent the getRollupIndices() request from being sent if // we're on /logout. There is a race condition that can arise on that page, whereby this // request resolves after the logout request resolves, and un-clears the session ID. - const isAnonymous = npSetup.core.http.anonymousPaths.isAnonymous(window.location.pathname); + const isAnonymous = this.httpClient.anonymousPaths.isAnonymous(window.location.pathname); if (!isAnonymous) { const response = await this.httpClient.get('/api/rollup/indices'); this.rollupIndicesCapabilities = response || {}; diff --git a/x-pack/legacy/plugins/rollup/public/kibana_services.ts b/x-pack/legacy/plugins/rollup/public/kibana_services.ts new file mode 100644 index 0000000000000..335eeb90282ca --- /dev/null +++ b/x-pack/legacy/plugins/rollup/public/kibana_services.ts @@ -0,0 +1,30 @@ +/* + * 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 { NotificationsStart, FatalErrorsSetup } from 'src/core/public'; + +let notifications: NotificationsStart | null = null; +let fatalErrors: FatalErrorsSetup | null = null; + +export function getNotifications() { + if (!notifications) { + throw new Error('Rollup notifications is not defined'); + } + return notifications; +} +export function setNotifications(newNotifications: NotificationsStart) { + notifications = newNotifications; +} + +export function getFatalErrors() { + if (!fatalErrors) { + throw new Error('Rollup fatalErrors is not defined'); + } + return fatalErrors; +} +export function setFatalErrors(newFatalErrors: FatalErrorsSetup) { + fatalErrors = newFatalErrors; +} diff --git a/x-pack/legacy/plugins/rollup/public/legacy.ts b/x-pack/legacy/plugins/rollup/public/legacy.ts index 9a0a5d49c9eda..fb98a47518068 100644 --- a/x-pack/legacy/plugins/rollup/public/legacy.ts +++ b/x-pack/legacy/plugins/rollup/public/legacy.ts @@ -4,13 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ -import { - npSetup, - npStart, - aggTypeFilters, - aggTypeFieldFilters, - editorConfigProviders, -} from './legacy_imports'; +import { npSetup, npStart } from 'ui/new_platform'; +import { aggTypeFilters, aggTypeFieldFilters, editorConfigProviders } from './legacy_imports'; import { addSearchStrategy } from '../../../../../src/legacy/core_plugins/data/public/search/search_strategy'; import { RollupPlugin } from './plugin'; import { setup as management } from '../../../../../src/legacy/core_plugins/management/public/legacy'; diff --git a/x-pack/legacy/plugins/rollup/public/legacy_imports.ts b/x-pack/legacy/plugins/rollup/public/legacy_imports.ts index 884e6102a4503..4c3431621b79c 100644 --- a/x-pack/legacy/plugins/rollup/public/legacy_imports.ts +++ b/x-pack/legacy/plugins/rollup/public/legacy_imports.ts @@ -7,8 +7,6 @@ // @ts-ignore export { findIllegalCharactersInIndexName, INDEX_ILLEGAL_CHARACTERS_VISIBLE } from 'ui/indices'; -export { npSetup, npStart } from 'ui/new_platform'; - export { aggTypeFilters, AggTypeFilters } from 'ui/agg_types/filter'; export { aggTypeFieldFilters, AggTypeFieldFilters } from 'ui/agg_types/param_types/filter'; export { editorConfigProviders } from 'ui/vis/editors/config/editor_config_providers'; diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.tsx index dd00e5fc5172a..26c6df3b563b4 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -43,7 +43,8 @@ import { ManagementStart } from '../../../../../src/plugins/management/public'; import { rollupJobsStore } from './crud_app/store'; import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; // @ts-ignore -import { setEsBaseAndXPackBase } from './crud_app/services'; +import { setEsBaseAndXPackBase, setHttp, setApiPrefix } from './crud_app/services'; +import { setNotifications, setFatalErrors } from './kibana_services'; export interface RollupPluginSetupDependencies { __LEGACY: { @@ -78,6 +79,7 @@ export class RollupPlugin implements Plugin { home, }: RollupPluginSetupDependencies ) { + setFatalErrors(core.fatalErrors); addBadgeExtension(rollupBadgeExtension); addToggleExtension(rollupToggleExtension); @@ -109,6 +111,9 @@ export class RollupPlugin implements Plugin { } start(core: CoreStart, { management }: RollupPluginStartDependencies) { + setHttp(core.http); + setApiPrefix(core.http.basePath.prepend('/api/rollup')); + setNotifications(core.notifications); setEsBaseAndXPackBase(core.docLinks.ELASTIC_WEBSITE_URL, core.docLinks.DOC_LINK_VERSION); const esSection = management.sections.getSection('elasticsearch'); @@ -133,9 +138,6 @@ export class RollupPlugin implements Plugin { From 24ba489cfe2e57044c2b82aa09d140b3a7d110e9 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Wed, 22 Jan 2020 12:49:49 +0300 Subject: [PATCH 24/39] Import search strategy stuff from the top level of the data plugin --- src/legacy/core_plugins/data/public/index.ts | 8 +++++++- src/legacy/core_plugins/data/public/search/index.ts | 2 ++ x-pack/legacy/plugins/rollup/public/legacy.ts | 2 +- .../rollup/public/search/rollup_search_strategy.ts | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index 4514d67ea5fcd..0b545f5e130ae 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -39,4 +39,10 @@ export { /** @public static code */ export * from '../common'; export { FilterStateManager } from './filter/filter_manager'; -export { getRequestInspectorStats, getResponseInspectorStats } from './search'; +export { + getRequestInspectorStats, + getResponseInspectorStats, + SearchError, + getSearchErrorType, + addSearchStrategy, +} from './search'; diff --git a/src/legacy/core_plugins/data/public/search/index.ts b/src/legacy/core_plugins/data/public/search/index.ts index d930a47219514..c2cd74fb37130 100644 --- a/src/legacy/core_plugins/data/public/search/index.ts +++ b/src/legacy/core_plugins/data/public/search/index.ts @@ -20,3 +20,5 @@ export { SearchService, SearchSetup, SearchStart } from './search_service'; export { getRequestInspectorStats, getResponseInspectorStats } from './utils'; + +export { SearchError, getSearchErrorType, addSearchStrategy } from './search_strategy'; diff --git a/x-pack/legacy/plugins/rollup/public/legacy.ts b/x-pack/legacy/plugins/rollup/public/legacy.ts index fb98a47518068..3b81ab4d5e821 100644 --- a/x-pack/legacy/plugins/rollup/public/legacy.ts +++ b/x-pack/legacy/plugins/rollup/public/legacy.ts @@ -6,7 +6,7 @@ import { npSetup, npStart } from 'ui/new_platform'; import { aggTypeFilters, aggTypeFieldFilters, editorConfigProviders } from './legacy_imports'; -import { addSearchStrategy } from '../../../../../src/legacy/core_plugins/data/public/search/search_strategy'; +import { addSearchStrategy } from '../../../../../src/legacy/core_plugins/data/public'; import { RollupPlugin } from './plugin'; import { setup as management } from '../../../../../src/legacy/core_plugins/management/public/legacy'; import { addBadgeExtension, addToggleExtension } from '../../index_management/public'; diff --git a/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts b/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts index 2ddc86a9ad1f0..0f079881f8b3e 100644 --- a/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts +++ b/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts @@ -8,7 +8,7 @@ import { HttpSetup } from 'src/core/public'; import { SearchError, getSearchErrorType, -} from '../../../../../../src/legacy/core_plugins/data/public/search/search_strategy'; +} from '../../../../../../src/legacy/core_plugins/data/public'; function serializeFetchParams(searchRequests: any) { return JSON.stringify( From 8225854d057668852061f51b8ab3984b8e8e7a0f Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Wed, 22 Jan 2020 14:05:16 +0300 Subject: [PATCH 25/39] Update unit tests --- .../__jest__/client_integration/helpers/setup_context.tsx | 3 --- .../client_integration/helpers/setup_environment.ts | 4 ++-- .../__jest__/client_integration/job_create_clone.test.js | 2 ++ .../client_integration/job_create_date_histogram.test.js | 2 ++ .../client_integration/job_create_histogram.test.js | 2 ++ .../client_integration/job_create_logistics.test.js | 2 ++ .../__jest__/client_integration/job_create_metrics.test.js | 2 ++ .../__jest__/client_integration/job_create_review.test.js | 6 ++++-- .../__jest__/client_integration/job_create_terms.test.js | 2 ++ .../rollup/__jest__/client_integration/job_list.test.js | 3 ++- .../__jest__/client_integration/job_list_clone.test.js | 2 ++ 11 files changed, 22 insertions(+), 8 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_context.tsx b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_context.tsx index 521903eaec045..4c5a8e17c586a 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_context.tsx +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_context.tsx @@ -12,9 +12,6 @@ const startMock = coreMock.createStart(); const services = { setBreadcrumbs: startMock.chrome.setBreadcrumbs, - http: startMock.http, - notifications: startMock.notifications, - chrome: startMock.chrome, }; const wrapComponent = (Component: FunctionComponent) => (props: any) => ( diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts index b5248458d04f8..c0fb8f6a0ab57 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts @@ -19,11 +19,11 @@ const mockHttpRequest = ( }: RequestMocks | { [key: string]: any } = {} ) => { http.get.mockImplementation(async (url: string) => { - if (url === '/api/rollup/jobs') { + if (url === '/jobs') { return jobs; } - if (url.startsWith('/api/rollup/index_pattern_validity')) { + if (url.startsWith('/index_pattern_validity')) { return { doesMatchIndices: true, doesMatchRollupIndices: false, diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_clone.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_clone.test.js index 55552ac075d6c..b7c98ed179c7a 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_clone.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_clone.test.js @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { setHttp } from '../../public/crud_app/services'; import { mockHttpRequest, pageHelpers, nextTick } from './helpers'; import { JOB_TO_CLONE, JOB_CLONE_INDEX_PATTERN_CHECK } from './helpers/constants'; @@ -26,6 +27,7 @@ describe('Cloning a rollup job through create job wizard', () => { beforeAll(() => { npStart = require('ui/new_platform').npStart; // eslint-disable-line + setHttp(npStart.core.http); }); beforeEach(() => { diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_date_histogram.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_date_histogram.test.js index b5b102e5e4e8a..b8ec7d9f85d00 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_date_histogram.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_date_histogram.test.js @@ -6,6 +6,7 @@ import moment from 'moment-timezone'; +import { setHttp } from '../../public/crud_app/services'; import { mockHttpRequest, pageHelpers } from './helpers'; jest.mock('ui/new_platform'); @@ -25,6 +26,7 @@ describe('Create Rollup Job, step 2: Date histogram', () => { beforeAll(() => { npStart = require('ui/new_platform').npStart; // eslint-disable-line + setHttp(npStart.core.http); }); beforeEach(() => { // Set "default" mock responses by not providing any arguments diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_histogram.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_histogram.test.js index 18f000d3222eb..c4b5d753f1a26 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_histogram.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_histogram.test.js @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { setHttp } from '../../public/crud_app/services'; import { mockHttpRequest, pageHelpers } from './helpers'; jest.mock('ui/new_platform'); @@ -24,6 +25,7 @@ describe('Create Rollup Job, step 4: Histogram', () => { beforeAll(() => { npStart = require('ui/new_platform').npStart; // eslint-disable-line + setHttp(npStart.core.http); }); beforeEach(() => { diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js index 5d6795f86a059..98af94437fa5a 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_logistics.test.js @@ -13,6 +13,7 @@ import { YEAR, } from '../../../../../../src/plugins/es_ui_shared/public/components/cron_editor'; import { indexPatterns } from '../../../../../../src/plugins/data/public'; +import { setHttp } from '../../public/crud_app/services'; import { mockHttpRequest, pageHelpers } from './helpers'; jest.mock('ui/new_platform'); @@ -31,6 +32,7 @@ describe('Create Rollup Job, step 1: Logistics', () => { beforeAll(() => { npStart = require('ui/new_platform').npStart; // eslint-disable-line + setHttp(npStart.core.http); }); beforeEach(() => { diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_metrics.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_metrics.test.js index 0ce816f39820a..a72dc8b25c083 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_metrics.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_metrics.test.js @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { setHttp } from '../../public/crud_app/services'; import { mockHttpRequest, pageHelpers } from './helpers'; jest.mock('ui/new_platform'); @@ -24,6 +25,7 @@ describe('Create Rollup Job, step 5: Metrics', () => { beforeAll(() => { npStart = require('ui/new_platform').npStart; // eslint-disable-line + setHttp(npStart.core.http); }); beforeEach(() => { diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js index 680d9229f82b9..442c7baa1d380 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js @@ -6,6 +6,7 @@ import { pageHelpers, mockHttpRequest } from './helpers'; import { first } from 'lodash'; +import { setHttp } from '../../public/crud_app/services'; import { JOBS } from './helpers/constants'; jest.mock('ui/new_platform'); @@ -26,6 +27,7 @@ describe('Create Rollup Job, step 6: Review', () => { beforeAll(() => { npStart = require('ui/new_platform').npStart; // eslint-disable-line + setHttp(npStart.core.http); }); beforeEach(() => { @@ -123,8 +125,8 @@ describe('Create Rollup Job, step 6: Review', () => { }); describe('save()', () => { - const jobCreateApiPath = '/api/rollup/create'; - const jobStartApiPath = '/api/rollup/start'; + const jobCreateApiPath = '/create'; + const jobStartApiPath = '/start'; describe('without starting job after creation', () => { it('should call the "create" Api server endpoint', async () => { diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_terms.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_terms.test.js index 28cc96590f61c..f111a7df2c250 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_terms.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_terms.test.js @@ -4,6 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ +import { setHttp } from '../../public/crud_app/services'; import { pageHelpers, mockHttpRequest } from './helpers'; jest.mock('ui/new_platform'); @@ -23,6 +24,7 @@ describe('Create Rollup Job, step 3: Terms', () => { beforeAll(() => { npStart = require('ui/new_platform').npStart; // eslint-disable-line + setHttp(npStart.core.http); }); beforeEach(() => { diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list.test.js index b857905966e8f..a9e474cf0b559 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list.test.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getRouter } from '../../public/crud_app/services'; +import { getRouter, setHttp } from '../../public/crud_app/services'; import { mockHttpRequest, pageHelpers, nextTick } from './helpers'; import { JOBS } from './helpers/constants'; @@ -29,6 +29,7 @@ describe('', () => { beforeAll(() => { npStart = require('ui/new_platform').npStart; // eslint-disable-line + setHttp(npStart.core.http); }); beforeEach(async () => { diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list_clone.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list_clone.test.js index 0fad35eddfa31..8a36af83def4c 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list_clone.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_list_clone.test.js @@ -7,6 +7,7 @@ import { mockHttpRequest, pageHelpers, nextTick } from './helpers'; import { JOB_TO_CLONE, JOB_CLONE_INDEX_PATTERN_CHECK } from './helpers/constants'; import { getRouter } from '../../public/crud_app/services/routing'; +import { setHttp } from '../../public/crud_app/services'; import { CRUD_APP_BASE_PATH } from '../../public/crud_app/constants'; jest.mock('ui/new_platform'); @@ -24,6 +25,7 @@ describe('Smoke test cloning an existing rollup job from job list', () => { beforeAll(() => { npStart = require('ui/new_platform').npStart; // eslint-disable-line + setHttp(npStart.core.http); }); beforeEach(async () => { From 58be10597af1c8fbd080cc8a2706d96e8a006939 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Thu, 23 Jan 2020 09:56:12 +0300 Subject: [PATCH 26/39] Do not prepend the url --- .../helpers/setup_environment.ts | 4 ++-- .../job_create_review.test.js | 4 ++-- .../rollup/public/crud_app/services/api.js | 22 ++++++------------- .../rollup/public/crud_app/services/index.js | 10 +-------- .../legacy/plugins/rollup/public/plugin.tsx | 3 +-- 5 files changed, 13 insertions(+), 30 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts index c0fb8f6a0ab57..b5248458d04f8 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts @@ -19,11 +19,11 @@ const mockHttpRequest = ( }: RequestMocks | { [key: string]: any } = {} ) => { http.get.mockImplementation(async (url: string) => { - if (url === '/jobs') { + if (url === '/api/rollup/jobs') { return jobs; } - if (url.startsWith('/index_pattern_validity')) { + if (url.startsWith('/api/rollup/index_pattern_validity')) { return { doesMatchIndices: true, doesMatchRollupIndices: false, diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js index 442c7baa1d380..0fa9509368d3f 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/job_create_review.test.js @@ -125,8 +125,8 @@ describe('Create Rollup Job, step 6: Review', () => { }); describe('save()', () => { - const jobCreateApiPath = '/create'; - const jobStartApiPath = '/start'; + const jobCreateApiPath = '/api/rollup/create'; + const jobStartApiPath = '/api/rollup/start'; describe('without starting job after creation', () => { it('should call the "create" Api server endpoint', async () => { diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js index 13983d207346c..8f95561b72d1d 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/api.js @@ -16,24 +16,16 @@ import { import { getHttp } from './http_provider'; import { trackUserRequest } from './track_ui_metric'; -let apiPrefix = ''; - -export async function setApiPrefix(url) { - apiPrefix = url; -} - -export function getApiPrefix() { - return apiPrefix; -} +const apiPrefix = '/api/rollup'; export async function loadJobs() { - const { jobs } = await getHttp().get(`${getApiPrefix()}/jobs`); + const { jobs } = await getHttp().get(`${apiPrefix}/jobs`); return jobs; } export async function startJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${getApiPrefix()}/start`, { + const request = getHttp().post(`${apiPrefix}/start`, { body: JSON.stringify(body), }); const actionType = jobIds.length > 1 ? UIM_JOB_START_MANY : UIM_JOB_START; @@ -42,7 +34,7 @@ export async function startJobs(jobIds) { export async function stopJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${getApiPrefix()}/stop`, { + const request = getHttp().post(`${apiPrefix}/stop`, { body: JSON.stringify(body), }); const actionType = jobIds.length > 1 ? UIM_JOB_STOP_MANY : UIM_JOB_STOP; @@ -51,7 +43,7 @@ export async function stopJobs(jobIds) { export async function deleteJobs(jobIds) { const body = { jobIds }; - const request = getHttp().post(`${getApiPrefix()}/delete`, { + const request = getHttp().post(`${apiPrefix}/delete`, { body: JSON.stringify(body), }); const actionType = jobIds.length > 1 ? UIM_JOB_DELETE_MANY : UIM_JOB_DELETE; @@ -60,12 +52,12 @@ export async function deleteJobs(jobIds) { export async function createJob(job) { const body = { job }; - const request = getHttp().put(`${getApiPrefix()}/create`, { + const request = getHttp().put(`${apiPrefix}/create`, { body: JSON.stringify(body), }); return await trackUserRequest(request, UIM_JOB_CREATE); } export async function validateIndexPattern(indexPattern) { - return await getHttp().get(`${getApiPrefix()}/index_pattern_validity/${indexPattern}`); + return await getHttp().get(`${apiPrefix}/index_pattern_validity/${indexPattern}`); } diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js index fb481b90c5dc1..16047ce7ce71f 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js @@ -4,15 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -export { - createJob, - deleteJobs, - loadJobs, - startJobs, - stopJobs, - validateIndexPattern, - setApiPrefix, -} from './api'; +export { createJob, deleteJobs, loadJobs, startJobs, stopJobs, validateIndexPattern } from './api'; export { showApiError, showApiWarning } from './api_errors'; diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.tsx index 26c6df3b563b4..756408829a482 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -43,7 +43,7 @@ import { ManagementStart } from '../../../../../src/plugins/management/public'; import { rollupJobsStore } from './crud_app/store'; import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; // @ts-ignore -import { setEsBaseAndXPackBase, setHttp, setApiPrefix } from './crud_app/services'; +import { setEsBaseAndXPackBase, setHttp } from './crud_app/services'; import { setNotifications, setFatalErrors } from './kibana_services'; export interface RollupPluginSetupDependencies { @@ -112,7 +112,6 @@ export class RollupPlugin implements Plugin { start(core: CoreStart, { management }: RollupPluginStartDependencies) { setHttp(core.http); - setApiPrefix(core.http.basePath.prepend('/api/rollup')); setNotifications(core.notifications); setEsBaseAndXPackBase(core.docLinks.ELASTIC_WEBSITE_URL, core.docLinks.DOC_LINK_VERSION); From 27400e92fb161ab81cdbb3e002831b3a793247f8 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Tue, 28 Jan 2020 12:18:06 +0300 Subject: [PATCH 27/39] Fix merge conflicts --- src/legacy/core_plugins/data/public/index.ts | 8 +------- src/legacy/core_plugins/data/public/search/index.ts | 2 -- src/plugins/data/public/search/index.ts | 1 + x-pack/legacy/plugins/rollup/public/plugin.tsx | 2 +- 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index 45de9af06dc5b..7fe487667f94e 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -37,10 +37,4 @@ export { /** @public static code */ export * from '../common'; export { FilterStateManager } from './filter/filter_manager'; -export { - getRequestInspectorStats, - getResponseInspectorStats, - SearchError, - getSearchErrorType, - addSearchStrategy, -} from './search'; +export { getRequestInspectorStats, getResponseInspectorStats } from './search'; diff --git a/src/legacy/core_plugins/data/public/search/index.ts b/src/legacy/core_plugins/data/public/search/index.ts index bf7f34c69ee6f..e1c93ec0e3b1c 100644 --- a/src/legacy/core_plugins/data/public/search/index.ts +++ b/src/legacy/core_plugins/data/public/search/index.ts @@ -18,5 +18,3 @@ */ export { getRequestInspectorStats, getResponseInspectorStats } from './utils'; - -export { SearchError, getSearchErrorType, addSearchStrategy } from './search_strategy'; diff --git a/src/plugins/data/public/search/index.ts b/src/plugins/data/public/search/index.ts index cf7e0268d745a..4289697f2684a 100644 --- a/src/plugins/data/public/search/index.ts +++ b/src/plugins/data/public/search/index.ts @@ -47,6 +47,7 @@ export { hasSearchStategyForIndexPattern, defaultSearchStrategy, SearchError, + SearchStrategyProvider, } from './search_strategy'; export { diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.tsx index 756408829a482..f123048bdb398 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -15,7 +15,7 @@ import { AggTypeFilters, AggTypeFieldFilters, } from './legacy_imports'; -import { SearchStrategyProvider } from '../../../../../src/legacy/core_plugins/data/public/search/search_strategy/types'; +import { SearchStrategyProvider } from '../../../../../src/plugins/data/public'; import { ManagementSetup } from '../../../../../src/legacy/core_plugins/management/public/np_ready'; import { rollupBadgeExtension, rollupToggleExtension } from './extend_index_management'; // @ts-ignore From 8c9163fdff30f1cea40537995a834d39223e29d4 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Tue, 28 Jan 2020 12:25:35 +0300 Subject: [PATCH 28/39] Refactoring --- .../confirm_delete_modal/confirm_delete_modal.js | 4 +--- .../crud_app/sections/job_create/navigation/navigation.js | 4 +--- .../crud_app/sections/job_create/steps/step_date_histogram.js | 4 +--- .../crud_app/sections/job_create/steps/step_histogram.js | 4 +--- .../crud_app/sections/job_create/steps/step_logistics.js | 4 +--- .../public/crud_app/sections/job_create/steps/step_metrics.js | 4 +--- .../public/crud_app/sections/job_create/steps/step_review.js | 4 +--- .../public/crud_app/sections/job_create/steps/step_terms.js | 4 +--- .../crud_app/sections/job_list/detail_panel/detail_panel.js | 4 +--- .../public/crud_app/sections/job_list/job_table/job_table.js | 4 +--- 10 files changed, 10 insertions(+), 30 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_action_menu/confirm_delete_modal/confirm_delete_modal.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_action_menu/confirm_delete_modal/confirm_delete_modal.js index cbf648044f9fc..de1bee29aed4d 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_action_menu/confirm_delete_modal/confirm_delete_modal.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/components/job_action_menu/confirm_delete_modal/confirm_delete_modal.js @@ -11,7 +11,7 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { EuiConfirmModal, EuiOverlayMask } from '@elastic/eui'; -class ConfirmDeleteModal extends Component { +export class ConfirmDeleteModal extends Component { static propTypes = { isSingleSelection: PropTypes.bool.isRequired, jobs: PropTypes.array.isRequired, @@ -115,5 +115,3 @@ class ConfirmDeleteModal extends Component { ); } } - -export { ConfirmDeleteModal }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/navigation/navigation.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/navigation/navigation.js index 000a74ead0eb2..bb0718370270a 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/navigation/navigation.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/navigation/navigation.js @@ -18,7 +18,7 @@ import { EuiCheckbox, } from '@elastic/eui'; -const Navigation = ({ +export const Navigation = ({ isSaving, hasNextStep, hasPreviousStep, @@ -129,5 +129,3 @@ Navigation.propTypes = { save: PropTypes.func.isRequired, canGoToNextStep: PropTypes.bool.isRequired, }; - -export { Navigation }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js index 6ebccfc861e70..c5ba36547cc11 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_date_histogram.js @@ -35,7 +35,7 @@ const timeZoneOptions = moment.tz.names().map(name => ({ text: name, })); -class StepDateHistogram extends Component { +export class StepDateHistogram extends Component { static propTypes = { fields: PropTypes.object.isRequired, onFieldsChange: PropTypes.func.isRequired, @@ -318,5 +318,3 @@ class StepDateHistogram extends Component { return ; }; } - -export { StepDateHistogram }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_histogram.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_histogram.js index d87245ac4fac6..9307c9074e663 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_histogram.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_histogram.js @@ -26,7 +26,7 @@ import { FieldList } from '../../components'; import { FieldChooser, StepError } from './components'; -class StepHistogram extends Component { +export class StepHistogram extends Component { static propTypes = { fields: PropTypes.object.isRequired, onFieldsChange: PropTypes.func.isRequired, @@ -212,5 +212,3 @@ class StepHistogram extends Component { return ; }; } - -export { StepHistogram }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js index b1f5d475461c6..024001d463240 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_logistics.js @@ -35,7 +35,7 @@ import { indexPatterns } from '../../../../../../../../../src/plugins/data/publi const indexPatternIllegalCharacters = indexPatterns.ILLEGAL_CHARACTERS_VISIBLE.join(' '); const indexIllegalCharacters = INDEX_ILLEGAL_CHARACTERS_VISIBLE.join(' '); -class StepLogistics extends Component { +export class StepLogistics extends Component { static propTypes = { fields: PropTypes.object.isRequired, onFieldsChange: PropTypes.func.isRequired, @@ -522,5 +522,3 @@ class StepLogistics extends Component { return ; }; } - -export { StepLogistics }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_metrics.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_metrics.js index 989ef128ec1ac..b71b6bfc805bf 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_metrics.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_metrics.js @@ -64,7 +64,7 @@ const metricTypesConfig = (function() { }); })(); -class StepMetrics extends Component { +export class StepMetrics extends Component { static propTypes = { fields: PropTypes.object.isRequired, onFieldsChange: PropTypes.func.isRequired, @@ -472,5 +472,3 @@ class StepMetrics extends Component { }, ]; } - -export { StepMetrics }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_review.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_review.js index b0876458f5929..0097792db3105 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_review.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_review.js @@ -30,7 +30,7 @@ const JOB_DETAILS_TABS = [ JOB_DETAILS_TAB_REQUEST, ]; -class StepReview extends Component { +export class StepReview extends Component { static propTypes = { job: PropTypes.object.isRequired, }; @@ -121,5 +121,3 @@ class StepReview extends Component { ); } } - -export { StepReview }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_terms.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_terms.js index 502a6665c3656..48e045e19f478 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_terms.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_create/steps/step_terms.js @@ -23,7 +23,7 @@ import { FieldList } from '../../components'; import { FieldChooser } from './components'; -class StepTerms extends Component { +export class StepTerms extends Component { static propTypes = { fields: PropTypes.object.isRequired, onFieldsChange: PropTypes.func.isRequired, @@ -140,5 +140,3 @@ class StepTerms extends Component { ); } } - -export { StepTerms }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/detail_panel/detail_panel.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/detail_panel/detail_panel.js index 04ce5fc85a622..4534ef698b718 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/detail_panel/detail_panel.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/detail_panel/detail_panel.js @@ -63,7 +63,7 @@ const tabToUiMetricMap = { [JOB_DETAILS_TAB_JSON]: UIM_DETAIL_PANEL_JSON_TAB_CLICK, }; -class DetailPanel extends Component { +export class DetailPanel extends Component { static propTypes = { isOpen: PropTypes.bool.isRequired, isLoading: PropTypes.bool, @@ -251,5 +251,3 @@ class DetailPanel extends Component { ); } } - -export { DetailPanel }; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_table/job_table.js b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_table/job_table.js index cd1616afb09a5..4dbe396ab8410 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_table/job_table.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/sections/job_list/job_table/job_table.js @@ -120,7 +120,7 @@ const COLUMNS = [ }, ]; -class JobTable extends Component { +export class JobTable extends Component { static propTypes = { jobs: PropTypes.array, pager: PropTypes.object.isRequired, @@ -404,5 +404,3 @@ class JobTable extends Component { ); } } - -export { JobTable }; From 07b58cd5c183e765fee3e12eeb8460c86572651f Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Tue, 28 Jan 2020 12:51:25 +0300 Subject: [PATCH 29/39] Revert removal of setUserHasLeftApp --- .../legacy/plugins/rollup/public/crud_app/app.js | 7 ++++++- .../rollup/public/crud_app/services/index.js | 8 +++++++- .../rollup/public/crud_app/services/routing.js | 10 ++++++++++ .../public/crud_app/store/middleware/clone_job.js | 10 ++++++---- .../crud_app/store/middleware/detail_panel.js | 14 ++++++++------ 5 files changed, 37 insertions(+), 12 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/app.js b/x-pack/legacy/plugins/rollup/public/crud_app/app.js index f28398ca58963..da35c8a56f2d2 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/app.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/app.js @@ -10,7 +10,7 @@ import { HashRouter, Switch, Route, Redirect, withRouter } from 'react-router-do import { UIM_APP_LOAD } from '../../common'; import { CRUD_APP_BASE_PATH } from './constants'; -import { registerRouter, trackUiMetric, METRIC_TYPE } from './services'; +import { registerRouter, setUserHasLeftApp, trackUiMetric, METRIC_TYPE } from './services'; import { JobList, JobCreate } from './sections'; class ShareRouterComponent extends Component { @@ -45,6 +45,11 @@ export class App extends Component { trackUiMetric(METRIC_TYPE.LOADED, UIM_APP_LOAD); } + componentWillUnmount() { + // Set internal flag so we can prevent reacting to route changes internally. + setUserHasLeftApp(true); + } + render() { return ( diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js index 16047ce7ce71f..790770b9b6a9f 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/index.js @@ -35,7 +35,13 @@ export { createNoticeableDelay } from './noticeable_delay'; export { extractQueryParams } from './query_params'; -export { registerRouter, getRouter, getRouterLinkProps } from './routing'; +export { + setUserHasLeftApp, + getUserHasLeftApp, + registerRouter, + getRouter, + getRouterLinkProps, +} from './routing'; export { sortTable } from './sort_table'; diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/services/routing.js b/x-pack/legacy/plugins/rollup/public/crud_app/services/routing.js index a21ed780a748a..3b78e73c6b3af 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/services/routing.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/services/routing.js @@ -10,6 +10,16 @@ import { createLocation } from 'history'; +let _userHasLeftApp = false; + +export function setUserHasLeftApp(userHasLeftApp) { + _userHasLeftApp = userHasLeftApp; +} + +export function getUserHasLeftApp() { + return _userHasLeftApp; +} + const isModifiedEvent = event => !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey); diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/clone_job.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/clone_job.js index 433934b0b9c38..e424232cce0a1 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/clone_job.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/clone_job.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getRouter } from '../../services'; +import { getRouter, getUserHasLeftApp } from '../../services'; import { CLONE_JOB_START } from '../action_types'; import { CRUD_APP_BASE_PATH } from '../../constants'; @@ -12,9 +12,11 @@ export const cloneJob = () => next => action => { const { type } = action; if (type === CLONE_JOB_START) { - getRouter().history.push({ - pathname: `${CRUD_APP_BASE_PATH}/create`, - }); + if (!getUserHasLeftApp()) { + getRouter().history.push({ + pathname: `${CRUD_APP_BASE_PATH}/create`, + }); + } } return next(action); diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/detail_panel.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/detail_panel.js index 062b44b51a9b1..cbe86fb7065b6 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/detail_panel.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/middleware/detail_panel.js @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { getRouter } from '../../services'; +import { getRouter, getUserHasLeftApp } from '../../services'; import { CLOSE_DETAIL_PANEL } from '../action_types'; export const detailPanel = () => next => action => { @@ -12,12 +12,14 @@ export const detailPanel = () => next => action => { switch (type) { case CLOSE_DETAIL_PANEL: - const { history } = getRouter(); + if (!getUserHasLeftApp()) { + const { history } = getRouter(); - // Persist state to query params by removing deep link. - history.replace({ - search: '', - }); + // Persist state to query params by removing deep link. + history.replace({ + search: '', + }); + } break; } From 32aa6fb126b19ef2016f96f53644097b117f9e72 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Tue, 28 Jan 2020 14:37:04 +0300 Subject: [PATCH 30/39] Export getSearchErrorType --- src/plugins/data/public/search/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/data/public/search/index.ts b/src/plugins/data/public/search/index.ts index 4289697f2684a..9d6e5072d657f 100644 --- a/src/plugins/data/public/search/index.ts +++ b/src/plugins/data/public/search/index.ts @@ -48,6 +48,7 @@ export { defaultSearchStrategy, SearchError, SearchStrategyProvider, + getSearchErrorType, } from './search_strategy'; export { From 14ef013b852fb241b8d433ea4b88f48c1c7de70a Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Tue, 28 Jan 2020 15:39:55 +0300 Subject: [PATCH 31/39] Remove extra wrapper - Router --- .../legacy/plugins/rollup/public/plugin.tsx | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.tsx index f123048bdb398..fd5f457a34dd0 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.tsx @@ -5,7 +5,6 @@ */ import { render, unmountComponentAtNode } from 'react-dom'; -import { HashRouter as Router } from 'react-router-dom'; import { Provider } from 'react-redux'; import React from 'react'; import { i18n } from '@kbn/i18n'; @@ -133,19 +132,17 @@ export class RollupPlugin implements Plugin { ]); render( - - - - - - - - - , + + + + + + + , params.element ); From 7000b9dbcebe2411b471137670a757413348de63 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Wed, 29 Jan 2020 10:25:14 +0300 Subject: [PATCH 32/39] Fix cause prop. --- .../rollup/public/crud_app/store/actions/create_job.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js index c6e72e3081769..c85b4c55f665e 100644 --- a/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js +++ b/x-pack/legacy/plugins/rollup/public/crud_app/store/actions/create_job.js @@ -40,12 +40,13 @@ export const createJob = jobConfig => async dispatch => { ]); } catch (error) { if (error) { - const { statusCode, body } = error; + const { body } = error; + const statusCode = error.statusCode || (body && body.statusCode); // Expect an error in the shape provided by http service. if (body) { // Some errors have statusCode directly available but some are under a data property. - if ((statusCode || (body && body.statusCode)) === 409) { + if (statusCode === 409) { return dispatch({ type: CREATE_JOB_FAILURE, payload: { @@ -68,9 +69,9 @@ export const createJob = jobConfig => async dispatch => { error: { message: i18n.translate('xpack.rollupJobs.createAction.failedDefaultErrorMessage', { defaultMessage: 'Request failed with a {statusCode} error. {message}', - values: { statusCode: body.statusCode, message: body.message }, + values: { statusCode, message: body.message }, }), - cause: body.error, + cause: body.cause, }, }, }); From 6a2f72ee09b6b3debd8dadce46c768281c4761ad Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Wed, 29 Jan 2020 11:14:04 +0300 Subject: [PATCH 33/39] Leave just static imports in legacy_imports.js --- x-pack/legacy/plugins/rollup/public/legacy.ts | 4 +++- x-pack/legacy/plugins/rollup/public/legacy_imports.ts | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/public/legacy.ts b/x-pack/legacy/plugins/rollup/public/legacy.ts index 326ef5ff8deb0..635bc5acecfe9 100644 --- a/x-pack/legacy/plugins/rollup/public/legacy.ts +++ b/x-pack/legacy/plugins/rollup/public/legacy.ts @@ -5,7 +5,9 @@ */ import { npSetup, npStart } from 'ui/new_platform'; -import { aggTypeFilters, aggTypeFieldFilters, editorConfigProviders } from './legacy_imports'; +import { editorConfigProviders } from 'ui/vis/editors/config/editor_config_providers'; +import { aggTypeFilters } from 'ui/agg_types/filter'; +import { aggTypeFieldFilters } from 'ui/agg_types/param_types/filter'; import { addSearchStrategy } from '../../../../../src/plugins/data/public'; import { RollupPlugin } from './plugin'; import { setup as management } from '../../../../../src/legacy/core_plugins/management/public/legacy'; diff --git a/x-pack/legacy/plugins/rollup/public/legacy_imports.ts b/x-pack/legacy/plugins/rollup/public/legacy_imports.ts index 4c3431621b79c..09319d5e4fd89 100644 --- a/x-pack/legacy/plugins/rollup/public/legacy_imports.ts +++ b/x-pack/legacy/plugins/rollup/public/legacy_imports.ts @@ -7,7 +7,6 @@ // @ts-ignore export { findIllegalCharactersInIndexName, INDEX_ILLEGAL_CHARACTERS_VISIBLE } from 'ui/indices'; -export { aggTypeFilters, AggTypeFilters } from 'ui/agg_types/filter'; -export { aggTypeFieldFilters, AggTypeFieldFilters } from 'ui/agg_types/param_types/filter'; -export { editorConfigProviders } from 'ui/vis/editors/config/editor_config_providers'; +export { AggTypeFilters } from 'ui/agg_types/filter'; +export { AggTypeFieldFilters } from 'ui/agg_types/param_types/filter'; export { EditorConfigProviderRegistry } from 'ui/vis/editors/config/editor_config_providers'; From aead81b1e8a39b1b81b5929aa5a770f6b35c324e Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Wed, 29 Jan 2020 12:29:35 +0300 Subject: [PATCH 34/39] Add TS --- .../helpers/setup_environment.ts | 13 ++++------ .../public/search/rollup_search_strategy.ts | 25 ++++++++++++------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts index b5248458d04f8..a8db058908ad4 100644 --- a/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts +++ b/x-pack/legacy/plugins/rollup/__jest__/client_integration/helpers/setup_environment.ts @@ -5,18 +5,15 @@ */ interface RequestMocks { - jobs: object; - createdJob: object; - indxPatternVldtResp: object; + jobs?: object; + createdJob?: object; + indxPatternVldtResp?: object; + [key: string]: any; } const mockHttpRequest = ( http: any, - { - jobs = {}, - createdJob = {}, - indxPatternVldtResp = {}, - }: RequestMocks | { [key: string]: any } = {} + { jobs = {}, createdJob = {}, indxPatternVldtResp = {} }: RequestMocks = {} ) => { http.get.mockImplementation(async (url: string) => { if (url === '/api/rollup/jobs') { diff --git a/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts b/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts index 4015682fc6891..5fd852af0e6e0 100644 --- a/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts +++ b/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts @@ -5,11 +5,18 @@ */ import { HttpSetup } from 'src/core/public'; -import { SearchError, getSearchErrorType } from '../../../../../../src/plugins/data/public'; +import { + SearchError, + getSearchErrorType, + IIndexPattern, + SearchStrategyProvider, + SearchResponse, + SearchRequest, +} from '../../../../../../src/plugins/data/public'; -function serializeFetchParams(searchRequests: any) { +function serializeFetchParams(searchRequests: SearchRequest[]) { return JSON.stringify( - searchRequests.map((searchRequestWithFetchParams: any) => { + searchRequests.map(searchRequestWithFetchParams => { const indexPattern = searchRequestWithFetchParams.index.title || searchRequestWithFetchParams.index; const { @@ -30,8 +37,8 @@ function serializeFetchParams(searchRequests: any) { // Rollup search always returns 0 hits, but visualizations expect search responses // to return hits > 0, otherwise they do not render. We fake the number of hits here // by counting the number of aggregation buckets/values returned by rollup search. -function shimHitsInFetchResponse(response: any) { - return response.map((result: any) => { +function shimHitsInFetchResponse(response: SearchResponse[]) { + return response.map(result => { const buckets = result.aggregations ? Object.keys(result.aggregations).reduce((allBuckets, agg) => { return allBuckets.concat( @@ -51,10 +58,10 @@ function shimHitsInFetchResponse(response: any) { }); } -export const getRollupSearchStrategy = (fetch: HttpSetup['fetch']) => ({ +export const getRollupSearchStrategy = (fetch: HttpSetup['fetch']): SearchStrategyProvider => ({ id: 'rollup', - search: ({ searchRequests }: any) => { + search: ({ searchRequests }) => { // Serialize the fetch params into a format suitable for the body of an ES query. const serializedFetchParams = serializeFetchParams(searchRequests); @@ -72,7 +79,7 @@ export const getRollupSearchStrategy = (fetch: HttpSetup['fetch']) => ({ res: { url }, } = error; - // Format kfetch error as a SearchError. + // Format fetch error as a SearchError. const searchError = new SearchError({ status: statusText, title, @@ -87,7 +94,7 @@ export const getRollupSearchStrategy = (fetch: HttpSetup['fetch']) => ({ }; }, - isViable: (indexPattern: any) => { + isViable: (indexPattern: IIndexPattern) => { if (!indexPattern) { return false; } From cc80ce0f40ae8b544bd4617fca6310a718242415 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Wed, 29 Jan 2020 12:47:39 +0300 Subject: [PATCH 35/39] Pass statusCode instead of statusText --- .../plugins/rollup/public/search/rollup_search_strategy.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts b/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts index 5fd852af0e6e0..4709c0aa498f8 100644 --- a/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts +++ b/x-pack/legacy/plugins/rollup/public/search/rollup_search_strategy.ts @@ -75,13 +75,13 @@ export const getRollupSearchStrategy = (fetch: HttpSetup['fetch']): SearchStrate return { searching: promise.then(shimHitsInFetchResponse).catch(error => { const { - body: { statusText, error: title, message }, + body: { statusCode, error: title, message }, res: { url }, } = error; // Format fetch error as a SearchError. const searchError = new SearchError({ - status: statusText, + status: statusCode, title, message: `Rollup search error: ${message}`, path: url, From 09518e3e7696ea109723c41c79bd1c99f5920d7e Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Wed, 29 Jan 2020 14:29:01 +0300 Subject: [PATCH 36/39] Move template in a separate file --- .../plugins/rollup/public/application.tsx | 46 ++++++++++++++ .../rollup/public/{plugin.tsx => plugin.ts} | 61 ++++++------------- 2 files changed, 64 insertions(+), 43 deletions(-) create mode 100644 x-pack/legacy/plugins/rollup/public/application.tsx rename x-pack/legacy/plugins/rollup/public/{plugin.tsx => plugin.ts} (76%) diff --git a/x-pack/legacy/plugins/rollup/public/application.tsx b/x-pack/legacy/plugins/rollup/public/application.tsx new file mode 100644 index 0000000000000..d35c9576072da --- /dev/null +++ b/x-pack/legacy/plugins/rollup/public/application.tsx @@ -0,0 +1,46 @@ +/* + * 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 React from 'react'; +import { render, unmountComponentAtNode } from 'react-dom'; +import { Provider } from 'react-redux'; +import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; +import { ChromeBreadcrumb, CoreStart } from '../../../../../src/core/public'; +// @ts-ignore +import { rollupJobsStore } from './crud_app/store'; +// @ts-ignore +import { App } from './crud_app/app'; + +/** + * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. + */ +export const renderApp = async ( + core: CoreStart, + { + element, + setBreadcrumbs, + }: { element: HTMLElement; setBreadcrumbs: (crumbs: ChromeBreadcrumb[]) => void } +) => { + const I18nContext = core.i18n.Context; + + render( + + + + + + + , + element + ); + return () => { + unmountComponentAtNode(element); + }; +}; diff --git a/x-pack/legacy/plugins/rollup/public/plugin.tsx b/x-pack/legacy/plugins/rollup/public/plugin.ts similarity index 76% rename from x-pack/legacy/plugins/rollup/public/plugin.tsx rename to x-pack/legacy/plugins/rollup/public/plugin.ts index fd5f457a34dd0..aedcfa1e49c24 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.tsx +++ b/x-pack/legacy/plugins/rollup/public/plugin.ts @@ -4,9 +4,6 @@ * you may not use this file except in compliance with the Elastic License. */ -import { render, unmountComponentAtNode } from 'react-dom'; -import { Provider } from 'react-redux'; -import React from 'react'; import { i18n } from '@kbn/i18n'; import { CoreSetup, CoreStart, Plugin } from 'kibana/public'; import { @@ -35,15 +32,11 @@ import { } from '../../../../../src/plugins/home/public'; // @ts-ignore import { CRUD_APP_BASE_PATH } from './crud_app/constants'; -// @ts-ignore -import { App } from './crud_app/app'; import { ManagementStart } from '../../../../../src/plugins/management/public'; // @ts-ignore -import { rollupJobsStore } from './crud_app/store'; -import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; -// @ts-ignore import { setEsBaseAndXPackBase, setHttp } from './crud_app/services'; import { setNotifications, setFatalErrors } from './kibana_services'; +import { renderApp } from './application'; export interface RollupPluginSetupDependencies { __LEGACY: { @@ -115,41 +108,23 @@ export class RollupPlugin implements Plugin { setEsBaseAndXPackBase(core.docLinks.ELASTIC_WEBSITE_URL, core.docLinks.DOC_LINK_VERSION); const esSection = management.sections.getSection('elasticsearch'); + if (esSection) { + esSection.registerApp({ + id: 'rollup_jobs', + title: i18n.translate('xpack.rollupJobs.appTitle', { defaultMessage: 'Rollup Jobs' }), + order: 3, + mount(params) { + params.setBreadcrumbs([ + { + text: i18n.translate('xpack.rollupJobs.breadcrumbsTitle', { + defaultMessage: 'Rollup Jobs', + }), + }, + ]); - const I18nContext = core.i18n.Context; - - esSection!.registerApp({ - id: 'rollup_jobs', - title: i18n.translate('xpack.rollupJobs.appTitle', { defaultMessage: 'Rollup Jobs' }), - order: 3, - mount(params) { - params.setBreadcrumbs([ - { - text: i18n.translate('xpack.rollupJobs.breadcrumbsTitle', { - defaultMessage: 'Rollup Jobs', - }), - }, - ]); - - render( - - - - - - - , - params.element - ); - - return () => { - unmountComponentAtNode(params.element); - }; - }, - }); + return renderApp(core, params); + }, + }); + } } } From 7d702a7a82568fc0333db74bcd9dcedce4883f5b Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Wed, 29 Jan 2020 18:30:05 +0300 Subject: [PATCH 37/39] Move app register to setup --- .../ui/public/new_platform/new_platform.ts | 3 ++- .../plugins/rollup/public/application.tsx | 7 ++--- x-pack/legacy/plugins/rollup/public/legacy.ts | 4 +-- x-pack/legacy/plugins/rollup/public/plugin.ts | 26 +++++++++---------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/legacy/ui/public/new_platform/new_platform.ts b/src/legacy/ui/public/new_platform/new_platform.ts index cb98e72591b03..2ade98ec54efd 100644 --- a/src/legacy/ui/public/new_platform/new_platform.ts +++ b/src/legacy/ui/public/new_platform/new_platform.ts @@ -32,7 +32,7 @@ import { DevToolsSetup, DevToolsStart } from '../../../../plugins/dev_tools/publ import { KibanaLegacySetup, KibanaLegacyStart } from '../../../../plugins/kibana_legacy/public'; import { HomePublicPluginSetup, HomePublicPluginStart } from '../../../../plugins/home/public'; import { SharePluginSetup, SharePluginStart } from '../../../../plugins/share/public'; -import { ManagementStart } from '../../../../plugins/management/public'; +import { ManagementSetup, ManagementStart } from '../../../../plugins/management/public'; import { BfetchPublicSetup, BfetchPublicStart } from '../../../../plugins/bfetch/public'; import { UsageCollectionSetup } from '../../../../plugins/usage_collection/public'; import { @@ -54,6 +54,7 @@ export interface PluginsSetup { kibana_legacy: KibanaLegacySetup; share: SharePluginSetup; usageCollection: UsageCollectionSetup; + management: ManagementSetup; } export interface PluginsStart { diff --git a/x-pack/legacy/plugins/rollup/public/application.tsx b/x-pack/legacy/plugins/rollup/public/application.tsx index d35c9576072da..df17d37bc3465 100644 --- a/x-pack/legacy/plugins/rollup/public/application.tsx +++ b/x-pack/legacy/plugins/rollup/public/application.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { Provider } from 'react-redux'; import { KibanaContextProvider } from '../../../../../src/plugins/kibana_react/public'; -import { ChromeBreadcrumb, CoreStart } from '../../../../../src/core/public'; +import { ChromeBreadcrumb, CoreSetup } from '../../../../../src/core/public'; // @ts-ignore import { rollupJobsStore } from './crud_app/store'; // @ts-ignore @@ -18,13 +18,14 @@ import { App } from './crud_app/app'; * This module will be loaded asynchronously to reduce the bundle size of your plugin's main bundle. */ export const renderApp = async ( - core: CoreStart, + core: CoreSetup, { element, setBreadcrumbs, }: { element: HTMLElement; setBreadcrumbs: (crumbs: ChromeBreadcrumb[]) => void } ) => { - const I18nContext = core.i18n.Context; + const [coreStart] = await core.getStartServices(); + const I18nContext = coreStart.i18n.Context; render( diff --git a/x-pack/legacy/plugins/rollup/public/legacy.ts b/x-pack/legacy/plugins/rollup/public/legacy.ts index 635bc5acecfe9..625f95c478d22 100644 --- a/x-pack/legacy/plugins/rollup/public/legacy.ts +++ b/x-pack/legacy/plugins/rollup/public/legacy.ts @@ -24,7 +24,7 @@ export const setup = plugin.setup(npSetup.core, { addSearchStrategy, addBadgeExtension, addToggleExtension, - management, + managementLegacy: management, }, }); -export const start = plugin.start(npStart.core, npStart.plugins); +export const start = plugin.start(npStart.core); diff --git a/x-pack/legacy/plugins/rollup/public/plugin.ts b/x-pack/legacy/plugins/rollup/public/plugin.ts index aedcfa1e49c24..97c03fd1fdfc2 100644 --- a/x-pack/legacy/plugins/rollup/public/plugin.ts +++ b/x-pack/legacy/plugins/rollup/public/plugin.ts @@ -12,7 +12,7 @@ import { AggTypeFieldFilters, } from './legacy_imports'; import { SearchStrategyProvider } from '../../../../../src/plugins/data/public'; -import { ManagementSetup } from '../../../../../src/legacy/core_plugins/management/public/np_ready'; +import { ManagementSetup as ManagementSetupLegacy } from '../../../../../src/legacy/core_plugins/management/public/np_ready'; import { rollupBadgeExtension, rollupToggleExtension } from './extend_index_management'; // @ts-ignore import { RollupIndexPatternCreationConfig } from './index_pattern_creation/rollup_index_pattern_creation_config'; @@ -32,7 +32,7 @@ import { } from '../../../../../src/plugins/home/public'; // @ts-ignore import { CRUD_APP_BASE_PATH } from './crud_app/constants'; -import { ManagementStart } from '../../../../../src/plugins/management/public'; +import { ManagementSetup } from '../../../../../src/plugins/management/public'; // @ts-ignore import { setEsBaseAndXPackBase, setHttp } from './crud_app/services'; import { setNotifications, setFatalErrors } from './kibana_services'; @@ -44,15 +44,12 @@ export interface RollupPluginSetupDependencies { aggTypeFieldFilters: AggTypeFieldFilters; editorConfigProviders: EditorConfigProviderRegistry; addSearchStrategy: (searchStrategy: SearchStrategyProvider) => void; - management: ManagementSetup; + managementLegacy: ManagementSetupLegacy; addBadgeExtension: (badgeExtension: any) => void; addToggleExtension: (toggleExtension: any) => void; }; home?: HomePublicPluginSetup; -} - -export interface RollupPluginStartDependencies { - management: ManagementStart; + management: ManagementSetup; } export class RollupPlugin implements Plugin { @@ -64,11 +61,12 @@ export class RollupPlugin implements Plugin { aggTypeFieldFilters, editorConfigProviders, addSearchStrategy, - management: managementLegacy, + managementLegacy, addBadgeExtension, addToggleExtension, }, home, + management, }: RollupPluginSetupDependencies ) { setFatalErrors(core.fatalErrors); @@ -100,12 +98,6 @@ export class RollupPlugin implements Plugin { category: FeatureCatalogueCategory.ADMIN, }); } - } - - start(core: CoreStart, { management }: RollupPluginStartDependencies) { - setHttp(core.http); - setNotifications(core.notifications); - setEsBaseAndXPackBase(core.docLinks.ELASTIC_WEBSITE_URL, core.docLinks.DOC_LINK_VERSION); const esSection = management.sections.getSection('elasticsearch'); if (esSection) { @@ -127,4 +119,10 @@ export class RollupPlugin implements Plugin { }); } } + + start(core: CoreStart) { + setHttp(core.http); + setNotifications(core.notifications); + setEsBaseAndXPackBase(core.docLinks.ELASTIC_WEBSITE_URL, core.docLinks.DOC_LINK_VERSION); + } } From 69675c0a61d065b9821b75ecf89fde51594dbe58 Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Wed, 29 Jan 2020 19:10:48 +0300 Subject: [PATCH 38/39] Add karma mock for management setup --- .../ui/public/new_platform/new_platform.karma_mock.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js index 0030084039fe8..f98b8801d5266 100644 --- a/src/legacy/ui/public/new_platform/new_platform.karma_mock.js +++ b/src/legacy/ui/public/new_platform/new_platform.karma_mock.js @@ -147,6 +147,13 @@ export const npSetup = { useChartsTheme: sinon.fake(), }, }, + management: { + sections: { + getSection: () => ({ + registerApp: sinon.fake(), + }), + }, + }, }, }; From 763e01df459eb25effd6bafc9f7221e2c61b18ee Mon Sep 17 00:00:00 2001 From: maryia-lapata Date: Thu, 30 Jan 2020 09:15:16 +0300 Subject: [PATCH 39/39] Add EditorConfigProviderRegistry export --- src/legacy/ui/public/vis/config/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/legacy/ui/public/vis/config/index.ts b/src/legacy/ui/public/vis/config/index.ts index 5e87ac17b98fb..ee7385518a85d 100644 --- a/src/legacy/ui/public/vis/config/index.ts +++ b/src/legacy/ui/public/vis/config/index.ts @@ -17,5 +17,5 @@ * under the License. */ -export { editorConfigProviders } from './editor_config_providers'; +export { editorConfigProviders, EditorConfigProviderRegistry } from './editor_config_providers'; export * from './types';