Skip to content

TypeScript Reporting Layouts#22454

Merged
stacey-gammon merged 13 commits intoelastic:masterfrom
bgaddis56:typescript-reporting-layouts
Sep 4, 2018
Merged

TypeScript Reporting Layouts#22454
stacey-gammon merged 13 commits intoelastic:masterfrom
bgaddis56:typescript-reporting-layouts

Conversation

@bgaddis56
Copy link
Copy Markdown
Contributor

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

@elasticmachine
Copy link
Copy Markdown
Contributor

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?

@stacey-gammon stacey-gammon self-requested a review August 28, 2018 13:47
@stacey-gammon stacey-gammon added :Sharing zDeprecated Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead v7.0.0 v6.5.0 labels Aug 28, 2018
WIP
Made sure all types are set on the new layout classes.
@bgaddis56 bgaddis56 force-pushed the typescript-reporting-layouts branch from c08aca2 to f2108a3 Compare August 28, 2018 14:00
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Preservelayout => PreserveLayout (capital L)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think this can be private

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kbn_server => KbnServer

}

export interface configObject {
get: (path: string) => ConfigEntry;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is never modified so can be a const too.

} from '../../../../../../../../src/server/index';
import { Layout } from './layout';

interface Pagesizeparams {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pagesizeparams => PageSizeParams

return this.server.config();
}

get captureConfig(): ConfigEntry {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think these can be readonly and private:

  private readonly height: number;
  private readonly width: number;

return this.height * this.zoom;
}

get scaledWidth(): number {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

instead of get functions, just make a class property, this.scaledWidth;

Changed location of type interfaces and fixed naming errors
Copy link
Copy Markdown

@stacey-gammon stacey-gammon left a comment

Choose a reason for hiding this comment

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

Getting close!!


export interface configObject {
get: (path: string) => any;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

createlayout => createLayout

zoom: number;
width: number;
height: number;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

shouldn't need the .d in the name, and I don't think you need to specify index too. Try:

import { ViewZoomWidthHeight } from '.';

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

import { CaptureConfig } from '.';

evaluate: (evaluateOptions: EvaluateOptions) => void;
}

const groupCount: number = 2;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fn => fn since it's referencing a variable, probably shouldn't be capitalized. Maybe even add back tics around it.

debug: (message: string) => void;
error: (message: string) => void;
warning: (message: string) => void;
} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Still need to remove this

Fix naming on properties and methods as well as a few other fixes
config: () => configObject;
}

export interface configObject {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

configObject => ConfigObject

viewport: Size;
zoom: number;
viewport: Size;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

-2 spaces for the }

@stacey-gammon
Copy link
Copy Markdown

jenkins, test this

Name Changes and spacing
@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

* you may not use this file except in compliance with the Elastic License.
*/

export { createlayout } from './layout_factory';
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

createlayout => createLayout

Name Change
@stacey-gammon
Copy link
Copy Markdown

jenkins, test this

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@stacey-gammon
Copy link
Copy Markdown

Error is because of the import path for KbnServer. Will try to find out tomorrow what the path should be.

Changes for typescript import and direct reference to layout_factory
@stacey-gammon
Copy link
Copy Markdown

jenkins, test this

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@stacey-gammon
Copy link
Copy Markdown

jenkins, test this

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Copy link
Copy Markdown

@stacey-gammon stacey-gammon left a comment

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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
@stacey-gammon
Copy link
Copy Markdown

jenkins, test this

dimensions: Size;
}

export function createLayout(server: KbnServer, layoutParams: LayoutParams): Layout {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
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.

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.

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@stacey-gammon
Copy link
Copy Markdown

@tsullivan re:

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.

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!

@stacey-gammon
Copy link
Copy Markdown

Looks like the pie chart didn't render. Could be flaky, it's happened before.

screen shot 2018-08-30 at 8 29 40 pm

jenkins, test this

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@stacey-gammon
Copy link
Copy Markdown

Sadly, it appears reporting tests are flaky again. Not the fault of this PR

screen shot 2018-08-31 at 8 19 38 am

@stacey-gammon
Copy link
Copy Markdown

jenkins, test this

@elasticmachine
Copy link
Copy Markdown
Contributor

💔 Build Failed

@stacey-gammon
Copy link
Copy Markdown

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!

@stacey-gammon
Copy link
Copy Markdown

retest

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

@stacey-gammon
Copy link
Copy Markdown

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.

@tsullivan
Copy link
Copy Markdown
Member

Thanks for helping me understand the context, @stacey-gammon

LGTM!

@stacey-gammon stacey-gammon merged commit 1464741 into elastic:master Sep 4, 2018
stacey-gammon pushed a commit to stacey-gammon/kibana that referenced this pull request Sep 4, 2018
* 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
@stacey-gammon
Copy link
Copy Markdown

Congrats on getting your first PR merged @bgaddis56! 🎉

stacey-gammon pushed a commit that referenced this pull request Sep 4, 2018
* 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
@bgaddis56 bgaddis56 deleted the typescript-reporting-layouts branch September 24, 2018 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v6.5.0 v7.0.0 zDeprecated Feature:Reporting Use Reporting:Screenshot, Reporting:CSV, or Reporting:Framework instead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants