mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
# Backport This will backport the following commits from `main` to `8.x`: - [[Vega] Add ability to open links in Vega in new window (#216200)](https://github.com/elastic/kibana/pull/216200) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Andreana Malama","email":"72010092+andrimal@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-04-14T14:42:32Z","message":"[Vega] Add ability to open links in Vega in new window (#216200)\n\n## Summary\n\nFix #70745 \n\nEnables the option to open the clickable mark links of a Vega\nVisualization in a new tab.\n\nTo achieve this functionality: \n- use the `usermeta.embedOptions.loader` property in the vega chart spec\nto pass the `\"target\": \"_blank\"` configuration:\n```javascript\n\"usermeta\": {\n \"embedOptions\": {\n \"loader\": {\"target\": \"_blank\"}\n }\n }\n``` \n\nLink opens in a new tab:\n\n\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [x] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n---------\n\nCo-authored-by: Marco Liberati <dej611@users.noreply.github.com>","sha":"f8e688f88135bf7675cfd0c6dfb918e23b6ebbb8","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:enhancement","Feature:Vega","Team:Visualizations","backport:version","v9.1.0","v8.19.0"],"title":"[Vega] Add ability to open links in Vega in new window","number":216200,"url":"https://github.com/elastic/kibana/pull/216200","mergeCommit":{"message":"[Vega] Add ability to open links in Vega in new window (#216200)\n\n## Summary\n\nFix #70745 \n\nEnables the option to open the clickable mark links of a Vega\nVisualization in a new tab.\n\nTo achieve this functionality: \n- use the `usermeta.embedOptions.loader` property in the vega chart spec\nto pass the `\"target\": \"_blank\"` configuration:\n```javascript\n\"usermeta\": {\n \"embedOptions\": {\n \"loader\": {\"target\": \"_blank\"}\n }\n }\n``` \n\nLink opens in a new tab:\n\n\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [x] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n---------\n\nCo-authored-by: Marco Liberati <dej611@users.noreply.github.com>","sha":"f8e688f88135bf7675cfd0c6dfb918e23b6ebbb8"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/216200","number":216200,"mergeCommit":{"message":"[Vega] Add ability to open links in Vega in new window (#216200)\n\n## Summary\n\nFix #70745 \n\nEnables the option to open the clickable mark links of a Vega\nVisualization in a new tab.\n\nTo achieve this functionality: \n- use the `usermeta.embedOptions.loader` property in the vega chart spec\nto pass the `\"target\": \"_blank\"` configuration:\n```javascript\n\"usermeta\": {\n \"embedOptions\": {\n \"loader\": {\"target\": \"_blank\"}\n }\n }\n``` \n\nLink opens in a new tab:\n\n\n\n### Checklist\n\nCheck the PR satisfies following conditions. \n\nReviewers should verify this PR satisfies this list as well.\n- [x] [Unit or functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere updated or added to match the most common scenarios\n- [x] The PR description includes the appropriate Release Notes section,\nand the correct `release_note:*` label is applied per the\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\n\n---------\n\nCo-authored-by: Marco Liberati <dej611@users.noreply.github.com>","sha":"f8e688f88135bf7675cfd0c6dfb918e23b6ebbb8"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Andreana Malama <72010092+andrimal@users.noreply.github.com>
This commit is contained in:
parent
0b60e4c08a
commit
595f8db751
2 changed files with 95 additions and 0 deletions
|
@ -236,6 +236,11 @@ export class VegaBaseView {
|
|||
|
||||
return result;
|
||||
};
|
||||
|
||||
const vegaSpec = this._parser.isVegaLite ? this._parser.vlspec : this._parser.spec;
|
||||
const usermetaLoaderOptions = vegaSpec.usermeta?.embedOptions?.loader;
|
||||
vegaLoader.options = usermetaLoaderOptions ?? {};
|
||||
|
||||
config.loader = vegaLoader;
|
||||
|
||||
const vegaLogger = logger(Warn);
|
||||
|
|
|
@ -27,6 +27,49 @@ signals: [ {
|
|||
}]
|
||||
}]}`;
|
||||
|
||||
const getLinkTestSpec = (url: string, usermeta?: string) => `
|
||||
{
|
||||
$schema: https://vega.github.io/schema/vega-lite/v5.json
|
||||
data: {
|
||||
url: {
|
||||
%context%: true
|
||||
%timefield%: @timestamp
|
||||
index: logstash-*
|
||||
body: {
|
||||
aggs: {
|
||||
country_buckets: {
|
||||
terms: {
|
||||
field: geo.dest
|
||||
size: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
size: 0
|
||||
}
|
||||
}
|
||||
format: {property: "aggregations.country_buckets.buckets"}
|
||||
}
|
||||
transform: [
|
||||
{
|
||||
"calculate": "'${url}'", "as": "url"
|
||||
}
|
||||
]
|
||||
mark: bar
|
||||
encoding: {
|
||||
x: {
|
||||
field: key
|
||||
type: nominal
|
||||
axis: {labelAngle: 0}
|
||||
}
|
||||
y: {
|
||||
field: doc_count
|
||||
type: quantitative
|
||||
}
|
||||
"href": {"field": "url", "type": "nominal"}
|
||||
}
|
||||
usermeta: ${usermeta}
|
||||
}`;
|
||||
|
||||
export default function ({ getPageObjects, getService }: FtrProviderContext) {
|
||||
const { timePicker, visualize, visChart, visEditor, vegaChart } = getPageObjects([
|
||||
'timePicker',
|
||||
|
@ -292,5 +335,52 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
|
|||
expect(await filterBar.getFilterCount()).to.be(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('clickable marks with links', () => {
|
||||
beforeEach(async () => {
|
||||
await timePicker.setDefaultAbsoluteRange();
|
||||
});
|
||||
|
||||
const fillSpecAndGo = async (newSpec: string) => {
|
||||
await vegaChart.fillSpec(newSpec);
|
||||
await visEditor.clickGo();
|
||||
|
||||
const viewContainer = await vegaChart.getViewContainer();
|
||||
const canvasElement = await viewContainer.findByTagName('canvas');
|
||||
const { width, height } = await canvasElement.getSize();
|
||||
|
||||
await canvasElement.moveMouseTo({
|
||||
xOffset: Math.round(width / 2),
|
||||
yOffset: Math.round(height / 2),
|
||||
});
|
||||
await canvasElement.click();
|
||||
};
|
||||
|
||||
const getKibanaBaseUrl = async () => {
|
||||
const currentUrl = await browser.getCurrentUrl();
|
||||
return currentUrl.substring(0, currentUrl.indexOf('#'));
|
||||
};
|
||||
|
||||
it('should open in a new tab when passing the appropriate usermeta to spec', async () => {
|
||||
const usermeta = JSON.stringify({ embedOptions: { loader: { target: '_blank' } } });
|
||||
const spec = getLinkTestSpec(await getKibanaBaseUrl(), usermeta);
|
||||
await fillSpecAndGo(spec);
|
||||
|
||||
const windowHandlers = await browser.getAllWindowHandles();
|
||||
expect(windowHandlers.length).to.equal(2);
|
||||
|
||||
await browser.switchTab(1);
|
||||
await browser.closeCurrentWindow();
|
||||
await browser.switchTab(0);
|
||||
});
|
||||
|
||||
it('should open in the same tab without passing the appropriate usermeta to spec', async () => {
|
||||
const spec = getLinkTestSpec(await getKibanaBaseUrl());
|
||||
await fillSpecAndGo(spec);
|
||||
|
||||
const windowHandlers = await browser.getAllWindowHandles();
|
||||
expect(windowHandlers.length).to.equal(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue