-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] fix dashboard "Copy Post URL" action #192530
Merged
tsullivan
merged 21 commits into
elastic:main
from
tsullivan:fix/share-menu-items-add-generate-url-function
Oct 7, 2024
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c30a593
Link to re-opened skipped test issue
tsullivan 5433322
Add getShareMenuItemsLegacy to ShareMenuProvider
tsullivan aa7d3b4
Add generateExportUrl
tsullivan 2b12a8c
Ensure ShareMenuItemV2
tsullivan cbc09c9
cleanup: use a discriminatory type for ShareMenuProvider
tsullivan c265fb4
Remove console.log
tsullivan d057a37
Declare relative path variables within the generateExportUrl functions
tsullivan 5d33128
Fixme comment
tsullivan 375f0f9
Comment
tsullivan e58bc38
JobParamsProviderLayoutOptions
tsullivan 79f5097
Cleanup diff
tsullivan 9d5531e
ScreenshotExportOpts
tsullivan 9946a74
Implement the generateExportUrl functions
tsullivan 85e8e47
Remove unused menu export option
tsullivan 2996866
fix i18n check
tsullivan bf7a09c
Add functional tests for COPY POST URL button
tsullivan 76a0386
unskip flaky test
tsullivan b3b707e
Merge branch 'main' into fix/share-menu-items-add-generate-url-function
tsullivan bc88a3d
Merge branch 'main' into fix/share-menu-items-add-generate-url-function
tsullivan 5b0952f
Handle the fact that some menu item may still be defined using the le…
tsullivan 6c1e7ea
Merge branch 'main' into fix/share-menu-items-add-generate-url-function
tsullivan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,31 +8,28 @@ | |
*/ | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { FormattedMessage, InjectedIntl } from '@kbn/i18n-react'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
import { toMountPoint } from '@kbn/react-kibana-mount'; | ||
import { ShareContext, ShareMenuItem, ShareMenuProvider } from '@kbn/share-plugin/public'; | ||
import { ShareContext, ShareMenuItemV2, ShareMenuProvider } from '@kbn/share-plugin/public'; | ||
import React from 'react'; | ||
import { firstValueFrom } from 'rxjs'; | ||
import { | ||
ExportModalShareOpts, | ||
ExportPanelShareOpts, | ||
JobParamsProviderOptions, | ||
ReportingSharingData, | ||
} from '.'; | ||
import { ScreenshotExportOpts } from '@kbn/share-plugin/public/types'; | ||
import { ExportModalShareOpts, JobParamsProviderOptions, ReportingSharingData } from '.'; | ||
import { checkLicense } from '../../license_check'; | ||
import { ScreenCapturePanelContent } from './screen_capture_panel_content_lazy'; | ||
|
||
const getJobParams = (opts: JobParamsProviderOptions, type: 'pngV2' | 'printablePdfV2') => () => { | ||
const { | ||
objectType, | ||
sharingData: { title, layout, locatorParams }, | ||
sharingData: { title, locatorParams }, | ||
optimizedForPrinting, | ||
} = opts; | ||
|
||
const baseParams = { | ||
objectType, | ||
layout, | ||
title, | ||
}; | ||
const el = document.querySelector('[data-shared-items-container]'); | ||
const { height, width } = el ? el.getBoundingClientRect() : { height: 768, width: 1024 }; | ||
const dimensions = { height, width }; | ||
const layoutId = optimizedForPrinting ? ('print' as const) : ('preserve_layout' as const); | ||
const layout = { id: layoutId, dimensions }; | ||
const baseParams = { objectType, layout, title }; | ||
|
||
if (type === 'printablePdfV2') { | ||
// multi locator for PDF V2 | ||
|
@@ -43,154 +40,8 @@ const getJobParams = (opts: JobParamsProviderOptions, type: 'pngV2' | 'printable | |
}; | ||
|
||
/** | ||
* This is used by Canvas | ||
* This is used by Dashboard and Visualize apps (sharing modal) | ||
*/ | ||
export const reportingScreenshotShareProvider = ({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Canvas integration doesn't use this export, and doesn't use the Sharing services for its menu. See |
||
apiClient, | ||
license, | ||
application, | ||
usesUiCapabilities, | ||
startServices$, | ||
}: ExportPanelShareOpts): ShareMenuProvider => { | ||
const getShareMenuItems = ({ | ||
objectType, | ||
objectId, | ||
isDirty, | ||
onClose, | ||
shareableUrl, | ||
shareableUrlForSavedObject, | ||
...shareOpts | ||
}: ShareContext) => { | ||
const { enableLinks, showLinks, message } = checkLicense(license.check('reporting', 'gold')); | ||
const licenseToolTipContent = message; | ||
const licenseHasScreenshotReporting = showLinks; | ||
const licenseDisabled = !enableLinks; | ||
|
||
let capabilityHasDashboardScreenshotReporting = false; | ||
let capabilityHasVisualizeScreenshotReporting = false; | ||
if (usesUiCapabilities) { | ||
capabilityHasDashboardScreenshotReporting = | ||
application.capabilities.dashboard?.generateScreenshot === true; | ||
capabilityHasVisualizeScreenshotReporting = | ||
application.capabilities.visualize?.generateScreenshot === true; | ||
} else { | ||
// deprecated | ||
capabilityHasDashboardScreenshotReporting = true; | ||
capabilityHasVisualizeScreenshotReporting = true; | ||
} | ||
|
||
if (!licenseHasScreenshotReporting) { | ||
return []; | ||
} | ||
const isSupportedType = ['dashboard', 'visualization', 'lens'].includes(objectType); | ||
|
||
if (!isSupportedType) { | ||
return []; | ||
} | ||
|
||
if (objectType === 'dashboard' && !capabilityHasDashboardScreenshotReporting) { | ||
return []; | ||
} | ||
|
||
if ( | ||
isSupportedType && | ||
!capabilityHasVisualizeScreenshotReporting && | ||
!capabilityHasDashboardScreenshotReporting | ||
) { | ||
return []; | ||
} | ||
|
||
const { sharingData } = shareOpts as unknown as { sharingData: ReportingSharingData }; | ||
const shareActions: ShareMenuItem[] = []; | ||
|
||
const pngPanelTitle = i18n.translate('reporting.share.contextMenu.pngReportsButtonLabel', { | ||
defaultMessage: 'PNG Reports', | ||
}); | ||
|
||
const jobProviderOptions: JobParamsProviderOptions = { | ||
shareableUrl: isDirty ? shareableUrl : shareableUrlForSavedObject ?? shareableUrl, | ||
objectType, | ||
sharingData, | ||
}; | ||
const isJobV2Params = ({ | ||
sharingData: _sharingData, | ||
}: { | ||
sharingData: Record<string, unknown>; | ||
}) => _sharingData.locatorParams != null; | ||
|
||
const isV2Job = isJobV2Params(jobProviderOptions); | ||
const requiresSavedState = !isV2Job; | ||
|
||
const panelPng = { | ||
shareMenuItem: { | ||
name: pngPanelTitle, | ||
icon: 'document', | ||
toolTipContent: licenseToolTipContent, | ||
disabled: licenseDisabled || sharingData.reportingDisabled, | ||
['data-test-subj']: 'PNGReports', | ||
sortOrder: 10, | ||
}, | ||
panel: { | ||
id: 'reportingPngPanel', | ||
title: pngPanelTitle, | ||
content: ( | ||
<ScreenCapturePanelContent | ||
apiClient={apiClient} | ||
startServices$={startServices$} | ||
reportType={'pngV2'} | ||
objectId={objectId} | ||
requiresSavedState={requiresSavedState} | ||
getJobParams={getJobParams(jobProviderOptions, 'pngV2')} | ||
isDirty={isDirty} | ||
onClose={onClose} | ||
/> | ||
), | ||
}, | ||
}; | ||
|
||
const pdfPanelTitle = i18n.translate('reporting.share.contextMenu.pdfReportsButtonLabel', { | ||
defaultMessage: 'PDF Reports', | ||
}); | ||
|
||
const panelPdf = { | ||
shareMenuItem: { | ||
name: pdfPanelTitle, | ||
icon: 'document', | ||
toolTipContent: licenseToolTipContent, | ||
disabled: licenseDisabled || sharingData.reportingDisabled, | ||
['data-test-subj']: 'PDFReports', | ||
sortOrder: 10, | ||
}, | ||
panel: { | ||
id: 'reportingPdfPanel', | ||
title: pdfPanelTitle, | ||
content: ( | ||
<ScreenCapturePanelContent | ||
apiClient={apiClient} | ||
startServices$={startServices$} | ||
reportType={'printablePdfV2'} | ||
objectId={objectId} | ||
requiresSavedState={requiresSavedState} | ||
layoutOption={objectType === 'dashboard' ? 'print' : undefined} | ||
getJobParams={getJobParams(jobProviderOptions, 'printablePdfV2')} | ||
isDirty={isDirty} | ||
onClose={onClose} | ||
/> | ||
), | ||
}, | ||
}; | ||
|
||
shareActions.push(panelPng); | ||
shareActions.push(panelPdf); | ||
return shareActions; | ||
}; | ||
|
||
return { | ||
id: 'screenCaptureReports', | ||
getShareMenuItems, | ||
}; | ||
}; | ||
|
||
export const reportingExportModalProvider = ({ | ||
apiClient, | ||
license, | ||
|
@@ -249,7 +100,7 @@ export const reportingExportModalProvider = ({ | |
} | ||
|
||
const { sharingData } = shareOpts as unknown as { sharingData: ReportingSharingData }; | ||
const shareActions: ShareMenuItem[] = []; | ||
const shareActions: ShareMenuItemV2[] = []; | ||
|
||
const jobProviderOptions: JobParamsProviderOptions = { | ||
shareableUrl: isDirty ? shareableUrl : shareableUrlForSavedObject ?? shareableUrl, | ||
|
@@ -259,32 +110,9 @@ export const reportingExportModalProvider = ({ | |
|
||
const requiresSavedState = sharingData.locatorParams === null; | ||
|
||
const relativePathPDF = apiClient.getReportingPublicJobPath( | ||
'printablePdfV2', | ||
apiClient.getDecoratedJobParams(getJobParams(jobProviderOptions, 'printablePdfV2')()) | ||
); | ||
|
||
const relativePathPNG = apiClient.getReportingPublicJobPath( | ||
'pngV2', | ||
apiClient.getDecoratedJobParams(getJobParams(jobProviderOptions, 'pngV2')()) | ||
); | ||
|
||
const generateReportPDF = ({ | ||
intl, | ||
optimizedForPrinting = false, | ||
}: { | ||
intl: InjectedIntl; | ||
optimizedForPrinting?: boolean; | ||
}) => { | ||
const el = document.querySelector('[data-shared-items-container]'); | ||
const { height, width } = el ? el.getBoundingClientRect() : { height: 768, width: 1024 }; | ||
const dimensions = { height, width }; | ||
|
||
const generateReportPDF = ({ intl, optimizedForPrinting = false }: ScreenshotExportOpts) => { | ||
const decoratedJobParams = apiClient.getDecoratedJobParams({ | ||
...getJobParams(jobProviderOptions, 'printablePdfV2')(), | ||
layout: { id: optimizedForPrinting ? 'print' : 'preserve_layout', dimensions }, | ||
objectType, | ||
title: sharingData.title, | ||
...getJobParams({ ...jobProviderOptions, optimizedForPrinting }, 'printablePdfV2')(), | ||
}); | ||
|
||
return apiClient | ||
|
@@ -330,19 +158,27 @@ export const reportingExportModalProvider = ({ | |
}); | ||
}; | ||
|
||
const generateReportPNG = ({ intl }: { intl: InjectedIntl }) => { | ||
const { layout: outerLayout } = getJobParams(jobProviderOptions, 'pngV2')(); | ||
let dimensions = outerLayout?.dimensions; | ||
if (!dimensions) { | ||
const el = document.querySelector('[data-shared-items-container]'); | ||
const { height, width } = el ? el.getBoundingClientRect() : { height: 768, width: 1024 }; | ||
dimensions = { height, width }; | ||
} | ||
const generateExportUrlPDF = ({ optimizedForPrinting }: ScreenshotExportOpts) => { | ||
const jobParams = apiClient.getDecoratedJobParams( | ||
getJobParams({ ...jobProviderOptions, optimizedForPrinting }, 'printablePdfV2')() | ||
); | ||
const relativePathPDF = apiClient.getReportingPublicJobPath('printablePdfV2', jobParams); | ||
|
||
return new URL(relativePathPDF, window.location.href).toString(); | ||
}; | ||
|
||
const generateExportUrlPNG = () => { | ||
const jobParams = apiClient.getDecoratedJobParams( | ||
getJobParams(jobProviderOptions, 'pngV2')() | ||
); | ||
const relativePathPNG = apiClient.getReportingPublicJobPath('pngV2', jobParams); | ||
|
||
return new URL(relativePathPNG, window.location.href).toString(); | ||
}; | ||
|
||
const generateReportPNG = ({ intl }: ScreenshotExportOpts) => { | ||
const decoratedJobParams = apiClient.getDecoratedJobParams({ | ||
...getJobParams(jobProviderOptions, 'pngV2')(), | ||
layout: { id: 'preserve_layout', dimensions }, | ||
objectType, | ||
title: sharingData.title, | ||
}); | ||
return apiClient | ||
.createReportingJob('pngV2', decoratedJobParams) | ||
|
@@ -398,6 +234,7 @@ export const reportingExportModalProvider = ({ | |
}, | ||
label: 'PDF' as const, | ||
generateExport: generateReportPDF, | ||
generateExportUrl: generateExportUrlPDF, | ||
reportType: 'printablePdfV2', | ||
requiresSavedState, | ||
helpText: ( | ||
|
@@ -415,7 +252,6 @@ export const reportingExportModalProvider = ({ | |
layoutOption: objectType === 'dashboard' ? ('print' as const) : undefined, | ||
renderLayoutOptionSwitch: objectType === 'dashboard', | ||
renderCopyURLButton: true, | ||
absoluteUrl: new URL(relativePathPDF, window.location.href).toString(), | ||
}); | ||
|
||
shareActions.push({ | ||
|
@@ -429,6 +265,7 @@ export const reportingExportModalProvider = ({ | |
}, | ||
label: 'PNG' as const, | ||
generateExport: generateReportPNG, | ||
generateExportUrl: generateExportUrlPNG, | ||
reportType: 'pngV2', | ||
requiresSavedState, | ||
helpText: ( | ||
|
@@ -442,7 +279,6 @@ export const reportingExportModalProvider = ({ | |
), | ||
layoutOption: objectType === 'dashboard' ? ('print' as const) : undefined, | ||
renderCopyURLButton: true, | ||
absoluteUrl: new URL(relativePathPNG, window.location.href).toString(), | ||
}); | ||
|
||
return shareActions; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for consolidating this logic!