Skip to content
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 @@ -9,13 +9,7 @@

import { firstValueFrom, Observable } from 'rxjs';

import {
AnalyticsServiceStart,
CoreSetup,
CoreStart,
I18nStart,
NotificationsSetup,
} from '@kbn/core/public';
import { CoreSetup, CoreStart, NotificationsSetup } from '@kbn/core/public';
import { DataPublicPluginStart, type SerializedSearchSourceFields } from '@kbn/data-plugin/public';
import {
loadSharingDataHelpers,
Expand Down Expand Up @@ -64,10 +58,7 @@ type StartServices = [
Pick<
CoreStart,
// required for modules that render React
| 'analytics'
| 'i18n'
| 'theme'
| 'userProfile'
| 'rendering'
// used extensively in Reporting share panel action
| 'application'
| 'uiSettings'
Expand All @@ -88,15 +79,11 @@ interface ExecutionParamsOld {
searchSource: SerializedSearchSourceFields;
columns: string[] | undefined;
title: string;
analytics: AnalyticsServiceStart;
i18nStart: I18nStart;
}

interface ExecutionParams {
searchModeParams: CsvSearchModeParams;
title: string;
analytics: AnalyticsServiceStart;
i18nStart: I18nStart;
}

type GetCsvActionApi = HasType &
Expand Down Expand Up @@ -191,7 +178,7 @@ export class ReportingCsvPanelAction implements ActionDefinition<EmbeddableApiCo
*/
private executeDownload = async (params: ExecutionParamsOld) => {
// Deprecated and does not support ES|QL mode
const [startServices] = await firstValueFrom(this.startServices$);
const [{ rendering }] = await firstValueFrom(this.startServices$);
const { searchSource, columns, title } = params;
const immediateJobParams = this.apiClient.getDecoratedJobParams({
searchSource,
Expand All @@ -204,7 +191,7 @@ export class ReportingCsvPanelAction implements ActionDefinition<EmbeddableApiCo

this.notifications.toasts.addSuccess({
title: this.i18nStrings.download.toasts.success.title,
text: toMountPoint(this.i18nStrings.download.toasts.success.body, startServices),
text: toMountPoint(this.i18nStrings.download.toasts.success.body, rendering),
'data-test-subj': 'csvDownloadStarted',
});

Expand Down Expand Up @@ -248,7 +235,7 @@ export class ReportingCsvPanelAction implements ActionDefinition<EmbeddableApiCo
};

private executeGenerate = async (params: ExecutionParams) => {
const [startServices] = await firstValueFrom(this.startServices$);
const [{ rendering }] = await firstValueFrom(this.startServices$);
const { searchModeParams, title } = params;
const { reportType, decoratedJobParams } = getSearchCsvJobParams({
apiClient: this.apiClient,
Expand All @@ -262,7 +249,7 @@ export class ReportingCsvPanelAction implements ActionDefinition<EmbeddableApiCo
if (job) {
this.notifications.toasts.addSuccess({
title: this.i18nStrings.generate.toasts.success.title,
text: toMountPoint(this.i18nStrings.generate.toasts.success.body, startServices),
text: toMountPoint(this.i18nStrings.generate.toasts.success.body, rendering),
'data-test-subj': 'csvReportStarted',
});
}
Expand Down Expand Up @@ -306,10 +293,7 @@ export class ReportingCsvPanelAction implements ActionDefinition<EmbeddableApiCo
return;
}

const [{ i18n: i18nStart, analytics }] = await firstValueFrom(this.startServices$);

const title = embeddable.title$.getValue() ?? '';
const executionParamsCommon = { title, i18nStart, analytics };

const { columns, getSearchSource } = await this.getSharingData(savedSearch);
const searchSource = getSearchSource({
Expand All @@ -318,12 +302,12 @@ export class ReportingCsvPanelAction implements ActionDefinition<EmbeddableApiCo
});

if (this.enablePanelActionDownload) {
const executionParams = { searchSource, columns, title, savedSearch, i18nStart, analytics };
const executionParams = { searchSource, columns, title, savedSearch };
return this.executeDownload(executionParams);
}
if (this.isEsqlMode(savedSearch)) {
return this.executeGenerate({
...executionParamsCommon,
title,
searchModeParams: {
isEsqlMode: true,
locatorParams: [
Expand All @@ -337,7 +321,7 @@ export class ReportingCsvPanelAction implements ActionDefinition<EmbeddableApiCo
}

return this.executeGenerate({
...executionParamsCommon,
title,
searchModeParams: { isEsqlMode: false, searchSource, columns },
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ export type StartServices = [
Pick<
CoreStart,
// required for modules that render React
| 'analytics'
| 'i18n'
| 'theme'
| 'userProfile'
| 'rendering'
// used extensively in Reporting share context menus and modal
| 'notifications'
>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const reportingCsvShareProvider = ({
usesUiCapabilities,
startServices$,
}: ExportModalShareOpts) => {
const getShareMenuItems = ({ objectType, sharingData, toasts }: ShareContext) => {
const getShareMenuItems = ({ objectType, sharingData }: ShareContext) => {
if ('search' !== objectType) {
return [];
}
Expand Down Expand Up @@ -80,50 +80,55 @@ export const reportingCsvShareProvider = ({
title: sharingData.title as string,
});

return apiClient
.createReportingShareJob(reportType, decoratedJobParams)
.then(() => firstValueFrom(startServices$))
.then(([startServices]) => {
toasts.addSuccess({
title: intl.formatMessage(
{
id: 'reporting.share.modalContent.successfullyQueuedReportNotificationTitle',
defaultMessage: 'Queued report for {objectType}',
},
{ objectType }
),
text: toMountPoint(
<FormattedMessage
id="reporting.share.modalContent.successfullyQueuedReportNotificationDescription"
defaultMessage="Track its progress in {path}."
values={{
path: (
<a href={apiClient.getManagementLink()}>
<FormattedMessage
id="reporting.share.publicNotifier.reportLink.reportingSectionUrlLinkLabel"
defaultMessage="Stack Management &gt; Reporting"
/>
</a>
),
}}
/>,
startServices
),
'data-test-subj': 'queueReportSuccess',
return firstValueFrom(startServices$).then(([startServices]) => {
const {
notifications: { toasts },
rendering,
} = startServices;
return apiClient
.createReportingShareJob(reportType, decoratedJobParams)
.then(() => {
toasts.addSuccess({
title: intl.formatMessage(
{
id: 'reporting.share.modalContent.successfullyQueuedReportNotificationTitle',
defaultMessage: 'Queued report for {objectType}',
},
{ objectType }
),
text: toMountPoint(
<FormattedMessage
id="reporting.share.modalContent.successfullyQueuedReportNotificationDescription"
defaultMessage="Track its progress in {path}."
values={{
path: (
<a href={apiClient.getManagementLink()}>
<FormattedMessage
id="reporting.share.publicNotifier.reportLink.reportingSectionUrlLinkLabel"
defaultMessage="Stack Management &gt; Reporting"
/>
</a>
),
}}
/>,
rendering
),
'data-test-subj': 'queueReportSuccess',
});
})
.catch((error) => {
toasts.addError(error, {
title: intl.formatMessage({
id: 'reporting.share.modalContent.notification.reportingErrorTitle',
defaultMessage: 'Unable to create report',
}),
toastMessage: (
// eslint-disable-next-line react/no-danger
<span dangerouslySetInnerHTML={{ __html: error.body?.message }} />
) as unknown as string,
});
});
})
.catch((error) => {
toasts.addError(error, {
title: intl.formatMessage({
id: 'reporting.share.modalContent.notification.reportingErrorTitle',
defaultMessage: 'Unable to create report',
}),
toastMessage: (
// eslint-disable-next-line react/no-danger
<span dangerouslySetInnerHTML={{ __html: error.body?.message }} />
) as unknown as string,
});
});
});
};

if (licenseHasCsvReporting && capabilityHasCsvReporting) {
Expand Down
Loading