Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into lens/pie
Browse files Browse the repository at this point in the history
  • Loading branch information
wylieconlon committed May 5, 2020
2 parents 2247a44 + fc6c78f commit acf291e
Show file tree
Hide file tree
Showing 101 changed files with 1,434 additions and 579 deletions.
2 changes: 0 additions & 2 deletions x-pack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { dashboardMode } from './legacy/plugins/dashboard_mode';
import { beats } from './legacy/plugins/beats_management';
import { maps } from './legacy/plugins/maps';
import { spaces } from './legacy/plugins/spaces';
import { canvas } from './legacy/plugins/canvas';
import { infra } from './legacy/plugins/infra';
import { taskManager } from './legacy/plugins/task_manager';
import { encryptedSavedObjects } from './legacy/plugins/encrypted_saved_objects';
Expand All @@ -28,7 +27,6 @@ module.exports = function(kibana) {
dashboardMode(kibana),
beats(kibana),
maps(kibana),
canvas(kibana),
infra(kibana),
taskManager(kibana),
encryptedSavedObjects(kibana),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
ExpressionFunctionDefinition,
ExpressionValueFilter,
} from 'src/plugins/expressions/common';
/* eslint-disable */
// @ts-ignore untyped local
import { buildESRequest } from '../../../server/lib/build_es_request';
import { buildESRequest } from '../../../../../../plugins/canvas/server/lib/build_es_request';
/* eslint-enable */
import { getFunctionHelp } from '../../../i18n';

interface Arguments {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

import squel from 'squel';
import { ExpressionFunctionDefinition } from 'src/plugins/expressions';
/* eslint-disable */
// @ts-ignore untyped local
import { queryEsSQL } from '../../../server/lib/query_es_sql';
import { queryEsSQL } from '../../../../../../plugins/canvas/server/lib/query_es_sql';
/* eslint-enable */
import { ExpressionValueFilter } from '../../../types';
import { getFunctionHelp } from '../../../i18n';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
*/

import { ExpressionFunctionDefinition } from 'src/plugins/expressions/common';
/* eslint-disable */
// @ts-ignore untyped local
import { queryEsSQL } from '../../../server/lib/query_es_sql';
import { queryEsSQL } from '../../../../../../plugins/canvas/server/lib/query_es_sql';
/* eslint-enable */
import { ExpressionValueFilter } from '../../../types';
import { getFunctionHelp } from '../../../i18n';

Expand Down
3 changes: 1 addition & 2 deletions x-pack/legacy/plugins/canvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import { resolve } from 'path';
import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/utils';
import { init } from './init';
import { CANVAS_APP, CANVAS_TYPE, CUSTOM_ELEMENT_TYPE } from './common/lib';

export function canvas(kibana) {
Expand Down Expand Up @@ -64,6 +63,6 @@ export function canvas(kibana) {
}).default();
},

init,
init: () => undefined,
});
}
16 changes: 0 additions & 16 deletions x-pack/legacy/plugins/canvas/init.ts

This file was deleted.

18 changes: 16 additions & 2 deletions x-pack/legacy/plugins/canvas/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { initRegistries, populateRegistries, destroyRegistries } from './registr
import { getDocumentationLinks } from './lib/documentation_links';
// @ts-ignore untyped component
import { HelpMenu } from './components/help_menu/help_menu';
import { createStore } from './store';
import { createStore, destroyStore } from './store';

import { VALUE_CLICK_TRIGGER, ActionByType } from '../../../../../src/plugins/ui_actions/public';
/* eslint-disable */
Expand All @@ -35,6 +35,12 @@ import { init as initStatsReporter } from './lib/ui_metric';
import { CapabilitiesStrings } from '../i18n';

import { startServices, stopServices, services } from './services';
// @ts-ignore Untyped local
import { destroyHistory } from './lib/history_provider';
// @ts-ignore Untyped local
import { stopRouter } from './lib/router_provider';

import './style/index.scss';

const { ReadOnlyBadge: strings } = CapabilitiesStrings;

Expand All @@ -54,6 +60,8 @@ export const renderApp = (
{ element }: AppMountParameters,
canvasStore: Store
) => {
element.classList.add('canvas');
element.classList.add('canvasContainerWrapper');
const canvasServices = Object.entries(services).reduce((reduction, [key, provider]) => {
reduction[key] = provider.getService();

Expand All @@ -70,7 +78,9 @@ export const renderApp = (
</KibanaContextProvider>,
element
);
return () => ReactDOM.unmountComponentAtNode(element);
return () => {
ReactDOM.unmountComponentAtNode(element);
};
};

export const initializeCanvas = async (
Expand Down Expand Up @@ -144,6 +154,7 @@ export const teardownCanvas = (coreStart: CoreStart, startPlugins: CanvasStartDe
stopServices();
destroyRegistries();
resetInterpreter();
destroyStore();

startPlugins.uiActions.detachAction(VALUE_CLICK_TRIGGER, emptyAction.id);
if (restoreAction) {
Expand All @@ -153,4 +164,7 @@ export const teardownCanvas = (coreStart: CoreStart, startPlugins: CanvasStartDe

coreStart.chrome.setBadge(undefined);
coreStart.chrome.setHelpExtension(undefined);

destroyHistory();
stopRouter();
};
3 changes: 1 addition & 2 deletions x-pack/legacy/plugins/canvas/public/components/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { getAppReady, getBasePath } from '../../state/selectors/app';
import { appReady, appError } from '../../state/actions/app';

import { App as Component } from './app';
import { trackRouteChange } from './track_route_change';

const mapStateToProps = state => {
// appReady could be an error object
Expand Down Expand Up @@ -46,6 +45,6 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
export const App = compose(
connect(mapStateToProps, mapDispatchToProps, mergeProps),
withProps(() => ({
onRouteChange: trackRouteChange,
onRouteChange: () => undefined,
}))
)(Component);
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/canvas/public/functions/timelion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { TimeRange } from 'src/plugins/data/common';
import { ExpressionFunctionDefinition, DatatableRow } from 'src/plugins/expressions/public';
import { fetch } from '../../common/lib/fetch';
// @ts-ignore untyped local
import { buildBoolArray } from '../../server/lib/build_bool_array';
import { buildBoolArray } from '../../public/lib/build_bool_array';
import { Datatable, ExpressionValueFilter } from '../../types';
import { getFunctionHelp } from '../../i18n';
import { InitializeArguments } from './';
Expand Down
7 changes: 0 additions & 7 deletions x-pack/legacy/plugins/canvas/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { CanvasStartDeps, CanvasSetupDeps } from './plugin'; // eslint-disable-l

// @ts-ignore Untyped Kibana Lib
import chrome, { loadingCount } from 'ui/chrome'; // eslint-disable-line import/order
import { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url'; // eslint-disable-line import/order
// @ts-ignore Untyped Kibana Lib
import { formatMsg } from '../../../../../src/plugins/kibana_legacy/public'; // eslint-disable-line import/order

Expand All @@ -32,12 +31,6 @@ const shimStartPlugins: CanvasStartDeps = {
expressions: npStart.plugins.expressions,
inspector: npStart.plugins.inspector,
uiActions: npStart.plugins.uiActions,
__LEGACY: {
// ToDo: Copy directly into canvas
absoluteToParsedUrl,
// ToDo: Won't be a part of New Platform. Will need to handle internally
trackSubUrlForApp: chrome.trackSubUrlForApp,
},
};

// These methods are intended to be a replacement for import from 'ui/whatever'
Expand Down
8 changes: 6 additions & 2 deletions x-pack/legacy/plugins/canvas/public/lib/history_provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import lzString from 'lz-string';
import { createMemoryHistory, parsePath, createPath } from 'history';
import createHashStateHistory from 'history-extra';
import createHashStateHistory from 'history-extra/dist/createHashStateHistory';
import { getWindow } from './get_window';

function wrapHistoryInstance(history) {
Expand Down Expand Up @@ -134,7 +134,7 @@ function wrapHistoryInstance(history) {
return wrappedHistory;
}

const instances = new WeakMap();
let instances = new WeakMap();

const getHistoryInstance = win => {
// if no window object, use memory module
Expand All @@ -158,3 +158,7 @@ export const historyProvider = (win = getWindow()) => {

return wrappedInstance;
};

export const destroyHistory = () => {
instances = new WeakMap();
};
12 changes: 12 additions & 0 deletions x-pack/legacy/plugins/canvas/public/lib/router_provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,19 @@ export function routerProvider(routes) {

return unlisten; // return function to remove change handler
},
stop: () => {
for (const listener of componentListeners) {
listener();
}
},
};

return router;
}

export const stopRouter = () => {
if (router) {
router.stop();
router = undefined;
}
};
37 changes: 13 additions & 24 deletions x-pack/legacy/plugins/canvas/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { Chrome } from 'ui/chrome';
import { CoreSetup, CoreStart, Plugin } from '../../../../../src/core/public';
import {
CoreSetup,
CoreStart,
Plugin,
AppMountParameters,
DEFAULT_APP_CATEGORIES,
} from '../../../../../src/core/public';
import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public';
import { initLoadingIndicator } from './lib/loading_indicator';
import { featureCatalogueEntry } from './feature_catalogue_entry';
Expand Down Expand Up @@ -40,12 +45,7 @@ export interface CanvasStartDeps {
embeddable: EmbeddableStart;
expressions: ExpressionsStart;
inspector: InspectorStart;

uiActions: UiActionsStart;
__LEGACY: {
absoluteToParsedUrl: (url: string, basePath: string) => any;
trackSubUrlForApp: Chrome['trackSubUrlForApp'];
};
}

/**
Expand All @@ -63,36 +63,26 @@ export class CanvasPlugin
implements Plugin<CanvasSetup, CanvasStart, CanvasSetupDeps, CanvasStartDeps> {
// TODO: Do we want to completely move canvas_plugin_src into it's own plugin?
private srcPlugin = new CanvasSrcPlugin();
private startPlugins: CanvasStartDeps | undefined;

public setup(core: CoreSetup<CanvasStartDeps>, plugins: CanvasSetupDeps) {
const { api: canvasApi, registries } = getPluginApi(plugins.expressions);

this.srcPlugin.setup(core, { canvas: canvasApi });

core.application.register({
category: DEFAULT_APP_CATEGORIES.analyze,
id: 'canvas',
title: 'Canvas App',
mount: async (context, params) => {
title: 'Canvas',
euiIconType: 'canvasApp',
order: 0, // need to figure out if this is the proper order for us
mount: async (params: AppMountParameters) => {
// Load application bundle
const { renderApp, initializeCanvas, teardownCanvas } = await import('./application');

// Get start services
const [coreStart, depsStart] = await core.getStartServices();

// TODO: We only need this to get the __LEGACY stuff that isn't coming from getStartSevices.
// We won't need this as soon as we move over to NP Completely
if (!this.startPlugins) {
throw new Error('Start Plugins not ready at mount time');
}

const canvasStore = await initializeCanvas(
core,
coreStart,
plugins,
this.startPlugins,
registries
);
const canvasStore = await initializeCanvas(core, coreStart, plugins, depsStart, registries);

const unmount = renderApp(coreStart, depsStart, params, canvasStore);

Expand Down Expand Up @@ -127,7 +117,6 @@ export class CanvasPlugin
}

public start(core: CoreStart, plugins: CanvasStartDeps) {
this.startPlugins = plugins;
this.srcPlugin.start(core, plugins);
initLoadingIndicator(core.http.addLoadingCountSource);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { createAction } from 'redux-actions';
import { createThunk } from 'redux-thunks';
import { createThunk } from 'redux-thunks/cjs';
import immutable from 'object-path-immutable';
import { get, pick, cloneDeep, without } from 'lodash';
import { toExpression, safeElementFromExpression } from '@kbn/interpreter/common';
Expand Down Expand Up @@ -116,7 +116,6 @@ export const fetchContext = createThunk(

const fetchRenderableWithContextFn = ({ dispatch }, element, ast, context) => {
const argumentPath = [element.id, 'expressionRenderable'];

dispatch(
args.setLoading({
path: argumentPath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { createAction } from 'redux-actions';
import { createThunk } from 'redux-thunks';
import { createThunk } from 'redux-thunks/cjs';
import { without, includes } from 'lodash';
import { getWorkpadColors } from '../selectors/workpad';
import { fetchAllRenderables } from './elements';
Expand Down
9 changes: 9 additions & 0 deletions x-pack/legacy/plugins/canvas/public/state/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,18 @@ export function createStore(initialState) {

const rootReducer = getRootReducer(initialState);
store = createReduxStore(rootReducer, initialState, middleware);

return store;
}

export function destroyStore() {
if (store) {
// Replace reducer so that anything that gets fired after navigating away doesn't really do anything
store.replaceReducer(state => state);
}
store = undefined;
}

export function getState() {
return store.getState();
}
6 changes: 5 additions & 1 deletion x-pack/legacy/plugins/canvas/public/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

// @ts-ignore Untyped local
import { createStore as createReduxStore } from './state/store';
import { createStore as createReduxStore, destroyStore as destroy } from './state/store';
// @ts-ignore Untyped local
import { getInitialState } from './state/initial_state';

Expand All @@ -29,3 +29,7 @@ export async function createStore(core: CoreSetup, plugins: CanvasSetupDeps) {

return createReduxStore(initialState);
}

export function destroyStore() {
destroy();
}
6 changes: 6 additions & 0 deletions x-pack/legacy/plugins/canvas/public/style/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
*/
$canvasElementCardWidth: 210px;


.canvas.canvasContainerWrapper {
display: flex;
flex-grow: 1;
}

.canvas.canvasContainer {
display: flex;
flex-grow: 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import './fade.css';
import './fade.scss';

import { TransitionStrings } from '../../../i18n';

Expand Down
Loading

0 comments on commit acf291e

Please sign in to comment.