@@ -13,21 +13,32 @@ import React from 'react';
1313import { firstValueFrom } from 'rxjs' ;
1414import type { SerializedSearchSourceFields } from '@kbn/data-plugin/common' ;
1515import { FormattedMessage , InjectedIntl } from '@kbn/i18n-react' ;
16- import { ShareContext , ShareMenuItemV2 } from '@kbn/share-plugin/public' ;
16+ import { ShareContext , type ExportShare } from '@kbn/share-plugin/public' ;
1717import { LocatorParams } from '@kbn/reporting-common/types' ;
1818import { getSearchCsvJobParams , CsvSearchModeParams } from '../shared/get_search_csv_job_params' ;
1919import type { ExportModalShareOpts } from '.' ;
2020import { checkLicense } from '../..' ;
2121
22- export const reportingCsvShareProvider = ( {
22+ export const reportingCsvExportProvider = ( {
2323 apiClient,
2424 application,
2525 license,
2626 startServices$,
27- } : ExportModalShareOpts ) => {
28- const getShareMenuItems = ( { objectType, sharingData, toasts } : ShareContext ) => {
29- if ( 'search' !== objectType ) {
30- return [ ] ;
27+ } : ExportModalShareOpts ) : ExportShare => {
28+ const getShareMenuItems = ( {
29+ objectType,
30+ sharingData,
31+ toasts,
32+ } : ShareContext ) : ReturnType < ExportShare [ 'config' ] > => {
33+ const licenseCheck = checkLicense ( license . check ( 'reporting' , 'basic' ) ) ;
34+ const licenseToolTipContent = licenseCheck . message ;
35+ const licenseHasCsvReporting = licenseCheck . showLinks ;
36+ const licenseDisabled = ! licenseCheck . enableLinks ;
37+
38+ const capabilityHasCsvReporting = application . capabilities . discover_v2 ?. generateCsv === true ;
39+
40+ if ( ! ( licenseHasCsvReporting && capabilityHasCsvReporting ) ) {
41+ return null ;
3142 }
3243
3344 const getSearchSource = sharingData . getSearchSource as ( {
@@ -58,15 +69,6 @@ export const reportingCsvShareProvider = ({
5869 } ;
5970 } ;
6071
61- const shareActions : ShareMenuItemV2 [ ] = [ ] ;
62-
63- const licenseCheck = checkLicense ( license . check ( 'reporting' , 'basic' ) ) ;
64- const licenseToolTipContent = licenseCheck . message ;
65- const licenseHasCsvReporting = licenseCheck . showLinks ;
66- const licenseDisabled = ! licenseCheck . enableLinks ;
67-
68- const capabilityHasCsvReporting = application . capabilities . discover_v2 ?. generateCsv === true ;
69-
7072 const generateReportingJobCSV = ( { intl } : { intl : InjectedIntl } ) => {
7173 const { reportType, decoratedJobParams } = getSearchCsvJobParams ( {
7274 apiClient,
@@ -120,66 +122,50 @@ export const reportingCsvShareProvider = ({
120122 } ) ;
121123 } ;
122124
123- if ( licenseHasCsvReporting && capabilityHasCsvReporting ) {
124- const panelTitle = i18n . translate (
125- 'reporting.share.contextMenu.export.csvReportsButtonLabel' ,
126- {
127- defaultMessage : 'Export' ,
128- }
129- ) ;
130-
131- const reportingUrl = new URL ( window . location . origin ) ;
132-
133- const { reportType, decoratedJobParams } = getSearchCsvJobParams ( {
134- apiClient,
135- searchModeParams : getSearchModeParams ( true ) ,
136- title : sharingData . title as string ,
137- } ) ;
138-
139- const relativePath = apiClient . getReportingPublicJobPath ( reportType , decoratedJobParams ) ;
140-
141- const absoluteUrl = new URL ( relativePath , window . location . href ) . toString ( ) ;
142-
143- shareActions . push ( {
144- shareMenuItem : {
145- name : panelTitle ,
146- toolTipContent : licenseToolTipContent ,
147- disabled : licenseDisabled ,
148- [ 'data-test-subj' ] : 'Export' ,
149- } ,
150- helpText : (
151- < FormattedMessage
152- id = "reporting.share.csv.reporting.helpTextCSV"
153- defaultMessage = "Export a CSV of this {objectType}."
154- values = { { objectType } }
155- />
156- ) ,
157- reportType,
158- label : 'CSV' ,
159- copyURLButton : {
160- id : 'reporting.share.modalContent.csv.copyUrlButtonLabel' ,
161- dataTestSubj : 'shareReportingCopyURL' ,
162- label : 'Post URL' ,
163- } ,
164- generateExportButton : (
165- < FormattedMessage
166- id = "reporting.share.generateButtonLabelCSV"
167- data-test-subj = "generateReportButton"
168- defaultMessage = "Generate CSV"
169- />
170- ) ,
171- generateExport : generateReportingJobCSV ,
172- generateExportUrl : ( ) => absoluteUrl ,
173- generateCopyUrl : reportingUrl ,
174- renderCopyURLButton : true ,
175- } ) ;
176- }
177-
178- return shareActions ;
125+ const panelTitle = i18n . translate ( 'reporting.share.contextMenu.export.csvReportsButtonLabel' , {
126+ defaultMessage : 'Export' ,
127+ } ) ;
128+
129+ const { reportType, decoratedJobParams } = getSearchCsvJobParams ( {
130+ apiClient,
131+ searchModeParams : getSearchModeParams ( true ) ,
132+ title : sharingData . title as string ,
133+ } ) ;
134+
135+ const relativePath = apiClient . getReportingPublicJobPath ( reportType , decoratedJobParams ) ;
136+
137+ const absoluteUrl = new URL ( relativePath , window . location . href ) . toString ( ) ;
138+
139+ return {
140+ name : panelTitle ,
141+ toolTipContent : licenseToolTipContent ,
142+ exportType : reportType ,
143+ label : 'CSV' ,
144+ disabled : licenseDisabled ,
145+ generateAssetExport : generateReportingJobCSV ,
146+ generateAssetURIValue : ( ) => absoluteUrl ,
147+ helpText : (
148+ < FormattedMessage
149+ id = "reporting.share.csv.reporting.helpTextCSV"
150+ defaultMessage = "Export a CSV of this {objectType}."
151+ values = { { objectType } }
152+ />
153+ ) ,
154+ generateExportButton : (
155+ < FormattedMessage
156+ id = "reporting.share.generateButtonLabelCSV"
157+ data-test-subj = "generateReportButton"
158+ defaultMessage = "Generate CSV"
159+ />
160+ ) ,
161+ renderCopyURIButton : true ,
162+ } ;
179163 } ;
180164
181165 return {
166+ shareType : 'integration' ,
182167 id : 'csvReportsModal' ,
183- getShareMenuItems,
168+ groupId : 'export' ,
169+ config : getShareMenuItems ,
184170 } ;
185171} ;
0 commit comments