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

[7.x] [Feature/Reporting] Export Saved Search CSV as Dashboard Panel Action (#34571) #37401

Merged
merged 1 commit into from
May 29, 2019
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class PanelActionsStore {
*/
public initializeFromRegistry(panelActionsRegistry: ContextMenuAction[]) {
panelActionsRegistry.forEach(panelAction => {
this.actions.push(panelAction);
if (!this.actions.includes(panelAction)) {
this.actions.push(panelAction);
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ export class SearchEmbeddable extends Embeddable {
return this.inspectorAdaptors;
}

public getPanelTitle() {
return this.panelTitle;
}

public onContainerStateChanged(containerState: ContainerState) {
this.customization = containerState.embeddableCustomization || {};
this.filters = containerState.filters;
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/reporting/__snapshots__/index.test.js.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import { isFunction } from 'lodash';

export class CancellationToken {
private isCancelled: boolean;
private _callbacks: any[];

constructor() {
this.isCancelled = false;
this._callbacks = [];
}

on = (callback) => {
on(callback: Function) {
if (!isFunction(callback)) {
throw new Error('Expected callback to be a function');
}
Expand All @@ -23,10 +26,10 @@ export class CancellationToken {
}

this._callbacks.push(callback);
};
}

cancel = () => {
cancel() {
this.isCancelled = true;
this._callbacks.forEach(callback => callback());
};
}
}
9 changes: 7 additions & 2 deletions x-pack/plugins/reporting/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@ export const PLUGIN_ID = 'reporting';
export const JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY =
'xpack.reporting.jobCompletionNotifications';

export const API_BASE_URL = '/api/reporting';
export const API_BASE_URL = '/api/reporting'; // "Generation URL" from share menu
export const API_BASE_URL_V1 = '/api/reporting/v1'; //
export const API_BASE_GENERATE_V1 = `${API_BASE_URL_V1}/generate`;

export const CONTENT_TYPE_CSV = 'text/csv';

export const WHITELISTED_JOB_CONTENT_TYPES = [
'application/json',
'application/pdf',
'text/csv',
CONTENT_TYPE_CSV,
'image/png',
];

Expand All @@ -41,4 +45,5 @@ export const KIBANA_REPORTING_TYPE = 'reporting';
export const PDF_JOB_TYPE = 'printable_pdf';
export const PNG_JOB_TYPE = 'PNG';
export const CSV_JOB_TYPE = 'csv';
export const CSV_FROM_SAVEDOBJECT_JOB_TYPE = 'csv_from_savedobject';
export const USES_HEADLESS_JOB_TYPES = [PDF_JOB_TYPE, PNG_JOB_TYPE];
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,15 @@ beforeEach(() => {
test(`fails if no URL is passed`, async () => {
await expect(
addForceNowQuerystring({
job: {},
job: {
title: 'cool-job-bro',
type: 'csv',
jobParams: {
savedObjectId: 'abc-123',
isImmediate: false,
savedObjectType: 'search',
},
},
server: mockServer,
})
).rejects.toBeDefined();
Expand All @@ -24,7 +32,17 @@ test(`fails if no URL is passed`, async () => {
test(`adds forceNow to hash's query, if it exists`, async () => {
const forceNow = '2000-01-01T00:00:00.000Z';
const { urls } = await addForceNowQuerystring({
job: { relativeUrl: '/app/kibana#/something', forceNow },
job: {
title: 'cool-job-bro',
type: 'csv',
jobParams: {
savedObjectId: 'abc-123',
isImmediate: false,
savedObjectType: 'search',
},
relativeUrl: '/app/kibana#/something',
forceNow,
},
server: mockServer,
});

Expand All @@ -38,6 +56,13 @@ test(`appends forceNow to hash's query, if it exists`, async () => {

const { urls } = await addForceNowQuerystring({
job: {
title: 'cool-job-bro',
type: 'csv',
jobParams: {
savedObjectId: 'abc-123',
isImmediate: false,
savedObjectType: 'search',
},
relativeUrl: '/app/kibana#/something?_g=something',
forceNow,
},
Expand All @@ -52,6 +77,13 @@ 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 addForceNowQuerystring({
job: {
title: 'cool-job-bro',
type: 'csv',
jobParams: {
savedObjectId: 'abc-123',
isImmediate: false,
savedObjectType: 'search',
},
relativeUrl: '/app/kibana#/something',
},
server: mockServer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
// @ts-ignore

import url from 'url';
import { getAbsoluteUrlFactory } from '../../../common/get_absolute_url';
import { ConditionalHeaders, KbnServer, ReportingJob } from '../../../types';
import { ConditionalHeaders, JobDocPayload, KbnServer } from '../../../types';

function getSavedObjectAbsoluteUrl(job: ReportingJob, relativeUrl: string, server: KbnServer) {
function getSavedObjectAbsoluteUrl(job: JobDocPayload, relativeUrl: string, server: KbnServer) {
const getAbsoluteUrl: any = getAbsoluteUrlFactory(server);

const { pathname: path, hash, search } = url.parse(relativeUrl);
Expand All @@ -21,7 +21,7 @@ export const addForceNowQuerystring = async ({
logo,
server,
}: {
job: ReportingJob;
job: JobDocPayload;
conditionalHeaders?: ConditionalHeaders;
logo?: any;
server: KbnServer;
Expand All @@ -34,7 +34,7 @@ export const addForceNowQuerystring = async ({
job.urls = [getSavedObjectAbsoluteUrl(job, job.relativeUrl, server)];
}

const urls = job.urls.map(jobUrl => {
const urls = job.urls.map((jobUrl: string) => {
if (!job.forceNow) {
return jobUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,17 @@ describe('headers', () => {
test(`fails if it can't decrypt headers`, async () => {
await expect(
decryptJobHeaders({
job: { relativeUrl: '/app/kibana#/something', timeRange: {} },
job: {
title: 'cool-job-bro',
type: 'csv',
jobParams: {
savedObjectId: 'abc-123',
isImmediate: false,
savedObjectType: 'search',
},
relativeUrl: '/app/kibana#/something',
timeRange: {},
},
server: mockServer,
})
).rejects.toBeDefined();
Expand All @@ -37,7 +47,17 @@ describe('headers', () => {

const encryptedHeaders = await encryptHeaders(headers);
const { decryptedHeaders } = await decryptJobHeaders({
job: { relativeUrl: '/app/kibana#/something', headers: encryptedHeaders },
job: {
title: 'cool-job-bro',
type: 'csv',
jobParams: {
savedObjectId: 'abc-123',
isImmediate: false,
savedObjectType: 'search',
},
relativeUrl: '/app/kibana#/something',
headers: encryptedHeaders,
},
server: mockServer,
});
expect(decryptedHeaders).toEqual(headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
*/
// @ts-ignore
import { cryptoFactory } from '../../../server/lib/crypto';
import { CryptoFactory, KbnServer, ReportingJob } from '../../../types';
import { CryptoFactory, JobDocPayload, KbnServer } from '../../../types';

export const decryptJobHeaders = async ({
job,
server,
}: {
job: ReportingJob;
job: JobDocPayload;
server: KbnServer;
}) => {
const crypto: CryptoFactory = cryptoFactory(server);
Expand Down
Loading