From f5416c34656a5d3392cb26f51cfb626191289f9a Mon Sep 17 00:00:00 2001 From: "Eyo O. Eyo" <7893459+eokoneyo@users.noreply.github.com> Date: Wed, 15 Jan 2025 15:21:15 +0100 Subject: [PATCH] Account for disabledShareUrl prop for rendered sharing options (#206592) ## Summary Closes https://github.com/elastic/kibana/issues/201980. This PR adds logic to honor the `disabledShareUrl` prop. For the user this means that in instances where the user doesn't have permissions to create a share url, the link tab doesn't get rendered to such user. ## How to test - Create a simple user and a custom role. Assign only Read capabilities to Visualize Library - Now sign up with that user, create a new lens visualization and try to share it - The share Link tab is not visible. (cherry picked from commit 44b756c2f5c1b22bc189c65f6b8ade597c5eea90) --- .../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; };