diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AnalyticsConfig.test.tsx b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AnalyticsConfig.test.tsx index 3143207db55..88edcf8bcfe 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AnalyticsConfig.test.tsx +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AnalyticsConfig.test.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { shallow } from 'enzyme'; +import { render, screen } from '@testing-library/react'; import AnalyticsConfig, { Props } from './AnalyticsConfig'; const setup = (propsFunc?: (props: Props) => Props) => { @@ -47,14 +47,14 @@ const setup = (propsFunc?: (props: Props) => Props) => { props = propsFunc(props); } - return shallow(); + return render(); }; describe('Render', () => { it('should render component', () => { const wrapper = setup(); - expect(wrapper).toMatchSnapshot(); + expect(wrapper.baseElement).toMatchSnapshot(); }); it('should disable log analytics credentials form', () => { @@ -68,7 +68,7 @@ describe('Render', () => { }, }, })); - expect(wrapper).toMatchSnapshot(); + expect(wrapper.baseElement).toMatchSnapshot(); }); it('should enable azure log analytics load workspaces button', () => { @@ -87,6 +87,37 @@ describe('Render', () => { }, }, })); - expect(wrapper).toMatchSnapshot(); + expect(wrapper.baseElement).toMatchSnapshot(); + }); + + it('should not render the Switch to use different creds for log analytics by default', () => { + setup((props) => ({ + ...props, + options: { + ...props.options, + jsonData: { + ...props.options.jsonData, + azureLogAnalyticsSameAs: undefined, + }, + }, + })); + expect(screen.queryByLabelText('Same details as Azure Monitor API')).not.toBeInTheDocument(); + expect(screen.queryByText('is deprecated', { exact: false })).not.toBeInTheDocument(); + }); + + // Remove this test with deprecated code + it('should not render the Switch if different creds for log analytics were set from before', () => { + setup((props) => ({ + ...props, + options: { + ...props.options, + jsonData: { + ...props.options.jsonData, + azureLogAnalyticsSameAs: false, + }, + }, + })); + expect(screen.queryByLabelText('Same details as Azure Monitor API')).toBeInTheDocument(); + expect(screen.queryByText('is deprecated', { exact: false })).toBeInTheDocument(); }); }); diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AnalyticsConfig.tsx b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AnalyticsConfig.tsx index 12fd326a06c..50cf4fc7485 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AnalyticsConfig.tsx +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AnalyticsConfig.tsx @@ -1,7 +1,7 @@ import React, { FunctionComponent, useEffect, useMemo, useReducer, useState } from 'react'; import { SelectableValue } from '@grafana/data'; import { AzureCredentialsForm } from './AzureCredentialsForm'; -import { InlineFormLabel, LegacyForms, Button } from '@grafana/ui'; +import { InlineFormLabel, LegacyForms, Button, Alert } from '@grafana/ui'; const { Select, Switch } = LegacyForms; import { AzureDataSourceSettings, AzureCredentials } from '../types'; import { @@ -23,11 +23,15 @@ export const AnalyticsConfig: FunctionComponent = (props: Props) => { const { updateOptions, getSubscriptions, getWorkspaces } = props; const primaryCredentials = useMemo(() => getCredentials(props.options), [props.options]); const logAnalyticsCredentials = useMemo(() => getLogAnalyticsCredentials(props.options), [props.options]); + const subscriptionId = logAnalyticsCredentials ? logAnalyticsCredentials.defaultSubscriptionId : primaryCredentials.defaultSubscriptionId; - const credentialsEnabled = primaryCredentials.authType === 'clientsecret'; + // Only show a section for setting LogAnalytics credentials if they were set from before + // And the authType is supported + const [credentialsUsed, _] = useState(!!logAnalyticsCredentials); + const credentialsEnabled = credentialsUsed && primaryCredentials.authType === 'clientsecret'; const hasRequiredFields = subscriptionId && @@ -134,6 +138,7 @@ export const AnalyticsConfig: FunctionComponent = (props: Props) => { onChange={onLogAnalyticsSameAsChange} {...tooltipAttribute} /> + {showSameAsHelpMsg && (
@@ -141,13 +146,23 @@ export const AnalyticsConfig: FunctionComponent = (props: Props) => {
)} + {logAnalyticsCredentials && ( - + <> + + Using different credentials for Azure Monitor Logs is deprecated and will be removed in a future + version. +
+ Create a different Data Source if you need to use different credentials. +
+ + + )} )} diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/__snapshots__/AnalyticsConfig.test.tsx.snap b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/__snapshots__/AnalyticsConfig.test.tsx.snap index 948182572f5..a8784310821 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/__snapshots__/AnalyticsConfig.test.tsx.snap +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/__snapshots__/AnalyticsConfig.test.tsx.snap @@ -1,281 +1,820 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`Render should disable log analytics credentials form 1`] = ` - -

- Azure Monitor Logs -

- -
+ +
+

+ Azure Monitor Logs +

- - Default Workspace -
- +
+
+
+
+
+
+
+
+
+
+
- -
- + +
-
+ `; exports[`Render should enable azure log analytics load workspaces button 1`] = ` - -

- Azure Monitor Logs -

- - -
+ +
+

+ Azure Monitor Logs +

+ +
+
- - Default Workspace -
+
+
+
- +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+ +
+
+
+ Choose +
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
- + `; exports[`Render should render component 1`] = ` - -

- Azure Monitor Logs -

- - -
+ +
+

+ Azure Monitor Logs +

+ +
+
- - Default Workspace -
+
+
+
- +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+ +
+
+
+
+
+
+ +
+
+
+ +
+
+
+ Choose +
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
- + `;