[Screenshotting] Remove the concept of "groups" from layouts (#137438)

* remove the concept of "groups" from layouts

* updated "next page" logic

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Jean-Louis Leysens 2022-07-29 22:05:30 +02:00 committed by GitHub
parent 2d3d930756
commit 82f22a03ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 25 deletions

View file

@ -80,21 +80,19 @@ export class PdfMaker {
);
}
_addContents(contents: Content[]) {
const groupCount = this.content.length;
// inject a page break for every 2 groups on the page
// TODO: Remove this code since we are now using Chromium to drive this
// layout via native print functionality.
if (groupCount > 0 && groupCount % this.layout.groupCount === 0) {
contents = [
{
text: '',
pageBreak: 'after',
} as ContentText as Content,
].concat(contents);
}
this.content.push(contents);
private addPageContents(contents: Content[]) {
this.content.push(
// Insert a page break after each content item
(this.content.length > 1
? [
{
text: '',
pageBreak: 'after',
} as ContentText as Content,
]
: []
).concat(contents)
);
}
addBrandedImage(img: ContentImage, { title = '', description = '' }) {
@ -127,7 +125,7 @@ export class PdfMaker {
contents.push(wrappedImg);
this._addContents(contents);
this.addPageContents(contents);
}
addImage(
@ -151,7 +149,7 @@ export class PdfMaker {
return this.addBrandedImage(img, opts);
}
this._addContents([img]);
this.addPageContents([img]);
}
setTitle(title: string) {

View file

@ -30,7 +30,6 @@ export interface PageSizeParams {
export abstract class BaseLayout {
public id: LayoutType;
public groupCount: number = 0;
public hasHeader: boolean = true;
public hasFooter: boolean = true;

View file

@ -21,7 +21,6 @@ const ZOOM: number = 2;
*/
export class CanvasLayout extends BaseLayout implements Layout {
public readonly selectors: LayoutSelectorDictionary = { ...DEFAULT_SELECTORS };
public readonly groupCount = 1;
public readonly height: number;
public readonly width: number;
private readonly scaledHeight: number;

View file

@ -17,7 +17,6 @@ describe('Create Layout', () => {
const layout = createLayout(preserveParams);
expect(layout).toMatchInlineSnapshot(`
PreserveLayout {
"groupCount": 1,
"hasFooter": true,
"hasHeader": true,
"height": 16,
@ -47,7 +46,6 @@ describe('Create Layout', () => {
const layout = createLayout(printParams);
expect(layout).toMatchInlineSnapshot(`
PrintLayout {
"groupCount": 2,
"hasFooter": true,
"hasHeader": true,
"id": "print",
@ -76,7 +74,6 @@ describe('Create Layout', () => {
const layout = createLayout(canvasParams);
expect(layout).toMatchInlineSnapshot(`
CanvasLayout {
"groupCount": 1,
"hasFooter": false,
"hasHeader": false,
"height": 18,

View file

@ -35,7 +35,6 @@ it('preserve layout uses default layout selectors', () => {
"timefilterDurationAttribute": "data-shared-timefilter-duration",
}
`);
expect(testPreserveLayout.groupCount).toBe(1);
expect(testPreserveLayout.height).toBe(16);
expect(testPreserveLayout.width).toBe(16);
});

View file

@ -17,7 +17,6 @@ const ZOOM: number = 2;
export class PreserveLayout extends BaseLayout implements Layout {
public readonly selectors: LayoutSelectorDictionary;
public readonly groupCount = 1;
public readonly height: number;
public readonly width: number;
private readonly scaledHeight: number;

View file

@ -19,7 +19,6 @@ export const getPrintLayoutSelectors: () => LayoutSelectorDictionary = () => ({
export class PrintLayout extends BaseLayout implements Layout {
public readonly selectors = getPrintLayoutSelectors();
public readonly groupCount = 2;
private readonly viewport = DEFAULT_VIEWPORT;
private zoom: number;