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

[Canvas] Fixes the Copy Post Url link #54831

Merged
merged 4 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions x-pack/legacy/plugins/canvas/public/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions x-pack/legacy/plugins/canvas/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down