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] Formatting fixes for CSV export in Discover, CSV download from Dashboard panel #67027

Merged
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: 2 additions & 0 deletions x-pack/plugins/reporting/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { ReportingConfigType } from '../server/config';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
export { LayoutInstance } from '../server/export_types/common/layouts';

export type JobId = string;
export type JobStatus =
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/reporting/public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { ManagementSectionId, ManagementSetup } from '../../../../src/plugins/management/public';
import { SharePluginSetup } from '../../../../src/plugins/share/public';
import { LicensingPluginSetup } from '../../licensing/public';
import { ReportingConfigType, JobId, JobStatusBuckets } from '../common/types';
import { JobId, JobStatusBuckets, ReportingConfigType } from '../common/types';
import { JOB_COMPLETION_NOTIFICATIONS_SESSION_KEY } from '../constants';
import { getGeneralErrorToast } from './components';
import { ReportListing } from './components/report_listing';
Expand Down Expand Up @@ -144,7 +144,7 @@ export class ReportingPublicPlugin implements Plugin<void, void> {

uiActions.addTriggerAction(CONTEXT_MENU_TRIGGER, action);

share.register(csvReportingProvider({ apiClient, toasts, license$ }));
share.register(csvReportingProvider({ apiClient, toasts, license$, uiSettings }));
share.register(
reportingPDFPNGProvider({
apiClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,29 @@
*/

import { i18n } from '@kbn/i18n';
import moment from 'moment-timezone';
import React from 'react';

import { ToastsSetup } from 'src/core/public';
import { IUiSettingsClient, ToastsSetup } from 'src/core/public';
import { ShareContext } from '../../../../../src/plugins/share/public';
import { LicensingPluginSetup } from '../../../licensing/public';
import { JobParamsDiscoverCsv, SearchRequest } from '../../server/export_types/csv/types';
import { ReportingPanelContent } from '../components/reporting_panel_content';
import { ReportingAPIClient } from '../lib/reporting_api_client';
import { checkLicense } from '../lib/license_check';
import { LicensingPluginSetup } from '../../../licensing/public';
import { ShareContext } from '../../../../../src/plugins/share/public';
import { ReportingAPIClient } from '../lib/reporting_api_client';

interface ReportingProvider {
apiClient: ReportingAPIClient;
toasts: ToastsSetup;
license$: LicensingPluginSetup['license$'];
uiSettings: IUiSettingsClient;
}

export const csvReportingProvider = ({ apiClient, toasts, license$ }: ReportingProvider) => {
export const csvReportingProvider = ({
apiClient,
toasts,
license$,
uiSettings,
}: ReportingProvider) => {
let toolTipContent = '';
let disabled = true;
let hasCSVReporting = false;
Expand All @@ -33,6 +40,14 @@ export const csvReportingProvider = ({ apiClient, toasts, license$ }: ReportingP
disabled = !enableLinks;
});

// If the TZ is set to the default "Browser", it will not be useful for
// server-side export. We need to derive the timezone and pass it as a param
// to the export API.
const browserTimezone =
uiSettings.get('dateFormat:tz') === 'Browser'
? moment.tz.guess()
: uiSettings.get('dateFormat:tz');

const getShareMenuItems = ({
objectType,
objectId,
Expand All @@ -44,13 +59,19 @@ export const csvReportingProvider = ({ apiClient, toasts, license$ }: ReportingP
return [];
}

const getJobParams = () => {
return {
...sharingData,
type: objectType,
};
const jobParams: JobParamsDiscoverCsv = {
browserTimezone,
objectType,
title: sharingData.title as string,
indexPatternId: sharingData.indexPatternId as string,
searchRequest: sharingData.searchRequest as SearchRequest,
fields: sharingData.fields as string[],
metaFields: sharingData.metaFields as string[],
conflictedTypesFields: sharingData.conflictedTypesFields as string[],
};

const getJobParams = () => jobParams;

const shareActions = [];

if (hasCSVReporting) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
import { i18n } from '@kbn/i18n';
import moment from 'moment-timezone';
import React from 'react';
import { ToastsSetup, IUiSettingsClient } from 'src/core/public';
import { ReportingAPIClient } from '../lib/reporting_api_client';
import { checkLicense } from '../lib/license_check';
import { ScreenCapturePanelContent } from '../components/screen_capture_panel_content';
import { LicensingPluginSetup } from '../../../licensing/public';
import { IUiSettingsClient, ToastsSetup } from 'src/core/public';
import { ShareContext } from '../../../../../src/plugins/share/public';
import { LicensingPluginSetup } from '../../../licensing/public';
import { LayoutInstance } from '../../common/types';
import { JobParamsPNG } from '../../server/export_types/png/types';
import { JobParamsPDF } from '../../server/export_types/printable_pdf/types';
import { ScreenCapturePanelContent } from '../components/screen_capture_panel_content';
import { checkLicense } from '../lib/license_check';
import { ReportingAPIClient } from '../lib/reporting_api_client';

interface ReportingPDFPNGProvider {
apiClient: ReportingAPIClient;
Expand All @@ -39,6 +42,14 @@ export const reportingPDFPNGProvider = ({
disabled = !enableLinks;
});

// If the TZ is set to the default "Browser", it will not be useful for
// server-side export. We need to derive the timezone and pass it as a param
// to the export API.
const browserTimezone =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this cleans up duplication

uiSettings.get('dateFormat:tz') === 'Browser'
? moment.tz.guess()
: uiSettings.get('dateFormat:tz');

const getShareMenuItems = ({
objectType,
objectId,
Expand All @@ -57,44 +68,36 @@ export const reportingPDFPNGProvider = ({
return [];
}

const getReportingJobParams = () => {
const getPdfJobParams = (): JobParamsPDF => {
// Relative URL must have URL prefix (Spaces ID prefix), but not server basePath
// Replace hashes with original RISON values.
const relativeUrl = shareableUrl.replace(
window.location.origin + apiClient.getServerBasePath(),
''
);

const browserTimezone =
uiSettings.get('dateFormat:tz') === 'Browser'
? moment.tz.guess()
: uiSettings.get('dateFormat:tz');

return {
...sharingData,
objectType,
browserTimezone,
relativeUrls: [relativeUrl],
relativeUrls: [relativeUrl], // multi URL for PDF
layout: sharingData.layout as LayoutInstance,
title: sharingData.title as string,
};
};

const getPngJobParams = () => {
const getPngJobParams = (): JobParamsPNG => {
// Replace hashes with original RISON values.
const relativeUrl = shareableUrl.replace(
window.location.origin + apiClient.getServerBasePath(),
''
);

const browserTimezone =
uiSettings.get('dateFormat:tz') === 'Browser'
? moment.tz.guess()
: uiSettings.get('dateFormat:tz');

return {
...sharingData,
objectType,
browserTimezone,
relativeUrl,
relativeUrl, // single URL for PNG
layout: sharingData.layout as LayoutInstance,
title: sharingData.title as string,
};
};

Expand Down Expand Up @@ -161,7 +164,7 @@ export const reportingPDFPNGProvider = ({
reportType="printablePdf"
objectType={objectType}
objectId={objectId}
getJobParams={getReportingJobParams}
getJobParams={getPdfJobParams}
isDirty={isDirty}
onClose={onClose}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,19 @@ export const scheduleTaskFnFactory: ScheduleTaskFnFactory<ESQueueCreateJobFn<
>> = function createJobFactoryFn(reporting) {
const config = reporting.getConfig();
const crypto = cryptoFactory(config.get('encryptionKey'));
const setupDeps = reporting.getPluginSetupDeps();

return async function scheduleTask(jobParams, context, request) {
const serializedEncryptedHeaders = await crypto.encrypt(request.headers);

const savedObjectsClient = context.core.savedObjects.client;
const indexPatternSavedObject = await savedObjectsClient.get(
'index-pattern',
jobParams.indexPatternId!
jobParams.indexPatternId
);

return {
headers: serializedEncryptedHeaders,
indexPatternSavedObject,
basePath: setupDeps.basePath(request),
...jobParams,
};
};
Expand Down
Loading