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

Remove kibana.defaultAppId setting #109798

Merged
merged 17 commits into from
Sep 3, 2021
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
6 changes: 0 additions & 6 deletions docs/setup/settings.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,6 @@ is an alternative to `elasticsearch.username` and `elasticsearch.password`.
| `interpreter.enableInVisualize`
| Enables use of interpreter in Visualize. *Default: `true`*

| `kibana.defaultAppId:`
| deprecated:[7.9.0,This setting will be removed in Kibana 8.0.]
Instead, use the <<defaultroute,`defaultRoute` advanced setting>>.
+
The default application to load. *Default: `"home"`*

|[[kibana-index]] `kibana.index:`
| deprecated:[7.11.0,This setting will be removed in 8.0.] Multitenancy by
changing `kibana.index` will not be supported starting in 8.0. See
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ kibana_vars=(
interpreter.enableInVisualize
kibana.autocompleteTerminateAfter
kibana.autocompleteTimeout
kibana.defaultAppId
kibana.index
logging.appenders
logging.appenders.console
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ export function NotFoundRoute(props: NotFoundRouteProps) {
useEffect(() => {
const path = window.location.hash.substr(1);
getUrlTracker().restorePreviousUrl();
const { navigated } = urlForwarding.navigateToLegacyKibanaUrl(path);
if (!navigated) {
urlForwarding.navigateToDefaultApp();
}
urlForwarding.navigateToLegacyKibanaUrl(path);

const bannerMessage = i18n.translate('discover.noMatchRoute.bannerTitleText', {
defaultMessage: 'Page not found',
Expand Down
13 changes: 2 additions & 11 deletions src/plugins/home/public/application/components/home_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,10 @@ import PropTypes from 'prop-types';
import { Home } from './home';
import { TutorialDirectory } from './tutorial_directory';
import { Tutorial } from './tutorial/tutorial';
import { HashRouter as Router, Switch, Route } from 'react-router-dom';
import { HashRouter as Router, Switch, Route, Redirect } from 'react-router-dom';
import { getTutorial } from '../load_tutorials';
import { replaceTemplateStrings } from './tutorial/replace_template_strings';
import { getServices } from '../kibana_services';
import useMount from 'react-use/lib/useMount';

const RedirectToDefaultApp = () => {
useMount(() => {
const { urlForwarding } = getServices();
urlForwarding.navigateToDefaultApp();
});
return null;
};

export function HomeApp({ directories, solutions }) {
const {
Expand Down Expand Up @@ -78,7 +69,7 @@ export function HomeApp({ directories, solutions }) {
hasUserIndexPattern={() => indexPatternService.hasUserIndexPattern()}
/>
</Route>
<Route path="*" exact={true} component={RedirectToDefaultApp} />
<Redirect to="/" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ This adds a redirect to the home page in case any unknown route has been entered. With the old logic the existing Route would have taken care of forwarding to the defaultAppId in this case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not redirect to defaultRoute set in uiSettings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question is: why would only the Home page do that in this case, and not ALL apps? I feel it's a bit weird, that something like /app/home#/fooobar would bring you to the default app, but /app/dashboard#/foobar wouldn't. Or we'd basically need to set this as an expactation to all apps, that if they can't find the route in their app they should forward to the default app, which sounds like a larger change to me. I am happy to rediscuss this behavior, but I think we should not make a special case JUST for the home app and nothing else, and in this case rather let every app handle their "unknown route" internally to do something reasonable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or we'd basically need to set this as an expactation to all apps, that if they can't find the route in their app they should forward to the default app, which sounds like a larger change to me.

agree. that sounds like a high-level policy.

</Switch>
</Router>
</I18nProvider>
Expand Down
21 changes: 1 addition & 20 deletions src/plugins/home/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
PluginInitializerContext,
} from 'kibana/public';
import { i18n } from '@kbn/i18n';
import { first } from 'rxjs/operators';

import {
EnvironmentService,
Expand Down Expand Up @@ -137,27 +136,9 @@ export class HomePublicPlugin
};
}

public start(
{ application: { capabilities, currentAppId$ }, http }: CoreStart,
{ urlForwarding }: HomePluginStartDependencies
) {
public start({ application: { capabilities } }: CoreStart) {
this.featuresCatalogueRegistry.start({ capabilities });

// If the home app is the initial location when loading Kibana...
if (
window.location.pathname === http.basePath.prepend(HOME_APP_BASE_PATH) &&
window.location.hash === ''
) {
// ...wait for the app to mount initially and then...
currentAppId$.pipe(first()).subscribe((appId) => {
if (appId === 'home') {
// ...navigate to default app set by `kibana.defaultAppId`.
// This doesn't do anything as along as the default settings are kept.
urlForwarding.navigateToDefaultApp({ overwriteHash: false });
}
});
}

return { featureCatalogue: this.featuresCatalogueRegistry };
}
}
Expand Down
15 changes: 0 additions & 15 deletions src/plugins/kibana_legacy/config.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/plugins/kibana_legacy/kibana.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "kibanaLegacy",
"version": "kibana",
"server": true,
"server": false,
"ui": true,
"owner": {
"name": "Vis Editors",
Expand Down
4 changes: 1 addition & 3 deletions src/plugins/kibana_legacy/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@
// TODO: https://github.com/elastic/kibana/issues/110891
/* eslint-disable @kbn/eslint/no_export_all */

import { PluginInitializerContext } from 'kibana/public';
import { KibanaLegacyPlugin } from './plugin';

export const plugin = (initializerContext: PluginInitializerContext) =>
new KibanaLegacyPlugin(initializerContext);
export const plugin = () => new KibanaLegacyPlugin();

export * from './plugin';

Expand Down
3 changes: 0 additions & 3 deletions src/plugins/kibana_legacy/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ export type Start = jest.Mocked<ReturnType<KibanaLegacyPlugin['start']>>;
const createSetupContract = (): Setup => ({});

const createStartContract = (): Start => ({
config: {
defaultAppId: 'home',
},
loadFontAwesome: jest.fn(),
loadAngularBootstrap: jest.fn(),
});
Expand Down
12 changes: 2 additions & 10 deletions src/plugins/kibana_legacy/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@
* Side Public License, v 1.
*/

import { PluginInitializerContext, CoreStart, CoreSetup } from 'kibana/public';
import { ConfigSchema } from '../config';
import { CoreStart, CoreSetup } from 'kibana/public';
import { injectHeaderStyle } from './utils/inject_header_style';

export class KibanaLegacyPlugin {
constructor(private readonly initializerContext: PluginInitializerContext<ConfigSchema>) {}

public setup(core: CoreSetup<{}, KibanaLegacyStart>) {
return {};
}

public start({ application, http: { basePath }, uiSettings }: CoreStart) {
public start({ uiSettings }: CoreStart) {
injectHeaderStyle(uiSettings);
return {
/**
Expand All @@ -35,11 +32,6 @@ export class KibanaLegacyPlugin {
const { initAngularBootstrap } = await import('./angular_bootstrap');
initAngularBootstrap();
},
/**
* @deprecated
* Just exported for wiring up with dashboard mode, should not be used.
*/
config: this.initializerContext.config.get(),
};
}
}
Expand Down
49 changes: 0 additions & 49 deletions src/plugins/kibana_legacy/server/index.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/plugins/url_forwarding/kibana.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
"owner": {
"name": "Vis Editors",
"githubTeam": "kibana-vis-editors"
},
"requiredPlugins": ["kibanaLegacy"]
}
}
54 changes: 54 additions & 0 deletions src/plugins/url_forwarding/public/forward_app/forward_app.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import type { Location } from 'history';
import type { AppMountParameters, CoreSetup, ScopedHistory } from 'kibana/public';
import { coreMock } from '../../../../core/public/mocks';
import type { UrlForwardingStart } from '../plugin';
import { createLegacyUrlForwardApp } from './forward_app';

function createAppMountParams(hash: string): AppMountParameters {
return {
history: {
location: {
hash,
} as Location<unknown>,
} as ScopedHistory,
} as AppMountParameters;
}

describe('forward_app', () => {
let coreSetup: CoreSetup<{}, UrlForwardingStart>;
let coreStart: ReturnType<typeof coreMock['createStart']>;

beforeEach(() => {
coreSetup = coreMock.createSetup({ basePath: '/base/path' });
coreStart = coreMock.createStart({ basePath: '/base/path' });
coreSetup.getStartServices = () => Promise.resolve([coreStart, {}, {} as any]);
});

it('should forward to defaultRoute if hash is not a known redirect', async () => {
coreStart.uiSettings.get.mockImplementation((key) => {
if (key === 'defaultRoute') return '/app/defaultApp';
throw new Error('Mock implementation missing');
});

const app = createLegacyUrlForwardApp(coreSetup, [
{ legacyAppId: 'discover', newAppId: 'discover', rewritePath: (p) => p },
]);
await app.mount(createAppMountParams('#/foobar'));
expect(coreStart.application.navigateToUrl).toHaveBeenCalledWith('/base/path/app/defaultApp');
});

it('should not forward to defaultRoute if hash path is a known redirect', async () => {
const app = createLegacyUrlForwardApp(coreSetup, [
{ legacyAppId: 'discover', newAppId: 'discover', rewritePath: (p) => p },
]);
await app.mount(createAppMountParams('#/discover'));
expect(coreStart.application.navigateToUrl).not.toHaveBeenCalled();
});
});
15 changes: 5 additions & 10 deletions src/plugins/url_forwarding/public/forward_app/forward_app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,18 @@ export const createLegacyUrlForwardApp = (
async mount(params: AppMountParameters) {
const hash = params.history.location.hash.substr(1);

if (!hash) {
const [, , kibanaLegacyStart] = await core.getStartServices();
kibanaLegacyStart.navigateToDefaultApp();
}

const [
{
application,
uiSettings,
http: { basePath },
},
] = await core.getStartServices();

const result = await navigateToLegacyKibanaUrl(hash, forwards, basePath, application);

if (!result.navigated) {
const [, , kibanaLegacyStart] = await core.getStartServices();
kibanaLegacyStart.navigateToDefaultApp();
const { navigated } = navigateToLegacyKibanaUrl(hash, forwards, basePath, application);
if (!navigated) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ This code is required to make sure that the following URLs keep working: /app/kibana#/foobarOrSomeOtherNonExistingNonesense Earlier the code navigated to the configured defaultAppId. With this change we'll just navigate to / in the current space (thus the basePath.get()), which will itself triggering the behavior looking for the configured defaultRoute and bringing us there.

const defaultRoute = uiSettings.get<string>('defaultRoute');
application.navigateToUrl(basePath.prepend(defaultRoute));
}

return () => {};
Expand Down
1 change: 0 additions & 1 deletion src/plugins/url_forwarding/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const createSetupContract = (): Setup => ({

const createStartContract = (): Start => ({
getForwards: jest.fn(),
navigateToDefaultApp: jest.fn(),
navigateToLegacyKibanaUrl: jest.fn(),
});

Expand Down
39 changes: 0 additions & 39 deletions src/plugins/url_forwarding/public/navigate_to_default_app.ts

This file was deleted.

Loading