Skip to content

Commit

Permalink
[Graph] Shim plugin (elastic#47469)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 committed Oct 25, 2019
1 parent f16803f commit a720d6c
Show file tree
Hide file tree
Showing 24 changed files with 984 additions and 731 deletions.
2 changes: 1 addition & 1 deletion src/dev/i18n/extractors/code.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function* extractCodeMessages(buffer, reporter) {
try {
ast = parse(buffer.toString(), {
sourceType: 'module',
plugins: ['jsx', 'typescript', 'objectRestSpread', 'classProperties', 'asyncGenerators'],
plugins: ['jsx', 'typescript', 'objectRestSpread', 'classProperties', 'asyncGenerators', 'dynamicImport'],
});
} catch (error) {
if (error instanceof SyntaxError) {
Expand Down
12 changes: 8 additions & 4 deletions src/legacy/ui/public/kbn_top_nav/kbn_top_nav.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { TopNavMenu } from '../../../core_plugins/kibana_react/public';

const module = uiModules.get('kibana');

module.directive('kbnTopNav', () => {
export function createTopNavDirective() {
return {
restrict: 'E',
template: '',
Expand Down Expand Up @@ -71,9 +71,11 @@ module.directive('kbnTopNav', () => {
return linkFn;
}
};
});
}

module.directive('kbnTopNavHelper', (reactDirective) => {
module.directive('kbnTopNav', createTopNavDirective);

export function createTopNavHelper(reactDirective) {
return reactDirective(
wrapInI18nContext(TopNavMenu),
[
Expand Down Expand Up @@ -113,4 +115,6 @@ module.directive('kbnTopNavHelper', (reactDirective) => {
'showAutoRefreshOnly',
],
);
});
}

module.directive('kbnTopNavHelper', createTopNavHelper);
6 changes: 2 additions & 4 deletions src/legacy/ui/public/legacy_compat/angular_config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,14 +286,12 @@ const $setupHelpExtensionAutoClear = (newPlatform: CoreStart) => (

const $setupUrlOverflowHandling = (newPlatform: CoreStart) => (
$location: ILocationService,
$rootScope: IRootScopeService,
Private: any,
config: any
$rootScope: IRootScopeService
) => {
const urlOverflow = new UrlOverflowService();
const check = () => {
// disable long url checks when storing state in session storage
if (config.get('state:storeInSessionStorage')) {
if (newPlatform.uiSettings.get('state:storeInSessionStorage')) {
return;
}

Expand Down
24 changes: 13 additions & 11 deletions src/legacy/ui/public/modals/confirm_modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,7 @@ export const ConfirmationButtonTypes = {
CANCEL: CANCEL_BUTTON
};

/**
* @typedef {Object} ConfirmModalOptions
* @property {String} confirmButtonText
* @property {String=} cancelButtonText
* @property {function} onConfirm
* @property {function=} onCancel
* @property {String=} title - If given, shows a title on the confirm modal.
*/

module.factory('confirmModal', function ($rootScope, $compile) {
export function confirmModalFactory($rootScope, $compile) {
let modalPopover;
const confirmQueue = [];

Expand Down Expand Up @@ -114,4 +105,15 @@ module.factory('confirmModal', function ($rootScope, $compile) {
}
}
};
});
}

/**
* @typedef {Object} ConfirmModalOptions
* @property {String} confirmButtonText
* @property {String=} cancelButtonText
* @property {function} onConfirm
* @property {function=} onCancel
* @property {String=} title - If given, shows a title on the confirm modal.
*/

module.factory('confirmModal', confirmModalFactory);
4 changes: 4 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export const npStart = {

export function __setup__(coreSetup) {
npSetup.core = coreSetup;

// no-op application register calls (this is overwritten to
// bootstrap an LP plugin outside of tests)
npSetup.core.application.register = () => {};
}

export function __start__(coreStart) {
Expand Down
146 changes: 74 additions & 72 deletions src/legacy/ui/public/private/private.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,98 +108,100 @@ function name(fn) {
return fn.name || fn.toString().split('\n').shift();
}

uiModules.get('kibana/private')
.provider('Private', function () {
const provider = this;

// one cache/swaps per Provider
const cache = {};
const swaps = {};
export function PrivateProvider() {
const provider = this;

// return the uniq id for this function
function identify(fn) {
if (typeof fn !== 'function') {
throw new TypeError('Expected private module "' + fn + '" to be a function');
}
// one cache/swaps per Provider
const cache = {};
const swaps = {};

if (fn.$$id) return fn.$$id;
else return (fn.$$id = nextId());
// return the uniq id for this function
function identify(fn) {
if (typeof fn !== 'function') {
throw new TypeError('Expected private module "' + fn + '" to be a function');
}

provider.stub = function (fn, instance) {
cache[identify(fn)] = instance;
return instance;
};
if (fn.$$id) return fn.$$id;
else return (fn.$$id = nextId());
}

provider.swap = function (fn, prov) {
const id = identify(fn);
swaps[id] = prov;
};
provider.stub = function (fn, instance) {
cache[identify(fn)] = instance;
return instance;
};

provider.$get = ['$injector', function PrivateFactory($injector) {
provider.swap = function (fn, prov) {
const id = identify(fn);
swaps[id] = prov;
};

// prevent circular deps by tracking where we came from
const privPath = [];
const pathToString = function () {
return privPath.map(name).join(' -> ');
};
provider.$get = ['$injector', function PrivateFactory($injector) {

// call a private provider and return the instance it creates
function instantiate(prov, locals) {
if (~privPath.indexOf(prov)) {
throw new Error(
'Circular reference to "' + name(prov) + '"' +
' found while resolving private deps: ' + pathToString()
);
}
// prevent circular deps by tracking where we came from
const privPath = [];
const pathToString = function () {
return privPath.map(name).join(' -> ');
};

privPath.push(prov);
// call a private provider and return the instance it creates
function instantiate(prov, locals) {
if (~privPath.indexOf(prov)) {
throw new Error(
'Circular reference to "' + name(prov) + '"' +
' found while resolving private deps: ' + pathToString()
);
}

const context = {};
let instance = $injector.invoke(prov, context, locals);
if (!_.isObject(instance)) instance = context;
privPath.push(prov);

privPath.pop();
return instance;
}
const context = {};
let instance = $injector.invoke(prov, context, locals);
if (!_.isObject(instance)) instance = context;

// retrieve an instance from cache or create and store on
function get(id, prov, $delegateId, $delegateProv) {
if (cache[id]) return cache[id];
privPath.pop();
return instance;
}

let instance;
// retrieve an instance from cache or create and store on
function get(id, prov, $delegateId, $delegateProv) {
if (cache[id]) return cache[id];

if ($delegateId != null && $delegateProv != null) {
instance = instantiate(prov, {
$decorate: _.partial(get, $delegateId, $delegateProv)
});
} else {
instance = instantiate(prov);
}
let instance;

return (cache[id] = instance);
if ($delegateId != null && $delegateProv != null) {
instance = instantiate(prov, {
$decorate: _.partial(get, $delegateId, $delegateProv)
});
} else {
instance = instantiate(prov);
}

// main api, get the appropriate instance for a provider
function Private(prov) {
let id = identify(prov);
let $delegateId;
let $delegateProv;
return (cache[id] = instance);
}

if (swaps[id]) {
$delegateId = id;
$delegateProv = prov;
// main api, get the appropriate instance for a provider
function Private(prov) {
let id = identify(prov);
let $delegateId;
let $delegateProv;

prov = swaps[$delegateId];
id = identify(prov);
}
if (swaps[id]) {
$delegateId = id;
$delegateProv = prov;

return get(id, prov, $delegateId, $delegateProv);
prov = swaps[$delegateId];
id = identify(prov);
}

Private.stub = provider.stub;
Private.swap = provider.swap;
return get(id, prov, $delegateId, $delegateProv);
}

Private.stub = provider.stub;
Private.swap = provider.swap;

return Private;
}];
}

return Private;
}];
});
uiModules.get('kibana/private')
.provider('Private', PrivateProvider);
10 changes: 6 additions & 4 deletions src/legacy/ui/public/promises/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ import { uiModules } from '../modules';

const module = uiModules.get('kibana');

// Provides a tiny subset of the excellent API from
// bluebird, reimplemented using the $q service
module.service('Promise', function ($q, $timeout) {
export function PromiseServiceCreator($q, $timeout) {
function Promise(fn) {
if (typeof this === 'undefined') throw new Error('Promise constructor must be called with "new"');

Expand Down Expand Up @@ -122,4 +120,8 @@ module.service('Promise', function ($q, $timeout) {
};

return Promise;
});
}

// Provides a tiny subset of the excellent API from
// bluebird, reimplemented using the $q service
module.service('Promise', PromiseServiceCreator);
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function isSuccess(result: SaveResult): result is { id?: string } {
return 'id' in result;
}

interface MinimalSaveModalProps {
export interface MinimalSaveModalProps {
onSave: (...args: any[]) => Promise<SaveResult>;
onClose: () => void;
}
Expand Down
32 changes: 17 additions & 15 deletions src/legacy/ui/public/state_management/config_provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,23 @@

import { uiModules } from '../modules';

uiModules.get('kibana/state_management')
.provider('stateManagementConfig', class StateManagementConfigProvider {
_enabled = true
export class StateManagementConfigProvider {
_enabled = true

$get(/* inject stuff */) {
return {
enabled: this._enabled,
};
}

$get(/* inject stuff */) {
return {
enabled: this._enabled,
};
}
disable() {
this._enabled = false;
}

disable() {
this._enabled = false;
}
enable() {
this._enabled = true;
}
}

enable() {
this._enabled = true;
}
});
uiModules.get('kibana/state_management')
.provider('stateManagementConfig', StateManagementConfigProvider);
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/graph/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export function graph(kibana) {
order: 9000,
icon: 'plugins/graph/icon.png',
euiIconType: 'graphApp',
main: 'plugins/graph/app',
main: 'plugins/graph/index',
},
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
hacks: ['plugins/graph/hacks/toggle_app_link_in_nav'],
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { uiModules } from 'ui/modules';
import { SavedObjectProvider } from 'ui/saved_objects/saved_object';
import { i18n } from '@kbn/i18n';
import {
extractReferences,
injectReferences,
} from './saved_workspace_references';

const module = uiModules.get('app/dashboard');

export function SavedWorkspaceProvider(Private) {
// SavedWorkspace constructor. Usually you'd interact with an instance of this.
// ID is option, without it one will be generated on save.
Expand Down Expand Up @@ -68,8 +65,3 @@ export function SavedWorkspaceProvider(Private) {
SavedWorkspace.searchsource = false;
return SavedWorkspace;
}

// Used only by the savedDashboards service, usually no reason to change this
module.factory('SavedGraphWorkspace', function (Private) {
return Private(SavedWorkspaceProvider);
});
Loading

0 comments on commit a720d6c

Please sign in to comment.