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

[Reporting] Restore legacy compatibility shim for PDF job creation - 7.15 backport/cleanup #108979

Merged
merged 3 commits into from
Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 0 additions & 2 deletions x-pack/plugins/reporting/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ export interface BaseParams {
layout?: LayoutParams;
objectType: string;
title: string;
savedObjectId?: string; // legacy (7.x) only
queryString?: string; // legacy (7.x) only
browserTimezone: string; // to format dates in the user's time zone
version: string; // to handle any state migrations
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ test(`fails if URLs are absolute for PDF`, async () => {
getFullUrls(
mockConfig,
getMockJob({
objects: [
{
relativeUrl,
},
],
objects: [{ relativeUrl }],
forceNow,
})
);
Expand Down Expand Up @@ -107,7 +103,7 @@ test(`fails if URL does not route to a visualization`, async () => {

test(`adds forceNow to hash's query, if it exists`, async () => {
const forceNow = '2000-01-01T00:00:00.000Z';
const urls = await getFullUrls(
const urls = getFullUrls(
mockConfig,
getMockJob({ relativeUrl: '/app/kibana#/something', forceNow })
);
Expand All @@ -120,7 +116,7 @@ test(`adds forceNow to hash's query, if it exists`, async () => {
test(`appends forceNow to hash's query, if it exists`, async () => {
const forceNow = '2000-01-01T00:00:00.000Z';

const urls = await getFullUrls(
const urls = getFullUrls(
mockConfig,
getMockJob({ relativeUrl: '/app/kibana#/something?_g=something', forceNow })
);
Expand All @@ -131,7 +127,7 @@ test(`appends forceNow to hash's query, if it exists`, async () => {
});

test(`doesn't append forceNow query to url, if it doesn't exists`, async () => {
const urls = await getFullUrls(mockConfig, getMockJob({ relativeUrl: '/app/kibana#/something' }));
const urls = getFullUrls(mockConfig, getMockJob({ relativeUrl: '/app/kibana#/something' }));

expect(urls[0]).toEqual('http://localhost:5601/sbp/app/kibana#/something');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function isPngJob(job: TaskPayloadPNG | TaskPayloadPDF): job is TaskPayloadPNG {
return (job as TaskPayloadPNG).relativeUrl !== undefined;
}
function isPdfJob(job: TaskPayloadPNG | TaskPayloadPDF): job is TaskPayloadPDF {
return (job as TaskPayloadPDF).objects !== undefined; // 7.x only
return (job as TaskPayloadPDF).objects !== undefined;
}

export function getFullUrls(config: ReportingConfig, job: TaskPayloadPDF | TaskPayloadPNG) {
Expand Down Expand Up @@ -49,7 +49,7 @@ export function getFullUrls(config: ReportingConfig, job: TaskPayloadPDF | TaskP
validateUrls(relativeUrls);

const urls = relativeUrls.map((relativeUrl) => {
const parsedRelative: UrlWithStringQuery = urlParse(relativeUrl);
const parsedRelative: UrlWithStringQuery = urlParse(relativeUrl); // FIXME: '(urlStr: string): UrlWithStringQuery' is deprecated
const jobUrl = getAbsoluteUrl({
path: parsedRelative.pathname === null ? undefined : parsedRelative.pathname,
hash: parsedRelative.hash === null ? undefined : parsedRelative.hash,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ const isBogusUrl = (url: string) => {
};

export const validateUrls = (urls: string[]): void => {
if (!Array.isArray(urls)) {
throw new Error('Invalid relativeUrls. String[] is expected.');
}
urls.forEach((url) => {
if (typeof url !== 'string') {
throw new Error('Invalid Relative URL in relativeUrls. String is expected.');
}
});

const badUrls = filter(urls, (url) => isBogusUrl(url));

if (badUrls.length) {
Expand Down

This file was deleted.

Loading