* Fixes the Copy Post Url link * Adds tests Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
6a30fca986
commit
bf114f6986
|
@ -62,12 +62,8 @@ export const WorkpadExport = compose<ComponentProps, {}>(
|
|||
enabled,
|
||||
getExportUrl: type => {
|
||||
if (type === 'pdf') {
|
||||
const { createPdfUri } = getPdfUrl(
|
||||
workpad,
|
||||
{ pageCount },
|
||||
kibana.services.http.basePath.prepend
|
||||
);
|
||||
return getAbsoluteUrl(createPdfUri);
|
||||
const pdfUrl = getPdfUrl(workpad, { pageCount }, kibana.services.http.basePath.prepend);
|
||||
return getAbsoluteUrl(pdfUrl);
|
||||
}
|
||||
|
||||
throw new Error(strings.getUnknownExportErrorMessage(type));
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
jest.mock('../../../../common/lib/fetch');
|
||||
|
||||
import { getPdfUrl, createPdf } from './utils';
|
||||
import { workpads } from '../../../../__tests__/fixtures/workpads';
|
||||
import { fetch } from '../../../../common/lib/fetch';
|
||||
|
||||
const addBasePath = jest.fn().mockImplementation(s => `basepath/${s}`);
|
||||
const workpad = workpads[0];
|
||||
|
||||
test('getPdfUrl returns the correct url', () => {
|
||||
const url = getPdfUrl(workpad, { pageCount: 2 }, addBasePath);
|
||||
|
||||
expect(url).toMatchInlineSnapshot(
|
||||
`"basepath//api/reporting/generate/printablePdf?jobParams=(browserTimezone:America%2FPhoenix,layout:(dimensions:(height:0,width:0),id:preserve_layout),objectType:'canvas%20workpad',relativeUrls:!(%2Fapp%2Fcanvas%23%2Fexport%2Fworkpad%2Fpdf%2Fbase-workpad%2Fpage%2F1,%2Fapp%2Fcanvas%23%2Fexport%2Fworkpad%2Fpdf%2Fbase-workpad%2Fpage%2F2),title:'base%20workpad')"`
|
||||
);
|
||||
});
|
||||
|
||||
test('createPdf posts to create the pdf', () => {
|
||||
createPdf(workpad, { pageCount: 2 }, addBasePath);
|
||||
|
||||
expect(fetch.post).toBeCalled();
|
||||
|
||||
const args = (fetch.post as jest.MockedFunction<typeof fetch.post>).mock.calls[0];
|
||||
|
||||
expect(args[0]).toMatchInlineSnapshot(`"basepath//api/reporting/generate/printablePdf"`);
|
||||
expect(args[1]).toMatchInlineSnapshot(`
|
||||
Object {
|
||||
"jobParams": "(browserTimezone:America/Phoenix,layout:(dimensions:(height:0,width:0),id:preserve_layout),objectType:'canvas workpad',relativeUrls:!(/app/canvas#/export/workpad/pdf/base-workpad/page/1,/app/canvas#/export/workpad/pdf/base-workpad/page/2),title:'base workpad')",
|
||||
}
|
||||
`);
|
||||
});
|
|
@ -7,6 +7,7 @@
|
|||
import rison from 'rison-node';
|
||||
// @ts-ignore Untyped local.
|
||||
import { fetch } from '../../../../common/lib/fetch';
|
||||
import { getStartPlugins } from '../../../legacy';
|
||||
import { CanvasWorkpad } from '../../../../types';
|
||||
|
||||
// type of the desired pdf output (print or preserve_layout)
|
||||
|
@ -25,7 +26,7 @@ interface PdfUrlData {
|
|||
createPdfPayload: { jobParams: string };
|
||||
}
|
||||
|
||||
export function getPdfUrl(
|
||||
function getPdfUrlParts(
|
||||
{ id, name: title, width, height }: CanvasWorkpad,
|
||||
{ pageCount }: PageCount,
|
||||
addBasePath: (path: string) => string
|
||||
|
@ -68,7 +69,16 @@ export function getPdfUrl(
|
|||
};
|
||||
}
|
||||
|
||||
export function getPdfUrl(...args: Arguments): string {
|
||||
const urlParts = getPdfUrlParts(...args);
|
||||
|
||||
return `${urlParts.createPdfUri}?${getStartPlugins().__LEGACY.QueryString.param(
|
||||
'jobParams',
|
||||
urlParts.createPdfPayload.jobParams
|
||||
)}`;
|
||||
}
|
||||
|
||||
export function createPdf(...args: Arguments) {
|
||||
const { createPdfUri, createPdfPayload } = getPdfUrl(...args);
|
||||
const { createPdfUri, createPdfPayload } = getPdfUrlParts(...args);
|
||||
return fetch.post(createPdfUri, createPdfPayload);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ import { absoluteToParsedUrl } from 'ui/url/absolute_to_parsed_url'; // eslint-d
|
|||
import { Storage } from '../../../../../src/plugins/kibana_utils/public'; // eslint-disable-line import/order
|
||||
// @ts-ignore Untyped Kibana Lib
|
||||
import { formatMsg } from 'ui/notify/lib/format_msg'; // eslint-disable-line import/order
|
||||
// @ts-ignore Untyped Kibana Lib
|
||||
import { QueryString } from 'ui/utils/query_string'; // eslint-disable-line import/order
|
||||
|
||||
const shimCoreSetup = {
|
||||
...npSetup.core,
|
||||
|
@ -30,6 +32,7 @@ const shimStartPlugins: CanvasStartDeps = {
|
|||
absoluteToParsedUrl,
|
||||
// ToDo: Copy directly into canvas
|
||||
formatMsg,
|
||||
QueryString,
|
||||
// ToDo: Remove in favor of core.application.register
|
||||
setRootController: chrome.setRootController,
|
||||
storage: Storage,
|
||||
|
|
|
@ -39,6 +39,7 @@ export interface CanvasStartDeps {
|
|||
__LEGACY: {
|
||||
absoluteToParsedUrl: (url: string, basePath: string) => any;
|
||||
formatMsg: any;
|
||||
QueryString: any;
|
||||
setRootController: Chrome['setRootController'];
|
||||
storage: typeof Storage;
|
||||
trackSubUrlForApp: Chrome['trackSubUrlForApp'];
|
||||
|
|
Loading…
Reference in a new issue