Skip to content
Merged
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 @@ -86,8 +77,6 @@ interface Params {
interface ExecutionParams {
searchModeParams: CsvSearchModeParams;
title: string;
analytics: AnalyticsServiceStart;
i18nStart: I18nStart;
}

type GetCsvActionApi = HasType &
Expand Down Expand Up @@ -168,7 +157,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 @@ -182,7 +171,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 @@ -226,10 +215,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 @@ -239,7 +225,7 @@ export class ReportingCsvPanelAction implements ActionDefinition<EmbeddableApiCo

if (this.isEsqlMode(savedSearch)) {
return this.executeGenerate({
...executionParamsCommon,
title,
searchModeParams: {
isEsqlMode: true,
locatorParams: [
Expand All @@ -253,7 +239,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 @@ -28,7 +28,6 @@ export const reportingCsvExportProvider = ({
const getShareMenuItems = ({
objectType,
sharingData,
toasts,
}: ShareContext): ReturnType<ExportShare['config']> => {
const licenseCheck = checkLicense(license.check('reporting', 'basic'));
const licenseToolTipContent = licenseCheck.message;
Expand Down Expand Up @@ -76,50 +75,56 @@ export const reportingCsvExportProvider = ({
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',
});
})
.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,
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,
});
});
});
});
};

const panelTitle = i18n.translate('reporting.share.contextMenu.export.csvReportsButtonLabel', {
Expand Down
Loading