Skip to content
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 an option for url types so that it can be opened in current tab (6.0 branch) #13211

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/core_plugins/kibana/common/field_formats/types/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ UrlFormat.prototype._convert = {
linkLabel = label;
}

return `<a href="${url}" target="_blank">${linkLabel}</a>`;
let linkTarget = this.param('openLinkInCurrentTab') ? '_self' : '_blank';

return `<a href="${url}" target="${linkTarget}">${linkLabel}</a>`;
}
}
};
10 changes: 9 additions & 1 deletion src/core_plugins/kibana/public/field_formats/__tests__/_url.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Url Format', function () {
Url = fieldFormats.getType('url');
});

it('ouputs a simple <a> tab by default', function () {
it('outputs a simple <a> tab by default', function () {
const url = new Url();

const $a = unwrap($(url.convert('http://elastic.co', 'html')));
Expand All @@ -34,6 +34,14 @@ describe('Url Format', function () {
expect($a.children().size()).to.be(0);
});

it('outputs a <a> link with target=_self if "open link in current tab" is checked', function () {
const url = new Url({ openLinkInCurrentTab: true });

const $a = unwrap($(url.convert('http://elastic.co', 'html')));
expect($a.is('a')).to.be(true);
expect($a.attr('target')).to.be('_self');
});

it('outputs an <image> if type === "img"', function () {
const url = new Url({ type: 'img' });

Expand Down
8 changes: 8 additions & 0 deletions src/ui/public/field_format_editor/editors/url/url.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
</select>
</div>

<div class="checkbox" ng-if="editor.formatParams.type == 'a'">
<label>
<input ng-model="editor.formatParams.openLinkInCurrentTab" class="ng-pristine ng-valid ng-touched" type="checkbox">
Open link in current tab
</label>
</div>

<div class="form-group">
<span class="pull-right text-info hintbox-label" ng-click="editor.showUrlTmplHelp = !editor.showUrlTmplHelp">
<i class="fa fa-info"></i> Url Template Help
Expand Down Expand Up @@ -119,6 +126,7 @@ <h4 class="hintbox-heading">
</div>

<input ng-model="editor.formatParams.labelTemplate" class="form-control">

</div>

<field-format-editor-samples inputs="url.samples[editor.formatParams.type]"></field-format-editor-samples>