Skip to content

Commit

Permalink
adding kibana url tracker to replace old track sub url
Browse files Browse the repository at this point in the history
  • Loading branch information
poffdeluxe committed Mar 25, 2020
1 parent a16968d commit 6431b3f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 55 deletions.
4 changes: 3 additions & 1 deletion src/core/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,9 @@ export type AppUpdatableFields = Pick<AppBase, 'status' | 'navLinkStatus' | 'too
* see {@link ApplicationSetup}
* @public
*/
export type AppUpdater = (app: AppBase) => Partial<AppUpdatableFields> | undefined;
export type AppUpdater = (
app: AppBase
) => Partial<AppUpdatableFields & { activeUrl: string }> | undefined;

/**
* Extension of {@link AppBase | common app properties} with the mount function.
Expand Down
5 changes: 3 additions & 2 deletions x-pack/legacy/plugins/canvas/public/application.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ export const renderApp = (
coreStart: CoreStart,
plugins: CanvasStartDeps,
{ element }: AppMountParameters,
canvasStore: Store
canvasStore: Store,
setActiveUrl: any
) => {
ReactDOM.render(
<KibanaContextProvider services={{ ...plugins, ...coreStart }}>
<I18nProvider>
<Provider store={canvasStore}>
<App />
<App setActiveUrl={setActiveUrl} />
</Provider>
</I18nProvider>
</KibanaContextProvider>,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/canvas/public/components/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class App extends React.PureComponent {
routes={routes}
showLoading={this.props.appState.ready === false}
loadingMessage={strings.getLoadingMessage()}
onRouteChange={this.props.onRouteChange}
onRouteChange={this.props.setActiveUrl}
onLoad={() => this.props.setAppReady(true)}
onError={err => this.props.setAppError(err)}
/>
Expand Down
10 changes: 2 additions & 8 deletions x-pack/legacy/plugins/canvas/public/components/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
*/

import { connect } from 'react-redux';
import { compose, withProps } from 'recompose';
import { compose } from 'recompose';
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 @@ -43,9 +42,4 @@ const mergeProps = (stateProps, dispatchProps, ownProps) => {
};
};

export const App = compose(
connect(mapStateToProps, mapDispatchToProps, mergeProps),
withProps(() => ({
onRouteChange: trackRouteChange,
}))
)(Component);
export const App = compose(connect(mapStateToProps, mapDispatchToProps, mergeProps))(Component);

This file was deleted.

11 changes: 0 additions & 11 deletions x-pack/legacy/plugins/canvas/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +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

const shimCoreSetup = {
...npSetup.core,
Expand All @@ -27,14 +24,6 @@ const shimSetupPlugins: CanvasSetupDeps = {
const shimStartPlugins: CanvasStartDeps = {
...npStart.plugins,
expressions: npStart.plugins.expressions,
__LEGACY: {
// ToDo: Copy directly into canvas
absoluteToParsedUrl,
// ToDo: Copy directly into canvas
formatMsg,
// 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: 3 additions & 5 deletions x-pack/legacy/plugins/canvas/public/lib/notify.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@
*/

import { get } from 'lodash';
import { getCoreStart, getStartPlugins } from '../legacy';
import { getCoreStart } from '../legacy';
// @ts-ignore Untyped Kibana Lib
import { formatMsg } from '../../../../../../src/plugins/kibana_legacy/public'; // eslint-disable-line import/order

const getToastNotifications = function() {
return getCoreStart().notifications.toasts;
};

const formatMsg = function(...args) {
return getStartPlugins().__LEGACY.formatMsg(...args);
};

const getToast = (err, opts = {}) => {
const errData = get(err, 'response') || err;
const errMsg = formatMsg(errData);
Expand Down
34 changes: 26 additions & 8 deletions x-pack/legacy/plugins/canvas/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
* 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 { BehaviorSubject } from 'rxjs';
import { CoreSetup, CoreStart, Plugin, AppUpdater } from '../../../../../src/core/public';
import { HomePublicPluginSetup } from '../../../../../src/plugins/home/public';
import { initLoadingIndicator } from './lib/loading_indicator';
// @ts-ignore untyped local
import { historyProvider } from './lib/history_provider';
import { featureCatalogueEntry } from './feature_catalogue_entry';
import { ExpressionsSetup, ExpressionsStart } from '../../../../../src/plugins/expressions/public';
import { createKbnUrlTracker } from '../../../../../src/plugins/kibana_utils/public';

// @ts-ignore untyped local
import { argTypeSpecs } from './expression_types/arg_types';
import { transitions } from './transitions';
Expand All @@ -31,11 +35,6 @@ export interface CanvasSetupDeps {

export interface CanvasStartDeps {
expressions: ExpressionsStart;
__LEGACY: {
absoluteToParsedUrl: (url: string, basePath: string) => any;
formatMsg: any;
trackSubUrlForApp: Chrome['trackSubUrlForApp'];
};
}

/**
Expand All @@ -51,25 +50,44 @@ export interface CanvasStart {} // eslint-disable-line @typescript-eslint/no-emp
/** @internal */
export class CanvasPlugin
implements Plugin<CanvasSetup, CanvasStart, CanvasSetupDeps, CanvasStartDeps> {
private appUpdater = new BehaviorSubject<AppUpdater>(() => ({}));

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

const { appMounted, appUnMounted, setActiveUrl } = createKbnUrlTracker({
baseUrl: core.http.basePath.prepend('/app/kibana/canvas'),
defaultSubUrl: `#/`,
storageKey: 'lastUrl:canvas',
navLinkUpdater$: this.appUpdater,
toastNotifications: core.notifications.toasts,
stateParams: [],
});

core.application.register({
id: 'canvas',
title: 'Canvas App',
updater$: this.appUpdater,
async mount(context, params) {
// Load application bundle
const { renderApp, initializeCanvas, teardownCanvas } = await import('./application');

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

// Tell URL tracker we've mounted the app
appMounted();

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

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

return () => {
unmount();

// Tell URL tracker we're unmounting the app
appUnMounted();

teardownCanvas(coreStart);
};
},
Expand Down

0 comments on commit 6431b3f

Please sign in to comment.