Skip to content

Commit

Permalink
[8.x] [ResponseOps][Rules] Hide the "Role visibility" dropd…
Browse files Browse the repository at this point in the history
…own in the new rule form in serverless (#200727) (#203077)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ResponseOps][Rules] Hide the "Role visibility" dropdown in
the new rule form in serverless
(#200727)](#200727)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Antonio","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-12-05T11:20:37Z","message":"[ResponseOps][Rules]
Hide the \"Role visibility\" dropdown in the new rule form in serverless
(#200727)\n\nFixes #199642\r\n\r\n## Summary\r\n\r\n~~This PR hides the
role visibility dropdown in the new rule form when\r\nin
serverless.~~\r\n\r\nThis PR hides the role visibility dropdown in the
new rule form **when\r\nonly one consumer is available**.\r\n\r\n## How
to test\r\n\r\n1. Run Kibana security serverless and confirm the rules
in stack\r\nmanagement do not have the role visibility dropdown.\r\n2.
Please also make sure that the drop-down still shows
when\r\nneeded(outside of
serverless).","sha":"7498ab00618baf5d5d30d32b989d4ba93da2803e","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Feature:Alerting","release_note:skip","Team:ResponseOps","v9.0.0","backport:prev-minor","v8.17.0","v8.18.0","v8.16.2"],"title":"[ResponseOps][Rules]
Hide the \"Role visibility\" dropdown in the new rule form in
serverless","number":200727,"url":"https://github.com/elastic/kibana/pull/200727","mergeCommit":{"message":"[ResponseOps][Rules]
Hide the \"Role visibility\" dropdown in the new rule form in serverless
(#200727)\n\nFixes #199642\r\n\r\n## Summary\r\n\r\n~~This PR hides the
role visibility dropdown in the new rule form when\r\nin
serverless.~~\r\n\r\nThis PR hides the role visibility dropdown in the
new rule form **when\r\nonly one consumer is available**.\r\n\r\n## How
to test\r\n\r\n1. Run Kibana security serverless and confirm the rules
in stack\r\nmanagement do not have the role visibility dropdown.\r\n2.
Please also make sure that the drop-down still shows
when\r\nneeded(outside of
serverless).","sha":"7498ab00618baf5d5d30d32b989d4ba93da2803e"}},"sourceBranch":"main","suggestedTargetBranches":["8.17","8.x","8.16"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/200727","number":200727,"mergeCommit":{"message":"[ResponseOps][Rules]
Hide the \"Role visibility\" dropdown in the new rule form in serverless
(#200727)\n\nFixes #199642\r\n\r\n## Summary\r\n\r\n~~This PR hides the
role visibility dropdown in the new rule form when\r\nin
serverless.~~\r\n\r\nThis PR hides the role visibility dropdown in the
new rule form **when\r\nonly one consumer is available**.\r\n\r\n## How
to test\r\n\r\n1. Run Kibana security serverless and confirm the rules
in stack\r\nmanagement do not have the role visibility dropdown.\r\n2.
Please also make sure that the drop-down still shows
when\r\nneeded(outside of
serverless).","sha":"7498ab00618baf5d5d30d32b989d4ba93da2803e"}},{"branch":"8.17","label":"v8.17.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.16","label":"v8.16.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Antonio <[email protected]>
  • Loading branch information
kibanamachine and adcoelho authored Dec 5, 2024
1 parent 4ffcaed commit 43f0dfa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
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 @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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]);

Expand Down

0 comments on commit 43f0dfa

Please sign in to comment.