Skip to content

Commit

Permalink
rm row.multi
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark committed Dec 9, 2019
1 parent 2b9babb commit d73c056
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
34 changes: 14 additions & 20 deletions lighthouse-core/report/html/renderer/details-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class DetailsRenderer {
* Render a details item value for embedding in a table. Renders the value
* based on the heading's valueType, unless the value itself has a `type`
* property to override it.
* @param {LH.Audit.Details.TableItem[string] | LH.Audit.Details.OpportunityItem[string]} value
* @param {LH.Audit.Details.Value} value
* @param {LH.Audit.Details.OpportunityColumnHeading} heading
* @return {Element|null}
*/
Expand All @@ -217,11 +217,6 @@ class DetailsRenderer {
return null;
}

if (typeof value === 'object' && value.type === 'multi') {
console.warn('Invalid multi value given to _renderTableValue');
return null;
}

// First deal with the possible object forms of value.
if (typeof value === 'object') {
// The value's type overrides the heading's for this column.
Expand Down Expand Up @@ -313,19 +308,20 @@ class DetailsRenderer {
key: heading.key,
label: heading.text,
valueType: heading.itemType,
multi: heading.multi,
displayUnit: heading.displayUnit,
granularity: heading.granularity,
};
});
}

/**
* @param {LH.Audit.Details.OpportunityItemMulti} multi
* @param {LH.Audit.Details.TableItem} row
* @param {LH.Audit.Details.OpportunityColumnHeading} heading
* @return {Element?}
*/
_renderMultiValue(multi, heading) {
const values = multi[heading.key];
_renderMultiValue(row, heading) {
const values = row[heading.key];
if (!Array.isArray(values)) return null;
const valueElement = this._dom.createElement('div', 'lh-multi-values');
for (const childValue of values) {
Expand Down Expand Up @@ -370,20 +366,18 @@ class DetailsRenderer {
valueFragment.appendChild(emptyElement);
} else {
const value = row[heading.key];
const valueElement = value !== undefined && this._renderTableValue(value, heading);
const valueElement =
value !== undefined && !Array.isArray(value) && this._renderTableValue(value, heading);
if (valueElement) valueFragment.appendChild(valueElement);
}

if (heading.multi && row.multi) {
// Make typescript happy.
if (typeof row.multi === 'object' && row.multi.type === 'multi') {
const multiHeading = {
...heading,
...heading.multi,
};
const multiElement = this._renderMultiValue(row.multi, multiHeading);
if (multiElement) valueFragment.appendChild(multiElement);
}
if (heading.multi) {
const multiHeading = {
...heading,
...heading.multi,
};
const multiElement = this._renderMultiValue(row, multiHeading);
if (multiElement) valueFragment.appendChild(multiElement);
}

if (valueFragment.childElementCount) {
Expand Down
23 changes: 13 additions & 10 deletions types/audit-details.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ declare global {

/** Possible types of values found within table items. */
type ItemValueTypes = 'bytes' | 'code' | 'link' | 'ms' | 'multi' | 'node' | 'source-location' | 'numeric' | 'text' | 'thumbnail' | 'timespanMs' | 'url';
type Value = string | number | boolean | DebugData | NodeValue | SourceLocationValue | LinkValue | UrlValue | CodeValue;

// TODO(bckenny): unify Table/Opportunity headings and items on next breaking change.

Expand All @@ -97,14 +98,19 @@ declare global {
* could also be objects with their own type to override this field.
*/
itemType: ItemValueTypes;
/**
* Optional header defining an inner table of values that correspond to this column.
* Key is required - if other properties are not provided, the value for the heading is used.
*/
multi?: {key: string, itemType?: ItemValueTypes, displayUnit?: string, granularity?: number};

displayUnit?: string;
granularity?: number;
}

export type TableItem = {
debugData?: DebugData;
[p: string]: undefined | string | number | boolean | undefined | DebugData | NodeValue | SourceLocationValue | LinkValue | UrlValue | CodeValue;
[p: string]: undefined | Value | Value[];
}

export interface OpportunityColumnHeading {
Expand All @@ -118,8 +124,11 @@ declare global {
* could also be objects with their own type to override this field.
*/
valueType: ItemValueTypes;
/** ... */
multi?: Omit<Partial<OpportunityColumnHeading>, 'label'|'multi'>;
/**
* Optional header defining an inner table of values that correspond to this column.
* Key is required - if other properties are not provided, the value for the heading is used.
*/
multi?: {key: string, valueType?: ItemValueTypes, displayUnit?: string, granularity?: number};

// NOTE: not used by opportunity details, but used in the renderer until table/opportunity unification.
displayUnit?: string;
Expand All @@ -132,13 +141,7 @@ declare global {
totalBytes?: number;
wastedMs?: number;
debugData?: DebugData;
[p: string]: number | boolean | string | undefined | DebugData | OpportunityItemMulti;
multi?: OpportunityItemMulti;
}

export interface OpportunityItemMulti {
type: 'multi',
[p: string]: number[] | boolean[] | string | string[] | undefined | DebugData[];
[p: string]: undefined | Value | Value[];
}

/**
Expand Down
1 change: 0 additions & 1 deletion types/audit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ declare global {
wastedBytes: number;
totalBytes: number;
wastedPercent?: number;
multi?: Audit.Details.OpportunityItemMulti;
}

/** Type returned by Audit.audit(). Only score is required. */
Expand Down

0 comments on commit d73c056

Please sign in to comment.