Skip to content

Commit

Permalink
Remove kbnUrl usages from disciver/dashboard/visualize
Browse files Browse the repository at this point in the history
  • Loading branch information
sulemanof committed Mar 19, 2020
1 parent 965679a commit 213c746
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,9 @@
*/

export { npSetup, npStart } from 'ui/new_platform';

export { KbnUrl } from 'ui/url/kbn_url';
// @ts-ignore
export { KbnUrlProvider } from 'ui/url/index';
export { IInjector } from 'ui/chrome';
export { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url';
export {
configureAppAngularModule,
IPrivate,
migrateLegacyQuery,
PrivateProvider,
PromiseServiceCreator,
subscribeWithScope,
} from '../../../../../plugins/kibana_legacy/public';
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,7 @@ import {
PluginInitializerContext,
} from 'kibana/public';
import { Storage } from '../../../../../../plugins/kibana_utils/public';
import {
configureAppAngularModule,
IPrivate,
KbnUrlProvider,
PrivateProvider,
PromiseServiceCreator,
} from '../legacy_imports';
import { configureAppAngularModule } from '../legacy_imports';
// @ts-ignore
import { initDashboardApp } from './legacy_app';
import { EmbeddableStart } from '../../../../../../plugins/embeddable/public';
Expand Down Expand Up @@ -116,21 +110,15 @@ function mountDashboardApp(appBasePath: string, element: HTMLElement) {

function createLocalAngularModule(core: AppMountContext['core'], navigation: NavigationStart) {
createLocalI18nModule();
createLocalPrivateModule();
createLocalPromiseModule();
createLocalConfigModule(core);
createLocalKbnUrlModule();
createLocalTopNavModule(navigation);
createLocalIconModule();

const dashboardAngularModule = angular.module(moduleName, [
...thirdPartyAngularDependencies,
'app/dashboard/Config',
'app/dashboard/I18n',
'app/dashboard/Private',
'app/dashboard/TopNav',
'app/dashboard/KbnUrl',
'app/dashboard/Promise',
'app/dashboard/icon',
]);
return dashboardAngularModule;
Expand All @@ -142,14 +130,8 @@ function createLocalIconModule() {
.directive('icon', reactDirective => reactDirective(EuiIcon));
}

function createLocalKbnUrlModule() {
angular
.module('app/dashboard/KbnUrl', ['app/dashboard/Private', 'ngRoute'])
.service('kbnUrl', (Private: IPrivate) => Private(KbnUrlProvider));
}

function createLocalConfigModule(core: AppMountContext['core']) {
angular.module('app/dashboard/Config', ['app/dashboard/Private']).provider('config', () => {
angular.module('app/dashboard/Config', []).provider('config', () => {
return {
$get: () => ({
get: core.uiSettings.get.bind(core.uiSettings),
Expand All @@ -158,14 +140,6 @@ function createLocalConfigModule(core: AppMountContext['core']) {
});
}

function createLocalPromiseModule() {
angular.module('app/dashboard/Promise', []).service('Promise', PromiseServiceCreator);
}

function createLocalPrivateModule() {
angular.module('app/dashboard/Private', []).provider('Private', PrivateProvider);
}

function createLocalTopNavModule(navigation: NavigationStart) {
angular
.module('app/dashboard/TopNav', ['react'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import moment from 'moment';
import { Subscription } from 'rxjs';
import { History } from 'history';

import { IInjector } from '../legacy_imports';

import { ViewMode } from '../../../../embeddable_api/public/np_ready/public';
import { SavedObjectDashboard } from '../saved_dashboard/saved_dashboard';
import { DashboardAppState, SavedDashboardPanel } from './types';
Expand Down Expand Up @@ -86,28 +84,26 @@ export interface DashboardAppScope extends ng.IScope {
}

export function initDashboardAppDirective(app: any, deps: RenderDeps) {
app.directive('dashboardApp', function($injector: IInjector) {
return {
restrict: 'E',
controllerAs: 'dashboardApp',
controller: (
$scope: DashboardAppScope,
$route: any,
$routeParams: {
id?: string;
},
kbnUrlStateStorage: IKbnUrlStateStorage,
history: History
) =>
new DashboardAppController({
$route,
$scope,
$routeParams,
indexPatterns: deps.data.indexPatterns,
kbnUrlStateStorage,
history,
...deps,
}),
};
});
app.directive('dashboardApp', () => ({
restrict: 'E',
controllerAs: 'dashboardApp',
controller: (
$scope: DashboardAppScope,
$route: any,
$routeParams: {
id?: string;
},
kbnUrlStateStorage: IKbnUrlStateStorage,
history: History
) =>
new DashboardAppController({
$route,
$scope,
$routeParams,
indexPatterns: deps.data.indexPatterns,
kbnUrlStateStorage,
history,
...deps,
}),
}));
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { i18n } from '@kbn/i18n';
import { parse } from 'query-string';

import dashboardTemplate from './dashboard_app.html';
import dashboardListingTemplate from './listing/dashboard_listing_ng_wrapper.html';
Expand Down Expand Up @@ -93,9 +94,8 @@ export function initDashboardApp(app, deps) {
.when(DashboardConstants.LANDING_PAGE_PATH, {
...defaults,
template: dashboardListingTemplate,
controller($injector, $location, $scope, kbnUrlStateStorage) {
controller($scope, kbnUrlStateStorage, history) {
const service = deps.savedDashboards;
const kbnUrl = $injector.get('kbnUrl');
const dashboardConfig = deps.dashboardConfig;

// syncs `_g` portion of url with query services
Expand All @@ -106,13 +106,13 @@ export function initDashboardApp(app, deps) {

$scope.listingLimit = deps.uiSettings.get('savedObjects:listingLimit');
$scope.create = () => {
kbnUrl.redirect(DashboardConstants.CREATE_NEW_DASHBOARD_URL);
history.push(DashboardConstants.CREATE_NEW_DASHBOARD_URL);
};
$scope.find = search => {
return service.find(search, $scope.listingLimit);
};
$scope.editItem = ({ id }) => {
kbnUrl.redirect(`${createDashboardEditUrl(id)}?_a=(viewMode:edit)`);
history.push(`${createDashboardEditUrl(id)}?_a=(viewMode:edit)`);
};
$scope.getViewUrl = ({ id }) => {
return deps.addBasePath(`#${createDashboardEditUrl(id)}`);
Expand All @@ -121,7 +121,7 @@ export function initDashboardApp(app, deps) {
return service.delete(dashboards.map(d => d.id));
};
$scope.hideWriteControls = dashboardConfig.getHideWriteControls();
$scope.initialFilter = $location.search().filter || EMPTY_FILTER;
$scope.initialFilter = parse(history.location.search).filter || EMPTY_FILTER;
deps.chrome.setBreadcrumbs([
{
text: i18n.translate('kbn.dashboard.dashboardBreadcrumbsTitle', {
Expand Down Expand Up @@ -191,7 +191,7 @@ export function initDashboardApp(app, deps) {
template: dashboardTemplate,
controller: createNewDashboardCtrl,
resolve: {
dash: function($route, kbnUrl, history) {
dash: function($route, history) {
const id = $route.current.params.id;

return ensureDefaultIndexPattern(deps.core, deps.data, history)
Expand All @@ -208,7 +208,7 @@ export function initDashboardApp(app, deps) {
// A corrupt dashboard was detected (e.g. with invalid JSON properties)
if (error instanceof InvalidJSONProperty) {
deps.core.notifications.toasts.addDanger(error.message);
kbnUrl.redirect(DashboardConstants.LANDING_PAGE_PATH);
history.push(DashboardConstants.LANDING_PAGE_PATH);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ import { i18nDirective, i18nFilter, I18nProvider } from '@kbn/i18n/angular';
import { CoreStart, LegacyCoreStart, IUiSettingsClient } from 'kibana/public';
// @ts-ignore
import { StateManagementConfigProvider } from 'ui/state_management/config_provider';
// @ts-ignore
import { KbnUrlProvider } from 'ui/url';
import { DataPublicPluginStart } from '../../../../../plugins/data/public';
import { Storage } from '../../../../../plugins/kibana_utils/public';
import { NavigationPublicPluginStart as NavigationStart } from '../../../../../plugins/navigation/public';
Expand Down Expand Up @@ -61,7 +59,6 @@ import { createRenderCompleteDirective } from './np_ready/angular/directives/ren
import {
initAngularBootstrap,
configureAppAngularModule,
IPrivate,
KbnAccessibleClickProvider,
PrivateProvider,
PromiseServiceCreator,
Expand Down Expand Up @@ -109,7 +106,6 @@ export function initializeInnerAngularModule(
createLocalPrivateModule();
createLocalPromiseModule();
createLocalConfigModule(core.uiSettings);
createLocalKbnUrlModule();
createLocalTopNavModule(navigation);
createLocalStorageModule();
createElasticSearchModule(data);
Expand Down Expand Up @@ -170,12 +166,6 @@ export function initializeInnerAngularModule(
.service('debounce', ['$timeout', DebounceProviderTimeout]);
}

function createLocalKbnUrlModule() {
angular
.module('discoverKbnUrl', ['discoverPrivate', 'ngRoute'])
.service('kbnUrl', (Private: IPrivate) => Private(KbnUrlProvider));
}

function createLocalConfigModule(uiSettings: IUiSettingsClient) {
angular
.module('discoverConfig', ['discoverPrivate'])
Expand Down Expand Up @@ -242,12 +232,7 @@ function createPagerFactoryModule() {

function createDocTableModule() {
angular
.module('discoverDocTable', [
'discoverKbnUrl',
'discoverConfig',
'discoverPagerFactory',
'react',
])
.module('discoverDocTable', ['discoverConfig', 'discoverPagerFactory', 'react'])
.directive('docTable', createDocTableDirective)
.directive('kbnTableHeader', createTableHeaderDirective)
.directive('toolBarPagerText', createToolBarPagerTextDirective)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ function discoverController(
$window,
Promise,
config,
kbnUrl,
localStorage,
uiCapabilities
) {
Expand Down Expand Up @@ -324,7 +323,7 @@ function discoverController(
}),
run: function() {
$scope.$evalAsync(() => {
kbnUrl.change('/discover');
history.push('/discover');
});
},
testId: 'discoverNewButton',
Expand Down Expand Up @@ -392,9 +391,7 @@ function discoverController(
testId: 'discoverOpenButton',
run: () => {
showOpenSearchPanel({
makeUrl: searchId => {
return kbnUrl.eval('#/discover/{{id}}', { id: searchId });
},
makeUrl: searchId => `#/discover/${searchId}`,
I18nContext: core.i18n.Context,
});
},
Expand Down Expand Up @@ -752,7 +749,7 @@ function discoverController(
});

if (savedSearch.id !== $route.current.params.id) {
kbnUrl.change('/discover/{{id}}', { id: savedSearch.id });
history.push(`/discover/${savedSearch.id}`);
} else {
// Update defaults so that "reload saved query" functions correctly
setAppState(getStateDefaults());
Expand Down Expand Up @@ -922,11 +919,11 @@ function discoverController(
};

$scope.resetQuery = function() {
kbnUrl.change('/discover/{{id}}', { id: $route.current.params.id });
history.push(`/discover/${$route.current.params.id}`);
};

$scope.newQuery = function() {
kbnUrl.change('/discover');
history.push('/discover');
};

$scope.updateDataSource = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ interface LazyScope extends ng.IScope {
export function createTableRowDirective(
$compile: ng.ICompileService,
$httpParamSerializer: any,
kbnUrl: any,
config: IUiSettingsClient
) {
const cellTemplate = _.template(noWhiteSpace(cellTemplateHtml));
Expand Down Expand Up @@ -112,10 +111,7 @@ export function createTableRowDirective(
};

$scope.getContextAppHref = () => {
const path = kbnUrl.eval('#/discover/context/{{ indexPattern }}/{{ anchorId }}', {
anchorId: $scope.row._id,
indexPattern: $scope.indexPattern.id,
});
const path = `#/discover/context/${$scope.indexPattern.id}/${$scope.row._id}`;
const globalFilters: any = getServices().filterManager.getGlobalFilters();
const appFilters: any = getServices().filterManager.getAppFilters();
const hash = $httpParamSerializer({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,13 @@
* directly where they are needed.
*/

// @ts-ignore
export { KbnUrlProvider } from 'ui/url';
export { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url';
export { KibanaParsedUrl } from 'ui/url/kibana_parsed_url';
export { wrapInI18nContext } from 'ui/i18n';
export { DashboardConstants } from '../dashboard/np_ready/dashboard_constants';
export { VisSavedObject, VISUALIZE_EMBEDDABLE_TYPE } from '../../../visualizations/public/';
export {
configureAppAngularModule,
IPrivate,
migrateLegacyQuery,
PrivateProvider,
PromiseServiceCreator,
subscribeWithScope,
} from '../../../../../plugins/kibana_legacy/public';
Loading

0 comments on commit 213c746

Please sign in to comment.