Hide Analyze Data button if no dashboard access (#106020)

Fixes #105476.
This commit is contained in:
Nathan L Smith 2021-07-19 08:21:00 -05:00 committed by GitHub
parent 00d8f05f2e
commit c0528f263f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 6 deletions

View file

@ -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;
}
@ -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
@ -52,6 +56,7 @@ export const Example: Story<Args> = () => {
};
Example.args = {
agentName: 'iOS/swift',
canShowDashboard: true,
environment: 'testEnvironment',
serviceName: 'testServiceName',
};

View file

@ -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" />);

View file

@ -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': {