TypeScript Reporting Layouts#22454
Conversation
|
Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually? |
Made sure all types are set on the new layout classes.
c08aca2 to
f2108a3
Compare
There was a problem hiding this comment.
Preservelayout => PreserveLayout (capital L)
src/server/index.d.ts
Outdated
src/server/index.d.ts
Outdated
| } | ||
|
|
||
| export interface configObject { | ||
| get: (path: string) => ConfigEntry; |
There was a problem hiding this comment.
I think ConfigEntry should be any. I know we generally avoid any as much as possible, but here, you really can't type what will be returned unless you know what path is. I think there is a way to map what the string is to expected object, but for the sake of this PR, I say just make any here for now, and move the below typings to the reporting folder, so you can still do get captureConfig(): ConfigEntry {
| import { oncePerServer } from '../../../../server/lib/once_per_server'; | ||
| import { screenshotsObservableFactory } from './screenshots'; | ||
| import { getLayoutFactory } from './layouts'; | ||
| import { getlayout } from './layouts/layout_factory'; |
There was a problem hiding this comment.
getlayout => getLayout. actually, I'd name is createLayout since it's creating a new object, not getting an existing one. (Though I know the current code uses getLayout so if that ends up requiring a large refactor, fine to leave as is)
| } | ||
|
|
||
| export class Preservelayout extends Layout { | ||
| public groupCount: number = 1; |
There was a problem hiding this comment.
This is never modified so can be a const too.
| } from '../../../../../../../../src/server/index'; | ||
| import { Layout } from './layout'; | ||
|
|
||
| interface Pagesizeparams { |
There was a problem hiding this comment.
Pagesizeparams => PageSizeParams
| return this.server.config(); | ||
| } | ||
|
|
||
| get captureConfig(): ConfigEntry { |
There was a problem hiding this comment.
I'm not a fan of the get syntax, and I think it adds unnecessary execution cycles. Can just make captureConfig a property on the class (i think const since it never changes), same with most of the other ones. e.g.:
private const captureConfig: CaptureConfig;
constructor(server: kbn_server, id: string) {
super(id); //(getting rid of server object into base class re: other comment)
this.captureConfig = server.config().get('xpack.reporting.capture')
}
actually... if the server object is only used to grab that capture config, you might not need to keep a reference around to the server object at all. This is more in line with the original code, which also did not keep a reference to the server object in the returned object.
Actually, can just pass in captureConfig object to the constructor and do the grabbing of it in the factory function. Would make this class easier to test.
private const captureConfig: CaptureConfig;
constructor(captureConfig: CaptureConfig, id: string) {
super(id); //(getting rid of server object into base class re: other comment)
this.captureConfig = captureConfig;
}
| }; | ||
|
|
||
| public height: number = 0; | ||
| public width: number = 0; |
There was a problem hiding this comment.
I think these can be readonly and private:
private readonly height: number;
private readonly width: number;
| return this.height * this.zoom; | ||
| } | ||
|
|
||
| get scaledWidth(): number { |
There was a problem hiding this comment.
instead of get functions, just make a class property, this.scaledWidth;
Changed location of type interfaces and fixed naming errors
…cript-reporting-layouts Merge of latest changes
|
|
||
| export interface configObject { | ||
| get: (path: string) => any; | ||
| } |
There was a problem hiding this comment.
hm, the aligning in this file didn't get auto corrected. Maybe because of the .d.ts extension.
can you update so it's only two space indentations? and the } on line 8 should have no spaces before it.
| import { oncePerServer } from '../../../../server/lib/once_per_server'; | ||
| import { screenshotsObservableFactory } from './screenshots'; | ||
| import { getLayoutFactory } from './layouts'; | ||
| import { createlayout } from './layouts/layout_factory'; |
| zoom: number; | ||
| width: number; | ||
| height: number; | ||
| } |
There was a problem hiding this comment.
same comment with this file and the space aligning. Looks like we'll have to update .d.ts files automatically. This will probably get hit by the linter when ci runs.
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
| import { Size } from '../../../../../types'; | ||
| import { ViewZoomWidthHeight } from './index.d'; |
There was a problem hiding this comment.
shouldn't need the .d in the name, and I don't think you need to specify index too. Try:
import { ViewZoomWidthHeight } from '.';
There was a problem hiding this comment.
For the record, this doesn't work because it resolves it to index.js which exists in the same location, so have to be explicit with index.d.ts. Maybe the file should just be named types.d.ts in that case. Which also matches our other types.d.ts file.
|
|
||
| public abstract getPdfPageOrientation(): string | undefined; | ||
|
|
||
| public abstract getPdfPageSize(pageSizeParamsIn: PageSizeParams): string | Size; |
There was a problem hiding this comment.
I would just call is pageSizeParams and drop the In part of the name. Not a common convention in our code base to suffix input parameters with In.
| import path from 'path'; | ||
| import { KbnServer } from '../../../../../../../../src/server/index'; | ||
| import { Size } from '../../../../../types'; | ||
| import { CaptureConfig } from './index.d'; |
There was a problem hiding this comment.
import { CaptureConfig } from '.';
| evaluate: (evaluateOptions: EvaluateOptions) => void; | ||
| } | ||
|
|
||
| const groupCount: number = 2; |
There was a problem hiding this comment.
Think this will cause a bug - need to move groupCount into the class, same as PreserveLayout so it's accessible from outside. Make public readonly
| type EvalArgs = any[]; | ||
|
|
||
| interface EvaluateOptions { | ||
| // Fn is a function in string form to avoid tslint from auto formatting it into a version not |
There was a problem hiding this comment.
Fn => fn since it's referencing a variable, probably shouldn't be capitalized. Maybe even add back tics around it.
x-pack/plugins/reporting/types.d.ts
Outdated
| debug: (message: string) => void; | ||
| error: (message: string) => void; | ||
| warning: (message: string) => void; | ||
| } No newline at end of file |
There was a problem hiding this comment.
alignment in this file, like others.
| // you'll notice that we aren't passing the zoom at this time, while it'd be possible to use | ||
| // window.pixelDensity to figure out what the current user is seeing, if they're going to send the | ||
| // PDF to someone else, I can see there being benefit to using a higher pixel density, so we're | ||
| // going to leave this hard-coded for the time being |
Fix naming on properties and methods as well as a few other fixes
src/server/index.d.ts
Outdated
| config: () => configObject; | ||
| } | ||
|
|
||
| export interface configObject { |
| viewport: Size; | ||
| zoom: number; | ||
| viewport: Size; | ||
| } |
|
jenkins, test this |
Name Changes and spacing
💔 Build Failed |
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| export { createlayout } from './layout_factory'; |
Name Change
|
jenkins, test this |
💔 Build Failed |
|
Error is because of the import path for |
Changes for typescript import and direct reference to layout_factory
|
jenkins, test this |
💔 Build Failed |
|
jenkins, test this |
💚 Build Succeeded |
stacey-gammon
left a comment
There was a problem hiding this comment.
Woot! Just sign the CLA and it's an LGTM from me!
| interface EvaluateOptions { | ||
| // 'fn' is a function in string form to avoid tslint from auto formatting it into a version not | ||
| // underfood by transform_fn safeWrap. | ||
| fn: ((...evalArgs: EvalArgs) => any) | string; |
There was a problem hiding this comment.
we can actually get rid of the | string part now, since we switched back to a function.
…sistency Removed String as a type and renamed index.d.ts to types.d.ts for consistency
|
jenkins, test this |
| dimensions: Size; | ||
| } | ||
|
|
||
| export function createLayout(server: KbnServer, layoutParams: LayoutParams): Layout { |
There was a problem hiding this comment.
let's call this file create_layout.ts to name it after what its primary export is.
| import { Size } from '../../../../../types'; | ||
| import { Layout, PageSizeParams } from './layout'; | ||
|
|
||
| const ZOOM: number = 2; |
There was a problem hiding this comment.
Zoom used to be a param that could be passed in from a caller, but 2 was the default. This makes it completely hardcoded.
Also, you've removed the explanatory comments: https://github.com/elastic/kibana/blob/master/x-pack/plugins/reporting/export_types/printable_pdf/server/lib/layouts/preserve_layout.js#L9-L12
There was a problem hiding this comment.
Intentional. This setting was never exposed to the user as configurable - #20091
I don't think we ever will expose it. The only reason we use it is to make sure the resolution is a little bigger on the screenshots.
From Brandon in that above issue:
The zoom is an undocumented setting that I intended to remove, but never got around to it.
tsullivan
left a comment
There was a problem hiding this comment.
Like to see the same mechanism for zoom able to be passed in for preserve_layout. Even if callers are not passing it and the constructor always uses its default. Also, keep in the comments that got removed.
💔 Build Failed |
|
@tsullivan re:
I disagree that this should be passed in as a param. No other value is passed in and the setting is untested and undocumented. Happy to discuss if you disagree though! |
💔 Build Failed |
|
jenkins, test this |
💔 Build Failed |
|
Ci is currently broken. Don't worry about the red build for now. Another fix is going in shortly to stabilize the reporting tests. Will kick this off when ci is back up! |
|
retest |
💚 Build Succeeded |
|
Spoke to @tsullivan offline. We agreed it would have been preferred to do the zoom refactor in a separate PR from the typescript (my bad, I steered this change towards that), but it's fine to leave as is now that it's done. Regarding the comment about the zoom, we agreed it would be nice to leave in the reason for why zoom is set to 2 (for higher resolution). I'll follow up with that in a separate PR so we can get this checked in, as @bgaddis56 will be offline for a few weeks and we don't want to hold this up for that long. tl;dr; good to go! I will merge shortly. |
|
Thanks for helping me understand the context, @stacey-gammon LGTM! |
* wip WIP * Changed any ypes to actual types Made sure all types are set on the new layout classes. * Changes recommended from code review Changed location of type interfaces and fixed naming errors * Latest Code Review Changes Fix naming on properties and methods as well as a few other fixes * Name Changes and spacing Name Changes and spacing * Name Change Name Change * Changes for typescript import and direct reference to layout_factory Changes for typescript import and direct reference to layout_factory * Move types locally * Evaluate function changes for puppeteer * Removed String as a type and renamed index.d.ts to types.d.ts for consistency Removed String as a type and renamed index.d.ts to types.d.ts for consistency * Changed layout_factoy to create_layout
|
Congrats on getting your first PR merged @bgaddis56! 🎉 |
* wip WIP * Changed any ypes to actual types Made sure all types are set on the new layout classes. * Changes recommended from code review Changed location of type interfaces and fixed naming errors * Latest Code Review Changes Fix naming on properties and methods as well as a few other fixes * Name Changes and spacing Name Changes and spacing * Name Change Name Change * Changes for typescript import and direct reference to layout_factory Changes for typescript import and direct reference to layout_factory * Move types locally * Evaluate function changes for puppeteer * Removed String as a type and renamed index.d.ts to types.d.ts for consistency Removed String as a type and renamed index.d.ts to types.d.ts for consistency * Changed layout_factoy to create_layout


Change the layout code to TypeScript format as well as create a new set of layout classes.