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] fix dashboard "Copy Post URL" action #192530

Conversation

tsullivan
Copy link
Member

@tsullivan tsullivan commented Sep 10, 2024

Summary

Closes #191673
Closes #183566

Fixes the ability for the POST URL used to automate generation of reports by adding a generateExportUrl function to the ShareMenuItemV2 interface. This function returns a dynamic export URL for PDF generation by using the selected layout option.

Other changes: provides more strictness in type definitions by:

  • splitting the types that define ShareMenuProvider:
    • ShareMenuProviderV2 provides the getShareMenuItems function
    • ShareMenuProviderLegacy provides the getShareMenuItemsLegacy function

Release note

Fixed an issue with the export options for PNG/PDF reports in a dashboard.

Checklist

Delete any items that are not applicable to this PR.

@tsullivan tsullivan force-pushed the fix/share-menu-items-add-generate-url-function branch 2 times, most recently from a75979a to 9b9d2d1 Compare September 11, 2024 04:38
@tsullivan tsullivan changed the title Fix/share menu items add generate url function [Reporting] fix dashboard "Copy Post URL" action Sep 11, 2024
@tsullivan tsullivan force-pushed the fix/share-menu-items-add-generate-url-function branch from 5375442 to 5f6a531 Compare September 18, 2024 20:11
*/
export const reportingScreenshotShareProvider = ({
Copy link
Member Author

@tsullivan tsullivan Sep 18, 2024

Choose a reason for hiding this comment

The 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 x-pack/plugins/canvas/public/components/workpad_header/share_menu/share_menu.tsx

interface ShareMenuProviderLegacy {
readonly id: string;
getShareMenuItemsLegacy: (context: ShareContext) => ShareMenuItemLegacy[];
}
Copy link
Member Author

Choose a reason for hiding this comment

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

After untangling ShareMenuItemLegacy from this area of code, it appears that nothing is actually using the legacy interface except for example code and test code. This should probably be cleaned up in a later PR.

@tsullivan tsullivan added v8.16.0 backport:version Backport to applied version labels v8.15.2 labels Sep 19, 2024
@tsullivan tsullivan force-pushed the fix/share-menu-items-add-generate-url-function branch from 3f98ee0 to 76a0386 Compare September 20, 2024 00:42
@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🎉 All tests passed! - kibana-flaky-test-suite-runner#6986

[✅] x-pack/test/functional/apps/dashboard/group3/config.ts: 50/50 tests passed.

see run history

@tsullivan tsullivan marked this pull request as ready for review September 20, 2024 02:28
@tsullivan tsullivan requested a review from a team as a code owner September 20, 2024 02:28
@tsullivan tsullivan requested a review from a team as a code owner September 20, 2024 02:28
Comment on lines +27 to +32
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 };
Copy link
Contributor

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!

@@ -36,7 +36,7 @@ export class ShareMenuRegistry {
return {
getShareMenuItems: (context: ShareContext) =>
Array.from(this.shareMenuProviders.values()).flatMap((shareActionProvider) =>
shareActionProvider.getShareMenuItems(context)
(shareActionProvider as ShareMenuProviderV2).getShareMenuItems(context)
Copy link
Contributor

Choose a reason for hiding this comment

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

This causes an error to be thrown when kibana is started with the --run-examples arg in dev, because the share menu of the demo plugin is registered to be retrieved using getShareMenuItemsLegacy, So maybe the following would be more appropriate

Suggested change
(shareActionProvider as ShareMenuProviderV2).getShareMenuItems(context)
(shareActionProvider.getShareMenuItems ?? shareActionProvider.getShareMenuItemsLegacy).call(shareActionProvider, context)

this way we are inclusive of the fact that some menu item might be defined still using the legacy method

Copy link
Member Author

@tsullivan tsullivan Oct 4, 2024

Choose a reason for hiding this comment

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

@eokoneyo I've made a change that addresses the error: 5b0952f

Unfortunately, registering menu items is broken in Kibana. It looks like this was last working in 8.13

image

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/reporting-public 107 106 -1
share 60 72 +12
total +11

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
share 12 15 +3

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
reporting 53.4KB 53.3KB -170.0B
share 57.0KB 57.1KB +144.0B
total -26.0B
Unknown metric groups

API count

id before after diff
share 121 135 +14

References to deprecated APIs

id before after diff
@kbn/reporting-public 2 1 -1

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@eokoneyo eokoneyo left a comment

Choose a reason for hiding this comment

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

Tested locally, code also LGTM

@tsullivan tsullivan enabled auto-merge (squash) October 7, 2024 22:32
@tsullivan tsullivan merged commit 38407ae into elastic:main Oct 7, 2024
21 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.15, 8.x

https://github.com/elastic/kibana/actions/runs/11225905491

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/reporting-public 107 106 -1
share 60 72 +12
total +11

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
share 12 15 +3

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
reporting 53.4KB 53.3KB -170.0B
share 57.0KB 57.1KB +144.0B
total -26.0B
Unknown metric groups

API count

id before after diff
share 121 135 +14

References to deprecated APIs

id before after diff
@kbn/reporting-public 2 1 -1

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Oct 7, 2024
## Summary

Closes elastic#191673
Closes elastic#183566

Fixes the ability for the POST URL used to automate generation of
reports by adding a `generateExportUrl` function to the ShareMenuItemV2
interface. This function returns a dynamic export URL for PDF generation
by using the selected layout option.

Other changes: provides more strictness in type definitions by:
  * splitting the types that define `ShareMenuProvider`:
    * `ShareMenuProviderV2` provides the `getShareMenuItems` function
* `ShareMenuProviderLegacy` provides the `getShareMenuItemsLegacy`
function

### Release note
Fixed an issue with the export options for PNG/PDF reports in a
dashboard.

### Checklist

Delete any items that are not applicable to this PR.

- [x] Use the `generateExportUrl` function inputs to return a POST URL
that is aware of the layout mode (`print` or `preserve_layout`) and
screen dimensions
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] Flaky test runner:
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6986

(cherry picked from commit 38407ae)
@kibanamachine
Copy link
Contributor

💔 Some backports could not be created

Status Branch Result
8.15 Backport failed because of merge conflicts
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 192530

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Oct 8, 2024
…2530) (#195334)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Reporting] fix dashboard "Copy Post URL" action
(#192530)](#192530)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Tim
Sullivan","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-07T23:54:21Z","message":"[Reporting]
fix dashboard \"Copy Post URL\" action (#192530)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/191673\r\nCloses
https://github.com/elastic/kibana/issues/183566\r\n\r\nFixes the ability
for the POST URL used to automate generation of\r\nreports by adding a
`generateExportUrl` function to the ShareMenuItemV2\r\ninterface. This
function returns a dynamic export URL for PDF generation\r\nby using the
selected layout option.\r\n\r\nOther changes: provides more strictness
in type definitions by:\r\n * splitting the types that define
`ShareMenuProvider`:\r\n * `ShareMenuProviderV2` provides the
`getShareMenuItems` function\r\n* `ShareMenuProviderLegacy` provides the
`getShareMenuItemsLegacy`\r\nfunction\r\n\r\n### Release note\r\nFixed
an issue with the export options for PNG/PDF reports in
a\r\ndashboard.\r\n\r\n### Checklist\r\n\r\nDelete any items that are
not applicable to this PR.\r\n\r\n- [x] Use the `generateExportUrl`
function inputs to return a POST URL\r\nthat is aware of the layout mode
(`print` or `preserve_layout`) and\r\nscreen dimensions\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] Flaky test
runner:\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6986","sha":"38407ae6b01e071757083fe358116b6dd75c4422","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","v8.16.0","backport:version","v8.15.2"],"title":"[Reporting]
fix dashboard \"Copy Post URL\"
action","number":192530,"url":"https://github.com/elastic/kibana/pull/192530","mergeCommit":{"message":"[Reporting]
fix dashboard \"Copy Post URL\" action (#192530)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/191673\r\nCloses
https://github.com/elastic/kibana/issues/183566\r\n\r\nFixes the ability
for the POST URL used to automate generation of\r\nreports by adding a
`generateExportUrl` function to the ShareMenuItemV2\r\ninterface. This
function returns a dynamic export URL for PDF generation\r\nby using the
selected layout option.\r\n\r\nOther changes: provides more strictness
in type definitions by:\r\n * splitting the types that define
`ShareMenuProvider`:\r\n * `ShareMenuProviderV2` provides the
`getShareMenuItems` function\r\n* `ShareMenuProviderLegacy` provides the
`getShareMenuItemsLegacy`\r\nfunction\r\n\r\n### Release note\r\nFixed
an issue with the export options for PNG/PDF reports in
a\r\ndashboard.\r\n\r\n### Checklist\r\n\r\nDelete any items that are
not applicable to this PR.\r\n\r\n- [x] Use the `generateExportUrl`
function inputs to return a POST URL\r\nthat is aware of the layout mode
(`print` or `preserve_layout`) and\r\nscreen dimensions\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] Flaky test
runner:\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6986","sha":"38407ae6b01e071757083fe358116b6dd75c4422"}},"sourceBranch":"main","suggestedTargetBranches":["8.x","8.15"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/192530","number":192530,"mergeCommit":{"message":"[Reporting]
fix dashboard \"Copy Post URL\" action (#192530)\n\n##
Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/191673\r\nCloses
https://github.com/elastic/kibana/issues/183566\r\n\r\nFixes the ability
for the POST URL used to automate generation of\r\nreports by adding a
`generateExportUrl` function to the ShareMenuItemV2\r\ninterface. This
function returns a dynamic export URL for PDF generation\r\nby using the
selected layout option.\r\n\r\nOther changes: provides more strictness
in type definitions by:\r\n * splitting the types that define
`ShareMenuProvider`:\r\n * `ShareMenuProviderV2` provides the
`getShareMenuItems` function\r\n* `ShareMenuProviderLegacy` provides the
`getShareMenuItemsLegacy`\r\nfunction\r\n\r\n### Release note\r\nFixed
an issue with the export options for PNG/PDF reports in
a\r\ndashboard.\r\n\r\n### Checklist\r\n\r\nDelete any items that are
not applicable to this PR.\r\n\r\n- [x] Use the `generateExportUrl`
function inputs to return a POST URL\r\nthat is aware of the layout mode
(`print` or `preserve_layout`) and\r\nscreen dimensions\r\n- [x] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] Flaky test
runner:\r\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6986","sha":"38407ae6b01e071757083fe358116b6dd75c4422"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.15","label":"v8.15.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Tim Sullivan <[email protected]>
@tsullivan tsullivan deleted the fix/share-menu-items-add-generate-url-function branch October 18, 2024 16:44
@tsullivan
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
8.15

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

tsullivan added a commit to tsullivan/kibana that referenced this pull request Oct 18, 2024
## Summary

Closes elastic#191673
Closes elastic#183566

Fixes the ability for the POST URL used to automate generation of
reports by adding a `generateExportUrl` function to the ShareMenuItemV2
interface. This function returns a dynamic export URL for PDF generation
by using the selected layout option.

Other changes: provides more strictness in type definitions by:
  * splitting the types that define `ShareMenuProvider`:
    * `ShareMenuProviderV2` provides the `getShareMenuItems` function
* `ShareMenuProviderLegacy` provides the `getShareMenuItemsLegacy`
function

### Release note
Fixed an issue with the export options for PNG/PDF reports in a
dashboard.

### Checklist

Delete any items that are not applicable to this PR.

- [x] Use the `generateExportUrl` function inputs to return a POST URL
that is aware of the layout mode (`print` or `preserve_layout`) and
screen dimensions
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] Flaky test runner:
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6986

(cherry picked from commit 38407ae)

# Conflicts:
#	src/plugins/share/public/components/share_tabs.test.tsx
#	src/plugins/share/public/services/share_menu_manager.tsx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment