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

Fixed create new connector from alert flyout form throw an error messages in external plugins. #65539

Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -11,7 +11,6 @@ import { registerBuiltInActionTypes } from './index';
import { ActionTypeModel, ActionParamsProps } from '../../../types';
import { IndexActionParams, EsIndexActionConnector } from './types';
import { coreMock } from '../../../../../../../src/core/public/mocks';
import { ActionsConnectorsContextProvider } from '../../context/actions_connectors_context';
jest.mock('../../../common/index_controls', () => ({
firstFieldOption: jest.fn(),
getFields: jest.fn(),
Expand Down Expand Up @@ -165,25 +164,13 @@ describe('IndexActionConnectorFields renders', () => {
},
} as EsIndexActionConnector;
const wrapper = mountWithIntl(
<ActionsConnectorsContextProvider
value={{
http: deps!.http,
actionTypeRegistry: deps!.actionTypeRegistry,
capabilities: deps!.capabilities,
toastNotifications: deps!.toastNotifications,
reloadConnectors: () => {
return new Promise<void>(() => {});
},
docLinks: deps!.docLinks,
}}
>
<ConnectorFields
action={actionConnector}
errors={{ index: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
/>
</ActionsConnectorsContextProvider>
<ConnectorFields
action={actionConnector}
errors={{ index: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
http={deps!.http}
/>
);

await act(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
getIndexPatterns,
} from '../../../common/index_controls';
import { AddMessageVariables } from '../add_message_variables';
import { useActionsConnectorsContext } from '../../context/actions_connectors_context';

export function getActionType(): ActionTypeModel {
return {
Expand Down Expand Up @@ -79,8 +78,7 @@ export function getActionType(): ActionTypeModel {

const IndexActionConnectorFields: React.FunctionComponent<ActionConnectorFieldsProps<
EsIndexActionConnector
>> = ({ action, editActionConfig, errors }) => {
const { http } = useActionsConnectorsContext();
>> = ({ action, editActionConfig, errors, http }) => {
const { index, refresh, executionTimeField } = action.config;
const [hasTimeFieldCheckbox, setTimeFieldCheckboxState] = useState<boolean>(
executionTimeField != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import React, { FunctionComponent } from 'react';
import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers';
import { act } from 'react-dom/test-utils';
import { coreMock } from '../../../../../../../src/core/public/mocks';
import { TypeRegistry } from '../../type_registry';
import { registerBuiltInActionTypes } from './index';
import { ActionTypeModel, ActionParamsProps } from '../../../types';
Expand All @@ -16,7 +15,6 @@ import {
SeverityActionOptions,
PagerDutyActionConnector,
} from './types';
import { ActionsConnectorsContextProvider } from '../../context/actions_connectors_context';

const ACTION_TYPE_ID = '.pagerduty';
let actionTypeModel: ActionTypeModel;
Expand All @@ -29,24 +27,7 @@ beforeAll(async () => {
if (getResult !== null) {
actionTypeModel = getResult;
}
const mocks = coreMock.createSetup();
const [
{
application: { capabilities },
},
] = await mocks.getStartServices();
deps = {
toastNotifications: mocks.notifications.toasts,
http: mocks.http,
capabilities: {
...capabilities,
actions: {
delete: true,
save: true,
show: true,
},
},
actionTypeRegistry: actionTypeRegistry as any,
docLinks: { ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' },
};
});
Expand Down Expand Up @@ -148,25 +129,13 @@ describe('PagerDutyActionConnectorFields renders', () => {
},
} as PagerDutyActionConnector;
const wrapper = mountWithIntl(
<ActionsConnectorsContextProvider
value={{
http: deps!.http,
actionTypeRegistry: deps!.actionTypeRegistry,
capabilities: deps!.capabilities,
toastNotifications: deps!.toastNotifications,
reloadConnectors: () => {
return new Promise<void>(() => {});
},
docLinks: deps!.docLinks,
}}
>
<ConnectorFields
action={actionConnector}
errors={{ index: [], routingKey: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
/>
</ActionsConnectorsContextProvider>
<ConnectorFields
action={actionConnector}
errors={{ index: [], routingKey: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
docLinks={deps!.docLinks}
/>
);

await act(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { PagerDutyActionParams, PagerDutyActionConnector } from './types';
import pagerDutySvg from './pagerduty.svg';
import { AddMessageVariables } from '../add_message_variables';
import { hasMustacheTokens } from '../../lib/has_mustache_tokens';
import { useActionsConnectorsContext } from '../../context/actions_connectors_context';

export function getActionType(): ActionTypeModel {
return {
Expand Down Expand Up @@ -105,8 +104,7 @@ export function getActionType(): ActionTypeModel {

const PagerDutyActionConnectorFields: React.FunctionComponent<ActionConnectorFieldsProps<
PagerDutyActionConnector
>> = ({ errors, action, editActionConfig, editActionSecrets }) => {
const { docLinks } = useActionsConnectorsContext();
>> = ({ errors, action, editActionConfig, editActionSecrets, docLinks }) => {
const { apiUrl } = action.config;
const { routingKey } = action.secrets;
return (
Expand Down Expand Up @@ -140,15 +138,17 @@ const PagerDutyActionConnectorFields: React.FunctionComponent<ActionConnectorFie
id="routingKey"
fullWidth
helpText={
<EuiLink
href={`${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/pagerduty-action-type.html`}
target="_blank"
>
<FormattedMessage
id="xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.routingKeyNameHelpLabel"
defaultMessage="Configure a PagerDuty account."
/>
</EuiLink>
docLinks ? (
YulNaumenko marked this conversation as resolved.
Show resolved Hide resolved
<EuiLink
href={`${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/pagerduty-action-type.html`}
target="_blank"
>
<FormattedMessage
id="xpack.triggersActionsUI.components.builtinActionTypes.pagerDutyAction.routingKeyNameHelpLabel"
defaultMessage="Configure a PagerDuty account."
/>
</EuiLink>
) : null
}
error={errors.routingKey}
isInvalid={errors.routingKey.length > 0 && routingKey !== undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
import React, { FunctionComponent } from 'react';
import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers';
import { act } from 'react-dom/test-utils';
import { coreMock } from '../../../../../../../src/core/public/mocks';
import { TypeRegistry } from '../../type_registry';
import { registerBuiltInActionTypes } from './index';
import { ActionTypeModel, ActionParamsProps } from '../../../types';
import { SlackActionParams, SlackActionConnector } from './types';
import { ActionsConnectorsContextProvider } from '../../context/actions_connectors_context';

const ACTION_TYPE_ID = '.slack';
let actionTypeModel: ActionTypeModel;
Expand All @@ -25,24 +23,7 @@ beforeAll(async () => {
if (getResult !== null) {
actionTypeModel = getResult;
}
const mocks = coreMock.createSetup();
const [
{
application: { capabilities },
},
] = await mocks.getStartServices();
deps = {
toastNotifications: mocks.notifications.toasts,
http: mocks.http,
capabilities: {
...capabilities,
actions: {
delete: true,
save: true,
show: true,
},
},
actionTypeRegistry: actionTypeRegistry as any,
docLinks: { ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' },
};
});
Expand Down Expand Up @@ -119,25 +100,13 @@ describe('SlackActionFields renders', () => {
config: {},
} as SlackActionConnector;
const wrapper = mountWithIntl(
<ActionsConnectorsContextProvider
value={{
http: deps!.http,
actionTypeRegistry: deps!.actionTypeRegistry,
capabilities: deps!.capabilities,
toastNotifications: deps!.toastNotifications,
reloadConnectors: () => {
return new Promise<void>(() => {});
},
docLinks: deps!.docLinks,
}}
>
<ConnectorFields
action={actionConnector}
errors={{ index: [], webhookUrl: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
/>
</ActionsConnectorsContextProvider>
<ConnectorFields
action={actionConnector}
errors={{ index: [], webhookUrl: [] }}
editActionConfig={() => {}}
editActionSecrets={() => {}}
docLinks={deps!.docLinks}
/>
);

await act(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
} from '../../../types';
import { SlackActionParams, SlackActionConnector } from './types';
import { AddMessageVariables } from '../add_message_variables';
import { useActionsConnectorsContext } from '../../context/actions_connectors_context';

export function getActionType(): ActionTypeModel {
return {
Expand Down Expand Up @@ -76,8 +75,7 @@ export function getActionType(): ActionTypeModel {

const SlackActionFields: React.FunctionComponent<ActionConnectorFieldsProps<
SlackActionConnector
>> = ({ action, editActionSecrets, errors }) => {
const { docLinks } = useActionsConnectorsContext();
>> = ({ action, editActionSecrets, errors, docLinks }) => {
const { webhookUrl } = action.secrets;

return (
Expand All @@ -86,15 +84,17 @@ const SlackActionFields: React.FunctionComponent<ActionConnectorFieldsProps<
id="webhookUrl"
fullWidth
helpText={
<EuiLink
href={`${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/slack-action-type.html`}
target="_blank"
>
<FormattedMessage
id="xpack.triggersActionsUI.components.builtinActionTypes.slackAction.webhookUrlHelpLabel"
defaultMessage="Create a Slack webhook URL"
/>
</EuiLink>
docLinks ? (
YulNaumenko marked this conversation as resolved.
Show resolved Hide resolved
<EuiLink
href={`${docLinks.ELASTIC_WEBSITE_URL}guide/en/kibana/${docLinks.DOC_LINK_VERSION}/slack-action-type.html`}
target="_blank"
>
<FormattedMessage
id="xpack.triggersActionsUI.components.builtinActionTypes.slackAction.webhookUrlHelpLabel"
defaultMessage="Create a Slack webhook URL"
/>
</EuiLink>
) : null
}
error={errors.webhookUrl}
isInvalid={errors.webhookUrl.length > 0 && webhookUrl !== undefined}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const AlertsContextProvider = ({
export const useAlertsContext = () => {
const ctx = useContext(AlertsContext);
if (!ctx) {
throw new Error('ActionsConnectorsContext has not been set.');
throw new Error('AlertsContext has not been set.');
}
return ctx;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,14 @@ import { coreMock } from '../../../../../../../src/core/public/mocks';
import { actionTypeRegistryMock } from '../../action_type_registry.mock';
import { ValidationResult, ActionConnector } from '../../../types';
import { ActionConnectorForm } from './action_connector_form';
import { ActionsConnectorsContextProvider } from '../../context/actions_connectors_context';
const actionTypeRegistry = actionTypeRegistryMock.create();

describe('action_connector_form', () => {
let deps: any;
beforeAll(async () => {
const mocks = coreMock.createSetup();
const [
{
application: { capabilities },
},
] = await mocks.getStartServices();
deps = {
toastNotifications: mocks.notifications.toasts,
http: mocks.http,
capabilities: {
...capabilities,
actions: {
delete: true,
save: true,
show: true,
},
},
actionTypeRegistry: actionTypeRegistry as any,
docLinks: { ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' },
};
Expand Down Expand Up @@ -63,25 +48,15 @@ describe('action_connector_form', () => {
let wrapper;
if (deps) {
wrapper = mountWithIntl(
<ActionsConnectorsContextProvider
value={{
http: deps!.http,
actionTypeRegistry: deps!.actionTypeRegistry,
capabilities: deps!.capabilities,
toastNotifications: deps!.toastNotifications,
reloadConnectors: () => {
return new Promise<void>(() => {});
},
docLinks: deps!.docLinks,
}}
>
<ActionConnectorForm
actionTypeName={'my-action-type-name'}
connector={initialConnector}
dispatch={() => {}}
errors={{ name: [] }}
/>
</ActionsConnectorsContextProvider>
<ActionConnectorForm
actionTypeName={'my-action-type-name'}
connector={initialConnector}
dispatch={() => {}}
errors={{ name: [] }}
http={deps!.http}
actionTypeRegistry={deps!.actionTypeRegistry}
docLinks={deps!.docLinks}
/>
);
}
const connectorNameField = wrapper?.find('[data-test-subj="nameInput"]');
Expand Down
Loading