-
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
[License Management] Add URL locator #153792
Merged
yuliacech
merged 10 commits into
elastic:main
from
yuliacech:8.8/license-management/url-locator
Mar 31, 2023
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0e928bb
[License Management] Add a url locator
yuliacech 2c6d696
[Watcher] Use a url locator for License Management
yuliacech 86f6de1
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine d1c6f86
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 7d2331a
[License Management] Add unit tests for the url locator
yuliacech b595976
[Watcher] Extract license prompt component
yuliacech 880d9f3
[Watcher] Add unit test for license prompt
yuliacech 57b10a4
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine c8fda1d
Merge branch 'main' into 8.8/license-management/url-locator
yuliacech 7cf3512
Merge branch 'main' into 8.8/license-management/url-locator
yuliacech 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,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { sharePluginMock } from '@kbn/share-plugin/public/mocks'; | ||
import { ManagementAppLocatorDefinition } from '@kbn/management-plugin/common/locator'; | ||
import { LicenseManagementLocatorDefinition, LICENSE_MANAGEMENT_LOCATOR_ID } from './locator'; | ||
describe('License Management URL locator', () => { | ||
let locator: LicenseManagementLocatorDefinition; | ||
beforeEach(() => { | ||
const managementDefinition = new ManagementAppLocatorDefinition(); | ||
locator = new LicenseManagementLocatorDefinition({ | ||
managementAppLocator: { | ||
...sharePluginMock.createLocator(), | ||
getLocation: (params) => managementDefinition.getLocation(params), | ||
}, | ||
}); | ||
}); | ||
test('locator has the right ID', () => { | ||
expect(locator.id).toBe(LICENSE_MANAGEMENT_LOCATOR_ID); | ||
}); | ||
|
||
test('locator returns the correct url for dashboard page', async () => { | ||
const { path } = await locator.getLocation({ page: 'dashboard' }); | ||
expect(path).toBe('/stack/license_management'); | ||
}); | ||
test('locator returns the correct url for upload license page', async () => { | ||
const { path } = await locator.getLocation({ page: 'upload_license' }); | ||
expect(path).toBe('/stack/license_management/upload_license'); | ||
}); | ||
}); |
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,51 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { SerializableRecord } from '@kbn/utility-types'; | ||
import { ManagementAppLocator } from '@kbn/management-plugin/common'; | ||
import { LocatorDefinition, LocatorPublic } from '@kbn/share-plugin/public'; | ||
import { PLUGIN } from '../common/constants'; | ||
|
||
export const LICENSE_MANAGEMENT_LOCATOR_ID = 'LICENSE_MANAGEMENT_LOCATOR'; | ||
export const UPLOAD_LICENSE_ROUTE = 'upload_license'; | ||
|
||
export interface LicenseManagementLocatorParams extends SerializableRecord { | ||
page: 'dashboard' | 'upload_license'; | ||
} | ||
|
||
export type LicenseManagementLocator = LocatorPublic<LicenseManagementLocatorParams>; | ||
|
||
export interface LicenseManagementLocatorDefinitionDependencies { | ||
managementAppLocator: ManagementAppLocator; | ||
} | ||
|
||
export class LicenseManagementLocatorDefinition | ||
implements LocatorDefinition<LicenseManagementLocatorParams> | ||
{ | ||
constructor(protected readonly deps: LicenseManagementLocatorDefinitionDependencies) {} | ||
|
||
public readonly id = LICENSE_MANAGEMENT_LOCATOR_ID; | ||
|
||
public readonly getLocation = async (params: LicenseManagementLocatorParams) => { | ||
const location = await this.deps.managementAppLocator.getLocation({ | ||
sectionId: 'stack', | ||
appId: PLUGIN.id, | ||
}); | ||
|
||
switch (params.page) { | ||
case 'upload_license': { | ||
return { | ||
...location, | ||
path: `${location.path}/${UPLOAD_LICENSE_ROUTE}`, | ||
}; | ||
} | ||
case 'dashboard': { | ||
return location; | ||
} | ||
} | ||
}; | ||
} |
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
80 changes: 80 additions & 0 deletions
80
x-pack/plugins/watcher/__jest__/__snapshots__/license_prompt.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { sharePluginMock } from '@kbn/share-plugin/public/mocks'; | ||
import { | ||
LicenseManagementLocator, | ||
LicenseManagementLocatorParams, | ||
} from '@kbn/license-management-plugin/public/locator'; | ||
import { LicensePrompt } from '../public/application/license_prompt'; | ||
|
||
describe('License prompt', () => { | ||
test('renders a prompt with a link to License Management', () => { | ||
const locator = { | ||
...sharePluginMock.createLocator(), | ||
useUrl: (params: LicenseManagementLocatorParams) => '/license_management', | ||
} as LicenseManagementLocator; | ||
const component = shallow( | ||
<LicensePrompt message="License error" licenseManagementLocator={locator} /> | ||
); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); | ||
|
||
test('renders a prompt without a link to License Management', () => { | ||
const component = shallow(<LicensePrompt message="License error" />); | ||
|
||
expect(component).toMatchSnapshot(); | ||
}); | ||
}); |
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
Oops, something went wrong.
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.
in which cases would the locator be undefined?
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.
For the case that the License Management plugin is hidden from the UI with
ui.enabled: false
. The plugin is still enabled, but we don't register it in the Kibana navigation and don't initialize the locator.