Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

Bump jspdf to 4.0.0 ([#13248](https://github.com/linode/manager/pull/13248))
3 changes: 1 addition & 2 deletions packages/manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"he": "^1.2.0",
"immer": "^9.0.6",
"ipaddr.js": "^1.9.1",
"jspdf": "^3.0.2",
"jspdf": "^4.0.0",
"jspdf-autotable": "^5.0.2",
"launchdarkly-react-client-sdk": "3.0.10",
"libphonenumber-js": "^1.10.6",
Expand Down Expand Up @@ -140,7 +140,6 @@
"@types/eslint-plugin-jsx-a11y": "^6.10.0",
"@types/he": "^1.1.0",
"@types/history": "4",
"@types/jspdf": "^1.3.3",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Great! I hate it when packages don't provide their own type-definitions!

"@types/luxon": "3.4.2",
"@types/markdown-it": "^14.1.2",
"@types/md5": "^2.1.32",
Expand Down
4 changes: 2 additions & 2 deletions packages/manager/src/dev-tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ export const saveSeedsCountMap = (countMap: { [key: string]: number }) => {
/**
* Retrieves the presets map from local storage.
*/
export const getExtraPresetsMap = (): {
export const getExtraPresetsMap = (): Partial<{
[K in MockPresetExtraId]: number;
} => {
}> => {
const encodedPresetsMap = localStorage.getItem(LOCAL_STORAGE_PRESETS_MAP_KEY);

return encodedPresetsMap ? JSON.parse(encodedPresetsMap) : {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export const BillingActivityPanel = React.memo((props: Props) => {
);

const downloadPaymentPDF = React.useCallback(
(paymentId: number) => {
async (paymentId: number) => {
const payment = payments?.find(
(thisPayment) => thisPayment.id === paymentId
);
Expand All @@ -307,7 +307,7 @@ export const BillingActivityPanel = React.memo((props: Props) => {
taxes?.date,
taxes?.country_tax
);
const result = printPayment(account, payment, countryTax);
const result = await printPayment(account, payment, countryTax);

if (result.status === 'error') {
pdfErrors.add(id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,12 @@ describe('PdfGenerator', () => {
});

// Call the printPayment function
const pdfResult = printPayment(account, payment, countryTax, timezone);
const pdfResult = await printPayment(
account,
payment,
countryTax,
timezone
);

// Expect the PDF generation to be successful
expect(pdfResult.status).toEqual('success');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,15 @@ const addTitle = (doc: jsPDF, y: number, ...textStrings: Title[]) => {
};

// M3-6177 only make one request to get the logo
const getAkamaiLogo = () => {
return axios
.get(AkamaiLogo, { responseType: 'blob' })
.then((res) => {
return URL.createObjectURL(res.data);
})
.catch(() => {
return AkamaiLogo;
});
const getAkamaiLogo = async () => {
const response = await axios.get(AkamaiLogo, { responseType: 'blob' });

return new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result as string);
reader.onerror = reject;
reader.readAsDataURL(response.data);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

tests were failing - this method is valid for both node (tests) and the browser

};

interface PrintInvoiceOptions {
Expand Down Expand Up @@ -324,12 +324,12 @@ export const printInvoice = async (
}
};

export const printPayment = (
export const printPayment = async (
account: Account,
payment: Payment,
countryTax?: TaxDetail,
timezone?: string
): PdfResult => {
): Promise<PdfResult> => {
try {
const date = formatDate(payment.date, {
displayTime: true,
Expand All @@ -340,7 +340,8 @@ export const printPayment = (
});
doc.setFontSize(10);

doc.addImage(AkamaiLogo, 'JPEG', 160, 10, 120, 40, undefined, 'MEDIUM');
const AkamaiLogoURL = await getAkamaiLogo();
doc.addImage(AkamaiLogoURL, 'JPEG', 160, 10, 120, 40, undefined, 'MEDIUM');

const leftHeaderYPosition = addLeftHeader(
doc,
Expand Down
10 changes: 10 additions & 0 deletions packages/manager/src/testSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@
unobserve() {}
};

// Fix TypeScript type pollution for window.location in tests
// Cypress types (via Mocha) pollute the Window interface, making location
// typed as 'string & Location' which is impossible to assign to.
// This global declaration fixes it for Vitest tests.
declare global {
interface Window {

Check warning on line 76 in packages/manager/src/testSetup.ts

View workflow job for this annotation

GitHub Actions / ESLint Review (manager)

[eslint] reported by reviewdog 🐶 'Window' is defined but never used. Raw Output: {"ruleId":"no-unused-vars","severity":1,"message":"'Window' is defined but never used.","line":76,"column":13,"nodeType":"Identifier","messageId":"unusedVar","endLine":76,"endColumn":19,"suggestions":[{"messageId":"removeVar","data":{"varName":"Window"},"fix":{"range":[1772,1778],"text":""},"desc":"Remove unused variable 'Window'."}]}
location: Location;
}
}

/**
***************************************
* Custom matchers & matchers overrides
Expand Down
26 changes: 9 additions & 17 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.