diff --git a/x-pack/plugins/security_solution/public/cases/components/edit_connector/index.tsx b/x-pack/plugins/security_solution/public/cases/components/edit_connector/index.tsx index 83f4eb15f7fb4..5553f4da68748 100644 --- a/x-pack/plugins/security_solution/public/cases/components/edit_connector/index.tsx +++ b/x-pack/plugins/security_solution/public/cases/components/edit_connector/index.tsx @@ -129,16 +129,14 @@ export const EditConnector = React.memo( type: 'SET_CURRENT_CONNECTOR', payload: getConnectorById(newConnectorId, connectors), }); - if (userActions.length > 0) { - dispatch({ - type: 'SET_FIELDS', - payload: getConnectorFieldsFromUserActions(newConnectorId, userActions), - }); - } - } else if (fields === null && userActions.length > 0) { dispatch({ type: 'SET_FIELDS', - payload: getConnectorFieldsFromUserActions(newConnectorId, userActions), + payload: getConnectorFieldsFromUserActions(newConnectorId, userActions ?? []), + }); + } else if (fields === null) { + dispatch({ + type: 'SET_FIELDS', + payload: getConnectorFieldsFromUserActions(newConnectorId, userActions ?? []), }); } }, diff --git a/x-pack/plugins/security_solution/public/cases/components/settings/jira/fields.tsx b/x-pack/plugins/security_solution/public/cases/components/settings/jira/fields.tsx index df19d4bbddee8..5fdc7bcd93587 100644 --- a/x-pack/plugins/security_solution/public/cases/components/settings/jira/fields.tsx +++ b/x-pack/plugins/security_solution/public/cases/components/settings/jira/fields.tsx @@ -26,10 +26,26 @@ const JiraSettingFieldsComponent: React.FunctionComponent) => { + if (issueType == null && issueTypeSelectOptions.length > 0) { + // if there is no issue type set in the edit view, set it to default + if (isEdit) { + onChange({ + issueType: issueTypeSelectOptions[0].value, + parent, + priority, + }); + } + } + }, + [isEdit, issueType, onChange, parent, priority] + ); const { isLoading: isLoadingIssueTypes, issueTypes } = useGetIssueTypes({ connector, http, toastNotifications: notifications.toasts, + handleIssueType, }); const issueTypesSelectOptions = useMemo( @@ -43,28 +59,15 @@ const JiraSettingFieldsComponent: React.FunctionComponent { if (!issueType && issueTypesSelectOptions.length > 0) { - // if there is no issue type set in the edit view, set it to default - if (isEdit) { - onChange({ - issueType: issueTypesSelectOptions[0].value, - parent, - priority, - }); - } return issueTypesSelectOptions[0].value; } else if ( issueTypesSelectOptions.length > 0 && !issueTypesSelectOptions.some(({ value }) => value === issueType) ) { - onChange({ - issueType: issueTypesSelectOptions[0].value, - parent, - priority, - }); return issueTypesSelectOptions[0].value; } return issueType; - }, [isEdit, issueType, issueTypesSelectOptions, onChange, parent, priority]); + }, [issueType, issueTypesSelectOptions]); const { isLoading: isLoadingFields, fields: fieldsByIssueType } = useGetFieldsByIssueType({ connector, diff --git a/x-pack/plugins/security_solution/public/cases/components/settings/jira/use_get_issue_types.tsx b/x-pack/plugins/security_solution/public/cases/components/settings/jira/use_get_issue_types.tsx index 076ef03b7cb42..dc7f78d21bbbb 100644 --- a/x-pack/plugins/security_solution/public/cases/components/settings/jira/use_get_issue_types.tsx +++ b/x-pack/plugins/security_solution/public/cases/components/settings/jira/use_get_issue_types.tsx @@ -18,6 +18,7 @@ interface Props { 'get$' | 'add' | 'remove' | 'addSuccess' | 'addWarning' | 'addDanger' | 'addError' >; connector?: ActionConnector; + handleIssueType: (options: Array<{ value: string; text: string }>) => void; } export interface UseGetIssueTypes { @@ -29,6 +30,7 @@ export const useGetIssueTypes = ({ http, connector, toastNotifications, + handleIssueType, }: Props): UseGetIssueTypes => { const [isLoading, setIsLoading] = useState(true); const [issueTypes, setIssueTypes] = useState([]); @@ -54,7 +56,12 @@ export const useGetIssueTypes = ({ if (!didCancel) { setIsLoading(false); + const asOptions = (res.data ?? []).map((type) => ({ + text: type.name ?? '', + value: type.id ?? '', + })); setIssueTypes(res.data ?? []); + handleIssueType(asOptions); if (res.status && res.status === 'error') { toastNotifications.addDanger({ title: i18n.ISSUE_TYPES_API_ERROR, @@ -81,7 +88,7 @@ export const useGetIssueTypes = ({ setIsLoading(false); abortCtrl.current.abort(); }; - }, [http, connector, toastNotifications]); + }, [http, connector, toastNotifications, handleIssueType]); return { issueTypes,