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

[Screenshotting] Add possibility to capture expressions #128552

Merged
merged 9 commits into from
Apr 7, 2022

Conversation

dokmic
Copy link
Contributor

@dokmic dokmic commented Mar 24, 2022

Summary

Apart from the screenshotting functionality this PR also fixes the following:

  • Fixes unnecessary rerendering in the Expressions Renderer React hook.
  • Fixes screenshotting plugin public API not to use generics.
  • Fixes screenshotting internal interfaces to segregate parameters instead of patching.

Checklist

For maintainers

@dokmic dokmic added release_note:enhancement review (Deprecated) Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead backport:skip This commit does not require backporting Team:AppServicesUx v8.2.0 labels Mar 24, 2022
@dokmic dokmic force-pushed the feature/KS-2061 branch 5 times, most recently from 7b3e72e to 71f0152 Compare March 28, 2022 20:34
@dokmic dokmic added v8.3.0 and removed v8.2.0 labels Mar 29, 2022
@dokmic dokmic marked this pull request as ready for review March 29, 2022 10:01
@dokmic dokmic requested review from a team as code owners March 29, 2022 10:01
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app-services (Team:AppServicesUx)

* 2.0.
*/

.expression {
Copy link
Contributor

Choose a reason for hiding this comment

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

These class names are quite generic which increases the likelihood of style overrides elsewhere in Kibana should this file ever get loaded more globally. To minimize this possibility, we recommend use a unique, 3-letter prefix such as .scrExpression and the child could be .scrExpression__viz, for example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ryankeairns That's a good point. I followed your recommendation and prefixed that, although I didn't add the prefix to the .visualization class since we override styles of the generic class here.
Could you please take another look?

@botelastic botelastic bot added the Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) label Mar 29, 2022
Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

Great work @dokmic 🍻 , I really like the overloaded getScreenshots method.

I still need to test this and I'd like to get your thoughts on my idea about rather composing formatting and screenshotting.

import type { ExpressionRendererParams } from 'src/plugins/expressions/public';
import { useExpressionRenderer } from '../../../../../src/plugins/expressions/public';
import { SCREENSHOTTING_EXPRESSION, SCREENSHOTTING_EXPRESSION_INPUT } from '../../common';
import { ScreenshotModeContext } from './screenshot_mode_context';
Copy link
Contributor

Choose a reason for hiding this comment

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

You can rather create a useScreenshotModeContext hook and import useContext there. One fewer thing to import here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would rather keep it that way since it is more up to the component implementation.

/**
* PDFs can be a single, long page or they can be multiple pages. For example:
*
* => When creating a PDF intended for print multiple PNGs will be spread out across pages
* => When creating a PDF from a Canvas workpad, each page in the workpad will be placed on a separate page
*/
export type PdfLayoutParams = LayoutParams<typeof supportedLayouts[number]>;
export type PdfLayoutParams = LayoutParams<Values<typeof LayoutTypes>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it's better to be explicit about which layout types are supported. If we ever add one that shouldn't be supported in PDF this will hide it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is an excellent point. I've updated that. But to make it pretty, I've changed the LayoutTypes to TypeScript's enum.

renderErrors: string[];
};
}
export interface PdfScreenshotResult {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a nice improvement!

Copy link
Contributor

@jloleysens jloleysens left a comment

Choose a reason for hiding this comment

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

This code look good to me, great work @dokmic !

I think one missing piece is an integration or functional test to prove that the changes are working as expected but since this code is not being used anywhere I'm happy that we do this in a follow up PR.

Comment on lines -84 to -86
setEmpty(false);
setError(newError);
setLoading(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this causing unnecessary re-renders? I thought react bundled these together (or is working on bundling them together) https://reactjs.org/docs/faq-state.html#when-is-setstate-asynchronous

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right but only for the actual rendering. It still re-renders the component (or calls the component function in our case) using that hook.

Copy link
Member

@tsullivan tsullivan left a comment

Choose a reason for hiding this comment

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

This is really great! I am exciting to see the next steps for capturing expressions in a feature.

I would like to see an additional test in the getScreenshots method, following the code paths where it is called with an expression in the options. After that, this would LGTM

@dokmic dokmic force-pushed the feature/KS-2061 branch 2 times, most recently from c05da85 to 4988c76 Compare April 6, 2022 16:45
Copy link
Contributor

@ryankeairns ryankeairns left a comment

Choose a reason for hiding this comment

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

Appreciate the change, LGTM

await screenshots
.getScreenshots({
...options,
expression: 'kibana',
Copy link
Member

Choose a reason for hiding this comment

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

🍌

Copy link
Member

@tsullivan tsullivan left a comment

Choose a reason for hiding this comment

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

LGTM

@dokmic
Copy link
Contributor Author

dokmic commented Apr 7, 2022

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Test Failures

  • [job] [logs] Default CI Group #27 / Cases Configure Closure options change closure option successfully

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
screenshotting - 18 +18

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
expressions 1701 1713 +12
screenshotting 12 7 -5
total +7

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
expressions 44.6KB 25.6KB -19.0KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
expressions 6 5 -1
screenshotting 5 4 -1
total -2

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
expressions 88.3KB 98.7KB +10.3KB
screenshotting - 7.7KB +7.7KB
total +18.1KB
Unknown metric groups

API count

id before after diff
expressions 2145 2158 +13
screenshotting 24 27 +3
total +16

async chunk count

id before after diff
expressions 8 5 -3

History

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

@dokmic dokmic merged commit 2736f9e into elastic:main Apr 7, 2022
@dokmic dokmic deleted the feature/KS-2061 branch April 7, 2022 10:01
@rashmivkulkarni rashmivkulkarni added release_note:skip Skip the PR/issue when compiling release notes and removed release_note:enhancement labels Jun 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting (Deprecated) Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) release_note:skip Skip the PR/issue when compiling release notes review v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants