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
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": "Kibana App",
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 @@ -6,11 +6,9 @@
* Side Public License, v 1.
*/

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": "Kibana App",
"githubTeam": "kibana-app"
},
"requiredPlugins": ["kibanaLegacy"]
}
}
13 changes: 3 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,16 @@ 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,
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.

application.navigateToUrl('/');
}

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.

35 changes: 1 addition & 34 deletions src/plugins/url_forwarding/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
*/

import { CoreStart, CoreSetup } from 'kibana/public';
import { KibanaLegacyStart } from 'src/plugins/kibana_legacy/public';
import { Subscription } from 'rxjs';
import { navigateToDefaultApp } from './navigate_to_default_app';
import { createLegacyUrlForwardApp } from './forward_app';
import { navigateToLegacyKibanaUrl } from './forward_app/navigate_to_legacy_kibana_url';

Expand All @@ -21,8 +18,6 @@ export interface ForwardDefinition {

export class UrlForwardingPlugin {
private forwardDefinitions: ForwardDefinition[] = [];
private currentAppId: string | undefined;
private currentAppIdSubscription: Subscription | undefined;

public setup(core: CoreSetup<{}, UrlForwardingStart>) {
core.application.register(createLegacyUrlForwardApp(core, this.forwardDefinitions));
Expand Down Expand Up @@ -71,30 +66,8 @@ export class UrlForwardingPlugin {
};
}

public start(
{ application, http: { basePath }, uiSettings }: CoreStart,
{ kibanaLegacy }: { kibanaLegacy: KibanaLegacyStart }
) {
this.currentAppIdSubscription = application.currentAppId$.subscribe((currentAppId) => {
this.currentAppId = currentAppId;
});
public start({ application, http: { basePath } }: CoreStart) {
return {
/**
* Navigates to the app defined as kibana.defaultAppId.
* This takes redirects into account and uses the right mechanism to navigate.
*/
navigateToDefaultApp: (
{ overwriteHash }: { overwriteHash: boolean } = { overwriteHash: true }
) => {
navigateToDefaultApp(
kibanaLegacy.config.defaultAppId,
this.forwardDefinitions,
application,
basePath,
this.currentAppId,
overwriteHash
);
},
/**
* Resolves the provided hash using the registered forwards and navigates to the target app.
* If a navigation happened, `{ navigated: true }` will be returned.
Expand All @@ -111,12 +84,6 @@ export class UrlForwardingPlugin {
getForwards: () => this.forwardDefinitions,
};
}

public stop() {
if (this.currentAppIdSubscription) {
this.currentAppIdSubscription.unsubscribe();
}
}
}

export type UrlForwardingSetup = ReturnType<UrlForwardingPlugin['setup']>;
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/home/_home.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export default function ({ getService, getPageObjects }) {
});

it('clicking on console on homepage should take you to console app', async () => {
await PageObjects.common.navigateToUrl('home');
await PageObjects.common.navigateToApp('home');
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 would actually not be needed with further changes I made to the PR, since those URLs are now handled properly, but imho that looks anyway nicer, so I just left it in :)

await testSubjects.click('homeDevTools');
const url = await browser.getCurrentUrl();
expect(url.includes('/app/dev_tools#/console')).to.be(true);
Expand Down