Skip to content

Commit

Permalink
Use some new platform methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Corey Robertson committed Nov 20, 2019
1 parent 0886fce commit cb871fc
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function CanvasRootControllerFactory(coreStart: CoreStart, plugins: Canva
const domNode = $element[0];

// set the read-only badge when appropriate
plugins.__LEGACY.badge.set(
coreStart.chrome.setBadge(
coreStart.application.capabilities.canvas.save
? undefined
: {
Expand Down
6 changes: 4 additions & 2 deletions x-pack/legacy/plugins/canvas/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ const shimSetupPlugins = {};
const shimStartPlugins: CanvasStartDeps = {
...npStart.plugins,
__LEGACY: {
// ToDo: Copy directly into canvas
absoluteToParsedUrl,
// ToDo: Copy directly into canvas
formatMsg,
loadingCount,
badge: chrome.badge,
// ToDo: Remove in favor of core.application.register
setRootController: chrome.setRootController,
storage: Storage,
// ToDo: Won't be a part of New Platform. Will need to handle internally
trackSubUrlForApp: chrome.trackSubUrlForApp,
uiModules,
},
Expand Down
12 changes: 9 additions & 3 deletions x-pack/legacy/plugins/canvas/public/lib/loading_indicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { getStartPlugins } from '../legacy';
import * as Rx from 'rxjs';
import { CoreStart } from 'src/core/public';

let isActive = false;

Expand All @@ -13,17 +14,22 @@ export interface LoadingIndicatorInterface {
hide: () => void;
}

const loadingCount$ = new Rx.BehaviorSubject(0);

export const initLoadingIndicator = (addLoadingCount: CoreStart['http']['addLoadingCount']) =>
addLoadingCount(loadingCount$);

export const loadingIndicator = {
show: () => {
if (!isActive) {
getStartPlugins().__LEGACY.loadingCount.increment();
isActive = true;
loadingCount$.next(1);
}
},
hide: () => {
if (isActive) {
getStartPlugins().__LEGACY.loadingCount.decrement();
isActive = false;
loadingCount$.next(0);
}
},
};
5 changes: 3 additions & 2 deletions x-pack/legacy/plugins/canvas/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { HelpMenu } from './components/help_menu/help_menu';
import { loadExpressionTypes } from './lib/load_expression_types';
// @ts-ignore: untyped local
import { loadTransitions } from './lib/load_transitions';
import { initLoadingIndicator } from './lib/loading_indicator';

// @ts-ignore: untyped local
import { initClipboard } from './lib/clipboard';
Expand All @@ -36,8 +37,6 @@ export interface CanvasStartDeps {
__LEGACY: {
absoluteToParsedUrl: (url: string, basePath: string) => any;
formatMsg: any;
loadingCount: any;
badge: Chrome['badge'];
setRootController: Chrome['setRootController'];
storage: typeof Storage;
trackSubUrlForApp: Chrome['trackSubUrlForApp'];
Expand All @@ -64,6 +63,7 @@ export class CanvasPlugin
// This is where any setup actions need to occur.
// Things like registering functions to the interpreter that need
// to be available everywhere, not just in Canvas

return {};
}

Expand All @@ -75,6 +75,7 @@ export class CanvasPlugin
initLocationProvider(core, plugins);
initStore(core, plugins);
initClipboard(plugins.__LEGACY.storage);
initLoadingIndicator(core.http.addLoadingCount);

const CanvasRootController = CanvasRootControllerFactory(core, plugins);
plugins.__LEGACY.setRootController('canvas', CanvasRootController);
Expand Down

0 comments on commit cb871fc

Please sign in to comment.