-
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
Add ApplicationService app status management #50223
Merged
pgayvallet
merged 40 commits into
elastic:master
from
pgayvallet:kbn-45291-application-filter
Jan 12, 2020
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
e87d550
add unimplemented registerAppStatusUpdater & remove observers for app…
pgayvallet 041cef1
adapt NavLinksService to use new application observables
pgayvallet 76ee873
merge availableApps$ and availableLegacyApps$
pgayvallet f278903
updating core docs
pgayvallet 5dba8fc
adapt the navLink updating methods
pgayvallet 865eec5
filters the inaccessible apps from availableApps$
pgayvallet 09cd6d8
restrict access to navigateToApp depending on app status
pgayvallet 0bde308
Merge remote-tracking branch 'upstream/master' into kbn-45291-applica…
pgayvallet ccd6344
fixes due to merge
pgayvallet dd8c438
add statusUpdater$ to AppBase
pgayvallet 038ae4e
export new types
pgayvallet 4aa0e2c
disable navlink depending on app status
pgayvallet 162ec01
update generated doc
pgayvallet 1c76e68
update snapshots for disabled prop
pgayvallet c5385f0
Merge remote-tracking branch 'upstream/master' into kbn-45291-applica…
pgayvallet b031186
Merge remote-tracking branch 'upstream/master' into kbn-45291-applica…
pgayvallet 8ace804
Merge remote-tracking branch 'upstream/master' into kbn-45291-applica…
pgayvallet 0bfe560
Merge remote-tracking branch 'upstream/master' into kbn-45291-applica…
pgayvallet 7dca7fa
Address josh review
pgayvallet a6e9d8f
Merge remote-tracking branch 'upstream/master' into kbn-45291-applica…
pgayvallet a5852a1
Address review comments
pgayvallet 8ccfc62
Merge remote-tracking branch 'upstream/master' into kbn-45291-applica…
pgayvallet eee0d44
Merge remote-tracking branch 'upstream/master' into kbn-45291-applica…
pgayvallet 6a0d0c1
fix merge conflicts
pgayvallet 132938b
Merge remote-tracking branch 'upstream/master' into kbn-45291-applica…
pgayvallet 514a362
adapt changes due to merge
pgayvallet 196d183
update generated doc
pgayvallet ad9ebb8
add comment and fix navlink url for custom url apps
pgayvallet 57be7fd
add AppNavLinkStatus type to split app/navlink states
pgayvallet 1c8d040
Merge remote-tracking branch 'upstream/master' into kbn-45291-applica…
pgayvallet b1b6159
fix typo
pgayvallet 87a7c40
review comments and improvements
pgayvallet 626493f
Merge remote-tracking branch 'upstream/master' into kbn-45291-applica…
pgayvallet f2b1e78
add functional tests
pgayvallet ab73ba3
Merge remote-tracking branch 'upstream/master' into kbn-45291-applica…
pgayvallet 12f469d
update generated docs and migration guide
pgayvallet f488946
fix wrong type cast on AppsMenuProvider.readLinks
pgayvallet 815617b
Merge remote-tracking branch 'upstream/master' into kbn-45291-applica…
pgayvallet cd6a2d7
Merge remote-tracking branch 'upstream/master' into kbn-45291-applica…
pgayvallet b66df7e
properly type return of navigateToApp
pgayvallet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"id": "core_app_status", | ||
"version": "0.0.1", | ||
"kibanaVersion": "kibana", | ||
"configPath": ["core_app_status"], | ||
"server": false, | ||
"ui": true | ||
} |
17 changes: 17 additions & 0 deletions
17
test/plugin_functional/plugins/core_app_status/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "core_app_status", | ||
"version": "1.0.0", | ||
"main": "target/test/plugin_functional/plugins/core_app_status", | ||
"kibana": { | ||
"version": "kibana", | ||
"templateVersion": "1.0.0" | ||
}, | ||
"license": "Apache-2.0", | ||
"scripts": { | ||
"kbn": "node ../../../../scripts/kbn.js", | ||
"build": "rm -rf './target' && tsc" | ||
}, | ||
"devDependencies": { | ||
"typescript": "3.5.3" | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
test/plugin_functional/plugins/core_app_status/public/application.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, unmountComponentAtNode } from 'react-dom'; | ||
import { | ||
EuiPage, | ||
EuiPageBody, | ||
EuiPageContent, | ||
EuiPageContentBody, | ||
EuiPageContentHeader, | ||
EuiPageContentHeaderSection, | ||
EuiPageHeader, | ||
EuiPageHeaderSection, | ||
EuiTitle, | ||
} from '@elastic/eui'; | ||
|
||
import { AppMountContext, AppMountParameters } from 'kibana/public'; | ||
|
||
const AppStatusApp = () => ( | ||
<EuiPage> | ||
<EuiPageBody data-test-subj="appStatusApp"> | ||
<EuiPageHeader> | ||
<EuiPageHeaderSection> | ||
<EuiTitle size="l"> | ||
<h1>Welcome to App Status Test App!</h1> | ||
</EuiTitle> | ||
</EuiPageHeaderSection> | ||
</EuiPageHeader> | ||
<EuiPageContent> | ||
<EuiPageContentHeader> | ||
<EuiPageContentHeaderSection> | ||
<EuiTitle> | ||
<h2>App Status Test App home page section title</h2> | ||
</EuiTitle> | ||
</EuiPageContentHeaderSection> | ||
</EuiPageContentHeader> | ||
<EuiPageContentBody>App Status Test App content</EuiPageContentBody> | ||
</EuiPageContent> | ||
</EuiPageBody> | ||
</EuiPage> | ||
); | ||
|
||
export const renderApp = (context: AppMountContext, { element }: AppMountParameters) => { | ||
render(<AppStatusApp />, element); | ||
|
||
return () => unmountComponentAtNode(element); | ||
}; |
24 changes: 24 additions & 0 deletions
24
test/plugin_functional/plugins/core_app_status/public/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { PluginInitializer } from 'kibana/public'; | ||
import { CoreAppStatusPlugin, CoreAppStatusPluginSetup, CoreAppStatusPluginStart } from './plugin'; | ||
|
||
export const plugin: PluginInitializer<CoreAppStatusPluginSetup, CoreAppStatusPluginStart> = () => | ||
new CoreAppStatusPlugin(); |
56 changes: 56 additions & 0 deletions
56
test/plugin_functional/plugins/core_app_status/public/plugin.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { Plugin, CoreSetup, AppUpdater, AppUpdatableFields, CoreStart } from 'kibana/public'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
|
||
export class CoreAppStatusPlugin | ||
implements Plugin<CoreAppStatusPluginSetup, CoreAppStatusPluginStart> { | ||
private appUpdater = new BehaviorSubject<AppUpdater>(() => ({})); | ||
|
||
public setup(core: CoreSetup, deps: {}) { | ||
core.application.register({ | ||
id: 'app_status', | ||
title: 'App Status', | ||
euiIconType: 'snowflake', | ||
updater$: this.appUpdater, | ||
async mount(context, params) { | ||
const { renderApp } = await import('./application'); | ||
return renderApp(context, params); | ||
}, | ||
}); | ||
|
||
return {}; | ||
} | ||
|
||
public start(core: CoreStart) { | ||
return { | ||
setAppStatus: (status: Partial<AppUpdatableFields>) => { | ||
this.appUpdater.next(() => status); | ||
}, | ||
navigateToApp: async (appId: string) => { | ||
return core.application.navigateToApp(appId); | ||
}, | ||
}; | ||
} | ||
public stop() {} | ||
} | ||
|
||
export type CoreAppStatusPluginSetup = ReturnType<CoreAppStatusPlugin['setup']>; | ||
export type CoreAppStatusPluginStart = ReturnType<CoreAppStatusPlugin['start']>; |
14 changes: 14 additions & 0 deletions
14
test/plugin_functional/plugins/core_app_status/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"extends": "../../../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./target", | ||
"skipLibCheck": true | ||
}, | ||
"include": [ | ||
"index.ts", | ||
"public/**/*.ts", | ||
"public/**/*.tsx", | ||
"../../../../typings/**/*", | ||
], | ||
"exclude": [] | ||
} |
112 changes: 112 additions & 0 deletions
112
test/plugin_functional/test_suites/core_plugins/application_status.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { | ||
AppNavLinkStatus, | ||
AppStatus, | ||
AppUpdatableFields, | ||
} from '../../../../src/core/public/application/types'; | ||
import { PluginFunctionalProviderContext } from '../../services'; | ||
import { CoreAppStatusPluginStart } from '../../plugins/core_app_status/public/plugin'; | ||
import '../../plugins/core_provider_plugin/types'; | ||
|
||
// eslint-disable-next-line import/no-default-export | ||
export default function({ getService, getPageObjects }: PluginFunctionalProviderContext) { | ||
const PageObjects = getPageObjects(['common']); | ||
const browser = getService('browser'); | ||
const appsMenu = getService('appsMenu'); | ||
|
||
const setAppStatus = async (s: Partial<AppUpdatableFields>) => { | ||
await browser.executeAsync(async (status: Partial<AppUpdatableFields>, cb: Function) => { | ||
const plugin = window.__coreProvider.start.plugins | ||
.core_app_status as CoreAppStatusPluginStart; | ||
plugin.setAppStatus(status); | ||
cb(); | ||
}, s); | ||
}; | ||
|
||
const navigateToApp = async (i: string) => { | ||
return await browser.executeAsync(async (appId, cb: Function) => { | ||
// navigating in legacy mode performs a page refresh | ||
// and webdriver seems to re-execute the script after the reload | ||
// as it considers it didn't end on the previous session. | ||
// however when testing navigation to NP app, __coreProvider is not accessible | ||
// so we need to check for existence. | ||
if (!window.__coreProvider) { | ||
cb(); | ||
} | ||
const plugin = window.__coreProvider.start.plugins | ||
.core_app_status as CoreAppStatusPluginStart; | ||
try { | ||
await plugin.navigateToApp(appId); | ||
cb(); | ||
} catch (e) { | ||
cb(e.message); | ||
} | ||
}, i); | ||
}; | ||
|
||
describe('application status management', () => { | ||
beforeEach(async () => { | ||
await PageObjects.common.navigateToApp('settings'); | ||
}); | ||
|
||
it('can change the navLink status at runtime', async () => { | ||
await setAppStatus({ | ||
navLinkStatus: AppNavLinkStatus.disabled, | ||
}); | ||
let link = await appsMenu.getLink('App Status'); | ||
expect(link).not.to.eql(undefined); | ||
expect(link!.disabled).to.eql(true); | ||
|
||
await setAppStatus({ | ||
navLinkStatus: AppNavLinkStatus.hidden, | ||
}); | ||
link = await appsMenu.getLink('App Status'); | ||
expect(link).to.eql(undefined); | ||
|
||
await setAppStatus({ | ||
navLinkStatus: AppNavLinkStatus.visible, | ||
tooltip: 'Some tooltip', | ||
}); | ||
link = await appsMenu.getLink('Some tooltip'); // the tooltip replaces the name in the selector we use. | ||
expect(link).not.to.eql(undefined); | ||
expect(link!.disabled).to.eql(false); | ||
}); | ||
|
||
it('shows an error when navigating to an inaccessible app', async () => { | ||
await setAppStatus({ | ||
status: AppStatus.inaccessible, | ||
}); | ||
|
||
const error = await navigateToApp('app_status'); | ||
expect(error).to.contain('Trying to navigate to an inaccessible application: app_status'); | ||
}); | ||
|
||
it('allows to navigate to an accessible app', async () => { | ||
await setAppStatus({ | ||
status: AppStatus.accessible, | ||
}); | ||
|
||
const error = await navigateToApp('app_status'); | ||
expect(error).to.eql(null); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: we can use an object to be more explicit
cb({error: e.message})
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.
Done. As you already mentioned, our wrong signature on
browser.executeAsync
forces to cast when returning a typed thing from the callback. But even the webdriver signature is quite wrong, as it does not explicitly specify the lastcb
parameter's type...