Skip to content

Commit 61d6e91

Browse files
committed
Deprecate chrome.navlinks.update and add documentation (#54893)
* add migration example on application status updater * update example with proper licensing plugin usage * fix line width
1 parent aa7b0b2 commit 61d6e91

File tree

5 files changed

+89
-25
lines changed

5 files changed

+89
-25
lines changed
Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
1-
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2-
3-
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLinks](./kibana-plugin-public.chromenavlinks.md) &gt; [update](./kibana-plugin-public.chromenavlinks.update.md)
4-
5-
## ChromeNavLinks.update() method
6-
7-
Update the navlink for the given id with the updated attributes. Returns the updated navlink or `undefined` if it does not exist.
8-
9-
<b>Signature:</b>
10-
11-
```typescript
12-
update(id: string, values: ChromeNavLinkUpdateableFields): ChromeNavLink | undefined;
13-
```
14-
15-
## Parameters
16-
17-
| Parameter | Type | Description |
18-
| --- | --- | --- |
19-
| id | <code>string</code> | |
20-
| values | <code>ChromeNavLinkUpdateableFields</code> | |
21-
22-
<b>Returns:</b>
23-
24-
`ChromeNavLink | undefined`
25-
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [kibana-plugin-public](./kibana-plugin-public.md) &gt; [ChromeNavLinks](./kibana-plugin-public.chromenavlinks.md) &gt; [update](./kibana-plugin-public.chromenavlinks.update.md)
4+
5+
## ChromeNavLinks.update() method
6+
7+
> Warning: This API is now obsolete.
8+
>
9+
> Uses the [AppBase.updater$](./kibana-plugin-public.appbase.updater_.md) property when registering your application with [ApplicationSetup.register()](./kibana-plugin-public.applicationsetup.register.md) instead.
10+
>
11+
12+
Update the navlink for the given id with the updated attributes. Returns the updated navlink or `undefined` if it does not exist.
13+
14+
<b>Signature:</b>
15+
16+
```typescript
17+
update(id: string, values: ChromeNavLinkUpdateableFields): ChromeNavLink | undefined;
18+
```
19+
20+
## Parameters
21+
22+
| Parameter | Type | Description |
23+
| --- | --- | --- |
24+
| id | <code>string</code> | |
25+
| values | <code>ChromeNavLinkUpdateableFields</code> | |
26+
27+
<b>Returns:</b>
28+
29+
`ChromeNavLink | undefined`
30+

src/core/MIGRATION.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ import { npStart: { core } } from 'ui/new_platform';
11311131
| Legacy Platform | New Platform | Notes |
11321132
| ----------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- |
11331133
| `chrome.addBasePath` | [`core.http.basePath.prepend`](/docs/development/core/public/kibana-plugin-public.httpservicebase.basepath.md) | |
1134+
| `chrome.navLinks.update` | [`core.appbase.updater`](/docs/development/core/public/kibana-plugin-public.appbase.updater_.md) | Use the `updater$` property when registering your application via `core.application.register` |
11341135
| `chrome.breadcrumbs.set` | [`core.chrome.setBreadcrumbs`](/docs/development/core/public/kibana-plugin-public.chromestart.setbreadcrumbs.md) | |
11351136
| `chrome.getUiSettingsClient` | [`core.uiSettings`](/docs/development/core/public/kibana-plugin-public.uisettingsclient.md) | |
11361137
| `chrome.helpExtension.set` | [`core.chrome.setHelpExtension`](/docs/development/core/public/kibana-plugin-public.chromestart.sethelpextension.md) | |

src/core/MIGRATION_EXAMPLES.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ APIs to their New Platform equivalents.
1515
- [4. New Platform plugin](#4-new-platform-plugin)
1616
- [Accessing Services](#accessing-services)
1717
- [Chrome](#chrome)
18+
- [Updating an application navlink](#updating-application-navlink)
1819

1920
## Configuration
2021

@@ -462,7 +463,59 @@ elsewhere.
462463
| `chrome.setVisible` | [`core.chrome.setIsVisible`](/docs/development/core/public/kibana-plugin-public.chromestart.setisvisible.md) | |
463464
| `chrome.getInjected` | [`core.injectedMetadata.getInjected`](/docs/development/core/public/kibana-plugin-public.coresetup.injectedmetadata.md) (temporary) | A temporary API is available to read injected vars provided by legacy plugins. This will be removed after [#41990](https://github.com/elastic/kibana/issues/41990) is completed. |
464465
| `chrome.setRootTemplate` / `chrome.setRootController` | -- | Use application mounting via `core.application.register` (not currently avaiable to legacy plugins). |
466+
| `chrome.navLinks.update` | [`core.appbase.updater`](/docs/development/core/public/kibana-plugin-public.appbase.updater_.md) | Use the `updater$` property when registering your application via `core.application.register` |
465467
466468
In most cases, the most convenient way to access these APIs will be via the
467469
[AppMountContext](/docs/development/core/public/kibana-plugin-public.appmountcontext.md)
468470
object passed to your application when your app is mounted on the page.
471+
472+
### Updating an application navlink
473+
474+
In the legacy platform, the navlink could be updated using `chrome.navLinks.update`
475+
476+
```ts
477+
uiModules.get('xpack/ml').run(() => {
478+
const showAppLink = xpackInfo.get('features.ml.showLinks', false);
479+
const isAvailable = xpackInfo.get('features.ml.isAvailable', false);
480+
481+
const navLinkUpdates = {
482+
// hide by default, only show once the xpackInfo is initialized
483+
hidden: !showAppLink,
484+
disabled: !showAppLink || (showAppLink && !isAvailable),
485+
};
486+
487+
npStart.core.chrome.navLinks.update('ml', navLinkUpdates);
488+
});
489+
```
490+
491+
In the new platform, navlinks should not be updated directly. Instead, it is now possible to add an `updater` when
492+
registering an application to change the application or the navlink state at runtime.
493+
494+
```ts
495+
// my_plugin has a required dependencie to the `licensing` plugin
496+
interface MyPluginSetupDeps {
497+
licensing: LicensingPluginSetup;
498+
}
499+
500+
export class MyPlugin implements Plugin {
501+
setup({ application }, { licensing }: MyPluginSetupDeps) {
502+
const updater$ = licensing.license$.pipe(
503+
map(license => {
504+
const { hidden, disabled } = calcStatusFor(license);
505+
if (hidden) return { navLinkStatus: AppNavLinkStatus.hidden };
506+
if (disabled) return { navLinkStatus: AppNavLinkStatus.disabled };
507+
return { navLinkStatus: AppNavLinkStatus.default };
508+
})
509+
);
510+
511+
application.register({
512+
id: 'my-app',
513+
title: 'My App',
514+
updater$,
515+
async mount(params) {
516+
const { renderApp } = await import('./application');
517+
return renderApp(params);
518+
},
519+
});
520+
}
521+
```

src/core/public/chrome/nav_links/nav_links_service.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ export interface ChromeNavLinks {
7272
/**
7373
* Update the navlink for the given id with the updated attributes.
7474
* Returns the updated navlink or `undefined` if it does not exist.
75+
*
76+
* @deprecated Uses the {@link AppBase.updater$} property when registering
77+
* your application with {@link ApplicationSetup.register} instead.
78+
*
7579
* @param id
7680
* @param values
7781
*/

src/core/public/public.api.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ export interface ChromeNavLinks {
279279
getNavLinks$(): Observable<Array<Readonly<ChromeNavLink>>>;
280280
has(id: string): boolean;
281281
showOnly(id: string): void;
282+
// @deprecated
282283
update(id: string, values: ChromeNavLinkUpdateableFields): ChromeNavLink | undefined;
283284
}
284285

0 commit comments

Comments
 (0)