Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Graph] Shim plugin #47469

Merged
merged 19 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary to support dynamic imports via await import(...

});
} 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() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exporting the directive definition as a module export to be able to put it in a separate angular module with a different name. This is done to use existing code like this one but make sure it's not using any dependencies from the global angular instance

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 @@ -287,14 +287,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')) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use config in here to avoid having to initialize it.

return;
}

Expand Down
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() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for the top nav directive. Private isn't used in this PR but it will become necessary for shimming discover and others in the same style

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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import _ from 'lodash';

import { uiModules } from 'ui/modules';
import chrome from 'ui/chrome';
import { SavedObjectRegistryProvider } from 'ui/saved_objects/saved_object_registry';
import { SavedObjectsClientProvider } from 'ui/saved_objects';
Expand Down Expand Up @@ -87,9 +86,5 @@ export function SavedWorkspacesProvider(kbnUrl, Private, Promise) {
});
};
}
// This is the only thing that gets injected into controllers
uiModules.get('app/graph').service('savedGraphWorkspaces', function (Private) {
return Private(SavedWorkspacesProvider);
});

SavedObjectRegistryProvider.register(SavedWorkspacesProvider);
Loading