Skip to content

Commit

Permalink
[7.6] Use app id instead of pluginId to generate navlink from legacy …
Browse files Browse the repository at this point in the history
…apps (#57542) (#57672)

* Use app id instead of pluginId to generate navlink from legacy apps (#57542)

* properly use app id instead of pluginId to generate navlink

* extract convertToNavLink, add more tests

* use distinct mapping methods

* fix linkToLastSubUrl default value

* nits & doc

* remove category, add disableSubUrlTracking

* update doc
  • Loading branch information
pgayvallet authored Feb 14, 2020
1 parent 3cafe10 commit 60de534
Show file tree
Hide file tree
Showing 10 changed files with 450 additions and 73 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLink](./kibana-plugin-public.chromenavlink.md) &gt; [disableSubUrlTracking](./kibana-plugin-public.chromenavlink.disablesuburltracking.md)

## ChromeNavLink.disableSubUrlTracking property

> Warning: This API is now obsolete.
>
>
A flag that tells legacy chrome to ignore the link when tracking sub-urls

<b>Signature:</b>

```typescript
readonly disableSubUrlTracking?: boolean;
```
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface ChromeNavLink
| [active](./kibana-plugin-public.chromenavlink.active.md) | <code>boolean</code> | Indicates whether or not this app is currently on the screen. |
| [baseUrl](./kibana-plugin-public.chromenavlink.baseurl.md) | <code>string</code> | The base route used to open the root of an application. |
| [disabled](./kibana-plugin-public.chromenavlink.disabled.md) | <code>boolean</code> | Disables a link from being clickable. |
| [disableSubUrlTracking](./kibana-plugin-public.chromenavlink.disablesuburltracking.md) | <code>boolean</code> | A flag that tells legacy chrome to ignore the link when tracking sub-urls |
| [euiIconType](./kibana-plugin-public.chromenavlink.euiicontype.md) | <code>string</code> | A EUI iconType that will be used for the app's icon. This icon takes precendence over the <code>icon</code> property. |
| [hidden](./kibana-plugin-public.chromenavlink.hidden.md) | <code>boolean</code> | Hides a link from the navigation. |
| [icon](./kibana-plugin-public.chromenavlink.icon.md) | <code>string</code> | A URL to an image file used as an icon. Used as a fallback if <code>euiIconType</code> is not provided. |
Expand Down
11 changes: 11 additions & 0 deletions src/core/public/chrome/nav_links/nav_link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ export interface ChromeNavLink {
*/
readonly subUrlBase?: string;

/**
* A flag that tells legacy chrome to ignore the link when
* tracking sub-urls
*
* @internalRemarks
* This should be removed once legacy apps are gone.
*
* @deprecated
*/
readonly disableSubUrlTracking?: boolean;

/**
* Whether or not the subUrl feature should be enabled.
*
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ export interface ChromeNavLink {
readonly baseUrl: string;
// @deprecated
readonly disabled?: boolean;
// @deprecated
readonly disableSubUrlTracking?: boolean;
readonly euiIconType?: string;
readonly hidden?: boolean;
readonly icon?: string;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 2 additions & 63 deletions src/core/server/legacy/plugins/find_legacy_plugin_specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,69 +30,8 @@ import { collectUiExports as collectLegacyUiExports } from '../../../../legacy/u

import { LoggerFactory } from '../../logging';
import { PackageInfo } from '../../config';

import {
LegacyUiExports,
LegacyNavLink,
LegacyPluginSpec,
LegacyPluginPack,
LegacyConfig,
} from '../types';

const REMOVE_FROM_ARRAY: LegacyNavLink[] = [];

function getUiAppsNavLinks({ uiAppSpecs = [] }: LegacyUiExports, pluginSpecs: LegacyPluginSpec[]) {
return uiAppSpecs.flatMap(spec => {
if (!spec) {
return REMOVE_FROM_ARRAY;
}

const id = spec.pluginId || spec.id;

if (!id) {
throw new Error('Every app must specify an id');
}

if (spec.pluginId && !pluginSpecs.some(plugin => plugin.getId() === spec.pluginId)) {
throw new Error(`Unknown plugin id "${spec.pluginId}"`);
}

const listed = typeof spec.listed === 'boolean' ? spec.listed : true;

if (spec.hidden || !listed) {
return REMOVE_FROM_ARRAY;
}

return {
id,
title: spec.title,
order: typeof spec.order === 'number' ? spec.order : 0,
icon: spec.icon,
euiIconType: spec.euiIconType,
url: spec.url || `/app/${id}`,
linkToLastSubUrl: spec.linkToLastSubUrl,
};
});
}

function getNavLinks(uiExports: LegacyUiExports, pluginSpecs: LegacyPluginSpec[]) {
return (uiExports.navLinkSpecs || [])
.map<LegacyNavLink>(spec => ({
id: spec.id,
title: spec.title,
order: typeof spec.order === 'number' ? spec.order : 0,
url: spec.url,
subUrlBase: spec.subUrlBase || spec.url,
icon: spec.icon,
euiIconType: spec.euiIconType,
linkToLastSub: 'linkToLastSubUrl' in spec ? spec.linkToLastSubUrl : false,
hidden: 'hidden' in spec ? spec.hidden : false,
disabled: 'disabled' in spec ? spec.disabled : false,
tooltip: spec.tooltip || '',
}))
.concat(getUiAppsNavLinks(uiExports, pluginSpecs))
.sort((a, b) => a.order - b.order);
}
import { LegacyPluginSpec, LegacyPluginPack, LegacyConfig } from '../types';
import { getNavLinks } from './get_nav_links';

export async function findLegacyPluginSpecs(
settings: unknown,
Expand Down
Loading

0 comments on commit 60de534

Please sign in to comment.