From d072c8436c615af8e2ae57889a1d90775bf3710a Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Thu, 16 Jan 2025 03:17:34 +1100 Subject: [PATCH] [8.16] Account for disabledShareUrl prop for rendered sharing options (#206592) (#206769) # Backport This will backport the following commits from `main` to `8.16`: - [Account for disabledShareUrl prop for rendered sharing options (#206592)](https://github.com/elastic/kibana/pull/206592) ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) ","sha":"44b756c2f5c1b22bc189c65f6b8ade597c5eea90","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","Feature:SharingURLs","v9.0.0","Team:SharedUX","backport:prev-major"],"title":"Account for disabledShareUrl prop for rendered sharing options","number":206592,"url":"https://github.com/elastic/kibana/pull/206592","mergeCommit":{"message":"Account for disabledShareUrl prop for rendered sharing options (#206592)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/201980. \r\n\r\nThis PR adds logic to honor the `disabledShareUrl` prop. For the user\r\nthis means that in instances where the user doesn't have permissions to\r\ncreate a share url, the link tab doesn't get rendered to such user.\r\n\r\n## How to test\r\n\r\n- Create a simple user and a custom role. Assign only Read capabilities\r\nto Visualize Library\r\n- Now sign up with that user, create a new lens visualization and try to\r\nshare it\r\n- The share Link tab is not visible.\r\n\r\n","sha":"44b756c2f5c1b22bc189c65f6b8ade597c5eea90"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/206592","number":206592,"mergeCommit":{"message":"Account for disabledShareUrl prop for rendered sharing options (#206592)\n\n## Summary\r\n\r\nCloses https://github.com/elastic/kibana/issues/201980. \r\n\r\nThis PR adds logic to honor the `disabledShareUrl` prop. For the user\r\nthis means that in instances where the user doesn't have permissions to\r\ncreate a share url, the link tab doesn't get rendered to such user.\r\n\r\n## How to test\r\n\r\n- Create a simple user and a custom role. Assign only Read capabilities\r\nto Visualize Library\r\n- Now sign up with that user, create a new lens visualization and try to\r\nshare it\r\n- The share Link tab is not visible.\r\n\r\n","sha":"44b756c2f5c1b22bc189c65f6b8ade597c5eea90"}}]}] BACKPORT--> Co-authored-by: Eyo O. Eyo <7893459+eokoneyo@users.noreply.github.com> --- .../public/components/share_tabs.test.tsx | 125 ++++++++++-------- .../share/public/components/share_tabs.tsx | 16 ++- 2 files changed, 82 insertions(+), 59 deletions(-) diff --git a/src/plugins/share/public/components/share_tabs.test.tsx b/src/plugins/share/public/components/share_tabs.test.tsx index 6b04a28304fdd..a2f3e51687fe0 100644 --- a/src/plugins/share/public/components/share_tabs.test.tsx +++ b/src/plugins/share/public/components/share_tabs.test.tsx @@ -9,7 +9,7 @@ import React from 'react'; import { ShareMenuTabs } from './share_tabs'; -import { ShareMenuProvider } from './context'; +import { ShareMenuProvider, type IShareContext } from './context'; import { mountWithIntl } from '@kbn/test-jest-helpers'; import { KibanaLocation, LocatorGetUrlParams, UrlService } from '../../common/url_service'; import { @@ -48,7 +48,9 @@ const service = new UrlService 'generated-export-url'); const CSV = 'CSV' as const; const PNG = 'PNG' as const; + describe('Share modal tabs', () => { - it('should render export tab when there are share menu items that are not disabled', async () => { - const testItem = [ - { - shareMenuItem: { name: 'test', disabled: false }, - label: CSV, - generateExport: mockGenerateExport, - generateExportUrl: mockGenerateExportUrl, - }, - ]; - const wrapper = mountWithIntl( - - - - ); - expect(wrapper.find('[data-test-subj="export"]').exists()).toBeTruthy(); + describe('link tab', () => { + it('should not render the link tab when the disableShareUrl prop is true', async () => { + const wrapper = mountWithIntl( + + + + ); + expect(wrapper.find('[data-test-subj="link"]').exists()).toBeFalsy(); + }); }); - it('should not render export tab when the license is disabled', async () => { - const testItems = [ - { - shareMenuItem: { name: 'test', disabled: true }, - label: CSV, - generateExport: mockGenerateExport, - generateExportUrl: mockGenerateExportUrl, - }, - ]; - const wrapper = mountWithIntl( - - - - ); + describe('export tab', () => { + it('should render export tab when there are share menu items that are not disabled', async () => { + const testItem = [ + { + shareMenuItem: { name: 'test', disabled: false }, + label: CSV, + generateExport: mockGenerateExport, + generateExportUrl: mockGenerateExportUrl, + }, + ]; + const wrapper = mountWithIntl( + + + + ); + expect(wrapper.find('[data-test-subj="export"]').exists()).toBeTruthy(); + }); + it('should not render export tab when the license is disabled', async () => { + const testItems = [ + { + shareMenuItem: { name: 'test', disabled: true }, + label: CSV, + generateExport: mockGenerateExport, + generateExportUrl: mockGenerateExportUrl, + }, + ]; - expect(wrapper.find('[data-test-subj="export"]').exists()).toBeFalsy(); - }); + const wrapper = mountWithIntl( + + + + ); + + expect(wrapper.find('[data-test-subj="export"]').exists()).toBeFalsy(); + }); - it('should render export tab is at least one is not disabled', async () => { - const testItem = [ - { - shareMenuItem: { name: 'test', disabled: false }, - label: CSV, - generateExport: mockGenerateExport, - generateExportUrl: mockGenerateExportUrl, - }, - { - shareMenuItem: { name: 'test', disabled: true }, - label: PNG, - generateExport: mockGenerateExport, - generateExportUrl: mockGenerateExportUrl, - }, - ]; - const wrapper = mountWithIntl( - - - - ); - expect(wrapper.find('[data-test-subj="export"]').exists()).toBeTruthy(); + it('would render the export tab when there is at least one export type which is not disabled', async () => { + const testItem = [ + { + shareMenuItem: { name: 'test', disabled: false }, + label: CSV, + generateExport: mockGenerateExport, + generateExportUrl: mockGenerateExportUrl, + }, + { + shareMenuItem: { name: 'test', disabled: true }, + label: PNG, + generateExport: mockGenerateExport, + generateExportUrl: mockGenerateExportUrl, + }, + ]; + const wrapper = mountWithIntl( + + + + ); + expect(wrapper.find('[data-test-subj="export"]').exists()).toBeTruthy(); + }); }); }); diff --git a/src/plugins/share/public/components/share_tabs.tsx b/src/plugins/share/public/components/share_tabs.tsx index 94c4ab8655dca..8f035cd0f7505 100644 --- a/src/plugins/share/public/components/share_tabs.tsx +++ b/src/plugins/share/public/components/share_tabs.tsx @@ -25,9 +25,15 @@ export const ShareMenu: FC<{ shareContext: IShareContext }> = ({ shareContext }) export const ShareMenuTabs = () => { const shareContext = useShareTabsContext(); - const { allowEmbed, objectTypeMeta, onClose, shareMenuItems, anchorElement } = shareContext; + const { allowEmbed, objectTypeMeta, onClose, shareMenuItems, anchorElement, disabledShareUrl } = + shareContext; - const tabs: Array> = [linkTab]; + const tabs: Array> = []; + + // do not show the link tab if the share url is disabled + if (!disabledShareUrl) { + tabs.push(linkTab); + } const enabledItems = shareMenuItems.filter(({ shareMenuItem }) => !shareMenuItem?.disabled); @@ -40,15 +46,15 @@ export const ShareMenuTabs = () => { tabs.push(embedTab); } - return ( + return Boolean(tabs.length) ? ( - ); + ) : null; };