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

report: make urls clickable #9224

Merged
merged 18 commits into from
Jun 29, 2019
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ class CriticalRequestChainRenderer {
const {file, hostname} = Util.parseURL(segment.node.request.url);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tests are failing b/c of this change. DetailsRenderer.renderTextURL tosses the host part if parsed.file === '/'. Before, the chain renderer always used the results of Util.parseURL w/o post-processing. The chain renderer now looks like this when run on the root url of a site:

image

before:

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The chain renderer now looks like this when run on the root url of a site:

this is an improvement, IMO.

const treevalEl = dom.find('.crc-node__tree-value', chainsEl);
dom.find('.crc-node__tree-file', treevalEl).textContent = `${file}`;
dom.find('.crc-node__tree-file', treevalEl).href = segment.node.request.url;
dom.find('.crc-node__tree-hostname', treevalEl).textContent = hostname ? `(${hostname})` : '';

if (!segment.hasChildren) {
Expand Down
15 changes: 14 additions & 1 deletion lighthouse-core/report/html/renderer/details-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class DetailsRenderer {
}

const element = this._dom.createElement('div', 'lh-text__url');
element.appendChild(this._renderText(displayedPath));
element.appendChild(this._renderAnchor(displayedPath, url));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like we should rename this method now ;)

maybe we can also share some logic with renderLink at this point since I was about to make _renderAnchor comments about falling back to text on invalid, etc

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, didn't see that method. done.


if (displayedHost) {
const hostElem = this._renderText(displayedHost);
Expand Down Expand Up @@ -160,6 +160,19 @@ class DetailsRenderer {
return element;
}

/**
* @param {string} text
* @param {string} href
* @return {Element}
*/
_renderAnchor(text, href) {
const element = this._dom.createElement('a', 'lh-anchor');
element.textContent = text;
element.href = href;
element.target = '_blank';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget rel=noopener ;)

return element;
}

/**
* @param {string} text
* @return {Element}
Expand Down
5 changes: 5 additions & 0 deletions lighthouse-core/report/html/report-styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,11 @@
object-fit: contain;
}

a.lh-anchor {
color: inherit;
brendankenny marked this conversation as resolved.
Show resolved Hide resolved
text-decoration: none;
}

/* Chevron
https://codepen.io/paulirish/pen/LmzEmK
*/
Expand Down
2 changes: 1 addition & 1 deletion lighthouse-core/report/html/templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@

</span>
<span class="crc-node__tree-value">
<span class="crc-node__tree-file"><!-- fill me: node.request.url.file --></span>
<a class="lh-anchor crc-node__tree-file" target="_blank"><!-- fill me: node.request.url.file --></a>
<span class="crc-node__tree-hostname">(<!-- fill me: node.request.url.host -->)</span>

</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ describe('DetailsRenderer', () => {
assert.equal(urlEl.localName, 'div');
assert.equal(urlEl.title, urlText);
assert.equal(urlEl.dataset.url, urlText);
assert.ok(urlEl.firstChild.classList.contains('lh-text'));
assert.ok(urlEl.firstChild.classList.contains('lh-anchor'));
assert.equal(urlEl.textContent, displayUrlText);
});

Expand All @@ -410,7 +410,7 @@ describe('DetailsRenderer', () => {
assert.equal(urlEl.localName, 'div');
assert.equal(urlEl.title, urlText);
assert.equal(urlEl.dataset.url, urlText);
assert.ok(urlEl.firstChild.classList.contains('lh-text'));
assert.ok(urlEl.firstChild.classList.contains('lh-anchor'));
assert.equal(urlEl.textContent, displayUrlText);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ describe('ReportUIFeatures', () => {

function getUrlsInTable() {
return dom
.findAll('#uses-webp-images .lh-details .lh-text__url .lh-text:first-child', container)
.findAll('#uses-webp-images .lh-details .lh-text__url .lh-anchor:first-child', container)
.map(el => el.textContent);
}

Expand Down