Skip to content

Commit

Permalink
Clean up shims of Graph, Home, Dashboard, Visualize (#57331)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Feb 14, 2020
1 parent 098a55a commit 948bfa9
Show file tree
Hide file tree
Showing 30 changed files with 270 additions and 248 deletions.
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ import { registerCspCollector } from './server/lib/csp_usage_collector';
import { injectVars } from './inject_vars';
import { i18n } from '@kbn/i18n';
import { DEFAULT_APP_CATEGORIES } from '../../../../src/core/utils';
import { kbnBaseUrl } from '../../../plugins/kibana_legacy/server';

const mkdirAsync = promisify(Fs.mkdir);

export default function(kibana) {
const kbnBaseUrl = '/app/kibana';
return new kibana.Plugin({
id: 'kibana',
config: function(Joi) {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/core_plugins/kibana/public/dashboard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ export { createSavedDashboardLoader } from './saved_dashboard/saved_dashboards';

// Core will be looking for this when loading our plugin in the new platform
export const plugin = (context: PluginInitializerContext) => {
return new DashboardPlugin();
return new DashboardPlugin(context);
};
14 changes: 4 additions & 10 deletions src/legacy/core_plugins/kibana/public/dashboard/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,12 @@

import { PluginInitializerContext } from 'kibana/public';
import { npSetup, npStart } from './legacy_imports';
import { start as data } from '../../../data/public/legacy';
import { start as embeddables } from '../../../embeddable_api/public/np_ready/public/legacy';
import { plugin } from './index';

(async () => {
const instance = plugin({} as PluginInitializerContext);
const instance = plugin({
env: npSetup.plugins.kibanaLegacy.env,
} as PluginInitializerContext);
instance.setup(npSetup.core, npSetup.plugins);
instance.start(npStart.core, {
...npStart.plugins,
data,
npData: npStart.plugins.data,
embeddables,
navigation: npStart.plugins.navigation,
});
instance.start(npStart.core, npStart.plugins);
})();
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ import {
AppMountContext,
ChromeStart,
IUiSettingsClient,
LegacyCoreStart,
CoreStart,
SavedObjectsClientContract,
PluginInitializerContext,
} from 'kibana/public';
import { Storage } from '../../../../../../plugins/kibana_utils/public';
import {
Expand All @@ -43,13 +44,14 @@ import {
import { initDashboardApp } from './legacy_app';
import { IEmbeddableStart } from '../../../../../../plugins/embeddable/public';
import { NavigationPublicPluginStart as NavigationStart } from '../../../../../../plugins/navigation/public';
import { DataPublicPluginStart as NpDataStart } from '../../../../../../plugins/data/public';
import { DataPublicPluginStart } from '../../../../../../plugins/data/public';
import { SharePluginStart } from '../../../../../../plugins/share/public';
import { KibanaLegacyStart } from '../../../../../../plugins/kibana_legacy/public';

export interface RenderDeps {
core: LegacyCoreStart;
npDataStart: NpDataStart;
pluginInitializerContext: PluginInitializerContext;
core: CoreStart;
data: DataPublicPluginStart;
navigation: NavigationStart;
savedObjectsClient: SavedObjectsClientContract;
savedDashboards: SavedObjectLoader;
Expand All @@ -58,8 +60,8 @@ export interface RenderDeps {
uiSettings: IUiSettingsClient;
chrome: ChromeStart;
addBasePath: (path: string) => string;
savedQueryService: NpDataStart['query']['savedQueries'];
embeddables: IEmbeddableStart;
savedQueryService: DataPublicPluginStart['query']['savedQueries'];
embeddable: IEmbeddableStart;
localStorage: Storage;
share: SharePluginStart;
config: KibanaLegacyStart['config'];
Expand All @@ -71,7 +73,11 @@ export const renderApp = (element: HTMLElement, appBasePath: string, deps: Rende
if (!angularModuleInstance) {
angularModuleInstance = createLocalAngularModule(deps.core, deps.navigation);
// global routing stuff
configureAppAngularModule(angularModuleInstance, deps.core as LegacyCoreStart, true);
configureAppAngularModule(
angularModuleInstance,
{ core: deps.core, env: deps.pluginInitializerContext.env },
true
);
initDashboardApp(angularModuleInstance, deps);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export function initDashboardAppDirective(app: any, deps: RenderDeps) {
$route,
$scope,
$routeParams,
indexPatterns: deps.npDataStart.indexPatterns,
indexPatterns: deps.data.indexPatterns,
kbnUrlStateStorage,
history,
...deps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,18 @@ export class DashboardAppController {
};

constructor({
pluginInitializerContext,
$scope,
$route,
$routeParams,
dashboardConfig,
localStorage,
indexPatterns,
savedQueryService,
embeddables,
embeddable,
share,
dashboardCapabilities,
npDataStart: { query: queryService },
data: { query: queryService },
core: {
notifications,
overlays,
Expand Down Expand Up @@ -141,7 +142,7 @@ export class DashboardAppController {
const dashboardStateManager = new DashboardStateManager({
savedDashboard: dash,
hideWriteControls: dashboardConfig.getHideWriteControls(),
kibanaVersion: injectedMetadata.getKibanaVersion(),
kibanaVersion: pluginInitializerContext.env.packageInfo.version,
kbnUrlStateStorage,
history,
});
Expand Down Expand Up @@ -186,9 +187,9 @@ export class DashboardAppController {

let panelIndexPatterns: IndexPattern[] = [];
Object.values(container.getChildIds()).forEach(id => {
const embeddable = container.getChild(id);
if (isErrorEmbeddable(embeddable)) return;
const embeddableIndexPatterns = (embeddable.getOutput() as any).indexPatterns;
const embeddableInstance = container.getChild(id);
if (isErrorEmbeddable(embeddableInstance)) return;
const embeddableIndexPatterns = (embeddableInstance.getOutput() as any).indexPatterns;
if (!embeddableIndexPatterns) return;
panelIndexPatterns.push(...embeddableIndexPatterns);
});
Expand Down Expand Up @@ -284,7 +285,7 @@ export class DashboardAppController {
let outputSubscription: Subscription | undefined;

const dashboardDom = document.getElementById('dashboardViewport');
const dashboardFactory = embeddables.getEmbeddableFactory(
const dashboardFactory = embeddable.getEmbeddableFactory(
DASHBOARD_CONTAINER_TYPE
) as DashboardContainerFactory;
dashboardFactory
Expand Down Expand Up @@ -818,8 +819,8 @@ export class DashboardAppController {
if (dashboardContainer && !isErrorEmbeddable(dashboardContainer)) {
openAddPanelFlyout({
embeddable: dashboardContainer,
getAllFactories: embeddables.getEmbeddableFactories,
getFactory: embeddables.getEmbeddableFactory,
getAllFactories: embeddable.getEmbeddableFactories,
getFactory: embeddable.getEmbeddableFactory,
notifications,
overlays,
SavedObjectFinder: getSavedObjectFinder(savedObjects, uiSettings),
Expand All @@ -829,7 +830,7 @@ export class DashboardAppController {

navActions[TopNavIds.VISUALIZE] = async () => {
const type = 'visualization';
const factory = embeddables.getEmbeddableFactory(type);
const factory = embeddable.getEmbeddableFactory(type);
if (!factory) {
throw new EmbeddableFactoryNotFoundError(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function initDashboardApp(app, deps) {

// syncs `_g` portion of url with query services
const { stop: stopSyncingGlobalStateWithUrl } = syncQuery(
deps.npDataStart.query,
deps.data.query,
kbnUrlStateStorage
);

Expand Down Expand Up @@ -137,36 +137,31 @@ export function initDashboardApp(app, deps) {
},
resolve: {
dash: function($rootScope, $route, redirectWhenMissing, kbnUrl, history) {
return ensureDefaultIndexPattern(deps.core, deps.npDataStart, $rootScope, kbnUrl).then(
() => {
const savedObjectsClient = deps.savedObjectsClient;
const title = $route.current.params.title;
if (title) {
return savedObjectsClient
.find({
search: `"${title}"`,
search_fields: 'title',
type: 'dashboard',
})
.then(results => {
// The search isn't an exact match, lets see if we can find a single exact match to use
const matchingDashboards = results.savedObjects.filter(
dashboard =>
dashboard.attributes.title.toLowerCase() === title.toLowerCase()
);
if (matchingDashboards.length === 1) {
history.replace(createDashboardEditUrl(matchingDashboards[0].id));
} else {
history.replace(
`${DashboardConstants.LANDING_PAGE_PATH}?filter="${title}"`
);
$route.reload();
}
return new Promise(() => {});
});
}
return ensureDefaultIndexPattern(deps.core, deps.data, $rootScope, kbnUrl).then(() => {
const savedObjectsClient = deps.savedObjectsClient;
const title = $route.current.params.title;
if (title) {
return savedObjectsClient
.find({
search: `"${title}"`,
search_fields: 'title',
type: 'dashboard',
})
.then(results => {
// The search isn't an exact match, lets see if we can find a single exact match to use
const matchingDashboards = results.savedObjects.filter(
dashboard => dashboard.attributes.title.toLowerCase() === title.toLowerCase()
);
if (matchingDashboards.length === 1) {
history.replace(createDashboardEditUrl(matchingDashboards[0].id));
} else {
history.replace(`${DashboardConstants.LANDING_PAGE_PATH}?filter="${title}"`);
$route.reload();
}
return new Promise(() => {});
});
}
);
});
},
},
})
Expand All @@ -177,7 +172,7 @@ export function initDashboardApp(app, deps) {
requireUICapability: 'dashboard.createNew',
resolve: {
dash: function(redirectWhenMissing, $rootScope, kbnUrl) {
return ensureDefaultIndexPattern(deps.core, deps.npDataStart, $rootScope, kbnUrl)
return ensureDefaultIndexPattern(deps.core, deps.data, $rootScope, kbnUrl)
.then(() => {
return deps.savedDashboards.get();
})
Expand All @@ -197,7 +192,7 @@ export function initDashboardApp(app, deps) {
dash: function($rootScope, $route, redirectWhenMissing, kbnUrl, history) {
const id = $route.current.params.id;

return ensureDefaultIndexPattern(deps.core, deps.npDataStart, $rootScope, kbnUrl)
return ensureDefaultIndexPattern(deps.core, deps.data, $rootScope, kbnUrl)
.then(() => {
return deps.savedDashboards.get(id);
})
Expand Down
Loading

0 comments on commit 948bfa9

Please sign in to comment.