Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
Merge pull request #156 from cloudflare/linkify
Browse files Browse the repository at this point in the history
Linkify URLs in annotations
  • Loading branch information
prymitive committed Aug 18, 2017
2 parents 8951926 + 44830cc commit 577c15e
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 2 deletions.
13 changes: 13 additions & 0 deletions assets/static/__snapshots__/templates.test.js.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`linkify kibana link 1`] = `"<a href=\\"https://kibana/app/kibana#/dashboard/dashboard_name?_g=(time:(from:now-1h,mode:quick,to:now))&_a=(filters:!((query:(match:(host:(query:hostname,type:phrase))),meta:(alias:!n,disabled:!f,index:'logstash-*',key:host,negate:!f,value:hostname)),(meta:(alias:!n,disabled:!f,index:'logstash-*',key:program,negate:!f,value:puppet-agent),query:(match:(program:(query:puppet-agent,type:phrase)))),(meta:(alias:!n,disabled:!f,index:'logstash-*',key:level,negate:!f,value:ERROR),query:(match:(level:(query:ERROR,type:phrase))))))\\" title=\\"https://kibana/app/kibana#/dashboard/dashboard_name?_g=(time:(from:now-1h,mode:quick,to:now))&_a=(filters:!((query:(match:(host:(query:hostname,type:phrase))),meta:(alias:!n,disabled:!f,index:'logstash-*',key:host,negate:!f,value:hostname)),(meta:(alias:!n,disabled:!f,index:'logstash-*',key:program,negate:!f,value:puppet-agent),query:(match:(program:(query:puppet-agent,type:phrase)))),(meta:(alias:!n,disabled:!f,index:'logstash-*',key:level,negate:!f,value:ERROR),query:(match:(level:(query:ERROR,type:phrase))))))\\">https://kibana/app/kibana#/dashboard/dashboard_name?_g=(time:(from:now-1h,mode:quick,to:now))&_a=(filters:!((query:(match:(host:(query:hostname,type:phrase))),meta:(alias:!n,disabled:!f,index:'logstash-*',key:host,negate:!f,value:hostname)),(meta:(alias:!n,disabled:!f,index:'logstash-*',key:program,negate:!f,value:puppet-agent),query:(match:(program:(query:puppet-agent,type:phrase)))),(meta:(alias:!n,disabled:!f,index:'logstash-*',key:level,negate:!f,value:ERROR),query:(match:(level:(query:ERROR,type:phrase))))))</a>"`;

exports[`linkify kibana link 2`] = `"foo <a href=\\"https://kibana/app/kibana#/dashboard/dashboard_name?_g=(time:(from:now-1h,mode:quick,to:now))&_a=(filters:!((query:(match:(host:(query:hostname,type:phrase))),meta:(alias:!n,disabled:!f,index:'logstash-*',key:host,negate:!f,value:hostname)),(meta:(alias:!n,disabled:!f,index:'logstash-*',key:program,negate:!f,value:puppet-agent),query:(match:(program:(query:puppet-agent,type:phrase)))),(meta:(alias:!n,disabled:!f,index:'logstash-*',key:level,negate:!f,value:ERROR),query:(match:(level:(query:ERROR,type:phrase))))))\\" title=\\"https://kibana/app/kibana#/dashboard/dashboard_name?_g=(time:(from:now-1h,mode:quick,to:now))&_a=(filters:!((query:(match:(host:(query:hostname,type:phrase))),meta:(alias:!n,disabled:!f,index:'logstash-*',key:host,negate:!f,value:hostname)),(meta:(alias:!n,disabled:!f,index:'logstash-*',key:program,negate:!f,value:puppet-agent),query:(match:(program:(query:puppet-agent,type:phrase)))),(meta:(alias:!n,disabled:!f,index:'logstash-*',key:level,negate:!f,value:ERROR),query:(match:(level:(query:ERROR,type:phrase))))))\\">https://kibana/app/kibana#/dashboard/dashboard_name?_g=(time:(from:now-1h,mode:quick,to:now))&_a=(filters:!((query:(match:(host:(query:hostname,type:phrase))),meta:(alias:!n,disabled:!f,index:'logstash-*',key:host,negate:!f,value:hostname)),(meta:(alias:!n,disabled:!f,index:'logstash-*',key:program,negate:!f,value:puppet-agent),query:(match:(program:(query:puppet-agent,type:phrase)))),(meta:(alias:!n,disabled:!f,index:'logstash-*',key:level,negate:!f,value:ERROR),query:(match:(level:(query:ERROR,type:phrase))))))</a> bar"`;

exports[`linkify simple link 1`] = `"<a href=\\"http://localhost\\" title=\\"http://localhost\\">http://localhost</a>"`;
exports[`linkify simple link 2`] = `"<a href=\\"http://localhost:8080/abc\\" title=\\"http://localhost:8080/abc\\">http://localhost:8080/abc</a>"`;
exports[`linkify simple link 3`] = `"<a href=\\"http://localhost:8080/abc#foo\\" title=\\"http://localhost:8080/abc#foo\\">http://localhost:8080/abc#foo</a>"`;
exports[`linkify simple link 4`] = `"<a href=\\"http://localhost:8080/abc?foo\\" title=\\"http://localhost:8080/abc?foo\\">http://localhost:8080/abc?foo</a>"`;
2 changes: 2 additions & 0 deletions assets/static/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const $ = require("jquery");
const _ = require("underscore");
const moment = require("moment");
require("javascript-linkify");

const alerts = require("./alerts");

Expand Down Expand Up @@ -73,6 +74,7 @@ function init() {

function renderTemplate(name, context) {
context["moment"] = moment;
context["linkify"] = window.linkify;
context["renderTemplate"] = renderTemplate;
context["sortMapByKey"] = alerts.sortMapByKey;
context["getLabelAttrs"] = alerts.getLabelAttrs;
Expand Down
23 changes: 23 additions & 0 deletions assets/static/templates.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
const templates = require("./templates");
const templatesMock = require("./__mocks__/templatesMock");
require("javascript-linkify");

test("templates init()", () => {
document.body.innerHTML = templatesMock.loadTemplates();
templates.init();
});

test("linkify simple link", () => {
expect(window.linkify("http://localhost")).toMatchSnapshot();
expect(window.linkify("http://localhost:8080/abc")).toMatchSnapshot();
expect(window.linkify("http://localhost:8080/abc#foo")).toMatchSnapshot();
expect(window.linkify("http://localhost:8080/abc?foo")).toMatchSnapshot();
});

test("linkify kibana link", () => {
let longLink =
"https://kibana/app/kibana#/dashboard/dashboard_name?_g=" +
"(time:(from:now-1h,mode:quick,to:now))&_a=(filters:!((query:" +
"(match:(host:(query:hostname,type:phrase))),meta:" +
"(alias:!n,disabled:!f,index:'logstash-*',key:host,negate:!f," +
"value:hostname)),(meta:(alias:!n,disabled:!f,index:'logstash-*'" +
",key:program,negate:!f,value:puppet-agent),query:(match:(program:" +
"(query:puppet-agent,type:phrase)))),(meta:(alias:!n,disabled:" +
"!f,index:'logstash-*',key:level,negate:!f,value:ERROR),query:" +
"(match:(level:(query:ERROR,type:phrase))))))";
expect(window.linkify(longLink)).toMatchSnapshot();
expect(window.linkify("foo " + longLink + " bar")).toMatchSnapshot();
});
4 changes: 2 additions & 2 deletions assets/templates/alertgroup.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
<script type="application/json" id="alert-group-annotations">
<% _.each(sortMapByKey(alert.annotations), function(annotation) { %>
<div class="well well-sm annotation-well">
<i class="fa fa-question-circle text-muted" title="<%= annotation.key %>" data-toggle="tooltip" data-placement="top"/>
<i class="fa fa-info-circle text-muted" title="<%- annotation.key %>" data-toggle="tooltip" data-placement="top"/>
<% if (annotation.value) { %>
<%- annotation.value %>
<%= linkify(_.escape(annotation.value)) %>
<% } else { %>
<span class="text-muted">
[ missing annotation value ]
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"favico.js": "^0.3.10",
"font-awesome": "^4.7.0",
"is-in-viewport": "^3.0.0",
"javascript-linkify": "^0.3.0",
"jquery": "^3.2.1",
"js-cookie": "^2.1.4",
"js-sha1": "^0.4.1",
Expand Down

0 comments on commit 577c15e

Please sign in to comment.