-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: ๐ธ stub discover_enhanced plugin * feat: ๐ธ improve view in discover action * feat: ๐ธ add URL generator to "View in Discover" action * feat: ๐ธ implement navigation and getHref in view raw logs actio * fix: ๐ disable action in "edit" mode * refactor: ๐ก renamce context menu view in discover action * feat: ๐ธ rename action to "explore data" * fix: ๐ correctly generate action path * feat: ๐ธ add internationalization to "explore action" * fix: ๐ correctly parse generated Discover URL path * test: ๐ setup basic functional tests * refactor: ๐ก modularize url generation logic * feat: ๐ธ export CommonlyUsed type * test: ๐ add test subjects to panel custom time range modal * test: ๐ add index patterna and time range functional tests * refactor: ๐ก rename action file * refactor: ๐ก use URL generator from Discover plugin's contract * test: ๐ add "Explore raw data" action unit tests * fix: ๐ import share plugin to check if it is enabled * Update x-pack/plugins/discover_enhanced/public/actions/view_in_discover/explore_data_context_menu_action.ts Co-authored-by: Matthias Wilhelm <ankertal@gmail.com> * chore: ๐ค add discover_enhanced to KibanaApp codeowners * test: ๐ improve "Explore underlying data" functional tests * test: ๐ improve <a> link assertion Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Matthias Wilhelm <ankertal@gmail.com>
- Loading branch information
1 parent
effd504
commit 3ee0bf2
Showing
23 changed files
with
963 additions
and
36 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules โฆ
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
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,9 @@ | ||
{ | ||
"id": "discoverEnhanced", | ||
"version": "8.0.0", | ||
"kibanaVersion": "kibana", | ||
"server": false, | ||
"ui": true, | ||
"requiredPlugins": ["uiActions", "embeddable", "discover"], | ||
"optionalPlugins": ["share"] | ||
} |
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,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export * from './view_in_discover'; |
209 changes: 209 additions & 0 deletions
209
...iscover_enhanced/public/actions/view_in_discover/explore_data_context_menu_action.test.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,209 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { | ||
ExploreDataContextMenuAction, | ||
ACTION_EXPLORE_DATA, | ||
Params, | ||
PluginDeps, | ||
} from './explore_data_context_menu_action'; | ||
import { coreMock } from '../../../../../../src/core/public/mocks'; | ||
import { UrlGeneratorContract } from '../../../../../../src/plugins/share/public'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { | ||
VisualizeEmbeddableContract, | ||
VISUALIZE_EMBEDDABLE_TYPE, | ||
} from '../../../../../../src/plugins/visualizations/public'; | ||
import { ViewMode } from '../../../../../../src/plugins/embeddable/public'; | ||
|
||
const i18nTranslateSpy = (i18n.translate as unknown) as jest.SpyInstance; | ||
|
||
jest.mock('@kbn/i18n', () => ({ | ||
i18n: { | ||
translate: jest.fn((key, options) => options.defaultMessage), | ||
}, | ||
})); | ||
|
||
afterEach(() => { | ||
i18nTranslateSpy.mockClear(); | ||
}); | ||
|
||
const setup = () => { | ||
type UrlGenerator = UrlGeneratorContract<'DISCOVER_APP_URL_GENERATOR'>; | ||
|
||
const core = coreMock.createStart(); | ||
|
||
const urlGenerator: UrlGenerator = ({ | ||
id: ACTION_EXPLORE_DATA, | ||
createUrl: jest.fn(() => Promise.resolve('/xyz/app/discover/foo#bar')), | ||
} as unknown) as UrlGenerator; | ||
|
||
const plugins: PluginDeps = { | ||
discover: { | ||
urlGenerator, | ||
}, | ||
}; | ||
|
||
const params: Params = { | ||
start: () => ({ | ||
plugins, | ||
self: {}, | ||
core, | ||
}), | ||
}; | ||
const action = new ExploreDataContextMenuAction(params); | ||
|
||
const input = { | ||
viewMode: ViewMode.VIEW, | ||
}; | ||
|
||
const output = { | ||
indexPatterns: [ | ||
{ | ||
id: 'index-ptr-foo', | ||
}, | ||
], | ||
}; | ||
|
||
const embeddable: VisualizeEmbeddableContract = ({ | ||
type: VISUALIZE_EMBEDDABLE_TYPE, | ||
getInput: () => input, | ||
getOutput: () => output, | ||
} as unknown) as VisualizeEmbeddableContract; | ||
|
||
const context = { | ||
embeddable, | ||
}; | ||
|
||
return { core, plugins, urlGenerator, params, action, input, output, embeddable, context }; | ||
}; | ||
|
||
describe('"Explore underlying data" panel action', () => { | ||
test('action has Discover icon', () => { | ||
const { action } = setup(); | ||
expect(action.getIconType()).toBe('discoverApp'); | ||
}); | ||
|
||
test('title is "Explore underlying data"', () => { | ||
const { action } = setup(); | ||
expect(action.getDisplayName()).toBe('Explore underlying data'); | ||
}); | ||
|
||
test('translates title', () => { | ||
expect(i18nTranslateSpy).toHaveBeenCalledTimes(0); | ||
|
||
setup().action.getDisplayName(); | ||
|
||
expect(i18nTranslateSpy).toHaveBeenCalledTimes(1); | ||
expect(i18nTranslateSpy.mock.calls[0][0]).toBe( | ||
'xpack.discover.FlyoutCreateDrilldownAction.displayName' | ||
); | ||
}); | ||
|
||
describe('isCompatible()', () => { | ||
test('returns true when all conditions are met', async () => { | ||
const { action, context } = setup(); | ||
|
||
const isCompatible = await action.isCompatible(context); | ||
|
||
expect(isCompatible).toBe(true); | ||
}); | ||
|
||
test('returns false when URL generator is not present', async () => { | ||
const { action, plugins, context } = setup(); | ||
(plugins.discover as any).urlGenerator = undefined; | ||
|
||
const isCompatible = await action.isCompatible(context); | ||
|
||
expect(isCompatible).toBe(false); | ||
}); | ||
|
||
test('returns false if embeddable is not Visualize embeddable', async () => { | ||
const { action, embeddable, context } = setup(); | ||
(embeddable as any).type = 'NOT_VISUALIZE_EMBEDDABLE'; | ||
|
||
const isCompatible = await action.isCompatible(context); | ||
|
||
expect(isCompatible).toBe(false); | ||
}); | ||
|
||
test('returns false if embeddable does not have index patterns', async () => { | ||
const { action, output, context } = setup(); | ||
delete output.indexPatterns; | ||
|
||
const isCompatible = await action.isCompatible(context); | ||
|
||
expect(isCompatible).toBe(false); | ||
}); | ||
|
||
test('returns false if embeddable index patterns are empty', async () => { | ||
const { action, output, context } = setup(); | ||
output.indexPatterns = []; | ||
|
||
const isCompatible = await action.isCompatible(context); | ||
|
||
expect(isCompatible).toBe(false); | ||
}); | ||
|
||
test('returns false if dashboard is in edit mode', async () => { | ||
const { action, input, context } = setup(); | ||
input.viewMode = ViewMode.EDIT; | ||
|
||
const isCompatible = await action.isCompatible(context); | ||
|
||
expect(isCompatible).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('getHref()', () => { | ||
test('returns URL path generated by URL generator', async () => { | ||
const { action, context } = setup(); | ||
|
||
const href = await action.getHref(context); | ||
|
||
expect(href).toBe('/xyz/app/discover/foo#bar'); | ||
}); | ||
|
||
test('calls URL generator with right arguments', async () => { | ||
const { action, urlGenerator, context } = setup(); | ||
|
||
expect(urlGenerator.createUrl).toHaveBeenCalledTimes(0); | ||
|
||
await action.getHref(context); | ||
|
||
expect(urlGenerator.createUrl).toHaveBeenCalledTimes(1); | ||
expect(urlGenerator.createUrl).toHaveBeenCalledWith({ | ||
indexPatternId: 'index-ptr-foo', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('execute()', () => { | ||
test('calls platform SPA navigation method', async () => { | ||
const { action, context, core } = setup(); | ||
|
||
expect(core.application.navigateToApp).toHaveBeenCalledTimes(0); | ||
|
||
await action.execute(context); | ||
|
||
expect(core.application.navigateToApp).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test('calls platform SPA navigation method with right arguments', async () => { | ||
const { action, context, core } = setup(); | ||
|
||
await action.execute(context); | ||
|
||
expect(core.application.navigateToApp).toHaveBeenCalledTimes(1); | ||
expect(core.application.navigateToApp.mock.calls[0]).toEqual([ | ||
'discover', | ||
{ | ||
path: '/foo#bar', | ||
}, | ||
]); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.