Skip to content

Commit

Permalink
Merge branch 'master' into stabilize_dfa_clone_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticmachine authored Mar 23, 2020
2 parents fe19503 + afd1179 commit 3552146
Show file tree
Hide file tree
Showing 12 changed files with 65 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 @@ -24,8 +24,6 @@ import angular from 'angular';
import { EuiIcon } from '@elastic/eui';
import { i18nDirective, i18nFilter, I18nProvider } from '@kbn/i18n/angular';
import { CoreStart, LegacyCoreStart } from 'kibana/public';
// @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 @@ -59,7 +57,6 @@ import { createRenderCompleteDirective } from './np_ready/angular/directives/ren
import {
initAngularBootstrap,
configureAppAngularModule,
IPrivate,
KbnAccessibleClickProvider,
PrivateProvider,
PromiseServiceCreator,
Expand Down Expand Up @@ -106,7 +103,6 @@ export function initializeInnerAngularModule(
createLocalI18nModule();
createLocalPrivateModule();
createLocalPromiseModule();
createLocalKbnUrlModule();
createLocalTopNavModule(navigation);
createLocalStorageModule();
createElasticSearchModule(data);
Expand Down Expand Up @@ -166,12 +162,6 @@ export function initializeInnerAngularModule(
.service('debounce', ['$timeout', DebounceProviderTimeout]);
}

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

function createLocalPromiseModule() {
angular.module('discoverPromise', []).service('Promise', PromiseServiceCreator);
}
Expand Down Expand Up @@ -223,7 +213,7 @@ function createPagerFactoryModule() {

function createDocTableModule() {
angular
.module('discoverDocTable', ['discoverKbnUrl', 'discoverPagerFactory', 'react'])
.module('discoverDocTable', ['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 @@ -184,7 +184,6 @@ function discoverController(
$timeout,
$window,
Promise,
kbnUrl,
localStorage,
uiCapabilities
) {
Expand Down Expand Up @@ -255,6 +254,15 @@ function discoverController(
}
});

// this listener is waiting for such a path http://localhost:5601/app/kibana#/discover
// which could be set through pressing "New" button in top nav or go to "Discover" plugin from the sidebar
// to reload the page in a right way
const unlistenHistoryBasePath = history.listen(({ pathname, search, hash }) => {
if (!search && !hash && pathname === '/discover') {
$route.reload();
}
});

$scope.setIndexPattern = async id => {
await replaceUrlAppState({ index: id });
$route.reload();
Expand Down Expand Up @@ -310,6 +318,7 @@ function discoverController(
stopStateSync();
stopSyncingGlobalStateWithUrl();
stopSyncingQueryAppStateWithStateContainer();
unlistenHistoryBasePath();
});

const getTopNavLinks = () => {
Expand All @@ -323,7 +332,7 @@ function discoverController(
}),
run: function() {
$scope.$evalAsync(() => {
kbnUrl.change('/discover');
history.push('/discover');
});
},
testId: 'discoverNewButton',
Expand Down Expand Up @@ -391,9 +400,7 @@ function discoverController(
testId: 'discoverOpenButton',
run: () => {
showOpenSearchPanel({
makeUrl: searchId => {
return kbnUrl.eval('#/discover/{{id}}', { id: searchId });
},
makeUrl: searchId => `#/discover/${encodeURIComponent(searchId)}`,
I18nContext: core.i18n.Context,
});
},
Expand Down Expand Up @@ -751,7 +758,7 @@ function discoverController(
});

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

$scope.resetQuery = function() {
kbnUrl.change('/discover/{{id}}', { id: $route.current.params.id });
history.push(`/discover/${encodeURIComponent($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 @@ -41,11 +41,7 @@ interface LazyScope extends ng.IScope {
[key: string]: any;
}

export function createTableRowDirective(
$compile: ng.ICompileService,
$httpParamSerializer: any,
kbnUrl: any
) {
export function createTableRowDirective($compile: ng.ICompileService, $httpParamSerializer: any) {
const cellTemplate = _.template(noWhiteSpace(cellTemplateHtml));
const truncateByHeightTemplate = _.template(noWhiteSpace(truncateByHeightTemplateHtml));

Expand Down Expand Up @@ -110,10 +106,9 @@ 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/${encodeURIComponent(
$scope.indexPattern.id
)}/${encodeURIComponent($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 3552146

Please sign in to comment.