Skip to content

Commit

Permalink
[Discover] Migrate angular routing to react router (#107042)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maja Grubic authored Aug 30, 2021
1 parent 079fc9a commit a4c0c1c
Show file tree
Hide file tree
Showing 36 changed files with 733 additions and 360 deletions.
4 changes: 4 additions & 0 deletions src/plugins/discover/public/__mocks__/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const discoverServiceMock = ({
location: {
search: '',
},
listen: jest.fn(),
}),
data: dataPlugin,
docLinks: docLinksServiceMock.createStartContract(),
Expand Down Expand Up @@ -68,6 +69,9 @@ export const discoverServiceMock = ({
return true;
},
},
http: {
basePath: '/',
},
indexPatternFieldEditor: {
openEditor: jest.fn(),
userPermissions: {
Expand Down
5 changes: 0 additions & 5 deletions src/plugins/discover/public/application/angular/context.html

This file was deleted.

43 changes: 0 additions & 43 deletions src/plugins/discover/public/application/angular/context.js

This file was deleted.

112 changes: 4 additions & 108 deletions src/plugins/discover/public/application/angular/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,106 +6,14 @@
* Side Public License, v 1.
*/

import { i18n } from '@kbn/i18n';
import { getState } from '../apps/main/services/discover_state';
import indexTemplateLegacy from './discover_legacy.html';
import {
getAngularModule,
getServices,
getUrlTracker,
redirectWhenMissing,
} from '../../kibana_services';
import { getRootBreadcrumbs, getSavedSearchBreadcrumbs } from '../helpers/breadcrumbs';
import { loadIndexPattern, resolveIndexPattern } from '../apps/main/utils/resolve_index_pattern';
import { getAngularModule, getServices } from '../../kibana_services';

const services = getServices();

const {
core,
capabilities,
chrome,
data,
history: getHistory,
toastNotifications,
uiSettings: config,
} = getServices();
const { history: getHistory } = getServices();

const app = getAngularModule();

app.config(($routeProvider) => {
const defaults = {
requireDefaultIndex: true,
requireUICapability: 'discover.show',
k7Breadcrumbs: ($route, $injector) =>
$injector.invoke($route.current.params.id ? getSavedSearchBreadcrumbs : getRootBreadcrumbs),
badge: () => {
if (capabilities.discover.save) {
return undefined;
}

return {
text: i18n.translate('discover.badge.readOnly.text', {
defaultMessage: 'Read only',
}),
tooltip: i18n.translate('discover.badge.readOnly.tooltip', {
defaultMessage: 'Unable to save searches',
}),
iconType: 'glasses',
};
},
};
const discoverRoute = {
...defaults,
template: indexTemplateLegacy,
reloadOnSearch: false,
resolve: {
savedObjects: function ($route, Promise) {
const history = getHistory();
const savedSearchId = $route.current.params.id;
return data.indexPatterns.ensureDefaultIndexPattern(history).then(() => {
const { appStateContainer } = getState({ history, uiSettings: config });
const { index } = appStateContainer.getState();
return Promise.props({
ip: loadIndexPattern(index, data.indexPatterns, config),
savedSearch: getServices()
.getSavedSearchById(savedSearchId)
.then((savedSearch) => {
if (savedSearchId) {
chrome.recentlyAccessed.add(
savedSearch.getFullPath(),
savedSearch.title,
savedSearchId
);
}
return savedSearch;
})
.catch(
redirectWhenMissing({
history,
navigateToApp: core.application.navigateToApp,
mapping: {
search: '/',
'index-pattern': {
app: 'management',
path: `kibana/objects/savedSearches/${$route.current.params.id}`,
},
},
toastNotifications,
onBeforeRedirect() {
getUrlTracker().setTrackedUrl('/');
},
})
),
});
});
},
},
};

$routeProvider.when('/view/:id?', discoverRoute);
$routeProvider.when('/', discoverRoute);
});

app.directive('discoverApp', function () {
return {
restrict: 'E',
Expand All @@ -114,30 +22,18 @@ app.directive('discoverApp', function () {
};
});

function discoverController($route, $scope) {
const savedSearch = $route.current.locals.savedObjects.savedSearch;
$scope.indexPattern = resolveIndexPattern(
$route.current.locals.savedObjects.ip,
savedSearch.searchSource,
toastNotifications
);

function discoverController(_, $scope) {
const history = getHistory();

$scope.opts = {
savedSearch,
history,
services,
indexPatternList: $route.current.locals.savedObjects.ip.list,
navigateTo: (path) => {
$scope.$evalAsync(() => {
history.push(path);
});
},
};

$scope.$on('$destroy', () => {
savedSearch.destroy();
data.search.session.clear();
});
$scope.$on('$destroy', () => {});
}
8 changes: 0 additions & 8 deletions src/plugins/discover/public/application/angular/doc.html

This file was deleted.

61 changes: 0 additions & 61 deletions src/plugins/discover/public/application/angular/doc.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import 'angular-sanitize';
import { EuiIcon } from '@elastic/eui';
import { i18nDirective, i18nFilter, I18nProvider } from '@kbn/i18n/angular';
import { CoreStart, PluginInitializerContext } from 'kibana/public';
import { DataPublicPluginStart } from '../../../../data/public';
import { DataPublicPluginStart } from 'src/plugins/data/public';
import { Storage } from '../../../../kibana_utils/public';
import { NavigationPublicPluginStart as NavigationStart } from '../../../../navigation/public';
import { createContextAppLegacy } from '../components/context_app/context_app_legacy_directive';
Expand All @@ -30,7 +30,6 @@ import {
import { PromiseServiceCreator } from './helpers';
import { DiscoverStartPlugins } from '../../plugin';
import { getScopedHistory } from '../../kibana_services';
import { createDiscoverDirective } from './create_discover_directive';

/**
* returns the main inner angular module, it contains all the parts of Angular Discover
Expand Down Expand Up @@ -94,7 +93,6 @@ export function initializeInnerAngularModule(
return angular
.module(name, [
'ngSanitize',
'ngRoute',
'react',
'ui.bootstrap',
'discoverI18n',
Expand All @@ -104,8 +102,7 @@ export function initializeInnerAngularModule(
'discoverDocTable',
])
.config(watchMultiDecorator)
.run(registerListenEventListener)
.directive('discover', createDiscoverDirective);
.run(registerListenEventListener);
}

function createLocalPromiseModule() {
Expand Down
4 changes: 0 additions & 4 deletions src/plugins/discover/public/application/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

// required for i18nIdDirective
import 'angular-sanitize';
// required for ngRoute
import 'angular-route';

import './discover';
import './doc';
import './context';
import './redirect';
29 changes: 0 additions & 29 deletions src/plugins/discover/public/application/angular/redirect.ts

This file was deleted.

Loading

0 comments on commit a4c0c1c

Please sign in to comment.