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

[Visualize] Centralize dependencies in kibana_services.ts #49293

Merged
merged 16 commits into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
75 changes: 40 additions & 35 deletions src/legacy/core_plugins/kibana/public/visualize/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,48 @@ import { i18n } from '@kbn/i18n';
import '../saved_visualizations/saved_visualizations';
import './visualization_editor';
import './visualization';
import 'ui/vis/editors/default/sidebar';
import 'ui/visualize';
import 'ui/collapsible_sidebar';
import 'ui/directives/storage';

import { capabilities } from 'ui/capabilities';
import chrome from 'ui/chrome';
import React from 'react';
import angular from 'angular';
import { FormattedMessage } from '@kbn/i18n/react';
import { toastNotifications } from 'ui/notify';
import { docTitle } from 'ui/doc_title';
import { FilterBarQueryFilterProvider } from 'ui/filter_manager/query_filter';
import { stateMonitorFactory } from 'ui/state_management/state_monitor_factory';
import { migrateAppState } from './lib';
import uiRoutes from 'ui/routes';
import { uiModules } from 'ui/modules';
import editorTemplate from './editor.html';
import { DashboardConstants } from '../../dashboard/dashboard_constants';
import { VisualizeConstants } from '../visualize_constants';
import { KibanaParsedUrl } from 'ui/url/kibana_parsed_url';
import { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url';
import { migrateLegacyQuery } from 'ui/utils/migrate_legacy_query';
import { subscribeWithScope } from 'ui/utils/subscribe_with_scope';
import { timefilter } from 'ui/timefilter';
import { showShareContextMenu, ShareContextMenuExtensionsRegistryProvider } from 'ui/share';
import { getUnhashableStatesProvider } from 'ui/state_management/state_hashing';
import { showSaveModal } from 'ui/saved_objects/show_saved_object_save_modal';
import { SavedObjectSaveModal } from 'ui/saved_objects/components/saved_object_save_modal';
import { getEditBreadcrumbs, getCreateBreadcrumbs } from '../breadcrumbs';
import { npStart } from 'ui/new_platform';
import { extractTimeFilter, changeTimeFilter } from '../../../../data/public';
import { start as data } from '../../../../data/public/legacy';
import { start as visualizations } from '../../../../visualizations/public/np_ready/public/legacy';

import { addHelpMenuToAppChrome } from '../help_menu/help_menu_util';

import {
getServices,
angular,
absoluteToParsedUrl,
getUnhashableStatesProvider,
KibanaParsedUrl,
migrateLegacyQuery,
SavedObjectSaveModal,
showShareContextMenu,
showSaveModal,
stateMonitorFactory,
subscribeWithScope,
} from '../kibana_services';

const {
capabilities,
chrome,
chromeLegacy,
data,
docTitle,
FilterBarQueryFilterProvider,
getBasePath,
ShareContextMenuExtensionsRegistryProvider,
toastNotifications,
timefilter,
uiModules,
uiRoutes,
visualizations,
} = getServices();

const { savedQueryService } = data.search.services;

uiRoutes
Expand Down Expand Up @@ -101,7 +106,7 @@ uiRoutes
savedVis: function (savedVisualizations, redirectWhenMissing, $route) {
return savedVisualizations.get($route.current.params.id)
.then((savedVis) => {
npStart.core.chrome.recentlyAccessed.add(
chrome.recentlyAccessed.add(
savedVis.getFullPath(),
savedVis.title,
savedVis.id);
Expand Down Expand Up @@ -169,7 +174,7 @@ function VisEditor(
dirty: !savedVis.id
};

$scope.topNavMenu = [...(capabilities.get().visualize.save ? [{
$scope.topNavMenu = [...(capabilities.visualize.save ? [{
id: 'save',
label: i18n.translate('kbn.topNavMenu.saveVisualizationButtonLabel', { defaultMessage: 'save' }),
description: i18n.translate('kbn.visualize.topNavMenu.saveVisualizationButtonAriaLabel', {
Expand Down Expand Up @@ -238,7 +243,7 @@ function VisEditor(
showShareContextMenu({
anchorElement,
allowEmbed: true,
allowShortUrl: capabilities.get().visualize.createShortUrl,
allowShortUrl: capabilities.visualize.createShortUrl,
getUnhashableStates,
objectId: savedVis.id,
objectType: 'visualization',
Expand Down Expand Up @@ -355,9 +360,9 @@ function VisEditor(
}
});

$scope.showSaveQuery = capabilities.get().visualize.saveQuery;
$scope.showSaveQuery = capabilities.visualize.saveQuery;

$scope.$watch(() => capabilities.get().visualize.saveQuery, (newCapability) => {
$scope.$watch(() => capabilities.visualize.saveQuery, (newCapability) => {
$scope.showSaveQuery = newCapability;
});

Expand Down Expand Up @@ -578,7 +583,7 @@ function VisEditor(

if ($scope.isAddToDashMode()) {
const savedVisualizationParsedUrl = new KibanaParsedUrl({
basePath: chrome.getBasePath(),
basePath: getBasePath(),
appId: kbnBaseUrl.slice('/app/'.length),
appPath: kbnUrl.eval(`${VisualizeConstants.EDIT_PATH}/{{id}}`, { id: savedVis.id }),
});
Expand All @@ -587,15 +592,15 @@ function VisEditor(
// Since we aren't reloading the page, only inserting a new browser history item, we need to manually update
// the last url for this app, so directly clicking on the Visualize tab will also bring the user to the saved
// url, not the unsaved one.
chrome.trackSubUrlForApp('kibana:visualize', savedVisualizationParsedUrl);
chromeLegacy.trackSubUrlForApp('kibana:visualize', savedVisualizationParsedUrl);

const lastDashboardAbsoluteUrl = npStart.core.chrome.navLinks.get('kibana:dashboard').url;
const dashboardParsedUrl = absoluteToParsedUrl(lastDashboardAbsoluteUrl, chrome.getBasePath());
const lastDashboardAbsoluteUrl = chrome.navLinks.get('kibana:dashboard').url;
const dashboardParsedUrl = absoluteToParsedUrl(lastDashboardAbsoluteUrl, getBasePath());
dashboardParsedUrl.addQueryParameter(DashboardConstants.NEW_VISUALIZATION_ID_PARAM, savedVis.id);
kbnUrl.change(dashboardParsedUrl.appPath);
} else if (savedVis.id === $route.current.params.id) {
docTitle.change(savedVis.lastSavedTitle);
chrome.breadcrumbs.set($injector.invoke(getEditBreadcrumbs));
chrome.setBreadcrumbs($injector.invoke(getEditBreadcrumbs));
savedVis.vis.title = savedVis.title;
savedVis.vis.description = savedVis.description;
// it's needed to save the state to update url string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* under the License.
*/

import { uiModules } from 'ui/modules';
import 'angular-sanitize';
import { start as embeddables } from '../../../../../core_plugins/embeddable_api/public/np_ready/public/legacy';
import { getServices } from '../kibana_services';

const { embeddables, uiModules } = getServices();

uiModules
.get('kibana/directive', ['ngSanitize'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
* under the License.
*/

import { uiModules } from 'ui/modules';
import 'angular-sanitize';
import { VisEditorTypesRegistryProvider } from 'ui/registry/vis_editor_types';
import { getServices, VisEditorTypesRegistryProvider } from '../kibana_services';

const { uiModules } = getServices();

uiModules
.get('kibana/directive', ['ngSanitize'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

import React from 'react';
import ReactDOM from 'react-dom';
import { Embeddable, EmbeddableOutput } from '../../../../../../plugins/embeddable/public';

import { Embeddable, EmbeddableOutput } from '../kibana_services';
import { DisabledLabVisualization } from './disabled_lab_visualization';
import { VisualizeInput } from './visualize_embeddable';
import { VISUALIZE_EMBEDDABLE_TYPE } from './constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
* under the License.
*/

import chrome from 'ui/chrome';
import { StaticIndexPattern, getFromSavedObject } from 'ui/index_patterns';
import { VisSavedObject } from 'ui/visualize/loader/types';
import {
getServices,
getFromSavedObject,
StaticIndexPattern,
VisSavedObject,
} from '../kibana_services';

const { savedObjectsClient, uiSettings } = getServices();

export async function getIndexPattern(
savedVis: VisSavedObject
Expand All @@ -28,9 +33,7 @@ export async function getIndexPattern(
return savedVis.vis.indexPattern;
}

const config = chrome.getUiSettingsClient();
const savedObjectsClient = chrome.getSavedObjectsClient();
const defaultIndex = config.get('defaultIndex');
const defaultIndex = uiSettings.get('defaultIndex');

if (savedVis.vis.params.index_pattern) {
const indexPatternObjects = await savedObjectsClient.find({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,27 @@
*/

import _ from 'lodash';
import { StaticIndexPattern } from 'ui/index_patterns';
import { PersistedState } from 'ui/persisted_state';
import { VisualizeLoader } from 'ui/visualize/loader';
import { EmbeddedVisualizeHandler } from 'ui/visualize/loader/embedded_visualize_handler';
import { AppState } from 'ui/state_management/app_state';
import {
VisSavedObject,
VisualizeLoaderParams,
VisualizeUpdateParams,
} from 'ui/visualize/loader/types';
import { Subscription } from 'rxjs';
import * as Rx from 'rxjs';
import { Filter } from '@kbn/es-query';
import { TimeRange, onlyDisabledFiltersChanged } from '../../../../../../plugins/data/public';
import { Query } from '../../../../data/public';
import { VISUALIZE_EMBEDDABLE_TYPE } from './constants';

import {
AppState,
Container,
Embeddable,
EmbeddableInput,
EmbeddableOutput,
Embeddable,
Container,
} from '../../../../../../plugins/embeddable/public';
import { Query } from '../../../../data/public';
import { VISUALIZE_EMBEDDABLE_TYPE } from './constants';
PersistedState,
StaticIndexPattern,
VisSavedObject,
VisualizeLoader,
VisualizeLoaderParams,
VisualizeUpdateParams,
} from '../kibana_services';

const getKeys = <T extends {}>(o: T): Array<keyof T> => Object.keys(o) as Array<keyof T>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,37 @@
* under the License.
*/

import 'ui/registry/field_formats';
import 'uiExports/contextMenuActions';
import 'uiExports/devTools';
import 'uiExports/docViews';
import 'uiExports/embeddableFactories';
import 'uiExports/embeddableActions';
import 'uiExports/fieldFormatEditors';
import 'uiExports/fieldFormats';
import 'uiExports/home';
import 'uiExports/indexManagement';
import 'uiExports/inspectorViews';
import 'uiExports/savedObjectTypes';
import 'uiExports/search';
import 'uiExports/shareContextMenuExtensions';
import 'uiExports/visEditorTypes';
import 'uiExports/visTypes';
import 'uiExports/visualize';

import { i18n } from '@kbn/i18n';

import { capabilities } from 'ui/capabilities';

import chrome from 'ui/chrome';
import { getVisualizeLoader } from 'ui/visualize/loader';

import { Legacy } from 'kibana';

import { SavedObjectAttributes } from 'kibana/server';
import { npSetup } from 'ui/new_platform';
import {
EmbeddableFactory,
ErrorEmbeddable,
Container,
EmbeddableOutput,
} from '../../../../../../plugins/embeddable/public';
import { start as visualizations } from '../../../../visualizations/public/np_ready/public/legacy';
import { showNewVisModal } from '../wizard';
import { SavedVisualizations } from '../types';
import { DisabledLabEmbeddable } from './disabled_lab_embeddable';
import { getIndexPattern } from './get_index_pattern';
import { VisualizeEmbeddable, VisualizeInput, VisualizeOutput } from './visualize_embeddable';
import { VISUALIZE_EMBEDDABLE_TYPE } from './constants';
import { TypesStart } from '../../../../visualizations/public/np_ready/public/types';
import { VisSavedObject } from '../../../../../ui/public/visualize/loader/types';

import {
getServices,
Container,
EmbeddableFactory,
EmbeddableOutput,
ErrorEmbeddable,
getVisualizeLoader,
VisSavedObject,
} from '../kibana_services';

const {
addBasePath,
capabilities,
embeddable,
getInjector,
uiSettings,
visualizations,
} = getServices();

interface VisualizationAttributes extends SavedObjectAttributes {
visState: string;
Expand Down Expand Up @@ -110,7 +97,7 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
if (!visType) {
return false;
}
if (chrome.getUiSettingsClient().get('visualize:enableLabs')) {
if (uiSettings.get('visualize:enableLabs')) {
return true;
}
return visType.stage !== 'experimental';
Expand All @@ -122,7 +109,7 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
}

public isEditable() {
return capabilities.get().visualize.save as boolean;
return capabilities.visualize.save as boolean;
}

public getDisplayName() {
Expand All @@ -136,16 +123,14 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
input: Partial<VisualizeInput> & { id: string },
parent?: Container
): Promise<VisualizeEmbeddable | ErrorEmbeddable | DisabledLabEmbeddable> {
const $injector = await chrome.dangerouslyGetActiveInjector();
const $injector = await getInjector();
const config = $injector.get<Legacy.KibanaConfig>('config');
const savedVisualizations = $injector.get<SavedVisualizations>('savedVisualizations');

try {
const visId = savedObject.id as string;

const editUrl = visId
? chrome.addBasePath(`/app/kibana${savedVisualizations.urlFor(visId)}`)
: '';
const editUrl = visId ? addBasePath(`/app/kibana${savedVisualizations.urlFor(visId)}`) : '';
const loader = await getVisualizeLoader();
const isLabsEnabled = config.get<boolean>('visualize:enableLabs');

Expand Down Expand Up @@ -179,7 +164,7 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
input: Partial<VisualizeInput> & { id: string },
parent?: Container
): Promise<VisualizeEmbeddable | ErrorEmbeddable | DisabledLabEmbeddable> {
const $injector = await chrome.dangerouslyGetActiveInjector();
const $injector = await getInjector();
const savedVisualizations = $injector.get<SavedVisualizations>('savedVisualizations');

try {
Expand All @@ -206,8 +191,5 @@ export class VisualizeEmbeddableFactory extends EmbeddableFactory<
}

VisualizeEmbeddableFactory.createVisualizeEmbeddableFactory().then(embeddableFactory => {
npSetup.plugins.embeddable.registerEmbeddableFactory(
VISUALIZE_EMBEDDABLE_TYPE,
embeddableFactory
);
embeddable.registerEmbeddableFactory(VISUALIZE_EMBEDDABLE_TYPE, embeddableFactory);
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import React, { Fragment, PureComponent } from 'react';
import { EuiButton, EuiHorizontalRule, EuiSpacer } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { ELASTIC_WEBSITE_URL, DOC_LINK_VERSION } from 'ui/documentation_links';

import { getServices } from '../kibana_services';

const { docLinks } = getServices();

export class HelpMenu extends PureComponent {
render() {
Expand All @@ -31,7 +34,7 @@ export class HelpMenu extends PureComponent {
<EuiButton
fill
iconType="popout"
href={`${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/visualize.html`}
href={`${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/visualize.html`}
target="_blank"
>
<FormattedMessage id="kbn.visualize.helpMenu.docLabel" defaultMessage="Visualize documentation" />
Expand Down
Loading