From 759f9c44cb11a3467e5b577a286c01546acd2c7b Mon Sep 17 00:00:00 2001 From: Andres Martinez Gotor Date: Mon, 5 Jul 2021 11:12:56 +0200 Subject: [PATCH] Add a button to clear Azure Monitor Logs credentials (#36256) --- .../components/AnalyticsConfig.test.tsx | 21 +++++++++++++++++++ .../components/AnalyticsConfig.tsx | 16 +++++++++++++- .../components/AzureCredentialsForm.test.tsx | 9 ++++++++ .../components/AzureCredentialsForm.tsx | 2 ++ .../AnalyticsConfig.test.tsx.snap | 9 ++++++++ 5 files changed, 56 insertions(+), 1 deletion(-) 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 d7b55294749..e4f69b4558c 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,6 +1,7 @@ import React from 'react'; import { render, screen } from '@testing-library/react'; import AnalyticsConfig, { Props } from './AnalyticsConfig'; +import userEvent from '@testing-library/user-event'; const setup = (propsFunc?: (props: Props) => Props) => { let props: Props = { @@ -103,6 +104,26 @@ describe('Render', () => { expect(screen.queryByText('is no longer supported', { exact: false })).toBeInTheDocument(); }); + it('should clean up the error when reseting the credentials', async () => { + const onUpdate = jest.fn(); + setup((props) => ({ + ...props, + options: { + ...props.options, + jsonData: { + ...props.options.jsonData, + azureLogAnalyticsSameAs: false, + }, + }, + updateOptions: onUpdate, + })); + expect(screen.queryByText('is no longer supported', { exact: false })).toBeInTheDocument(); + userEvent.click(screen.getByText('Clear Azure Monitor Logs Credentials')); + expect(onUpdate).toHaveBeenCalled(); + const newOpts = onUpdate.mock.calls[0][0]({}); + expect(newOpts).toEqual({ jsonData: { azureLogAnalyticsSameAs: true } }); + }); + it('should disable inputs', () => { setup((props) => ({ ...props, 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 b5738e76c7a..b5336ac4b56 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 @@ -91,6 +91,18 @@ export const AnalyticsConfig: FunctionComponent = (props: Props) => { }); }; + const onClearAzLogsCreds = () => { + updateOptions((options) => { + return { + ...options, + jsonData: { + ...options.jsonData, + azureLogAnalyticsSameAs: true, + }, + }; + }); + }; + return ( <>

Azure Monitor Logs

@@ -113,7 +125,9 @@ export const AnalyticsConfig: FunctionComponent = (props: Props) => { }} getSubscriptions={getSubscriptions} disabled={true} - /> + > + + )}
diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AzureCredentialsForm.test.tsx b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AzureCredentialsForm.test.tsx index 2c3ede90413..75fe8b0c85f 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AzureCredentialsForm.test.tsx +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AzureCredentialsForm.test.tsx @@ -95,5 +95,14 @@ describe('Render', () => { const selects = wrapper.find(Select); selects.forEach((s) => expect(s.prop('isDisabled')).toBe(true)); }); + + it('should render a children component', () => { + const wrapper = setup((props) => ({ + ...props, + children: , + })); + const button = wrapper.find('button'); + expect(button.text()).toBe('click me'); + }); }); }); diff --git a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AzureCredentialsForm.tsx b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AzureCredentialsForm.tsx index 4199dc68b1a..7b23c3940ee 100644 --- a/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AzureCredentialsForm.tsx +++ b/public/app/plugins/datasource/grafana-azure-monitor-datasource/components/AzureCredentialsForm.tsx @@ -12,6 +12,7 @@ export interface Props { onCredentialsChange?: (updatedCredentials: AzureCredentials) => void; getSubscriptions?: () => Promise; disabled?: boolean; + children?: JSX.Element; } const authTypeOptions: Array> = [ @@ -282,6 +283,7 @@ export const AzureCredentialsForm: FunctionComponent = (props: Props) => )} )} + {props.children}
); }; 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 0a8189bffe8..fd79ceeced2 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 @@ -284,6 +284,15 @@ exports[`Render should enable azure log analytics load workspaces button 1`] = ` +