Skip to content
4 changes: 4 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ class PWMetrics {

if (this.flags.upload) {
const driveResponse = await upload(data, this.clientSecret);

preparedData.fileId = driveResponse.id;
preparedData.fileName = driveResponse.name;

this.view(driveResponse.id);
}

Expand Down
2 changes: 2 additions & 0 deletions lib/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ function prepareData(res: LighthouseResults): MetricsResults {
});

return {
fileId: '',
fileName: '',
timings,
timestamps,
generatedTime: res.generatedTime,
Expand Down
10 changes: 9 additions & 1 deletion lib/sheets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const metricsIds = require('../metrics').ids;
const SHEET_TYPES = {
'GOOGLE_SHEETS': 'GOOGLE_SHEETS'
};
const VIEWER_URL_PREFIX = 'https://chromedevtools.github.io/timeline-viewer/?loadTimelineFromURL=drive://';

class Sheets {
constructor(public config: SheetsConfig, public clientSecret: AuthorizeCredentials) {
Expand Down Expand Up @@ -50,6 +51,12 @@ class Sheets {
results.forEach(data => {
const getTiming = (key: string) => data.timings.find(t => t.id === key).timing;
const dateObj = new Date(data.generatedTime);
let viewerUrl = '';

if(typeof data.fileName !== 'undefined' && typeof data.fileName !== 'undefined') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if(data.fileName) {
  viewerUrl = VIEWER_URL_PREFIX + data.fileId;
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Huh - just noticed one of those is supposed to be data.fileId, but that's the only one needed now - I originally intended to use both, but ditched the idea of using the file name as the link text.

I use typeof rather than a truthy check as it's won't choke on undefined.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So you don't need to be concerned of that because undefined is false when type checked in a boolean scenario.

viewerUrl = VIEWER_URL_PREFIX + data.fileId;
}

// order matters
valuesToAppend.push([
data.lighthouseVersion,
Expand All @@ -62,7 +69,8 @@ class Sheets {
getTiming(metricsIds.VC100),
getTiming(metricsIds.TTFI),
getTiming(metricsIds.TTCI),
getTiming(metricsIds.VC85)
getTiming(metricsIds.VC85),
viewerUrl
]);
});

Expand Down
2 changes: 2 additions & 0 deletions types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ interface FeatureFlags {
}

interface MetricsResults {
fileName: string,
fileId: string,
timestamps: Timestamp[];
timings: Timing[];
generatedTime: string;
Expand Down