-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
1,600 additions
and
158 deletions.
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
141 changes: 0 additions & 141 deletions
141
x-pack/examples/ui_actions_enhanced_examples/public/dashboard_to_url_drilldown/index.tsx
This file was deleted.
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
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
21 changes: 21 additions & 0 deletions
21
x-pack/plugins/embeddable_enhanced/public/drilldowns/url_drilldown/README.md
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,21 @@ | ||
# Basic url drilldown implementation | ||
|
||
Url drilldown allows navigating to external URL or to internal kibana URL. | ||
By using variables in url template result url can be dynamic and depend on user's interaction. | ||
|
||
URL drilldown has 3 sources for variables: | ||
|
||
- Global static variables like, for example, `kibanaUrl`. Such variables won’t change depending on a place where url drilldown is used. | ||
- Context variables are dynamic and different depending on where drilldown is created and used. For example: | ||
- Event variables depend on a trigger context. These variables are dynamically extracted from the action context when drilldown is executed. | ||
|
||
In current implementation url drilldown has to be used inside the embeddable and with `ValueClickTrigger` or `RangeSelectTrigger`. | ||
|
||
- `context` variables extracted from `embeddable` | ||
- `event` variables extracted from `trigger` context | ||
|
||
In future this basic url drilldown implementation would allow injecting more variables into `context` (e.g. `dashboard` app specific variables) and would allow providing support for new trigger types from outside. | ||
This extensibility improvements are tracked here: https://github.com/elastic/kibana/issues/55324 | ||
|
||
In case a solution app has a use case for url drilldown that has to be different from current basic implementation and | ||
just extending variables list is not enough, then recommendation is to create own custom url drilldown and reuse building blocks from `ui_actions_enhanced`. |
166 changes: 166 additions & 0 deletions
166
x-pack/plugins/embeddable_enhanced/public/drilldowns/url_drilldown/url_drilldown.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,166 @@ | ||
/* | ||
* 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 { UrlDrilldown, ActionContext, Config } from './url_drilldown'; | ||
import { coreMock } from '../../../../../../src/core/public/mocks'; | ||
import { IEmbeddable } from '../../../../../../src/plugins/embeddable/public/lib/embeddables'; | ||
|
||
const mockDataPoints = [ | ||
{ | ||
table: { | ||
columns: [ | ||
{ | ||
name: 'test', | ||
id: '1-1', | ||
meta: { | ||
type: 'histogram', | ||
indexPatternId: 'logstash-*', | ||
aggConfigParams: { | ||
field: 'bytes', | ||
interval: 30, | ||
otherBucket: true, | ||
}, | ||
}, | ||
}, | ||
], | ||
rows: [ | ||
{ | ||
'1-1': '2048', | ||
}, | ||
], | ||
}, | ||
column: 0, | ||
row: 0, | ||
value: 'test', | ||
}, | ||
]; | ||
|
||
const mockEmbeddable = ({ | ||
getInput: () => ({ | ||
filters: [], | ||
timeRange: { from: 'now-15m', to: 'now' }, | ||
query: { query: 'test', language: 'kuery' }, | ||
}), | ||
getOutput: () => ({}), | ||
} as unknown) as IEmbeddable; | ||
|
||
const mockNavigateToUrl = jest.fn(() => Promise.resolve()); | ||
|
||
describe('UrlDrilldown', () => { | ||
const urlDrilldown = new UrlDrilldown({ | ||
getGlobalScope: () => ({ kibanaUrl: 'http://localhost:5601/' }), | ||
getOpenModal: () => Promise.resolve(coreMock.createStart().overlays.openModal), | ||
getSyntaxHelpDocsLink: () => 'http://localhost:5601/docs', | ||
navigateToUrl: mockNavigateToUrl, | ||
}); | ||
|
||
test('license', () => { | ||
expect(urlDrilldown.minimalLicense).toBe('gold'); | ||
}); | ||
|
||
describe('isCompatible', () => { | ||
test('throws if no embeddable', async () => { | ||
const config: Config = { | ||
url: { | ||
template: `https://elasti.co/?{{event.value}}`, | ||
}, | ||
openInNewTab: false, | ||
}; | ||
|
||
const context: ActionContext = { | ||
data: { | ||
data: mockDataPoints, | ||
}, | ||
}; | ||
|
||
await expect(urlDrilldown.isCompatible(config, context)).rejects.toThrowError(); | ||
}); | ||
|
||
test('compatible if url is valid', async () => { | ||
const config: Config = { | ||
url: { | ||
template: `https://elasti.co/?{{event.value}}&{{rison context.panel.query}}`, | ||
}, | ||
openInNewTab: false, | ||
}; | ||
|
||
const context: ActionContext = { | ||
data: { | ||
data: mockDataPoints, | ||
}, | ||
embeddable: mockEmbeddable, | ||
}; | ||
|
||
await expect(urlDrilldown.isCompatible(config, context)).resolves.toBe(true); | ||
}); | ||
|
||
test('not compatible if url is invalid', async () => { | ||
const config: Config = { | ||
url: { | ||
template: `https://elasti.co/?{{event.value}}&{{rison context.panel.somethingFake}}`, | ||
}, | ||
openInNewTab: false, | ||
}; | ||
|
||
const context: ActionContext = { | ||
data: { | ||
data: mockDataPoints, | ||
}, | ||
embeddable: mockEmbeddable, | ||
}; | ||
|
||
await expect(urlDrilldown.isCompatible(config, context)).resolves.toBe(false); | ||
}); | ||
}); | ||
|
||
describe('getHref & execute', () => { | ||
beforeEach(() => { | ||
mockNavigateToUrl.mockReset(); | ||
}); | ||
|
||
test('valid url', async () => { | ||
const config: Config = { | ||
url: { | ||
template: `https://elasti.co/?{{event.value}}&{{rison context.panel.query}}`, | ||
}, | ||
openInNewTab: false, | ||
}; | ||
|
||
const context: ActionContext = { | ||
data: { | ||
data: mockDataPoints, | ||
}, | ||
embeddable: mockEmbeddable, | ||
}; | ||
|
||
const url = await urlDrilldown.getHref(config, context); | ||
expect(url).toMatchInlineSnapshot(`"https://elasti.co/?test&(language:kuery,query:test)"`); | ||
|
||
await urlDrilldown.execute(config, context); | ||
expect(mockNavigateToUrl).toBeCalledWith(url); | ||
}); | ||
|
||
test('invalid url', async () => { | ||
const config: Config = { | ||
url: { | ||
template: `https://elasti.co/?{{event.value}}&{{rison context.panel.invalid}}`, | ||
}, | ||
openInNewTab: false, | ||
}; | ||
|
||
const context: ActionContext = { | ||
data: { | ||
data: mockDataPoints, | ||
}, | ||
embeddable: mockEmbeddable, | ||
}; | ||
|
||
await expect(urlDrilldown.getHref(config, context)).rejects.toThrowError(); | ||
await expect(urlDrilldown.execute(config, context)).rejects.toThrowError(); | ||
expect(mockNavigateToUrl).not.toBeCalled(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.