Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ import {
} from '@elastic/eui';
import { RuleSpecificFlappingProperties } from '@kbn/alerting-types';
import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common';
import { AlertConsumers } from '@kbn/rule-data-utils';
import {
DOC_LINK_TITLE,
LOADING_RULE_TYPE_PARAMS_TITLE,
SCHEDULE_TITLE,
SCHEDULE_DESCRIPTION_TEXT,
SCHEDULE_TOOLTIP_TEXT,
ALERT_DELAY_TITLE,
SCOPE_TITLE,
SCOPE_DESCRIPTION_TEXT,
ADVANCED_OPTIONS_TITLE,
ALERT_DELAY_DESCRIPTION_TEXT,
ALERT_DELAY_HELP_TEXT,
ALERT_DELAY_TITLE,
FEATURE_NAME_MAP,
ALERT_FLAPPING_DETECTION_TITLE,
ALERT_FLAPPING_DETECTION_DESCRIPTION,
} from '../translations';
Expand Down Expand Up @@ -114,15 +114,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]);

Expand Down
Loading