Skip to content

Commit

Permalink
Review comments from #14697
Browse files Browse the repository at this point in the history
  • Loading branch information
alexnj committed Jan 31, 2023
1 parent 46a9e1e commit f4287fc
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions report/renderer/report-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ class ReportUtils {
}

// Attach table/opportunity items with entity information.
ReportUtils.classifyEntities(result.entities, audit);
if (audit.details.type === 'opportunity' || audit.details.type === 'table') {
if (result.entities) {
ReportUtils.classifyEntities(result.entities, audit.details);
}
}

// TODO: convert printf-style displayValue.
// Added: #5099, v3
Expand Down Expand Up @@ -194,7 +198,7 @@ class ReportUtils {
* Given an audit's details, identify and return a URL locator function that
* can be called later with an `item` to extract the URL of it.
* @param {LH.FormattedIcu<LH.Audit.Details.TableColumnHeading[]>} headings
* @return {{(item: LH.FormattedIcu<LH.Audit.Details.TableItem>): string|undefined}=}
* @return {((item: LH.FormattedIcu<LH.Audit.Details.TableItem>) => string|undefined)=}
*/
static getUrlLocatorFn(headings) {
// The most common type, valueType=url.
Expand Down Expand Up @@ -224,17 +228,12 @@ class ReportUtils {

/**
* Mark TableItems/OpportunityItems with entity names.
* @param {LH.Result.Entities|undefined} entityClassification
* @param {import('../../types/lhr/audit-result').Result} audit
* @param {LH.Result.Entities} entityClassification
* @param {LH.FormattedIcu<LH.Audit.Details.Opportunity|LH.Audit.Details.Table>} details
*/
static classifyEntities(entityClassification, audit) {
if (!entityClassification) return;
if (audit.details?.type !== 'opportunity' && audit.details?.type !== 'table') {
return;
}

static classifyEntities(entityClassification, details) {
// If details.items are already marked with entity attribute during an audit, nothing to do here.
const {items, headings} = audit.details;
const {items, headings} = details;
if (!items.length || items.some(item => item.entity)) return;

// Identify a URL-locator function that we could call against each item to get its URL.
Expand Down

0 comments on commit f4287fc

Please sign in to comment.