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

[Discover] Migrate angular routing to react router #107042

Merged
merged 60 commits into from
Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
da87505
[Discover] Always show multifields if reading from source
majagrubic Jul 13, 2021
dd8bd6b
Add a unit test
majagrubic Jul 13, 2021
da89edc
Merge branch 'master' into react-router-1
majagrubic Jul 14, 2021
fc1deeb
[Discover] Add React router: initial commit
majagrubic Jul 27, 2021
729641e
Add breadcrumbs
majagrubic Jul 27, 2021
d4f5705
Add doc route
majagrubic Jul 28, 2021
61ba18b
Add badge for readonly
majagrubic Jul 28, 2021
0c3f427
Remove unused import
majagrubic Jul 28, 2021
3f4438f
Merge master
majagrubic Jul 28, 2021
2ad5f68
Remove invalid leftover
majagrubic Jul 28, 2021
8b7fb8e
Add missing route
majagrubic Jul 28, 2021
bf3e9c2
Fix typescript failure
majagrubic Jul 29, 2021
b470dec
Merge branch 'master' into react-router-1
majagrubic Jul 29, 2021
a047241
Fix unmounting issue
majagrubic Jul 29, 2021
2746c2b
Fix typescript error
majagrubic Jul 29, 2021
f722b71
Remove unused variable
majagrubic Jul 29, 2021
cce81bc
Fix linting errors
majagrubic Jul 30, 2021
19f3a0d
Reload context if anchorId changes
majagrubic Jul 30, 2021
87cb6ea
Fix DOM structure
majagrubic Jul 31, 2021
c0c2afb
Add index pattern list
majagrubic Jul 31, 2021
324ac82
Reload state from props
majagrubic Aug 3, 2021
2ab4860
Fix linting error
majagrubic Aug 3, 2021
a96a95a
Merge branch 'master' into react-router-1
majagrubic Aug 3, 2021
029b2cb
Merge branch 'master' into react-router-1
majagrubic Aug 4, 2021
4b124df
Applying Matthias's changes
majagrubic Aug 4, 2021
78ac177
Fix wrongly modified file
majagrubic Aug 4, 2021
0870c6f
Attempt at fixing imports?
majagrubic Aug 4, 2021
6aefd9a
Minor polish
majagrubic Aug 5, 2021
6d195af
Fix typescript issue
majagrubic Aug 5, 2021
5aaebd0
Fix one failing functional test
majagrubic Aug 10, 2021
25f363e
Applying Matthias's changes
majagrubic Aug 11, 2021
ac1ca7c
Merge master
majagrubic Aug 11, 2021
cc83751
Add loading spinner
majagrubic Aug 12, 2021
674ab80
Remove failing unit test
majagrubic Aug 12, 2021
f97fd03
Merge branch 'master' into react-router-1
kibanamachine Aug 12, 2021
6bb0768
Merge branch 'master' into react-router-1
kibanamachine Aug 12, 2021
e73b636
Add missing dependency
majagrubic Aug 12, 2021
bd5e2d7
Align indicator
majagrubic Aug 12, 2021
abe0d91
Fix linting error
majagrubic Aug 12, 2021
e832ab3
Merge branch 'master' into react-router-1
majagrubic Aug 13, 2021
e22ca4c
Merge branch 'master' into react-router-1
kibanamachine Aug 13, 2021
8f49789
Code cleanup
majagrubic Aug 13, 2021
eb888de
Merge branch 'react-router-1' of https://github.com/majagrubic/kibana…
majagrubic Aug 13, 2021
0599dde
Fix typescript error
majagrubic Aug 13, 2021
f4c2cde
Refactoring and testing
majagrubic Aug 13, 2021
4216b15
Fix typescript error
majagrubic Aug 13, 2021
f630582
Merge branch 'master' into react-router-1
kibanamachine Aug 17, 2021
bfe7a29
Cleanup
majagrubic Aug 18, 2021
9543992
Merge branch 'master' into react-router-1
majagrubic Aug 18, 2021
7a51331
cleanup of discover state
majagrubic Aug 18, 2021
ab0f42c
Merge branch 'master' into react-router-1
kibanamachine Aug 18, 2021
d349ebe
Merge branch 'master' into react-router-1
majagrubic Aug 20, 2021
c0cf063
Addressing PR comments
majagrubic Aug 20, 2021
d282794
Merge branch 'master' into react-router-1
kibanamachine Aug 23, 2021
8f3789c
Merge branch 'master' into react-router-1
majagrubic Aug 25, 2021
ef007f7
Fix breadcrumb issue
majagrubic Aug 25, 2021
8b8d494
Index pattern loading hook
majagrubic Aug 25, 2021
ddd62ff
Merge branch 'master' into react-router-1
kibanamachine Aug 26, 2021
fe0aebb
Fix issue with not preserving state
majagrubic Aug 26, 2021
2654abe
Merge branch 'master' into react-router-1
kibanamachine Aug 30, 2021
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
3 changes: 3 additions & 0 deletions src/plugins/discover/public/__mocks__/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,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.

Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { DiscoverMainApp } from '../apps/main';
import { DiscoverMainRoute } from '../apps/main';
kertal marked this conversation as resolved.
Show resolved Hide resolved

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function createDiscoverDirective(reactDirective: any) {
return reactDirective(DiscoverMainApp, [
return reactDirective(DiscoverMainRoute, [
['indexPattern', { watchDepth: 'reference' }],
['opts', { watchDepth: 'reference' }],
]);
Expand Down
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) {
kertal marked this conversation as resolved.
Show resolved Hide resolved
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';
kertal marked this conversation as resolved.
Show resolved Hide resolved
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
3 changes: 0 additions & 3 deletions src/plugins/discover/public/application/angular/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@

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

import './discover';
import './doc';
import './context';
import './redirect';
kertal marked this conversation as resolved.
Show resolved Hide resolved
29 changes: 0 additions & 29 deletions src/plugins/discover/public/application/angular/redirect.ts

This file was deleted.

Loading