[ResponseOps][Rules] Hide the "Role visibility" dropdown in the new rule form in serverless (#200727)

Fixes #199642

## Summary

~~This PR hides the role visibility dropdown in the new rule form when
in serverless.~~

This PR hides the role visibility dropdown in the new rule form **when
only one consumer is available**.

## How to test

1. Run Kibana security serverless and confirm the rules in stack
management do not have the role visibility dropdown.
2. Please also make sure that the drop-down still shows when
needed(outside of serverless).
This commit is contained in:
Antonio 2024-12-05 12:20:37 +01:00 committed by GitHub
parent f30f0a8f33
commit 7498ab0061
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 39 additions and 8 deletions

View file

@ -236,6 +236,34 @@ describe('Rule Definition', () => {
expect(screen.queryByTestId('ruleConsumerSelection')).not.toBeInTheDocument();
});
test('Hides consumer selection if there are irrelevant consumers and only 1 consumer to select', () => {
useRuleFormState.mockReturnValue({
plugins,
formData: {
id: 'test-id',
params: {},
schedule: {
interval: '1m',
},
alertDelay: {
active: 5,
},
notifyWhen: null,
consumer: 'stackAlerts',
ruleTypeId: '.es-query',
},
selectedRuleType: ruleType,
selectedRuleTypeModel: ruleModel,
availableRuleTypes: [ruleType],
canShowConsumerSelect: true,
validConsumers: ['logs', 'observability'],
});
render(<RuleDefinition />);
expect(screen.queryByTestId('ruleConsumerSelection')).not.toBeInTheDocument();
});
test('Hides consumer selection if valid consumers contain observability', () => {
useRuleFormState.mockReturnValue({
plugins,

View file

@ -30,7 +30,6 @@ import {
RuleSettingsFlappingTitleTooltip,
} from '@kbn/alerts-ui-shared/lib';
import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common';
import { AlertConsumers } from '@kbn/rule-data-utils';
import React, { Suspense, useCallback, useEffect, useMemo, useState } from 'react';
import { ALERTING_FEATURE_ID, MULTI_CONSUMER_RULE_TYPE_IDS } from '../constants';
import { IS_RULE_SPECIFIC_FLAPPING_ENABLED } from '../constants/rule_flapping';
@ -41,6 +40,7 @@ import {
ALERT_DELAY_HELP_TEXT,
ALERT_DELAY_TITLE,
ALERT_FLAPPING_DETECTION_DESCRIPTION,
FEATURE_NAME_MAP,
ALERT_FLAPPING_DETECTION_TITLE,
DOC_LINK_TITLE,
LOADING_RULE_TYPE_PARAMS_TITLE,
@ -116,15 +116,18 @@ export const RuleDefinition = () => {
if (!canShowConsumerSelection) {
return false;
}
if (!authorizedConsumers.length) {
return false;
}
if (
authorizedConsumers.length <= 1 ||
authorizedConsumers.includes(AlertConsumers.OBSERVABILITY)
) {
/*
* This will filter out values like 'alerts' and 'observability' that will not be displayed
* in the drop down. It will allow us to hide the consumer select when there is only one
* selectable value.
*/
const authorizedValidConsumers = authorizedConsumers.filter((c) => c in FEATURE_NAME_MAP);
if (authorizedValidConsumers.length <= 1) {
return false;
}
return !!(ruleTypeId && MULTI_CONSUMER_RULE_TYPE_IDS.includes(ruleTypeId));
}, [ruleTypeId, authorizedConsumers, canShowConsumerSelection]);