From 7256f7ad2b25fe57d993434c388bb438affbc7a4 Mon Sep 17 00:00:00 2001 From: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Date: Mon, 19 Jul 2021 14:30:05 -0400 Subject: [PATCH] Hide Analyze Data button if no dashboard access (#106020) (#106094) Fixes #105476. Co-authored-by: Nathan L Smith --- .../analyze_data_button.stories.tsx | 15 ++++++++++----- .../analyze_data_button.test.tsx | 8 ++++++++ .../apm_service_template/analyze_data_button.tsx | 6 +++++- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.stories.tsx b/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.stories.tsx index 9c7e6803e44500..991c3764019af5 100644 --- a/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.stories.tsx +++ b/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.stories.tsx @@ -13,12 +13,9 @@ import { APMServiceContext } from '../../../../context/apm_service/apm_service_c import { MockUrlParamsContextProvider } from '../../../../context/url_params_context/mock_url_params_context_provider'; import { AnalyzeDataButton } from './analyze_data_button'; -const KibanaContext = createKibanaReactContext(({ - http: { basePath: { get: () => '' } }, -} as unknown) as Partial); - interface Args { agentName: string; + canShowDashboard: boolean; environment?: string; serviceName: string; } @@ -28,7 +25,14 @@ export default { component: AnalyzeDataButton, decorators: [ (StoryComponent: ComponentType, { args }: StoryContext) => { - const { agentName, environment, serviceName } = args; + const { agentName, canShowDashboard, environment, serviceName } = args; + + const KibanaContext = createKibanaReactContext(({ + application: { + capabilities: { dashboard: { show: canShowDashboard } }, + }, + http: { basePath: { get: () => '' } }, + } as unknown) as Partial); return ( = () => { }; Example.args = { agentName: 'iOS/swift', + canShowDashboard: true, environment: 'testEnvironment', serviceName: 'testServiceName', }; diff --git a/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.test.tsx b/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.test.tsx index fdd28fdb378b4c..b8b0cfa3054db4 100644 --- a/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.test.tsx +++ b/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.test.tsx @@ -25,6 +25,14 @@ describe('AnalyzeDataButton', () => { }); }); + describe('with no dashboard show capabilities', () => { + it('renders nothing', () => { + render(); + + expect(screen.queryByRole('link')).not.toBeInTheDocument(); + }); + }); + describe('with a RUM agent', () => { it('uses a ux dataType', () => { render(); diff --git a/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.tsx b/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.tsx index e963349364442e..d8ff7fdf47c582 100644 --- a/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.tsx +++ b/x-pack/plugins/apm/public/components/routing/templates/apm_service_template/analyze_data_button.tsx @@ -47,8 +47,12 @@ export function AnalyzeDataButton() { const { urlParams } = useUrlParams(); const { rangeTo, rangeFrom, environment } = urlParams; const basepath = services.http?.basePath.get(); + const canShowDashboard = services.application?.capabilities.dashboard.show; - if (isRumAgentName(agentName) || isIosAgentName(agentName)) { + if ( + (isRumAgentName(agentName) || isIosAgentName(agentName)) && + canShowDashboard + ) { const href = createExploratoryViewUrl( { 'apm-series': {