Skip to content

Commit

Permalink
Hide Analyze Data button if no dashboard access (#106020) (#106095)
Browse files Browse the repository at this point in the history
Fixes #105476.

Co-authored-by: Nathan L Smith <[email protected]>
  • Loading branch information
kibanamachine and smith authored Jul 19, 2021
1 parent 1084248 commit f6782ad
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<CoreStart>);

interface Args {
agentName: string;
canShowDashboard: boolean;
environment?: string;
serviceName: string;
}
Expand All @@ -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<CoreStart>);

return (
<MockUrlParamsContextProvider
Expand All @@ -52,6 +56,7 @@ export const Example: Story<Args> = () => {
};
Example.args = {
agentName: 'iOS/swift',
canShowDashboard: true,
environment: 'testEnvironment',
serviceName: 'testServiceName',
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ describe('AnalyzeDataButton', () => {
});
});

describe('with no dashboard show capabilities', () => {
it('renders nothing', () => {
render(<Example canShowDashboard={false} />);

expect(screen.queryByRole('link')).not.toBeInTheDocument();
});
});

describe('with a RUM agent', () => {
it('uses a ux dataType', () => {
render(<Example agentName="rum-js" />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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': {
Expand Down

0 comments on commit f6782ad

Please sign in to comment.