From d73c056b7c9ae43cbe22f4888ea1d69f81c75d77 Mon Sep 17 00:00:00 2001 From: Connor Clark Date: Mon, 9 Dec 2019 13:32:41 -0800 Subject: [PATCH] rm row.multi --- .../report/html/renderer/details-renderer.js | 34 ++++++++----------- types/audit-details.d.ts | 23 +++++++------ types/audit.d.ts | 1 - 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/lighthouse-core/report/html/renderer/details-renderer.js b/lighthouse-core/report/html/renderer/details-renderer.js index 50bfb7192741..fb95e519f914 100644 --- a/lighthouse-core/report/html/renderer/details-renderer.js +++ b/lighthouse-core/report/html/renderer/details-renderer.js @@ -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} */ @@ -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. @@ -313,6 +308,7 @@ class DetailsRenderer { key: heading.key, label: heading.text, valueType: heading.itemType, + multi: heading.multi, displayUnit: heading.displayUnit, granularity: heading.granularity, }; @@ -320,12 +316,12 @@ class DetailsRenderer { } /** - * @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) { @@ -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) { diff --git a/types/audit-details.d.ts b/types/audit-details.d.ts index 64910c6b4461..9ba7c4eb62b4 100644 --- a/types/audit-details.d.ts +++ b/types/audit-details.d.ts @@ -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. @@ -97,6 +98,11 @@ 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; @@ -104,7 +110,7 @@ declare global { 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 { @@ -118,8 +124,11 @@ declare global { * could also be objects with their own type to override this field. */ valueType: ItemValueTypes; - /** ... */ - multi?: Omit, '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; @@ -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[]; } /** diff --git a/types/audit.d.ts b/types/audit.d.ts index ad68dcd18313..05ecf3d85fc1 100644 --- a/types/audit.d.ts +++ b/types/audit.d.ts @@ -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. */