Skip to content

Commit

Permalink
move links register from start to mount
Browse files Browse the repository at this point in the history
  • Loading branch information
semd committed May 18, 2022
1 parent a77c93b commit ac944aa
Showing 1 changed file with 65 additions and 58 deletions.
123 changes: 65 additions & 58 deletions x-pack/plugins/security_solution/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
*/
private _store?: SecurityAppStore;

/**
* Lazily registered `app_links`.
*/
private _linksRegistered?: boolean;

public setup(core: CoreSetup<StartPlugins, PluginStart>, plugins: SetupPlugins): PluginSetup {
initTelemetry(
{
Expand Down Expand Up @@ -150,6 +155,7 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
registerAlertsTableConfiguration(alertsTableConfigurationRegistry, this.storage);

const [coreStart, startPlugins] = await core.getStartServices();
await this.registerLinks(coreStart, startPlugins);
const subPlugins = await this.startSubPlugins(this.storage, coreStart, startPlugins);
const { renderApp } = await this.lazyApplicationDependencies();
return renderApp({
Expand Down Expand Up @@ -221,64 +227,6 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
Component: LazyEndpointCustomAssetsExtension,
});
}
licenseService.start(plugins.licensing.license$);
const licensing = licenseService.getLicenseInformation$();

const newNavEnabled = core.uiSettings.get(ENABLE_GROUPED_NAVIGATION, false);

/**
* Register deepLinks and pass an appUpdater for each subPlugin, to change deepLinks as needed when licensing changes.
*/

if (newNavEnabled) {
registerDeepLinksUpdater(this.appUpdater$);
}

// Not using await to prevent blocking start execution
this.lazyApplicationLinks().then(({ getAppLinks }) => {
getAppLinks(core, plugins).then((appLinks) => {
if (licensing !== null) {
this.licensingSubscription = licensing.subscribe((currentLicense) => {
if (currentLicense.type !== undefined) {
updateAppLinks(appLinks, {
experimentalFeatures: this.experimentalFeatures,
license: currentLicense,
capabilities: core.application.capabilities,
});

if (!newNavEnabled) {
// TODO: remove block when nav flag no longer needed
this.appUpdater$.next(() => ({
navLinkStatus: AppNavLinkStatus.hidden, // workaround to prevent main navLink to switch to visible after update. should not be needed
deepLinks: getDeepLinks(
this.experimentalFeatures,
currentLicense.type,
core.application.capabilities
),
}));
}
}
});
} else {
updateAppLinks(appLinks, {
experimentalFeatures: this.experimentalFeatures,
capabilities: core.application.capabilities,
});

if (!newNavEnabled) {
// TODO: remove block when nav flag no longer needed
this.appUpdater$.next(() => ({
navLinkStatus: AppNavLinkStatus.hidden, // workaround to prevent main navLink to switch to visible after update. should not be needed
deepLinks: getDeepLinks(
this.experimentalFeatures,
undefined,
core.application.capabilities
),
}));
}
}
});
});

return {};
}
Expand Down Expand Up @@ -494,4 +442,63 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
}
return this._store;
}

/**
* Lazily instantiate a `SecurityAppStore`. We lazily instantiate this because it requests large dynamic imports. We instantiate it once because each subPlugin needs to share the same reference.
*/
private async registerLinks(coreStart: CoreStart, startPlugins: StartPlugins): Promise<void> {
if (this._linksRegistered) {
return;
}
// Will need reload after settings toggle change, to take fill effect on deepLinks
const newNavEnabled = coreStart.uiSettings.get(ENABLE_GROUPED_NAVIGATION, false);

const { capabilities } = coreStart.application;

licenseService.start(startPlugins.licensing.license$);
const licensing = licenseService.getLicenseInformation$();

const { getAppLinks } = await this.lazyApplicationLinks();
const appLinks = await getAppLinks(coreStart, startPlugins);

// Register deepLinks and pass an appUpdater, any change in appLinks will be reflected to the plugin deepLinks.
if (newNavEnabled) {
registerDeepLinksUpdater(this.appUpdater$);
}

if (licensing !== null) {
this.licensingSubscription = licensing.subscribe((currentLicense) => {
if (currentLicense.type !== undefined) {
updateAppLinks(appLinks, {
experimentalFeatures: this.experimentalFeatures,
license: currentLicense,
capabilities,
});

if (!newNavEnabled) {
// TODO: remove block when nav flag no longer needed
this.appUpdater$.next(() => ({
navLinkStatus: AppNavLinkStatus.hidden, // workaround to prevent main navLink to switch to visible after update. should not be needed
deepLinks: getDeepLinks(this.experimentalFeatures, currentLicense.type, capabilities),
}));
}
}
});
} else {
updateAppLinks(appLinks, {
experimentalFeatures: this.experimentalFeatures,
capabilities,
});

if (!newNavEnabled) {
// TODO: remove block when nav flag no longer needed
this.appUpdater$.next(() => ({
navLinkStatus: AppNavLinkStatus.hidden, // workaround to prevent main navLink to switch to visible after update. should not be needed
deepLinks: getDeepLinks(this.experimentalFeatures, undefined, capabilities),
}));
}
}

this._linksRegistered = true;
}
}

0 comments on commit ac944aa

Please sign in to comment.