diff --git a/x-pack/legacy/plugins/canvas/public/components/router/index.js b/x-pack/legacy/plugins/canvas/public/components/router/index.js deleted file mode 100644 index 430d6a5343662..0000000000000 --- a/x-pack/legacy/plugins/canvas/public/components/router/index.js +++ /dev/null @@ -1,23 +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 { connect } from 'react-redux'; -import { setFullscreen } from '../../state/actions/transient'; -import { - enableAutoplay, - setRefreshInterval, - setAutoplayInterval, -} from '../../state/actions/workpad'; -import { Router as Component } from './router'; - -const mapDispatchToState = { - enableAutoplay, - setAutoplayInterval, - setFullscreen, - setRefreshInterval, -}; - -export const Router = connect(null, mapDispatchToState)(Component); diff --git a/x-pack/legacy/plugins/canvas/public/components/router/index.ts b/x-pack/legacy/plugins/canvas/public/components/router/index.ts new file mode 100644 index 0000000000000..5e014870f5158 --- /dev/null +++ b/x-pack/legacy/plugins/canvas/public/components/router/index.ts @@ -0,0 +1,63 @@ +/* + * 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 { connect } from 'react-redux'; +// @ts-ignore untyped local +import { setFullscreen } from '../../state/actions/transient'; +import { + enableAutoplay, + setRefreshInterval, + setAutoplayInterval, + // @ts-ignore untyped local +} from '../../state/actions/workpad'; +// @ts-ignore untyped local +import { Router as Component } from './router'; +import { State } from '../../../types'; + +const mapDispatchToProps = { + enableAutoplay, + setAutoplayInterval, + setFullscreen, + setRefreshInterval, +}; + +const mapStateToProps = (state: State) => ({ + refreshInterval: state.transient.refresh.interval, + autoplayInterval: state.transient.autoplay.interval, + autoplay: state.transient.autoplay.enabled, + fullscreen: state.transient.fullScreen, +}); + +export const Router = connect( + mapStateToProps, + mapDispatchToProps, + (stateProps, dispatchProps, ownProps) => { + return { + ...ownProps, + ...dispatchProps, + setRefreshInterval: (interval: number) => { + if (interval !== stateProps.refreshInterval) { + dispatchProps.setRefreshInterval(interval); + } + }, + setAutoplayInterval: (interval: number) => { + if (interval !== stateProps.autoplayInterval) { + dispatchProps.setRefreshInterval(interval); + } + }, + enableAutoplay: (autoplay: boolean) => { + if (autoplay !== stateProps.autoplay) { + dispatchProps.enableAutoplay(autoplay); + } + }, + setFullscreen: (fullscreen: boolean) => { + if (fullscreen !== stateProps.fullscreen) { + dispatchProps.setFullscreen(fullscreen); + } + }, + }; + } +)(Component); diff --git a/x-pack/legacy/plugins/canvas/public/components/workpad_header/workpad_export/index.ts b/x-pack/legacy/plugins/canvas/public/components/workpad_header/workpad_export/index.ts index 39611dd6c2994..7f81adad6bf9b 100644 --- a/x-pack/legacy/plugins/canvas/public/components/workpad_header/workpad_export/index.ts +++ b/x-pack/legacy/plugins/canvas/public/components/workpad_header/workpad_export/index.ts @@ -6,7 +6,7 @@ import { connect } from 'react-redux'; import { compose, withProps } from 'recompose'; -import { jobCompletionNotifications } from '../../../../../reporting/public/lib/job_completion_notifications'; +import * as jobCompletionNotifications from '../../../../../reporting/public/lib/job_completion_notifications'; // @ts-ignore Untyped local import { getWorkpad, getPages } from '../../../state/selectors/workpad'; // @ts-ignore Untyped local diff --git a/x-pack/legacy/plugins/canvas/public/legacy_start.ts b/x-pack/legacy/plugins/canvas/public/legacy_start.ts index 972427e166afc..21bf5aaa6d818 100644 --- a/x-pack/legacy/plugins/canvas/public/legacy_start.ts +++ b/x-pack/legacy/plugins/canvas/public/legacy_start.ts @@ -16,6 +16,12 @@ import 'uiExports/spyModes'; import 'uiExports/embeddableFactories'; import 'uiExports/interpreter'; +// TODO: These dependencies should be moved into plugin startup methods +// Load the interpreter so that the kbnInterpreter global will be available when plugins load +import 'plugins/interpreter/interpreter'; +// Load our app component to initialize registries +import './components/app'; + // load application code import 'uiExports/canvas'; diff --git a/x-pack/legacy/plugins/canvas/public/lib/app_state.ts b/x-pack/legacy/plugins/canvas/public/lib/app_state.ts index 955125b713140..c93e505c595fd 100644 --- a/x-pack/legacy/plugins/canvas/public/lib/app_state.ts +++ b/x-pack/legacy/plugins/canvas/public/lib/app_state.ts @@ -13,7 +13,7 @@ import { getWindow } from './get_window'; import { historyProvider } from './history_provider'; // @ts-ignore untyped local import { routerProvider } from './router_provider'; -import { createTimeInterval, isValidTimeInterval } from './time_interval'; +import { createTimeInterval, isValidTimeInterval, getTimeInterval } from './time_interval'; import { AppState, AppStateKeys } from '../../types'; export function getDefaultAppState(): AppState { @@ -112,7 +112,12 @@ export function setRefreshInterval(payload: string) { const appValue = appState[AppStateKeys.REFRESH_INTERVAL]; if (payload !== appValue) { - appState[AppStateKeys.REFRESH_INTERVAL] = payload; - routerProvider().updateAppState(appState); + if (getTimeInterval(payload)) { + appState[AppStateKeys.REFRESH_INTERVAL] = payload; + routerProvider().updateAppState(appState); + } else { + delete appState[AppStateKeys.REFRESH_INTERVAL]; + routerProvider().updateAppState(appState); + } } } diff --git a/x-pack/legacy/plugins/canvas/server/plugin.ts b/x-pack/legacy/plugins/canvas/server/plugin.ts index ac3edbabce930..1f17e85bfd294 100644 --- a/x-pack/legacy/plugins/canvas/server/plugin.ts +++ b/x-pack/legacy/plugins/canvas/server/plugin.ts @@ -5,14 +5,11 @@ */ import { CoreSetup, PluginsSetup } from './shim'; -import { routes } from './routes'; import { functions } from '../canvas_plugin_src/functions/server'; import { loadSampleData } from './sample_data'; export class Plugin { public setup(core: CoreSetup, plugins: PluginsSetup) { - routes(core); - plugins.interpreter.register({ serverFunctions: functions }); core.injectUiAppVars('canvas', async () => { diff --git a/x-pack/legacy/plugins/canvas/server/routes/index.ts b/x-pack/legacy/plugins/canvas/server/routes/index.ts deleted file mode 100644 index 6898a3c459e3d..0000000000000 --- a/x-pack/legacy/plugins/canvas/server/routes/index.ts +++ /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 { shareableWorkpads } from './shareables'; -import { CoreSetup } from '../shim'; - -export function routes(setup: CoreSetup): void { - shareableWorkpads(setup.http.route); -} diff --git a/x-pack/legacy/plugins/canvas/server/routes/shareables.ts b/x-pack/legacy/plugins/canvas/server/routes/shareables.ts deleted file mode 100644 index e8186ceceb47f..0000000000000 --- a/x-pack/legacy/plugins/canvas/server/routes/shareables.ts +++ /dev/null @@ -1,72 +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 archiver from 'archiver'; - -import { - API_ROUTE_SHAREABLE_RUNTIME, - API_ROUTE_SHAREABLE_RUNTIME_DOWNLOAD, - API_ROUTE_SHAREABLE_ZIP, -} from '../../common/lib/constants'; - -import { - SHAREABLE_RUNTIME_FILE, - SHAREABLE_RUNTIME_NAME, - SHAREABLE_RUNTIME_SRC, -} from '../../shareable_runtime/constants'; - -import { CoreSetup } from '../shim'; - -export function shareableWorkpads(route: CoreSetup['http']['route']) { - // get runtime - route({ - method: 'GET', - path: API_ROUTE_SHAREABLE_RUNTIME, - - handler: { - file: { - path: SHAREABLE_RUNTIME_FILE, - // The option setting is not for typical use. We're using it here to avoid - // problems in Cloud environments. See elastic/kibana#47405. - confine: false, - }, - }, - }); - - // download runtime - route({ - method: 'GET', - path: API_ROUTE_SHAREABLE_RUNTIME_DOWNLOAD, - - handler(_request, handler) { - // The option setting is not for typical use. We're using it here to avoid - // problems in Cloud environments. See elastic/kibana#47405. - // @ts-ignore No type for inert Hapi handler - const file = handler.file(SHAREABLE_RUNTIME_FILE, { confine: false }); - file.type('application/octet-stream'); - return file; - }, - }); - - route({ - method: 'POST', - path: API_ROUTE_SHAREABLE_ZIP, - handler(request, handler) { - const workpad = request.payload; - - const archive = archiver('zip'); - archive.append(JSON.stringify(workpad), { name: 'workpad.json' }); - archive.file(`${SHAREABLE_RUNTIME_SRC}/template.html`, { name: 'index.html' }); - archive.file(SHAREABLE_RUNTIME_FILE, { name: `${SHAREABLE_RUNTIME_NAME}.js` }); - - const response = handler.response(archive); - response.header('content-type', 'application/zip'); - archive.finalize(); - - return response; - }, - }); -} diff --git a/x-pack/legacy/plugins/console_extensions/index.js b/x-pack/legacy/plugins/console_extensions/index.js deleted file mode 100644 index fd1b48f0fd6b1..0000000000000 --- a/x-pack/legacy/plugins/console_extensions/index.js +++ /dev/null @@ -1,47 +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 { join } from 'path'; -import { processors } from './spec/ingest'; - -export function consoleExtensions(kibana) { - return new kibana.Plugin({ - id: 'console_extensions', - require: ['kibana', 'console'], - isEnabled(config) { - return ( - config.get('console_extensions.enabled') && - config.has('console.enabled') && - config.get('console.enabled') - ); - }, - - config(Joi) { - return Joi.object({ - enabled: Joi.boolean().default(true), - }).default(); - }, - - init: server => { - if ( - server.plugins.console && - server.plugins.console.addExtensionSpecFilePath && - server.plugins.console.addProcessorDefinition - ) { - const { addExtensionSpecFilePath, addProcessorDefinition } = server.plugins.console; - - addExtensionSpecFilePath(join(__dirname, 'spec/')); - - processors.forEach(processor => addProcessorDefinition(processor)); - } else { - console.warn( - 'Missing server.plugins.console.addExtensionSpecFilePath extension point.', - 'Cannot add xpack APIs to autocomplete.' - ); - } - }, - }); -} diff --git a/x-pack/legacy/plugins/encrypted_saved_objects/index.ts b/x-pack/legacy/plugins/encrypted_saved_objects/index.ts index 85aa5c22135b6..69058a7a33f59 100644 --- a/x-pack/legacy/plugins/encrypted_saved_objects/index.ts +++ b/x-pack/legacy/plugins/encrypted_saved_objects/index.ts @@ -21,7 +21,9 @@ export const encryptedSavedObjects = (kibana: { // Some legacy plugins still use `enabled` config key, so we keep it here, but the rest of the // keys is handled by the New Platform plugin. config: (Joi: Root) => - Joi.object({ enabled: Joi.boolean().default(true) }) + Joi.object({ + enabled: Joi.boolean().default(true), + }) .unknown(true) .default(), diff --git a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.ts b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.ts index b8b67a0f36bd2..dcee956130a29 100644 --- a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.ts +++ b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/helpers/mappings_editor.helpers.ts @@ -13,4 +13,4 @@ export const setup = (props: any) => wrapComponent: false, }, defaultProps: props, - }); + })(); diff --git a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx index 9e390e785c7d5..723c105d403b8 100644 --- a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx +++ b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/__jest__/client_integration/mappings_editor.test.tsx @@ -28,7 +28,7 @@ describe('', () => { }, }, }; - const testBed = await setup({ onUpdate: mockOnUpdate, defaultValue })(); + const testBed = await setup({ onUpdate: mockOnUpdate, defaultValue }); const { exists } = testBed; expect(exists('mappingsEditor')).toBe(true); @@ -44,7 +44,7 @@ describe('', () => { }, }, }; - const testBed = await setup({ onUpdate: mockOnUpdate, defaultValue })(); + const testBed = await setup({ onUpdate: mockOnUpdate, defaultValue }); const { exists } = testBed; expect(exists('mappingsEditor')).toBe(true); diff --git a/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/components/load_mappings/load_mappings_provider.test.tsx b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/components/load_mappings/load_mappings_provider.test.tsx new file mode 100644 index 0000000000000..a9433d3a7530f --- /dev/null +++ b/x-pack/legacy/plugins/index_management/public/app/components/mappings_editor/components/load_mappings/load_mappings_provider.test.tsx @@ -0,0 +1,77 @@ +/* + * 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 { act } from 'react-dom/test-utils'; + +jest.mock('@elastic/eui', () => ({ + ...jest.requireActual('@elastic/eui'), + // Mocking EuiCodeEditor, which uses React Ace under the hood + EuiCodeEditor: (props: any) => ( + { + props.onChange(syntheticEvent.jsonString); + }} + /> + ), +})); + +import { registerTestBed, nextTick, TestBed } from '../../../../../../../../../test_utils'; +import { LoadMappingsProvider } from './load_mappings_provider'; + +const ComponentToTest = ({ onJson }: { onJson: () => void }) => ( + + {openModal => ( +