-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Deprecate chrome.navlinks.update
and add documentation
#54893
Changes from 2 commits
bf66dca
24e0433
4016923
f953d3d
def5229
b2e69f0
97b14f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,30 @@ | ||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [ChromeNavLinks](./kibana-plugin-public.chromenavlinks.md) > [update](./kibana-plugin-public.chromenavlinks.update.md) | ||
|
||
## ChromeNavLinks.update() method | ||
|
||
Update the navlink for the given id with the updated attributes. Returns the updated navlink or `undefined` if it does not exist. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
update(id: string, values: ChromeNavLinkUpdateableFields): ChromeNavLink | undefined; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| id | <code>string</code> | | | ||
| values | <code>ChromeNavLinkUpdateableFields</code> | | | ||
|
||
<b>Returns:</b> | ||
|
||
`ChromeNavLink | undefined` | ||
|
||
<!-- Do not edit this file. It is automatically generated by API Documenter. --> | ||
|
||
[Home](./index.md) > [kibana-plugin-public](./kibana-plugin-public.md) > [ChromeNavLinks](./kibana-plugin-public.chromenavlinks.md) > [update](./kibana-plugin-public.chromenavlinks.update.md) | ||
|
||
## ChromeNavLinks.update() method | ||
|
||
> Warning: This API is now obsolete. | ||
> | ||
> 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. | ||
> | ||
|
||
Update the navlink for the given id with the updated attributes. Returns the updated navlink or `undefined` if it does not exist. | ||
|
||
<b>Signature:</b> | ||
|
||
```typescript | ||
update(id: string, values: ChromeNavLinkUpdateableFields): ChromeNavLink | undefined; | ||
``` | ||
|
||
## Parameters | ||
|
||
| Parameter | Type | Description | | ||
| --- | --- | --- | | ||
| id | <code>string</code> | | | ||
| values | <code>ChromeNavLinkUpdateableFields</code> | | | ||
|
||
<b>Returns:</b> | ||
|
||
`ChromeNavLink | undefined` | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ APIs to their New Platform equivalents. | |
- [4. New Platform plugin](#4-new-platform-plugin) | ||
- [Accessing Services](#accessing-services) | ||
- [Chrome](#chrome) | ||
- [Updating an application navlink](#updating-application-navlink) | ||
|
||
## Configuration | ||
|
||
|
@@ -462,7 +463,56 @@ elsewhere. | |
| `chrome.setVisible` | [`core.chrome.setIsVisible`](/docs/development/core/public/kibana-plugin-public.chromestart.setisvisible.md) | | | ||
| `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. | | ||
| `chrome.setRootTemplate` / `chrome.setRootController` | -- | Use application mounting via `core.application.register` (not currently avaiable to legacy plugins). | | ||
| `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` | | ||
|
||
In most cases, the most convenient way to access these APIs will be via the | ||
[AppMountContext](/docs/development/core/public/kibana-plugin-public.appmountcontext.md) | ||
object passed to your application when your app is mounted on the page. | ||
|
||
### Updating an application navlink | ||
|
||
In the legacy platform, the navlink could be updated using `chrome.navLinks.update` | ||
|
||
```ts | ||
uiModules.get('xpack/ml').run(() => { | ||
const showAppLink = xpackInfo.get('features.ml.showLinks', false); | ||
const isAvailable = xpackInfo.get('features.ml.isAvailable', false); | ||
|
||
const navLinkUpdates = { | ||
// hide by default, only show once the xpackInfo is initialized | ||
hidden: !showAppLink, | ||
disabled: !showAppLink || (showAppLink && !isAvailable), | ||
}; | ||
|
||
npStart.core.chrome.navLinks.update('ml', navLinkUpdates); | ||
}); | ||
``` | ||
|
||
In the new platform, navlinks should not be updated directly. Instead, it is now possible to add an `updater` when registering | ||
an application to change the application and the navlink state at runtime | ||
|
||
```ts | ||
// inside your plugin's setup function | ||
export class MyPlugin implements Plugin { | ||
private appUpdater = new BehaviorSubject<AppUpdater>(() => ({})); | ||
|
||
setup({ application }) { | ||
application.register({ | ||
id: 'my-app', | ||
title: 'My App', | ||
updater$: this.appUpdater, | ||
async mount(params) { | ||
const { renderApp } = await import('./application'); | ||
return renderApp(params); | ||
}, | ||
}); | ||
} | ||
start() { | ||
// later, when the navlink needs to be updated | ||
if(!isAvailable) { | ||
appUpdater.next(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. optional: probably we should provide updated version of the legacy code from https://github.com/elastic/kibana/pull/54893/files#diff-ca730ff688cc29f7cfb77853005355a1R478-R487 ? const updater$ = license$.pipe(
map(license => {
const { hidden, disabled } = calcStatusFor(license);
if (hidden) return { navLinkStatus: AppNavLinkStatus.hidden };
if (disabled) return { navLinkStatus: AppNavLinkStatus.disabled };
return { navLinkStatus: AppNavLinkStatus.default };
})
); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, was looking for that. |
||
navLinkStatus: AppNavLinkStatus.hidden, | ||
}) | ||
} | ||
} | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optional: appUpdater$