Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into use-np-registry-f…
Browse files Browse the repository at this point in the history
…ield-formats
  • Loading branch information
Avinar-24 committed Nov 20, 2019
2 parents dca6f91 + ff2a3ab commit f7ae0bf
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 98 deletions.
2 changes: 2 additions & 0 deletions src/legacy/plugin_discovery/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export interface LegacyPluginOptions {
}>;
apps: any;
hacks: string[];
visualize: string[];
devTools: string[];
styleSheetPaths: string;
injectDefaultVars: (server: Server) => Record<string, any>;
noParse: string[];
Expand Down
8 changes: 6 additions & 2 deletions x-pack/legacy/plugins/lens/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

export const PLUGIN_ID = 'lens';

export const BASE_APP_URL = '/app/lens';
export const BASE_APP_URL = '/app/kibana';
export const BASE_API_URL = '/api/lens';

export function getBasePath() {
return `${BASE_APP_URL}#/lens`;
}

export function getEditPath(id: string) {
return `${BASE_APP_URL}#/edit/${encodeURIComponent(id)}`;
return `${BASE_APP_URL}#/lens/edit/${encodeURIComponent(id)}`;
}
7 changes: 4 additions & 3 deletions x-pack/legacy/plugins/lens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import mappings from './mappings.json';
import { PLUGIN_ID, getEditPath } from './common';
import { lensServerPlugin } from './server';

const NOT_INTERNATIONALIZED_PRODUCT_NAME = 'Lens Visualizations';
export const NOT_INTERNATIONALIZED_PRODUCT_NAME = 'Lens Visualizations';

export const lens: LegacyPluginInitializer = kibana => {
return new kibana.Plugin({
Expand All @@ -26,10 +26,11 @@ export const lens: LegacyPluginInitializer = kibana => {
app: {
title: NOT_INTERNATIONALIZED_PRODUCT_NAME,
description: 'Explore and visualize data.',
main: `plugins/${PLUGIN_ID}/index`,
main: `plugins/${PLUGIN_ID}/redirect`,
listed: false,
},
embeddableFactories: ['plugins/lens/register_embeddable'],
visualize: [`plugins/${PLUGIN_ID}/legacy`],
embeddableFactories: [`plugins/${PLUGIN_ID}/legacy`],
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
mappings,
visTypes: ['plugins/lens/register_vis_type_alias'],
Expand Down
7 changes: 6 additions & 1 deletion x-pack/legacy/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ describe('Lens App', () => {
data: {
query: {
filterManager: createMockFilterManager(),
timefilter: {
timefilter: {
getTime: jest.fn(() => ({ from: 'now-7d', to: 'now' })),
setTime: jest.fn(),
},
},
},
},
dataShim: {
Expand All @@ -109,7 +115,6 @@ describe('Lens App', () => {
}),
},
},
timefilter: { history: {} },
},
storage: {
get: jest.fn(),
Expand Down
29 changes: 16 additions & 13 deletions x-pack/legacy/plugins/lens/public/app_plugin/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,35 @@ export function App({
docStorage: SavedObjectStore;
redirectTo: (id?: string) => void;
}) {
const timeDefaults = core.uiSettings.get('timepicker:timeDefaults');
const language =
storage.get('kibana.userQueryLanguage') || core.uiSettings.get('search:queryLanguage');

const [state, setState] = useState<State>({
isLoading: !!docId,
isSaveModalVisible: false,
indexPatternsForTopNav: [],
query: { query: '', language },
dateRange: {
fromDate: timeDefaults.from,
toDate: timeDefaults.to,
},
filters: [],
const [state, setState] = useState<State>(() => {
const currentRange = data.query.timefilter.timefilter.getTime();
return {
isLoading: !!docId,
isSaveModalVisible: false,
indexPatternsForTopNav: [],
query: { query: '', language },
dateRange: {
fromDate: currentRange.from,
toDate: currentRange.to,
},
filters: [],
};
});

const { lastKnownDoc } = state;

useEffect(() => {
const subscription = data.query.filterManager.getUpdates$().subscribe({
const filterSubscription = data.query.filterManager.getUpdates$().subscribe({
next: () => {
setState(s => ({ ...s, filters: data.query.filterManager.getFilters() }));
trackUiEvent('app_filters_updated');
},
});
return () => {
subscription.unsubscribe();
filterSubscription.unsubscribe();
};
}, []);

Expand Down Expand Up @@ -199,6 +201,7 @@ export function App({
dateRange.from !== state.dateRange.fromDate ||
dateRange.to !== state.dateRange.toDate
) {
data.query.timefilter.timefilter.setTime(dateRange);
trackUiEvent('app_date_change');
} else {
trackUiEvent('app_query_change');
Expand Down
68 changes: 45 additions & 23 deletions x-pack/legacy/plugins/lens/public/app_plugin/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@
* you may not use this file except in compliance with the Elastic License.
*/

import 'ui/autoload/all';
// Used to run esaggs queries
import 'uiExports/fieldFormats';
import 'uiExports/search';
import 'uiExports/visRequestHandlers';
import 'uiExports/visResponseHandlers';
// Used for kibana_context function
import 'uiExports/savedObjectTypes';

import React from 'react';
import { I18nProvider, FormattedMessage } from '@kbn/i18n/react';
import { HashRouter, Switch, Route, RouteComponentProps } from 'react-router-dom';
import { render, unmountComponentAtNode } from 'react-dom';
import chrome from 'ui/chrome';
import { CoreSetup, CoreStart } from 'src/core/public';
import { npSetup, npStart } from 'ui/new_platform';
import { DataPublicPluginStart } from 'src/plugins/data/public';
import { DataStart } from '../../../../../../src/legacy/core_plugins/data/public';
import { start as dataShimStart } from '../../../../../../src/legacy/core_plugins/data/public/legacy';
import { Storage } from '../../../../../../src/plugins/kibana_utils/public';
import { editorFrameSetup, editorFrameStart, editorFrameStop } from '../editor_frame_plugin';
import { indexPatternDatasourceSetup, indexPatternDatasourceStop } from '../indexpattern_plugin';
import { addHelpMenuToAppChrome } from '../help_menu_util';
import { SavedObjectIndexStore } from '../persistence';
import { xyVisualizationSetup, xyVisualizationStop } from '../xy_visualization_plugin';
import { metricVisualizationSetup, metricVisualizationStop } from '../metric_visualization_plugin';
Expand All @@ -31,10 +40,15 @@ import {
stopReportManager,
trackUiEvent,
} from '../lens_ui_telemetry';
import { LocalApplicationService } from '../../../../../../src/legacy/core_plugins/kibana/public/local_application_service';
import { NOT_INTERNATIONALIZED_PRODUCT_NAME } from '../../index';

export interface LensPluginStartDependencies {
data: DataPublicPluginStart;
dataShim: DataStart;
__LEGACY: {
localApplicationService: LocalApplicationService;
};
}
export class AppPlugin {
private instance: EditorFrameInstance | null = null;
Expand All @@ -58,11 +72,16 @@ export class AppPlugin {
editorFrameSetupInterface.registerDatasource('indexpattern', indexPattern);
}

start(core: CoreStart, { data, dataShim }: LensPluginStartDependencies) {
start(
core: CoreStart,
{ data, dataShim, __LEGACY: { localApplicationService } }: LensPluginStartDependencies
) {
if (this.store === null) {
throw new Error('Start lifecycle called before setup lifecycle');
}

addHelpMenuToAppChrome(core.chrome);

const store = this.store;

const editorFrameStartInterface = editorFrameStart();
Expand All @@ -89,9 +108,9 @@ export class AppPlugin {
docStorage={store}
redirectTo={id => {
if (!id) {
routeProps.history.push('/');
routeProps.history.push('/lens');
} else {
routeProps.history.push(`/edit/${id}`);
routeProps.history.push(`/lens/edit/${id}`);
}
}}
/>
Expand All @@ -103,17 +122,27 @@ export class AppPlugin {
return <FormattedMessage id="xpack.lens.app404" defaultMessage="404 Not Found" />;
}

return (
<I18nProvider>
<HashRouter>
<Switch>
<Route exact path="/edit/:id" render={renderEditor} />
<Route exact path="/" render={renderEditor} />
<Route component={NotFound} />
</Switch>
</HashRouter>
</I18nProvider>
);
localApplicationService.register({
id: 'lens',
title: NOT_INTERNATIONALIZED_PRODUCT_NAME,
mount: async (context, params) => {
render(
<I18nProvider>
<HashRouter>
<Switch>
<Route exact path="/lens/edit/:id" render={renderEditor} />
<Route exact path="/lens" render={renderEditor} />
<Route path="/lens" component={NotFound} />
</Switch>
</HashRouter>
</I18nProvider>,
params.element
);
return () => {
unmountComponentAtNode(params.element);
};
},
});
}

stop() {
Expand All @@ -131,10 +160,3 @@ export class AppPlugin {
editorFrameStop();
}
}

const app = new AppPlugin();

export const appSetup = () => app.setup(npSetup.core, {});
export const appStart = () =>
app.start(npStart.core, { dataShim: dataShimStart, data: npStart.plugins.data });
export const appStop = () => app.stop();
6 changes: 3 additions & 3 deletions x-pack/legacy/plugins/lens/public/help_menu_util.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } from 'ui/documentation_links';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { render, unmountComponentAtNode } from 'react-dom';
import { Chrome } from 'ui/chrome';
import { ChromeStart } from 'kibana/public';

const docsPage = 'lens';

export function addHelpMenuToAppChrome(chrome: Chrome) {
chrome.helpExtension.set(domElement => {
export function addHelpMenuToAppChrome(chrome: ChromeStart) {
chrome.setHelpExtension(domElement => {
render(<HelpMenu />, domElement);
return () => {
unmountComponentAtNode(domElement);
Expand Down
31 changes: 0 additions & 31 deletions x-pack/legacy/plugins/lens/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,3 @@
*/

export * from './types';

import 'ui/autoload/all';
import 'uiExports/search';
import 'uiExports/visRequestHandlers';
import 'uiExports/visResponseHandlers';
import 'uiExports/interpreter';
// Used for kibana_context function
import 'uiExports/savedObjectTypes';

import { render, unmountComponentAtNode } from 'react-dom';
import { IScope } from 'angular';
import chrome from 'ui/chrome';
import { appStart, appSetup, appStop } from './app_plugin';
import { PLUGIN_ID } from '../common';
import { addHelpMenuToAppChrome } from './help_menu_util';

// TODO: Convert this to the "new platform" way of doing UI
function Root($scope: IScope, $element: JQLite) {
const el = $element[0];
$scope.$on('$destroy', () => {
unmountComponentAtNode(el);
appStop();
});

appSetup();
addHelpMenuToAppChrome(chrome);

return render(appStart(), el);
}

chrome.setRootController(PLUGIN_ID, Root);
23 changes: 23 additions & 0 deletions x-pack/legacy/plugins/lens/public/legacy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 { start as dataShimStart } from '../../../../../src/legacy/core_plugins/data/public/legacy';

export * from './types';

import { localApplicationService } from '../../../../../src/legacy/core_plugins/kibana/public/local_application_service';
import { AppPlugin } from './app_plugin';

const app = new AppPlugin();
app.setup(npSetup.core, {});
app.start(npStart.core, {
dataShim: dataShimStart,
data: npStart.plugins.data,
__LEGACY: {
localApplicationService,
},
});
19 changes: 19 additions & 0 deletions x-pack/legacy/plugins/lens/public/redirect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.
*/

// This file redirects lens urls starting with app/lens#... to their counterpart on app/kibana#lens/... to
// make sure it's compatible with the 7.5 release

import { npSetup } from 'ui/new_platform';
import chrome from 'ui/chrome';

chrome.setRootController('lens', () => {
// prefix the path in the hash with lens/
const prefixedHashRoute = window.location.hash.replace(/^#\//, '#/lens/');

// redirect to the new lens url `app/kibana#/lens/...`
window.location.href = npSetup.core.http.basePath.prepend('/app/kibana' + prefixedHashRoute);
});
20 changes: 0 additions & 20 deletions x-pack/legacy/plugins/lens/public/register_embeddable.ts

This file was deleted.

4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/lens/public/register_vis_type_alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

import { i18n } from '@kbn/i18n';
import { visualizations } from '../../../../../src/legacy/core_plugins/visualizations/public';
import { BASE_APP_URL, getEditPath } from '../common';
import { getBasePath, getEditPath } from '../common';

visualizations.types.registerAlias({
aliasUrl: BASE_APP_URL,
aliasUrl: getBasePath(),
name: 'lens',
promotion: {
description: i18n.translate('xpack.lens.visTypeAlias.promotion.description', {
Expand Down

0 comments on commit f7ae0bf

Please sign in to comment.