@lighthouse/common 4.31.1-canary.6 → 4.31.1-canary.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/pdf/audit/index.js +14 -9
- package/dist/pdf/helpers/build-audit-content/index.js +3 -3
- package/dist/pdf/helpers/build-audit-follow-ups/index.js +2 -10
- package/lib/pdf/audit/index.js +11 -9
- package/lib/pdf/audit/index.js.map +1 -1
- package/lib/pdf/helpers/build-audit-content/index.js +3 -3
- package/lib/pdf/helpers/build-audit-content/index.js.map +1 -1
- package/lib/pdf/helpers/build-audit-follow-ups/index.js +3 -11
- package/lib/pdf/helpers/build-audit-follow-ups/index.js.map +1 -1
- package/package.json +1 -1
package/dist/pdf/audit/index.js
CHANGED
|
@@ -44,14 +44,17 @@ function buildAuditPdf(pdfOptions, data) {
|
|
|
44
44
|
entity,
|
|
45
45
|
timezone
|
|
46
46
|
} = data;
|
|
47
|
+
const {
|
|
48
|
+
flags = {}
|
|
49
|
+
} = pdfOptions;
|
|
47
50
|
console.log('buildAuditPdf', {
|
|
48
|
-
version: '4.
|
|
51
|
+
version: '4.31.1-canary.8'
|
|
49
52
|
});
|
|
50
53
|
const sequenceId = entity.sequenceId;
|
|
51
54
|
const timestamp = entity.createdAt;
|
|
52
55
|
const title = entity.title || 'Unknown';
|
|
53
56
|
const fileTitle = `Audit Report - ${title}`;
|
|
54
|
-
return generateContent(data).then(content => (0, _helpers.generateDefinition)({
|
|
57
|
+
return generateContent(data, flags).then(content => (0, _helpers.generateDefinition)({
|
|
55
58
|
content,
|
|
56
59
|
fileTitle,
|
|
57
60
|
sequenceId,
|
|
@@ -64,7 +67,10 @@ function buildAuditPdf(pdfOptions, data) {
|
|
|
64
67
|
});
|
|
65
68
|
}
|
|
66
69
|
|
|
67
|
-
function generateContent(data) {
|
|
70
|
+
function generateContent(data, flags) {
|
|
71
|
+
const {
|
|
72
|
+
rolloutAuditFollowUps
|
|
73
|
+
} = flags;
|
|
68
74
|
const {
|
|
69
75
|
entity
|
|
70
76
|
} = data;
|
|
@@ -78,9 +84,8 @@ function generateContent(data) {
|
|
|
78
84
|
title = 'Unknown'
|
|
79
85
|
} = entity;
|
|
80
86
|
const entityDetails = (0, _helpers2.getAuditEntryDetails)(data);
|
|
81
|
-
const hasFollowUps = !!entity.followUps;
|
|
82
87
|
console.log('buildAuditPdf', {
|
|
83
|
-
|
|
88
|
+
rolloutAuditFollowUps
|
|
84
89
|
});
|
|
85
90
|
const {
|
|
86
91
|
gpsText,
|
|
@@ -172,17 +177,17 @@ function generateContent(data) {
|
|
|
172
177
|
margin: [0, 10, 0, 0]
|
|
173
178
|
});
|
|
174
179
|
const hLineBottom = (0, _helpers.horizontalLine)();
|
|
175
|
-
const followUpItems =
|
|
180
|
+
const followUpItems = rolloutAuditFollowUps ? (0, _helpers.buildAuditFollowUps)(followUps, {
|
|
176
181
|
timezone
|
|
177
182
|
}) : [];
|
|
178
183
|
const promises = {
|
|
179
184
|
entry: (0, _helpers.buildAuditContent)(groupedData.items, {
|
|
180
|
-
|
|
185
|
+
rolloutAuditFollowUps
|
|
181
186
|
}),
|
|
182
187
|
footerTemplate: (0, _helpers.buildTemplateContent)(footerFields.formGroups, data),
|
|
183
188
|
headerTemplate: (0, _helpers.buildTemplateContent)(headerFields.formGroups, data)
|
|
184
189
|
};
|
|
185
|
-
const auditItemsTitle =
|
|
190
|
+
const auditItemsTitle = rolloutAuditFollowUps ? [{
|
|
186
191
|
text: 'Audit Items',
|
|
187
192
|
style: {
|
|
188
193
|
font: 'Gotham',
|
|
@@ -193,7 +198,7 @@ function generateContent(data) {
|
|
|
193
198
|
entry,
|
|
194
199
|
footerTemplate,
|
|
195
200
|
headerTemplate
|
|
196
|
-
}) => [titleTable,
|
|
201
|
+
}) => [titleTable, followUpItems, ...auditItemsTitle, ...headerTemplate, ...entry, hLineTop, totalScoreTable, hLineBottom, ...footerTemplate]).catch(err => {
|
|
197
202
|
throw new Error(`GenerateContentError: ${err.message}`);
|
|
198
203
|
});
|
|
199
204
|
}
|
|
@@ -19,7 +19,7 @@ var _table = require("../table");
|
|
|
19
19
|
|
|
20
20
|
const buildAuditContent = _bluebird.default.method((items, options) => {
|
|
21
21
|
const {
|
|
22
|
-
|
|
22
|
+
rolloutAuditFollowUps
|
|
23
23
|
} = options;
|
|
24
24
|
return _bluebird.default.map(items, group => {
|
|
25
25
|
return _bluebird.default.map(group.items, (item, index) => {
|
|
@@ -37,9 +37,9 @@ const buildAuditContent = _bluebird.default.method((items, options) => {
|
|
|
37
37
|
const rows = [];
|
|
38
38
|
const fillColor = index % 2 === 0 ? _table.WHITE : _table.LIGHT_BLUE;
|
|
39
39
|
const hasImages = !(0, _lodash.isEmpty)(rowImages);
|
|
40
|
-
const hasComments = !(0, _lodash.isEmpty)(item.comments); // Some audits use questionId to link a follow
|
|
40
|
+
const hasComments = !(0, _lodash.isEmpty)(item.comments); // Some audits use questionId to link a follow-up issue and its question
|
|
41
41
|
|
|
42
|
-
const label =
|
|
42
|
+
const label = rolloutAuditFollowUps ? {
|
|
43
43
|
text: item.label,
|
|
44
44
|
fillColor,
|
|
45
45
|
id: item.questionId
|
|
@@ -15,14 +15,6 @@ var _ = require("../");
|
|
|
15
15
|
|
|
16
16
|
var _images = require("../../../images");
|
|
17
17
|
|
|
18
|
-
// Still to do:
|
|
19
|
-
// *. Setup the page breaks, either on the last item here or the first in the next section
|
|
20
|
-
// - I want to do this in a way that avoids orphans, or at least only add a page break if the result looks balanced
|
|
21
|
-
// - If we can work out the page position of the last follow up item then we can determine whether to use a page break or not
|
|
22
|
-
// *. If you're not using the flag then you should make sure that all of the variables necessary have been passed in
|
|
23
|
-
// - If the required data isn't present then you should probably just not process follow up issues for the document
|
|
24
|
-
// - If you establish this at the start you can build it into the `hasFollowUps` flag
|
|
25
|
-
// *. Is there some way that you can setup an override for the pdfmake version used by storybook?
|
|
26
18
|
const LIGHTHOUSE_BASE_URL = 'https://app.lighthouse.io';
|
|
27
19
|
|
|
28
20
|
function buildAuditFollowUps(rawFollowUpIssues = [], options = {}) {
|
|
@@ -44,9 +36,9 @@ function buildAuditFollowUps(rawFollowUpIssues = [], options = {}) {
|
|
|
44
36
|
const followUpIssues = rawFollowUpIssues.filter(item => !item.errorMessage);
|
|
45
37
|
|
|
46
38
|
if (!followUpIssues.length) {
|
|
47
|
-
// Show a `no follow
|
|
39
|
+
// Show a `no follow-up issues` message if there are no follow up issues
|
|
48
40
|
return [sectionTitle, sectionDivider, {
|
|
49
|
-
text: 'No follow
|
|
41
|
+
text: 'No follow-up issues exist for this audit',
|
|
50
42
|
style: _.defaultStyles.subTitle,
|
|
51
43
|
margin: [0, 5, 0, 50]
|
|
52
44
|
}];
|
package/lib/pdf/audit/index.js
CHANGED
|
@@ -37,14 +37,16 @@ import { getAuditEntryDetails } from '../../helpers';
|
|
|
37
37
|
export function buildAuditPdf(pdfOptions, data) {
|
|
38
38
|
var entity = data.entity,
|
|
39
39
|
timezone = data.timezone;
|
|
40
|
+
var _pdfOptions$flags = pdfOptions.flags,
|
|
41
|
+
flags = _pdfOptions$flags === void 0 ? {} : _pdfOptions$flags;
|
|
40
42
|
console.log('buildAuditPdf', {
|
|
41
|
-
version: '4.
|
|
43
|
+
version: '4.31.1-canary.8'
|
|
42
44
|
});
|
|
43
45
|
var sequenceId = entity.sequenceId;
|
|
44
46
|
var timestamp = entity.createdAt;
|
|
45
47
|
var title = entity.title || 'Unknown';
|
|
46
48
|
var fileTitle = "Audit Report - ".concat(title);
|
|
47
|
-
return generateContent(data).then(function (content) {
|
|
49
|
+
return generateContent(data, flags).then(function (content) {
|
|
48
50
|
return generateDefinition(_objectSpread({
|
|
49
51
|
content: content,
|
|
50
52
|
fileTitle: fileTitle,
|
|
@@ -58,7 +60,8 @@ export function buildAuditPdf(pdfOptions, data) {
|
|
|
58
60
|
});
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
function generateContent(data) {
|
|
63
|
+
function generateContent(data, flags) {
|
|
64
|
+
var rolloutAuditFollowUps = flags.rolloutAuditFollowUps;
|
|
62
65
|
var entity = data.entity;
|
|
63
66
|
var _entity$followUps = entity.followUps,
|
|
64
67
|
followUps = _entity$followUps === void 0 ? [] : _entity$followUps,
|
|
@@ -74,9 +77,8 @@ function generateContent(data) {
|
|
|
74
77
|
_entity$title = entity.title,
|
|
75
78
|
title = _entity$title === void 0 ? 'Unknown' : _entity$title;
|
|
76
79
|
var entityDetails = getAuditEntryDetails(data);
|
|
77
|
-
var hasFollowUps = !!entity.followUps;
|
|
78
80
|
console.log('buildAuditPdf', {
|
|
79
|
-
|
|
81
|
+
rolloutAuditFollowUps: rolloutAuditFollowUps
|
|
80
82
|
});
|
|
81
83
|
var gpsText = entityDetails.gpsText,
|
|
82
84
|
groupedData = entityDetails.groupedData,
|
|
@@ -166,17 +168,17 @@ function generateContent(data) {
|
|
|
166
168
|
margin: [0, 10, 0, 0]
|
|
167
169
|
});
|
|
168
170
|
var hLineBottom = horizontalLine();
|
|
169
|
-
var followUpItems =
|
|
171
|
+
var followUpItems = rolloutAuditFollowUps ? buildAuditFollowUps(followUps, {
|
|
170
172
|
timezone: timezone
|
|
171
173
|
}) : [];
|
|
172
174
|
var promises = {
|
|
173
175
|
entry: buildAuditContent(groupedData.items, {
|
|
174
|
-
|
|
176
|
+
rolloutAuditFollowUps: rolloutAuditFollowUps
|
|
175
177
|
}),
|
|
176
178
|
footerTemplate: buildTemplateContent(footerFields.formGroups, data),
|
|
177
179
|
headerTemplate: buildTemplateContent(headerFields.formGroups, data)
|
|
178
180
|
};
|
|
179
|
-
var auditItemsTitle =
|
|
181
|
+
var auditItemsTitle = rolloutAuditFollowUps ? [{
|
|
180
182
|
text: 'Audit Items',
|
|
181
183
|
style: {
|
|
182
184
|
font: 'Gotham',
|
|
@@ -187,7 +189,7 @@ function generateContent(data) {
|
|
|
187
189
|
var entry = _ref.entry,
|
|
188
190
|
footerTemplate = _ref.footerTemplate,
|
|
189
191
|
headerTemplate = _ref.headerTemplate;
|
|
190
|
-
return [titleTable].concat(_toConsumableArray(headerTemplate),
|
|
192
|
+
return [titleTable, followUpItems].concat(auditItemsTitle, _toConsumableArray(headerTemplate), _toConsumableArray(entry), [hLineTop, totalScoreTable, hLineBottom], _toConsumableArray(footerTemplate));
|
|
191
193
|
}).catch(function (err) {
|
|
192
194
|
throw new Error("GenerateContentError: ".concat(err.message));
|
|
193
195
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/pdf/audit/index.js"],"names":["Promise","isEmpty","round","buildAuditContent","buildAuditFollowUps","buildTemplateContent","generateDefinition","getFormattedAddress","horizontalLine","text","twoColumnTable","getAuditEntryDetails","buildAuditPdf","pdfOptions","data","entity","timezone","console","log","version","sequenceId","timestamp","createdAt","title","fileTitle","generateContent","then","content","type","catch","err","Error","message","followUps","footerFields","gps","headerFields","score","entityDetails","hasFollowUps","gpsText","groupedData","locationText","referenceValue","timezoneHourTime","scoreText","target","targetServiceLevel","renderTargetFields","headerTitle","style","headerScore","alignment","firstRow","subTitle","headerSubTitle","colSpan","secondRow","reverseGeocoded","address","renderHeaderAddress","dummyColumn","headerAddress","renderThirdRow","thirdRow","serviceLevelBelow","serviceLevelText","scoreServiceLevelSubTitle","truncatedTargetPercent","scoreTargetText","scoreTargetSubTitle","scoreBreakdown","actual","max","scorePercentage","scoreTitle","body","titleTable","layout","widths","margin","totalScoreTable","hLineTop","hLineBottom","followUpItems","promises","entry","items","footerTemplate","formGroups","headerTemplate","auditItemsTitle","font","lineHeight","props"],"mappings":";;;;;;;AAAA,OAAOA,OAAP,MAAoB,UAApB;AACA,SAASC,OAAT,EAAkBC,KAAlB,QAA+B,QAA/B;AAEA,SACEC,iBADF,EAEEC,mBAFF,EAGEC,oBAHF,EAIEC,kBAJF,EAKEC,mBALF,EAMEC,cANF,EAOEC,IAPF,EAQEC,cARF,QASO,YATP;AAWA,SAASC,oBAAT,QAAqC,eAArC;AAEA;;;;;;;;;;;;;;;;;;;;;;;;;AAwBA,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AAoB,CAAC+B,YAAY,CAACqD,UAAd,EAA0B3E,IAA1B;AAHrB,GAAjB;AAMA,MAAM6E,eAAe,GAAGpD,YAAY,GAChC,CACE;AACE9B,IAAAA,IAAI,EAAE,aADR;AAEEyC,IAAAA,KAAK,EAAE;AACL0C,MAAAA,IAAI,EAAE,QADD;AAELC,MAAAA,UAAU,EAAE;AAFP;AAFT,GADF,EAQEX,QARF,CADgC,GAWhC,EAXJ;AAaA,SAAOlF,OAAO,CAAC8F,KAAR,CAAcT,QAAd,EACJ3D,IADI,CACC;AAAA,QAAG4D,KAAH,QAAGA,KAAH;AAAA,QAAUE,cAAV,QAAUA,cAAV;AAAA,QAA0BE,cAA1B,QAA0BA,cAA1B;AAAA,YACJb,UADI,4BAEDa,cAFC,IAGJN,aAHI,GAIDO,eAJC,qBAKDL,KALC,IAMJJ,QANI,EAOJD,eAPI,EAQJE,WARI,sBASDK,cATC;AAAA,GADD,EAYJ3D,KAZI,CAYE,UAAAC,GAAG,EAAI;AACZ,UAAM,IAAIC,KAAJ,iCAAmCD,GAAG,CAACE,OAAvC,EAAN;AACD,GAdI,CAAP;AAeD","sourcesContent":["import Promise from 'bluebird'\nimport { isEmpty, round } from 'lodash'\n\nimport {\n buildAuditContent,\n buildAuditFollowUps,\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n horizontalLine,\n text,\n twoColumnTable,\n} from '../helpers'\n\nimport { getAuditEntryDetails } from '../../helpers'\n\n/**\n * buildAuditPdf\n *\n * @param {object} pdfOptions - the pdf options\n * @param {string} pdfOptions.fileTitle - pdf file title\n * @param {function} pdfOptions.footer - function executed to generate footer\n * @param {function} pdfOptions.header - function executed to generate header\n * @param {string} pdfOptions.logoUrl - pdf logo url\n * @param {array} pdfOptions.pageMargins - pdf page margins\n * @param {string} pdfOptions.pageOrientation - pdf page orientation\n * @param {string} pdfOptions.pageSize - pdf page size\n * @param {object} pdfOptions.styles - pdf styles\n * @param {object} pdfOptions.title - pdf title\n * @param {object} pdfOptions.flags - flags to conditionally render parts of the pdf\n * @param {object} data - pdf data\n * @param {object} data.entity - audit document\n * @param {object} data.locations - locations documents\n * @param {object} data.settings - settings properties\n * @param {string} data.settings.awsS3BaseUrl - aws S3 base url\n * @param {string} data.settings.cloudinaryBaseUrl - cloudinary base url\n * @param {string} data.timezone - timezone string\n * @param {object} data.users - application user documents\n * @returns {Promise} returns pdfmake definition object\n */\nexport function buildAuditPdf(pdfOptions, data) {\n const { entity, timezone } = data\n\n console.log('buildAuditPdf', {\n version: '4.30.1-canary.3',\n })\n \n const sequenceId = entity.sequenceId\n const timestamp = entity.createdAt\n const title = entity.title || 'Unknown'\n const fileTitle = `Audit Report - ${title}`\n\n return generateContent(data)\n .then(content =>\n generateDefinition({\n content,\n fileTitle,\n sequenceId,\n timestamp,\n timezone,\n type: 'Audit',\n ...pdfOptions,\n })\n )\n .catch(err => {\n throw new Error(`BuildAuditPdfError: ${err.message}`)\n })\n}\n\nfunction generateContent(data) {\n const { entity } = data\n\n const {\n followUps = [],\n footerFields = {},\n gps = {},\n headerFields = {},\n score = {},\n timezone,\n title = 'Unknown',\n } = entity\n\n const entityDetails = getAuditEntryDetails(data)\n const hasFollowUps = !!entity.followUps\n \n console.log('buildAuditPdf', {\n hasFollowUps,\n })\n\n const {\n gpsText,\n groupedData,\n locationText,\n referenceValue,\n timezoneHourTime,\n scoreText,\n target,\n targetServiceLevel,\n } = entityDetails\n\n const renderTargetFields = !!targetServiceLevel\n const headerTitle = text(title, { style: 'title' })\n const headerScore = text(scoreText, { alignment: 'right', style: 'title' })\n const firstRow = [headerTitle, headerScore]\n const subTitle = `${locationText ||\n gpsText} - ${timezoneHourTime} by ${referenceValue}`\n\n let headerSubTitle = text(subTitle, { colSpan: 2, style: 'subTitle' })\n let secondRow = [headerSubTitle]\n\n const reverseGeocoded = gps.reverseGeocoded\n const address = !isEmpty(reverseGeocoded)\n ? getFormattedAddress(reverseGeocoded)\n : ''\n const renderHeaderAddress = !isEmpty(reverseGeocoded)\n const dummyColumn = text(' ', { style: 'small' })\n\n let headerAddress = text(address, { colSpan: 2, style: 'small' })\n const renderThirdRow = renderHeaderAddress || renderTargetFields\n let thirdRow = renderHeaderAddress ? [headerAddress] : []\n\n if (renderTargetFields) {\n headerSubTitle = text(subTitle, { style: 'subTitle' })\n\n const serviceLevelBelow = targetServiceLevel === 'below'\n const serviceLevelText =\n targetServiceLevel === 'above'\n ? 'Above Target'\n : targetServiceLevel === 'on'\n ? 'On Target'\n : targetServiceLevel === 'below'\n ? 'Below Target'\n : ''\n\n const scoreServiceLevelSubTitle = text(serviceLevelText, {\n alignment: 'right',\n style: serviceLevelBelow ? 'serviceLevelBelow' : 'serviceLevelAboveOrOn',\n })\n\n secondRow = [headerSubTitle, scoreServiceLevelSubTitle]\n headerAddress = text(address, { style: 'small' })\n\n const truncatedTargetPercent = round(target, 2)\n const scoreTargetText = `(Target - ${truncatedTargetPercent}%)`\n const scoreTargetSubTitle = text(scoreTargetText, {\n alignment: 'right',\n style: 'subTitle',\n })\n\n thirdRow = renderHeaderAddress\n ? [headerAddress, scoreTargetSubTitle]\n : [dummyColumn, scoreTargetSubTitle]\n }\n\n const scoreBreakdown = text(\n `${round(score.actual, 2)} / ${round(score.max, 2)}`,\n {\n alignment: 'right',\n style: 'totalScore',\n }\n )\n const scorePercentage = text(scoreText, {\n alignment: 'right',\n colSpan: 2,\n style: 'totalAuditScore',\n })\n const scoreTitle = text('Total Score', { style: 'totalScore' })\n\n const body = renderThirdRow\n ? [firstRow, secondRow, thirdRow]\n : [firstRow, secondRow]\n\n const titleTable = twoColumnTable({\n body,\n layout: 'noBorders',\n style: 'titleTable',\n widths: ['*', 100],\n margin: [0, 0, 0, 30],\n })\n\n const totalScoreTable = twoColumnTable({\n body: [[scoreTitle, scoreBreakdown], [scorePercentage]],\n layout: 'noBorders',\n widths: ['*', 100],\n })\n\n const hLineTop = horizontalLine({ margin: [0, 10, 0, 0] })\n const hLineBottom = horizontalLine()\n\n const followUpItems = hasFollowUps\n ? buildAuditFollowUps(followUps, { timezone })\n : []\n\n const promises = {\n entry: buildAuditContent(groupedData.items, { hasFollowUps }),\n footerTemplate: buildTemplateContent(footerFields.formGroups, data),\n headerTemplate: buildTemplateContent(headerFields.formGroups, data),\n }\n\n const auditItemsTitle = hasFollowUps\n ? [\n {\n text: 'Audit Items',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n },\n },\n hLineTop,\n ]\n : []\n\n return Promise.props(promises)\n .then(({ entry, footerTemplate, headerTemplate }) => [\n titleTable,\n ...headerTemplate,\n followUpItems,\n ...auditItemsTitle,\n ...entry,\n hLineTop,\n totalScoreTable,\n hLineBottom,\n ...footerTemplate,\n ])\n .catch(err => {\n throw new Error(`GenerateContentError: ${err.message}`)\n })\n}\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../../src/pdf/audit/index.js"],"names":["Promise","isEmpty","round","buildAuditContent","buildAuditFollowUps","buildTemplateContent","generateDefinition","getFormattedAddress","horizontalLine","text","twoColumnTable","getAuditEntryDetails","buildAuditPdf","pdfOptions","data","entity","timezone","flags","console","log","version","sequenceId","timestamp","createdAt","title","fileTitle","generateContent","then","content","type","catch","err","Error","message","rolloutAuditFollowUps","followUps","footerFields","gps","headerFields","score","entityDetails","gpsText","groupedData","locationText","referenceValue","timezoneHourTime","scoreText","target","targetServiceLevel","renderTargetFields","headerTitle","style","headerScore","alignment","firstRow","subTitle","headerSubTitle","colSpan","secondRow","reverseGeocoded","address","renderHeaderAddress","dummyColumn","headerAddress","renderThirdRow","thirdRow","serviceLevelBelow","serviceLevelText","scoreServiceLevelSubTitle","truncatedTargetPercent","scoreTargetText","scoreTargetSubTitle","scoreBreakdown","actual","max","scorePercentage","scoreTitle","body","titleTable","layout","widths","margin","totalScoreTable","hLineTop","hLineBottom","followUpItems","promises","entry","items","footerTemplate","formGroups","headerTemplate","auditItemsTitle","font","lineHeight","props"],"mappings":";;;;;;;AAAA,OAAOA,OAAP,MAAoB,UAApB;AACA,SAASC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SAAD,EAAY;AAAEnB,IAAAA,QAAQ,EAARA;AAAF,GAAZ,CADqB,GAExC,EAFJ;AAIA,MAAMsE,QAAQ,GAAG;AACfC,IAAAA,KAAK,EAAEpF,iBAAiB,CAACuC,WAAW,CAAC8C,KAAb,EAAoB;AAAEtD,MAAAA,qBAAqB,EAArBA;AAAF,KAApB,CADT;AAEfuD,IAAAA,cAAc,EAAEpF,oBAAoB,CAAC+B,YAAY,CAACsD,UAAd,EAA0B5E,IAA1B,CAFrB;AAGf6E,IAAAA,cAAc,EAAEtF,oBAAoB,CAACiC,YAAY,CAACoD,UAAd,EAA0B5E,IAA1B;AAHrB,GAAjB;AAMA,MAAM8E,eAAe,GAAG1D,qBAAqB,GACzC,CACE;AACEzB,IAAAA,IAAI,EAAE,aADR;AAEE0C,IAAAA,KAAK,EAAE;AACL0C,MAAAA,IAAI,EAAE,QADD;AAELC,MAAAA,UAAU,EAAE;AAFP;AAFT,GADF,EAQEX,QARF,CADyC,GAWzC,EAXJ;AAaA,SAAOnF,OAAO,CAAC+F,KAAR,CAAcT,QAAd,EACJ3D,IADI,CACC;AAAA,QAAG4D,KAAH,QAAGA,KAAH;AAAA,QAAUE,cAAV,QAAUA,cAAV;AAAA,QAA0BE,cAA1B,QAA0BA,cAA1B;AAAA,YACJb,UADI,EAEJO,aAFI,SAGDO,eAHC,qBAIDD,cAJC,sBAKDJ,KALC,IAMJJ,QANI,EAOJD,eAPI,EAQJE,WARI,sBASDK,cATC;AAAA,GADD,EAYJ3D,KAZI,CAYE,UAAAC,GAAG,EAAI;AACZ,UAAM,IAAIC,KAAJ,iCAAmCD,GAAG,CAACE,OAAvC,EAAN;AACD,GAdI,CAAP;AAeD","sourcesContent":["import Promise from 'bluebird'\nimport { isEmpty, round } from 'lodash'\n\nimport {\n buildAuditContent,\n buildAuditFollowUps,\n buildTemplateContent,\n generateDefinition,\n getFormattedAddress,\n horizontalLine,\n text,\n twoColumnTable,\n} from '../helpers'\n\nimport { getAuditEntryDetails } from '../../helpers'\n\n/**\n * buildAuditPdf\n *\n * @param {object} pdfOptions - the pdf options\n * @param {string} pdfOptions.fileTitle - pdf file title\n * @param {function} pdfOptions.footer - function executed to generate footer\n * @param {function} pdfOptions.header - function executed to generate header\n * @param {string} pdfOptions.logoUrl - pdf logo url\n * @param {array} pdfOptions.pageMargins - pdf page margins\n * @param {string} pdfOptions.pageOrientation - pdf page orientation\n * @param {string} pdfOptions.pageSize - pdf page size\n * @param {object} pdfOptions.styles - pdf styles\n * @param {object} pdfOptions.title - pdf title\n * @param {object} pdfOptions.flags - flags to conditionally render parts of the pdf\n * @param {object} data - pdf data\n * @param {object} data.entity - audit document\n * @param {object} data.locations - locations documents\n * @param {object} data.settings - settings properties\n * @param {string} data.settings.awsS3BaseUrl - aws S3 base url\n * @param {string} data.settings.cloudinaryBaseUrl - cloudinary base url\n * @param {string} data.timezone - timezone string\n * @param {object} data.users - application user documents\n * @returns {Promise} returns pdfmake definition object\n */\nexport function buildAuditPdf(pdfOptions, data) {\n const { entity, timezone } = data\n const { flags = {} } = pdfOptions\n\n console.log('buildAuditPdf', {\n version: '4.31.1-canary.8',\n })\n \n const sequenceId = entity.sequenceId\n const timestamp = entity.createdAt\n const title = entity.title || 'Unknown'\n const fileTitle = `Audit Report - ${title}`\n\n return generateContent(data, flags)\n .then(content =>\n generateDefinition({\n content,\n fileTitle,\n sequenceId,\n timestamp,\n timezone,\n type: 'Audit',\n ...pdfOptions,\n })\n )\n .catch(err => {\n throw new Error(`BuildAuditPdfError: ${err.message}`)\n })\n}\n\nfunction generateContent(data, flags) {\n const { rolloutAuditFollowUps } = flags\n const { entity } = data\n\n const {\n followUps = [],\n footerFields = {},\n gps = {},\n headerFields = {},\n score = {},\n timezone,\n title = 'Unknown',\n } = entity\n\n const entityDetails = getAuditEntryDetails(data)\n \n console.log('buildAuditPdf', {\n rolloutAuditFollowUps,\n })\n\n const {\n gpsText,\n groupedData,\n locationText,\n referenceValue,\n timezoneHourTime,\n scoreText,\n target,\n targetServiceLevel,\n } = entityDetails\n\n const renderTargetFields = !!targetServiceLevel\n const headerTitle = text(title, { style: 'title' })\n const headerScore = text(scoreText, { alignment: 'right', style: 'title' })\n const firstRow = [headerTitle, headerScore]\n const subTitle = `${locationText ||\n gpsText} - ${timezoneHourTime} by ${referenceValue}`\n\n let headerSubTitle = text(subTitle, { colSpan: 2, style: 'subTitle' })\n let secondRow = [headerSubTitle]\n\n const reverseGeocoded = gps.reverseGeocoded\n const address = !isEmpty(reverseGeocoded)\n ? getFormattedAddress(reverseGeocoded)\n : ''\n const renderHeaderAddress = !isEmpty(reverseGeocoded)\n const dummyColumn = text(' ', { style: 'small' })\n\n let headerAddress = text(address, { colSpan: 2, style: 'small' })\n const renderThirdRow = renderHeaderAddress || renderTargetFields\n let thirdRow = renderHeaderAddress ? [headerAddress] : []\n\n if (renderTargetFields) {\n headerSubTitle = text(subTitle, { style: 'subTitle' })\n\n const serviceLevelBelow = targetServiceLevel === 'below'\n const serviceLevelText =\n targetServiceLevel === 'above'\n ? 'Above Target'\n : targetServiceLevel === 'on'\n ? 'On Target'\n : targetServiceLevel === 'below'\n ? 'Below Target'\n : ''\n\n const scoreServiceLevelSubTitle = text(serviceLevelText, {\n alignment: 'right',\n style: serviceLevelBelow ? 'serviceLevelBelow' : 'serviceLevelAboveOrOn',\n })\n\n secondRow = [headerSubTitle, scoreServiceLevelSubTitle]\n headerAddress = text(address, { style: 'small' })\n\n const truncatedTargetPercent = round(target, 2)\n const scoreTargetText = `(Target - ${truncatedTargetPercent}%)`\n const scoreTargetSubTitle = text(scoreTargetText, {\n alignment: 'right',\n style: 'subTitle',\n })\n\n thirdRow = renderHeaderAddress\n ? [headerAddress, scoreTargetSubTitle]\n : [dummyColumn, scoreTargetSubTitle]\n }\n\n const scoreBreakdown = text(\n `${round(score.actual, 2)} / ${round(score.max, 2)}`,\n {\n alignment: 'right',\n style: 'totalScore',\n }\n )\n const scorePercentage = text(scoreText, {\n alignment: 'right',\n colSpan: 2,\n style: 'totalAuditScore',\n })\n const scoreTitle = text('Total Score', { style: 'totalScore' })\n\n const body = renderThirdRow\n ? [firstRow, secondRow, thirdRow]\n : [firstRow, secondRow]\n\n const titleTable = twoColumnTable({\n body,\n layout: 'noBorders',\n style: 'titleTable',\n widths: ['*', 100],\n margin: [0, 0, 0, 30],\n })\n\n const totalScoreTable = twoColumnTable({\n body: [[scoreTitle, scoreBreakdown], [scorePercentage]],\n layout: 'noBorders',\n widths: ['*', 100],\n })\n\n const hLineTop = horizontalLine({ margin: [0, 10, 0, 0] })\n const hLineBottom = horizontalLine()\n\n const followUpItems = rolloutAuditFollowUps\n ? buildAuditFollowUps(followUps, { timezone })\n : []\n\n const promises = {\n entry: buildAuditContent(groupedData.items, { rolloutAuditFollowUps }),\n footerTemplate: buildTemplateContent(footerFields.formGroups, data),\n headerTemplate: buildTemplateContent(headerFields.formGroups, data),\n }\n\n const auditItemsTitle = rolloutAuditFollowUps\n ? [\n {\n text: 'Audit Items',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n },\n },\n hLineTop,\n ]\n : []\n\n return Promise.props(promises)\n .then(({ entry, footerTemplate, headerTemplate }) => [\n titleTable,\n followUpItems,\n ...auditItemsTitle,\n ...headerTemplate,\n ...entry,\n hLineTop,\n totalScoreTable,\n hLineBottom,\n ...footerTemplate,\n ])\n .catch(err => {\n throw new Error(`GenerateContentError: ${err.message}`)\n })\n}\n"],"file":"index.js"}
|
|
@@ -5,7 +5,7 @@ import { fetchImage } from '../../../helpers';
|
|
|
5
5
|
import { fourColumnTable, horizontalLine, imageTables, table, text } from '../';
|
|
6
6
|
import { LIGHT_BLUE, WHITE } from '../table';
|
|
7
7
|
export var buildAuditContent = Promise.method(function (items, options) {
|
|
8
|
-
var
|
|
8
|
+
var rolloutAuditFollowUps = options.rolloutAuditFollowUps;
|
|
9
9
|
return Promise.map(items, function (group) {
|
|
10
10
|
return Promise.map(group.items, function (item, index) {
|
|
11
11
|
return Promise.map(item.assets, function (_ref) {
|
|
@@ -23,9 +23,9 @@ export var buildAuditContent = Promise.method(function (items, options) {
|
|
|
23
23
|
var rows = [];
|
|
24
24
|
var fillColor = index % 2 === 0 ? WHITE : LIGHT_BLUE;
|
|
25
25
|
var hasImages = !isEmpty(rowImages);
|
|
26
|
-
var hasComments = !isEmpty(item.comments); // Some audits use questionId to link a follow
|
|
26
|
+
var hasComments = !isEmpty(item.comments); // Some audits use questionId to link a follow-up issue and its question
|
|
27
27
|
|
|
28
|
-
var label =
|
|
28
|
+
var label = rolloutAuditFollowUps ? {
|
|
29
29
|
text: item.label,
|
|
30
30
|
fillColor: fillColor,
|
|
31
31
|
id: item.questionId
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/pdf/helpers/build-audit-content/index.js"],"names":["flatten","isEmpty","round","Promise","fetchImage","fourColumnTable","horizontalLine","imageTables","table","text","LIGHT_BLUE","WHITE","buildAuditContent","method","items","options","
|
|
1
|
+
{"version":3,"sources":["../../../../src/pdf/helpers/build-audit-content/index.js"],"names":["flatten","isEmpty","round","Promise","fetchImage","fourColumnTable","horizontalLine","imageTables","table","text","LIGHT_BLUE","WHITE","buildAuditContent","method","items","options","rolloutAuditFollowUps","map","group","item","index","assets","assetUrl","link","then","base64String","alignment","fit","image","rowImages","rows","fillColor","hasImages","hasComments","comments","label","id","questionId","push","scoreLabel","weight","scoreWeight","imageRow","colSpan","stack","commentsRow","margin","style","groupTableRows","actual","groupActualScore","max","groupMaximumScore","resultText","groupPercentageResultScore","skipped","groupScoreText","bold","headerText","title","groupHeaderTable","body","layout","widths","groupTableHeader","groupTable","headerRows","hLine"],"mappings":";AAAA,SAASA,OAAT,EAAkBC,OAAlB,EAA2BC,KAA3B,QAAwC,QAAxC;AACA,OAAOC,OAAP,MAAoB,UAApB;AAEA,SAASC,UAAT,QAA2B,kBAA3B;AACA,SAASC,eAAT,EAA0BC,cAA1B,EAA0CC,WAA1C,EAAuDC,KAAvD,EAA8DC,IAA9D,QAA0E,KAA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C,OAAD,EAAU;AAAEiB,QAAAA,SAAS,EAAE,OAAb;AAAsB+B,QAAAA,IAAI,EAAE;AAA5B,OAAV,CAJmB,CAAzB;AAOA,UAAMQ,UAAU,GAAG5D,eAAe,CAAC;AACjC6D,QAAAA,UAAU,EAAE,CADqB;AAEjC;AACAL,QAAAA,IAAI,GAAGG,gBAAH,4BAAwBhE,OAAO,CAACgD,cAAD,CAA/B,EAH6B;AAIjCe,QAAAA,MAAM,EAAE,CAAC,KAAD,EAAQ,KAAR,EAAe,IAAf,EAAqB,IAArB;AAJyB,OAAD,CAAlC;AAOA,UAAMI,KAAK,GAAG7D,cAAc,EAA5B;AAEA,aAAO,CAACsD,gBAAD,EAAmBO,KAAnB,EAA0BF,UAA1B,CAAP;AACD,KAhGM,CAAP;AAiGD,GAlGM,CAAP;AAmGD,CAtGgC,CAA1B","sourcesContent":["import { flatten, isEmpty, round } from 'lodash'\nimport Promise from 'bluebird'\n\nimport { fetchImage } from '../../../helpers'\nimport { fourColumnTable, horizontalLine, imageTables, table, text } from '../'\nimport { LIGHT_BLUE, WHITE } from '../table'\n\nexport const buildAuditContent = Promise.method((items, options) => {\n const { rolloutAuditFollowUps } = options\n\n return Promise.map(items, group => {\n return Promise.map(group.items, (item, index) => {\n return Promise.map(item.assets, ({ assetUrl, link }) => {\n return fetchImage(assetUrl).then(base64String => ({\n alignment: 'center',\n fit: [210, 210],\n image: base64String,\n link,\n }))\n }).then(rowImages => {\n const rows = []\n\n const fillColor = index % 2 === 0 ? WHITE : LIGHT_BLUE\n const hasImages = !isEmpty(rowImages)\n const hasComments = !isEmpty(item.comments)\n\n // Some audits use questionId to link a follow-up issue and its question\n const label = rolloutAuditFollowUps\n ? { text: item.label, fillColor, id: item.questionId }\n : { text: item.label, fillColor }\n\n rows.push([\n label,\n { text: item.scoreLabel, fillColor },\n { alignment: 'center', text: item.weight, fillColor },\n { alignment: 'right', text: item.scoreWeight, fillColor },\n ])\n\n if (hasImages) {\n const imageRow = [\n {\n colSpan: 4,\n fillColor,\n stack: imageTables(rowImages),\n },\n ]\n\n rows.push(imageRow)\n }\n\n if (hasComments) {\n const commentsRow = [\n {\n colSpan: 4,\n fillColor,\n margin: [0, -10, 0, 0],\n stack: [\n { text: 'Comments:', style: 'commentsHeader' },\n { text: item.comments },\n ],\n },\n ]\n\n rows.push(commentsRow)\n }\n\n return rows\n })\n }).then(groupTableRows => {\n const actual = round(group.groupActualScore, 2)\n const max = round(group.groupMaximumScore, 2)\n const resultText = `${group.groupPercentageResultScore}%`\n\n const { skipped } = group\n\n const groupScoreText = skipped\n ? null\n : text(`${actual} / ${max} (${resultText})`, {\n alignment: 'right',\n bold: true,\n })\n const headerText = text(group.title)\n\n const groupHeaderTable = table({\n body: [[headerText, groupScoreText]],\n layout: 'noBorders',\n style: 'groupHeaderTable',\n widths: ['*', '*'],\n })\n\n const groupTableHeader = [\n text('Question', { bold: true }),\n text('Answer', { bold: true }),\n text('Weight', { alignment: 'center', bold: true }),\n text('Score', { alignment: 'right', bold: true }),\n ]\n\n const groupTable = fourColumnTable({\n headerRows: 0,\n // NOTE: must flatten here as we have arrays of rows\n body: [groupTableHeader, ...flatten(groupTableRows)],\n widths: ['60%', '24%', '8%', '8%'],\n })\n\n const hLine = horizontalLine()\n\n return [groupHeaderTable, hLine, groupTable]\n })\n })\n})\n"],"file":"index.js"}
|
|
@@ -7,15 +7,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
7
7
|
import moment from 'moment-timezone';
|
|
8
8
|
import { getStatusDetails, getUserFullName } from '../../../helpers';
|
|
9
9
|
import { defaultStyles, horizontalLine, sixColumnTable } from '../';
|
|
10
|
-
import { launchIcon, internalLinkIcon } from '../../../images';
|
|
11
|
-
// *. Setup the page breaks, either on the last item here or the first in the next section
|
|
12
|
-
// - I want to do this in a way that avoids orphans, or at least only add a page break if the result looks balanced
|
|
13
|
-
// - If we can work out the page position of the last follow up item then we can determine whether to use a page break or not
|
|
14
|
-
// *. If you're not using the flag then you should make sure that all of the variables necessary have been passed in
|
|
15
|
-
// - If the required data isn't present then you should probably just not process follow up issues for the document
|
|
16
|
-
// - If you establish this at the start you can build it into the `hasFollowUps` flag
|
|
17
|
-
// *. Is there some way that you can setup an override for the pdfmake version used by storybook?
|
|
18
|
-
|
|
10
|
+
import { launchIcon, internalLinkIcon } from '../../../images';
|
|
19
11
|
var LIGHTHOUSE_BASE_URL = 'https://app.lighthouse.io';
|
|
20
12
|
export function buildAuditFollowUps() {
|
|
21
13
|
var rawFollowUpIssues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
@@ -40,9 +32,9 @@ export function buildAuditFollowUps() {
|
|
|
40
32
|
});
|
|
41
33
|
|
|
42
34
|
if (!followUpIssues.length) {
|
|
43
|
-
// Show a `no follow
|
|
35
|
+
// Show a `no follow-up issues` message if there are no follow up issues
|
|
44
36
|
return [sectionTitle, sectionDivider, {
|
|
45
|
-
text: 'No follow
|
|
37
|
+
text: 'No follow-up issues exist for this audit',
|
|
46
38
|
style: defaultStyles.subTitle,
|
|
47
39
|
margin: [0, 5, 0, 50]
|
|
48
40
|
}];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/pdf/helpers/build-audit-follow-ups/index.js"],"names":["moment","getStatusDetails","getUserFullName","defaultStyles","horizontalLine","sixColumnTable","launchIcon","internalLinkIcon","LIGHTHOUSE_BASE_URL","buildAuditFollowUps","rawFollowUpIssues","options","console","log","sectionTitle","text","style","font","lineHeight","margin","sectionDivider","followUpIssues","filter","item","errorMessage","length","subTitle","timezone","tableBody","forEach","mappedStatus","status","toUpperCase","small","color","alignment","updatedAt","format","tz","link","issueId","iconLinkCell","fit","image","linkToDestination","questionId","iconJumpCell","assignees","assigneeUsername","push","issueTitle","questionLabel","headerLinkIconCell","headerJumpIconCell","headerStyle","bold","fontSize","headerRow","followUpsTable","body","widths"],"mappings":";;;;;;AAAA,OAAOA,MAAP,MAAmB,iBAAnB;AACA,SAASC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EAAS,EAAT,EAAa,EAAb,EAAiB,CAAjB,EAAoB,GAApB,EAAyB,KAAzB,CAH4B;AAIpCzC,IAAAA,MAAM,EAAE,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,EAAV;AAJ4B,GAAD,CAArC;AAOAP,EAAAA,OAAO,CAACC,GAAR,CAAY,qBAAZ,EAAmC;AACjC6C,IAAAA,cAAc,EAAdA;AADiC,GAAnC;AAIA,SAAO,CAAC5C,YAAD,EAAeM,cAAf,EAA+BsC,cAA/B,CAAP;AACD","sourcesContent":["import moment from 'moment-timezone'\nimport { getStatusDetails, getUserFullName } from '../../../helpers'\nimport { defaultStyles, horizontalLine, sixColumnTable } from '../'\nimport { launchIcon, internalLinkIcon } from '../../../images'\n// Still to do:\n// *. Setup the page breaks, either on the last item here or the first in the next section\n// - I want to do this in a way that avoids orphans, or at least only add a page break if the result looks balanced\n// - If we can work out the page position of the last follow up item then we can determine whether to use a page break or not\n// *. If you're not using the flag then you should make sure that all of the variables necessary have been passed in\n// - If the required data isn't present then you should probably just not process follow up issues for the document\n// - If you establish this at the start you can build it into the `hasFollowUps` flag\n// *. Is there some way that you can setup an override for the pdfmake version used by storybook?\n\nconst LIGHTHOUSE_BASE_URL = 'https://app.lighthouse.io'\n\nexport function buildAuditFollowUps(rawFollowUpIssues = [], options = {}) {\n console.log('buildAuditFollowUps', {\n rawFollowUpIssues,\n options,\n })\n\n const sectionTitle = [\n {\n text: 'Follow-up Issues',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n margin: [0, 0, 0, 50],\n },\n },\n ]\n const sectionDivider = horizontalLine({ margin: [0, 0, 0, 0] })\n\n const followUpIssues = rawFollowUpIssues.filter(item => !item.errorMessage)\n if (!followUpIssues.length) {\n // Show a `no follow up issues` message if there are no follow up issues\n return [\n sectionTitle,\n sectionDivider,\n {\n text: 'No follow up issues exist for this Audit',\n style: defaultStyles.subTitle,\n margin: [0, 5, 0, 50],\n },\n ]\n }\n\n const { timezone = 'America/New_York' } = options\n const tableBody = []\n followUpIssues.forEach(item => {\n const mappedStatus = getStatusDetails(item.status)\n const status = {\n text: mappedStatus.text.toUpperCase(),\n style: {\n ...defaultStyles.small,\n color: mappedStatus.style.color,\n alignment: 'center',\n },\n }\n\n let updatedAt = ''\n if (item.updatedAt) {\n const format = 'MMM D h:mma' // e.g. Jan 21 12:59am in the Audit timezone\n updatedAt = moment.tz(item.updatedAt, timezone).format(format)\n }\n\n const link = `${LIGHTHOUSE_BASE_URL}/reports/issues/${item.issueId}`\n const iconLinkCell = launchIcon\n ? { alignment: 'center', fit: [8, 8], image: launchIcon, link }\n : { text: '' }\n\n const linkToDestination = item.questionId\n const iconJumpCell = launchIcon\n ? {\n alignment: 'center',\n fit: [8, 8],\n image: internalLinkIcon,\n linkToDestination,\n }\n : { text: '' }\n\n const assignees = item.assignees || []\n const assigneeUsername = assignees.length === 0\n ? 'Unassigned'\n : assignees.length === 1\n // TODO Currently this gives `first last`, I don't think it can fall back to 'Unknown User' here\n ? getUserFullName(assignees, 0)\n : `${assignees.length} users`\n \n tableBody.push([\n iconLinkCell,\n { text: item.issueTitle || '', link, style: 'small', image: launchIcon },\n status,\n { text: assigneeUsername, style: 'small' },\n iconJumpCell,\n { text: item.questionLabel || '', style: 'small', linkToDestination },\n { text: updatedAt || '', style: 'small', alignment: 'right' },\n ])\n })\n\n const headerLinkIconCell = launchIcon\n ? { alignment: 'center', fit: [8, 8], image: launchIcon }\n : { text: '' }\n \n const headerJumpIconCell = launchIcon\n ? { alignment: 'center', fit: [8, 8], image: internalLinkIcon }\n : { text: '' }\n \n const headerStyle = {\n bold: true,\n font: 'Gotham',\n fontSize: 8,\n alignment: 'left',\n }\n \n const headerRow = [\n headerLinkIconCell,\n { text: 'Issue Title', style: headerStyle },\n { text: 'Status', style: headerStyle, alignment: 'center' },\n { text: 'Assignees', style: headerStyle },\n headerJumpIconCell,\n { text: 'Audit Question', style: headerStyle },\n { text: 'Last Updated', style: headerStyle , alignment: 'right'},\n ]\n \n const followUpsTable = sixColumnTable({\n body: [headerRow, ...tableBody],\n style: 'titleTable',\n widths: [6, '*', 55, 55, 6, '*', '16%'],\n margin: [0, 0, 0, 30],\n })\n\n console.log('buildAuditFollowUps', {\n followUpsTable,\n })\n\n return [sectionTitle, sectionDivider, followUpsTable]\n}\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/pdf/helpers/build-audit-follow-ups/index.js"],"names":["moment","getStatusDetails","getUserFullName","defaultStyles","horizontalLine","sixColumnTable","launchIcon","internalLinkIcon","LIGHTHOUSE_BASE_URL","buildAuditFollowUps","rawFollowUpIssues","options","console","log","sectionTitle","text","style","font","lineHeight","margin","sectionDivider","followUpIssues","filter","item","errorMessage","length","subTitle","timezone","tableBody","forEach","mappedStatus","status","toUpperCase","small","color","alignment","updatedAt","format","tz","link","issueId","iconLinkCell","fit","image","linkToDestination","questionId","iconJumpCell","assignees","assigneeUsername","push","issueTitle","questionLabel","headerLinkIconCell","headerJumpIconCell","headerStyle","bold","fontSize","headerRow","followUpsTable","body","widths"],"mappings":";;;;;;AAAA,OAAOA,MAAP,MAAmB,iBAAnB;AACA,SAASC,gBAAT,EAA2BC,eAA3B,QAAkD,kBAAlD;AACA,SAASC,aAAT,EAAwBC,cAAxB,EAAwCC,cAAxC,QAA8D,KAA9D;AACA,SAASC,UAAT,EAAqBC,gBAArB,QAA6C,iBAA7C;AAEA,IAAMC,mBAAmB,GAAG,2BAA5B;AAEA,OAAO,SAASC,mBAAT,GAAmE;AAAA,MAAtCC,iBAAsC,uEAAlB,EAAkB;AAAA,MAAdC,OAAc,uEAAJ,EAAI;AACxEC,EAAAA,OAAO,CAACC,GAAR,CAAY,qBAAZ,EAAmC;AACjCH,IAAAA,iBAAiB,EAAjBA,iBADiC;AAEjCC,IAAAA,OAAO,EAAPA;AAFiC,GAAnC;AAKA,MAAMG,YAAY,GAAG,CACnB;AACEC,IAAAA,IAAI,EAAE,kBADR;AAEEC,IAAAA,KAAK,EAAE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AAR;AAAuBC,IAAAA,KAAK,EAAEsC;AAA9B,GAFgB,EAGhB;AAAEvC,IAAAA,IAAI,EAAE,QAAR;AAAkBC,IAAAA,KAAK,EAAEsC,WAAzB;AAAsCnB,IAAAA,SAAS,EAAE;AAAjD,GAHgB,EAIhB;AAAEpB,IAAAA,IAAI,EAAE,WAAR;AAAqBC,IAAAA,KAAK,EAAEsC;AAA5B,GAJgB,EAKhBD,kBALgB,EAMhB;AAAEtC,IAAAA,IAAI,EAAE,gBAAR;AAA0BC,IAAAA,KAAK,EAAEsC;AAAjC,GANgB,EAOhB;AAAEvC,IAAAA,IAAI,EAAE,cAAR;AAAwBC,IAAAA,KAAK,EAAEsC,WAA/B;AAA6CnB,IAAAA,SAAS,EAAE;AAAxD,GAPgB,CAAlB;AAUA,MAAMuB,cAAc,GAAGrD,cAAc,CAAC;AACpCsD,IAAAA,IAAI,GAAGF,SAAH,SAAiB7B,SAAjB,CADgC;AAEpCZ,IAAAA,KAAK,EAAE,YAF6B;AAGpC4C,IAAAA,MAAM,EAAE,CAAC,CAAD,EAAI,GAAJ,EAAS,EAAT,EAAa,EAAb,EAAiB,CAAjB,EAAoB,GAApB,EAAyB,KAAzB,CAH4B;AAIpCzC,IAAAA,MAAM,EAAE,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,EAAV;AAJ4B,GAAD,CAArC;AAOAP,EAAAA,OAAO,CAACC,GAAR,CAAY,qBAAZ,EAAmC;AACjC6C,IAAAA,cAAc,EAAdA;AADiC,GAAnC;AAIA,SAAO,CAAC5C,YAAD,EAAeM,cAAf,EAA+BsC,cAA/B,CAAP;AACD","sourcesContent":["import moment from 'moment-timezone'\nimport { getStatusDetails, getUserFullName } from '../../../helpers'\nimport { defaultStyles, horizontalLine, sixColumnTable } from '../'\nimport { launchIcon, internalLinkIcon } from '../../../images'\n\nconst LIGHTHOUSE_BASE_URL = 'https://app.lighthouse.io'\n\nexport function buildAuditFollowUps(rawFollowUpIssues = [], options = {}) {\n console.log('buildAuditFollowUps', {\n rawFollowUpIssues,\n options,\n })\n\n const sectionTitle = [\n {\n text: 'Follow-up Issues',\n style: {\n font: 'Gotham',\n lineHeight: 1.1,\n margin: [0, 0, 0, 50],\n },\n },\n ]\n const sectionDivider = horizontalLine({ margin: [0, 0, 0, 0] })\n\n const followUpIssues = rawFollowUpIssues.filter(item => !item.errorMessage)\n if (!followUpIssues.length) {\n // Show a `no follow-up issues` message if there are no follow up issues\n return [\n sectionTitle,\n sectionDivider,\n {\n text: 'No follow-up issues exist for this audit',\n style: defaultStyles.subTitle,\n margin: [0, 5, 0, 50],\n },\n ]\n }\n\n const { timezone = 'America/New_York' } = options\n const tableBody = []\n followUpIssues.forEach(item => {\n const mappedStatus = getStatusDetails(item.status)\n const status = {\n text: mappedStatus.text.toUpperCase(),\n style: {\n ...defaultStyles.small,\n color: mappedStatus.style.color,\n alignment: 'center',\n },\n }\n\n let updatedAt = ''\n if (item.updatedAt) {\n const format = 'MMM D h:mma' // e.g. Jan 21 12:59am in the Audit timezone\n updatedAt = moment.tz(item.updatedAt, timezone).format(format)\n }\n\n const link = `${LIGHTHOUSE_BASE_URL}/reports/issues/${item.issueId}`\n const iconLinkCell = launchIcon\n ? { alignment: 'center', fit: [8, 8], image: launchIcon, link }\n : { text: '' }\n\n const linkToDestination = item.questionId\n const iconJumpCell = launchIcon\n ? {\n alignment: 'center',\n fit: [8, 8],\n image: internalLinkIcon,\n linkToDestination,\n }\n : { text: '' }\n\n const assignees = item.assignees || []\n const assigneeUsername = assignees.length === 0\n ? 'Unassigned'\n : assignees.length === 1\n // TODO Currently this gives `first last`, I don't think it can fall back to 'Unknown User' here\n ? getUserFullName(assignees, 0)\n : `${assignees.length} users`\n \n tableBody.push([\n iconLinkCell,\n { text: item.issueTitle || '', link, style: 'small', image: launchIcon },\n status,\n { text: assigneeUsername, style: 'small' },\n iconJumpCell,\n { text: item.questionLabel || '', style: 'small', linkToDestination },\n { text: updatedAt || '', style: 'small', alignment: 'right' },\n ])\n })\n\n const headerLinkIconCell = launchIcon\n ? { alignment: 'center', fit: [8, 8], image: launchIcon }\n : { text: '' }\n \n const headerJumpIconCell = launchIcon\n ? { alignment: 'center', fit: [8, 8], image: internalLinkIcon }\n : { text: '' }\n \n const headerStyle = {\n bold: true,\n font: 'Gotham',\n fontSize: 8,\n alignment: 'left',\n }\n \n const headerRow = [\n headerLinkIconCell,\n { text: 'Issue Title', style: headerStyle },\n { text: 'Status', style: headerStyle, alignment: 'center' },\n { text: 'Assignees', style: headerStyle },\n headerJumpIconCell,\n { text: 'Audit Question', style: headerStyle },\n { text: 'Last Updated', style: headerStyle , alignment: 'right'},\n ]\n \n const followUpsTable = sixColumnTable({\n body: [headerRow, ...tableBody],\n style: 'titleTable',\n widths: [6, '*', 55, 55, 6, '*', '16%'],\n margin: [0, 0, 0, 30],\n })\n\n console.log('buildAuditFollowUps', {\n followUpsTable,\n })\n\n return [sectionTitle, sectionDivider, followUpsTable]\n}\n"],"file":"index.js"}
|