Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reporting/Tech Debt] Convert PdfMaker class to TypeScript #81242

Merged
merged 13 commits into from
Oct 21, 2020

Conversation

tsullivan
Copy link
Member

@tsullivan tsullivan commented Oct 20, 2020

Summary

Preliminary cleanup and work on tech debt for #78726

Problem: Canvas integrates with Reporting using the preserve_layout option for PDF. This is not ideal as Canvas pages themselves are the only layout that the user wants in the report.

In a future PR, we will add a new Layout class for Canvas that will just use the image as the page contents, instead of a layout with a header, margins, and a footer.

Until we can do that, this PR is needed to take care of tech debt on the classes that are involved with generating a PDF using a Layout.

Cleanups:

  • Broke up x-pack/plugins/reporting/server/export_types/printable_pdf/lib/pdf/index.js by moving helper functions to separate files
  • Converted PdfMaker to TypeScript
  • Removed a pointless factory function for constructing the PdfMaker instance
  • Added a dependency of @types/pdfmake to ensure our objects are structured with the right interface
  • Fixed the structure of an object that didn't match the expected interface
  • Searched for some any usage and fixed it.
  • Expanded on Layout definitions to account for the way PdfMaker is using the layout objects
  • Added a comment that explains where the default logo gets imported

Checklist

Delete any items that are not applicable to this PR.

For maintainers

margin: [0, 0, subheadingMarginBottom, 20],
},
warning: {
color: '#f39c12', // same as @brand-warning in Kibana colors.less
Copy link
Member Author

Choose a reason for hiding this comment

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

Wow, this comment is a bit outdated.

Will leave it as-is until it becomes an issue.

@tsullivan tsullivan changed the title convert pdf.js to TS [Reporting/Tech Debt] Convert PdfMaker class to TypeScript Oct 20, 2020
alignment: 'left',
fontSize: headingFontSize,
bold: true,
margin: [headingMarginTop, 0, headingMarginBottom, 0],
Copy link
Member Author

Choose a reason for hiding this comment

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

Compare to

marginTop: headingMarginTop,
marginBottom: headingMarginBottom,

The previous code used invalid properties: marginTop, marginBottom

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like the margin(Left|Top|Right|Bottom) is supported in the code, which means the previous code should be expected to work. So changing to margin: [x, y, z, q] should lead to the same result.

https://github.com/bpampuch/pdfmake/blob/b4b4906f7db27a78b33051cd90410aec4ec73478/tests/unit/DocMeasure.spec.js#L502

alignment: 'left',
fontSize: subheadingFontSize,
italics: true,
margin: [0, 0, subheadingMarginBottom, 20],
Copy link
Member Author

@tsullivan tsullivan Oct 21, 2020

Choose a reason for hiding this comment

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

The previous code used invalid deprecated properties: marginBottom, marginLeft

marginLeft: 20,
marginBottom: subheadingMarginBottom,


getBuffer(): Promise<Buffer | null> {
return new Promise((resolve, reject) => {
if (!this._pdfDoc) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: the previous code did the undefined check outside of the Promise, which caused TS to complain about lines 143-145

@tsullivan tsullivan requested review from joelgriffith, poffdeluxe and a team October 21, 2020 14:13
@tsullivan tsullivan added v8.0.0 v7.11.0 (Deprecated) Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead release_note:skip Skip the PR/issue when compiling release notes labels Oct 21, 2020
@tsullivan tsullivan marked this pull request as ready for review October 21, 2020 16:22
@tsullivan
Copy link
Member Author

@elasticmachine merge upstream

Copy link
Contributor

@poffdeluxe poffdeluxe left a comment

Choose a reason for hiding this comment

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

Looks good to me. Test it out on a few different workpads and all seems good!

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

async chunks size

id before after diff
enterpriseSearch 642.7KB 642.7KB +27.0B

distributable file count

id before after diff
default 48052 48055 +3

page load bundle size

id before after diff
upgradeAssistant 65.0KB 65.0KB +27.0B

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@tsullivan tsullivan merged commit ae95bf2 into elastic:master Oct 21, 2020
@tsullivan tsullivan deleted the reporting/canvas-layout branch October 21, 2020 20:54
tsullivan added a commit to tsullivan/kibana that referenced this pull request Oct 21, 2020
…1242)

* convert pdf.js to TS

* more typescript

* simplify caller

* more typescript

* more typescript

* fix the code to match the expected interface

* very cool comment

* interface correction

* remove unused class method

* add unit test for PdfMaker

* file rename for typo correction

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
gmmorris added a commit to gmmorris/kibana that referenced this pull request Oct 22, 2020
* master: (63 commits)
  [KP] Fix Headers timeout issue (elastic#81140)
  [ML] Functional tests - stabilize typing with checks service method (elastic#81338)
  tabify - support docs (elastic#80351)
  [Security Solution][Detections] Look-back time logic fix (elastic#81383)
  [Workplace Search] Add top-level tests for Groups (elastic#81215)
  [Fleet] Fix agent action observable for long polling (elastic#81376)
  [Maps] fix feature tooltip remains open when zoom level change hides layer (elastic#81373)
  skip flaky suite (elastic#78689)
  chore(NA): add spec-to-console and plugin-helpers as devOnly dependencies (elastic#81357)
  Ensure some data is returned (elastic#81375)
  Change dumb-init to tini (elastic#81126)
  [Reporting/Tech Debt] Convert PdfMaker class to TypeScript (elastic#81242)
  Use Storybook Controls instead of Knobs (elastic#80705)
  [junit] make sure that report paths are unique (elastic#81255)
  bump elastic/elasticsearch-js version to 7.10.0-rc1 (elastic#81288)
  run ssl tests on CI (elastic#81320)
  Fix alert defaults (elastic#81207)
  [ML] DF Analytics wizard: ensure user can set mml manually or select to use given estimate (elastic#81078)
  Add UI notifier to indicate secret fields and to remember / reenter values (elastic#80657)
  [Monitoring] Use async/await (elastic#81200)
  ...
tsullivan added a commit that referenced this pull request Oct 23, 2020
…81400)

* convert pdf.js to TS

* more typescript

* simplify caller

* more typescript

* more typescript

* fix the code to match the expected interface

* very cool comment

* interface correction

* remove unused class method

* add unit test for PdfMaker

* file rename for typo correction

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
(Deprecated) Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead release_note:skip Skip the PR/issue when compiling release notes v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants