Loki: Apply default_manage_alerts_ui_toggle config (#112297)
Datasources: Apply default_manage_alerts_ui_toggle config to Loki datasource - Update AlertingSettings component to use config.defaultDatasourceManageAlertsUiToggle - Change from options.jsonData.manageAlerts !== false to nullish coalescing operator - Add comprehensive tests for config behavior - Ensures consistency with Prometheus datasource implementation from PR #98441 Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
import { config } from '@grafana/runtime';
|
||||
|
||||
import { createDefaultConfigOptions } from '../mocks/datasource';
|
||||
|
||||
import { AlertingSettings } from './AlertingSettings';
|
||||
@@ -19,4 +21,43 @@ describe('AlertingSettings', () => {
|
||||
await userEvent.click(screen.getByRole('switch'));
|
||||
expect(onChange).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
describe('Switch checked behavior', () => {
|
||||
describe('when options.jsonData.manageAlerts is unset', () => {
|
||||
it('uses the config default `true`', () => {
|
||||
const testOptions = createDefaultConfigOptions();
|
||||
testOptions.jsonData.manageAlerts = undefined;
|
||||
|
||||
config.defaultDatasourceManageAlertsUiToggle = true;
|
||||
|
||||
render(<AlertingSettings options={testOptions} onOptionsChange={() => {}} />);
|
||||
|
||||
expect(screen.getByRole('switch')).toBeChecked();
|
||||
});
|
||||
|
||||
it('uses the config default `false`', () => {
|
||||
const testOptions = createDefaultConfigOptions();
|
||||
testOptions.jsonData.manageAlerts = undefined;
|
||||
|
||||
config.defaultDatasourceManageAlertsUiToggle = false;
|
||||
|
||||
render(<AlertingSettings options={testOptions} onOptionsChange={() => {}} />);
|
||||
|
||||
expect(screen.getByRole('switch')).not.toBeChecked();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when options.jsonData.manageAlerts is set', () => {
|
||||
it.each([true, false])('uses the manageAlerts value even when the config default is %s', (configDefault) => {
|
||||
const testOptions = createDefaultConfigOptions();
|
||||
testOptions.jsonData.manageAlerts = true;
|
||||
|
||||
config.defaultDatasourceManageAlertsUiToggle = configDefault;
|
||||
|
||||
render(<AlertingSettings options={testOptions} onOptionsChange={() => {}} />);
|
||||
|
||||
expect(screen.getByRole('switch')).toBeChecked();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { DataSourcePluginOptionsEditorProps } from '@grafana/data';
|
||||
import { ConfigDescriptionLink, ConfigSubSection } from '@grafana/plugin-ui';
|
||||
import { config } from '@grafana/runtime';
|
||||
import { InlineField, InlineSwitch } from '@grafana/ui';
|
||||
|
||||
export function AlertingSettings({
|
||||
@@ -24,7 +25,7 @@ export function AlertingSettings({
|
||||
tooltip="Manage alert rules for this data source. To manage other alerting resources, add an Alertmanager data source."
|
||||
>
|
||||
<InlineSwitch
|
||||
value={options.jsonData.manageAlerts !== false}
|
||||
value={options.jsonData.manageAlerts ?? config.defaultDatasourceManageAlertsUiToggle}
|
||||
onChange={(event) =>
|
||||
onOptionsChange({
|
||||
...options,
|
||||
|
||||
Reference in New Issue
Block a user