Skip to content

Commit

Permalink
[8.17] [ResponseOps] Use the feature ID to get connector types for th…
Browse files Browse the repository at this point in the history
…e stack management rule form (#201674) (#201967)

# Backport

This will backport the following commits from `main` to `8.17`:
- [[ResponseOps] Use the feature ID to get connector types for the stack
management rule form
(#201674)](#201674)

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

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

<!--BACKPORT [{"author":{"name":"Alexi
Doak","email":"109488926+doakalexi@users.noreply.github.com"},"sourceCommit":{"committedDate":"2024-11-27T12:23:05Z","message":"[ResponseOps]
Use the feature ID to get connector types for the stack management rule
form (#201674)\n\n## Summary\r\n\r\nThis PR reinstates the `featureId`
parameter in requests to the\r\nconnector type API within the new stack
management rule form.\r\n\r\n### Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### To
verify\r\n\r\n1. Create a connector with supportedFeatureIds that does
not include\r\nAlertingConnectorFeatureId (e.g., the SentinelOne
connector).\r\n2. Use the new rule form to create a rule.\r\n3. Confirm
that the SentinelOne connector is not displayed in the rule\r\nform as
an available
option.","sha":"e306255c18d47baecc8b6b9ffffabeb47e3f6d32","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:ResponseOps","v9.0.0","backport:prev-major","v8.17.0","v8.18.0","v8.16.2"],"title":"[ResponseOps]
Use the feature ID to get connector types for the stack management rule
form","number":201674,"url":"https://github.com/elastic/kibana/pull/201674","mergeCommit":{"message":"[ResponseOps]
Use the feature ID to get connector types for the stack management rule
form (#201674)\n\n## Summary\r\n\r\nThis PR reinstates the `featureId`
parameter in requests to the\r\nconnector type API within the new stack
management rule form.\r\n\r\n### Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### To
verify\r\n\r\n1. Create a connector with supportedFeatureIds that does
not include\r\nAlertingConnectorFeatureId (e.g., the SentinelOne
connector).\r\n2. Use the new rule form to create a rule.\r\n3. Confirm
that the SentinelOne connector is not displayed in the rule\r\nform as
an available
option.","sha":"e306255c18d47baecc8b6b9ffffabeb47e3f6d32"}},"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/201674","number":201674,"mergeCommit":{"message":"[ResponseOps]
Use the feature ID to get connector types for the stack management rule
form (#201674)\n\n## Summary\r\n\r\nThis PR reinstates the `featureId`
parameter in requests to the\r\nconnector type API within the new stack
management rule form.\r\n\r\n### Checklist\r\n\r\n- [ ] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n\r\n### To
verify\r\n\r\n1. Create a connector with supportedFeatureIds that does
not include\r\nAlertingConnectorFeatureId (e.g., the SentinelOne
connector).\r\n2. Use the new rule form to create a rule.\r\n3. Confirm
that the SentinelOne connector is not displayed in the rule\r\nform as
an available
option.","sha":"e306255c18d47baecc8b6b9ffffabeb47e3f6d32"}},{"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: Alexi Doak <109488926+doakalexi@users.noreply.github.com>
  • Loading branch information
kibanamachine and doakalexi authored Nov 27, 2024
1 parent 1cbf988 commit 77dfb4b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe('useLoadConnectorTypes', () => {
useLoadConnectorTypes({
http,
includeSystemActions: true,
featureId: 'alerting',
}),
{ wrapper }
);
Expand All @@ -69,6 +70,11 @@ describe('useLoadConnectorTypes', () => {
supportedFeatureIds: ['alerting'],
},
]);
expect(http.get).toHaveBeenCalledWith('/internal/actions/connector_types', {
query: {
feature_id: 'alerting',
},
});
});

test('should call the correct endpoint if system actions is true', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@ export interface UseLoadConnectorTypesProps {
http: HttpStart;
includeSystemActions?: boolean;
enabled?: boolean;
featureId?: string;
}

export const useLoadConnectorTypes = (props: UseLoadConnectorTypesProps) => {
const { http, includeSystemActions, enabled = true } = props;
const { http, includeSystemActions, enabled = true, featureId } = props;

const queryFn = () => {
return fetchConnectorTypes({ http, includeSystemActions });
return fetchConnectorTypes({ http, featureId, includeSystemActions });
};

const { data, isLoading, isFetching, isInitialLoading } = useQuery({
queryKey: ['useLoadConnectorTypes', includeSystemActions],
queryKey: ['useLoadConnectorTypes', includeSystemActions, featureId],
queryFn,
refetchOnWindowFocus: false,
enabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export interface CreateRuleFormProps {
ruleTypeId: string;
plugins: RuleFormPlugins;
consumer?: string;
connectorFeatureId?: string;
multiConsumerSelection?: RuleCreationValidConsumer | null;
hideInterval?: boolean;
validConsumers?: RuleCreationValidConsumer[];
Expand All @@ -52,6 +53,7 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
ruleTypeId,
plugins,
consumer = 'alerts',
connectorFeatureId = 'alerting',
multiConsumerSelection,
validConsumers = DEFAULT_VALID_CONSUMERS,
filteredRuleTypes = [],
Expand Down Expand Up @@ -107,6 +109,7 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
consumer,
validConsumers,
filteredRuleTypes,
connectorFeatureId,
});

const onSave = useCallback(
Expand Down
11 changes: 10 additions & 1 deletion packages/kbn-alerts-ui-shared/src/rule_form/edit_rule_form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ export interface EditRuleFormProps {
id: string;
plugins: RuleFormPlugins;
showMustacheAutocompleteSwitch?: boolean;
connectorFeatureId?: string;
onCancel?: () => void;
onSubmit?: (ruleId: string) => void;
}

export const EditRuleForm = (props: EditRuleFormProps) => {
const { id, plugins, showMustacheAutocompleteSwitch = false, onCancel, onSubmit } = props;
const {
id,
plugins,
showMustacheAutocompleteSwitch = false,
connectorFeatureId = 'alerting',
onCancel,
onSubmit,
} = props;
const { http, notifications, docLinks, ruleTypeRegistry, i18n, theme, application } = plugins;
const { toasts } = notifications;

Expand Down Expand Up @@ -80,6 +88,7 @@ export const EditRuleForm = (props: EditRuleFormProps) => {
capabilities: plugins.application.capabilities,
ruleTypeRegistry,
id,
connectorFeatureId,
});

const onSave = useCallback(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface UseLoadDependencies {
ruleTypeId?: string;
validConsumers?: RuleCreationValidConsumer[];
filteredRuleTypes?: string[];
connectorFeatureId?: string;
}

export const useLoadDependencies = (props: UseLoadDependencies) => {
Expand All @@ -46,6 +47,7 @@ export const useLoadDependencies = (props: UseLoadDependencies) => {
ruleTypeId,
capabilities,
filteredRuleTypes = [],
connectorFeatureId,
} = props;

const canReadConnectors = !!capabilities.actions?.show;
Expand Down Expand Up @@ -113,6 +115,7 @@ export const useLoadDependencies = (props: UseLoadDependencies) => {
http,
includeSystemActions: true,
enabled: canReadConnectors,
featureId: connectorFeatureId,
});

const {
Expand Down

0 comments on commit 77dfb4b

Please sign in to comment.