Skip to content

Commit bb9eaf7

Browse files
authored
Fixed create new connector from alert flyout form throw an error messages in external plugins. (#65539)
* Fixed create new connector from alert flyout form throw an error messages in external plugins. * Fixed due to comments
1 parent c03bdcc commit bb9eaf7

File tree

13 files changed

+64
-162
lines changed

13 files changed

+64
-162
lines changed

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index.test.tsx

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { registerBuiltInActionTypes } from './index';
1111
import { ActionTypeModel, ActionParamsProps } from '../../../types';
1212
import { IndexActionParams, EsIndexActionConnector } from './types';
1313
import { coreMock } from '../../../../../../../src/core/public/mocks';
14-
import { ActionsConnectorsContextProvider } from '../../context/actions_connectors_context';
1514
jest.mock('../../../common/index_controls', () => ({
1615
firstFieldOption: jest.fn(),
1716
getFields: jest.fn(),
@@ -165,25 +164,13 @@ describe('IndexActionConnectorFields renders', () => {
165164
},
166165
} as EsIndexActionConnector;
167166
const wrapper = mountWithIntl(
168-
<ActionsConnectorsContextProvider
169-
value={{
170-
http: deps!.http,
171-
actionTypeRegistry: deps!.actionTypeRegistry,
172-
capabilities: deps!.capabilities,
173-
toastNotifications: deps!.toastNotifications,
174-
reloadConnectors: () => {
175-
return new Promise<void>(() => {});
176-
},
177-
docLinks: deps!.docLinks,
178-
}}
179-
>
180-
<ConnectorFields
181-
action={actionConnector}
182-
errors={{ index: [] }}
183-
editActionConfig={() => {}}
184-
editActionSecrets={() => {}}
185-
/>
186-
</ActionsConnectorsContextProvider>
167+
<ConnectorFields
168+
action={actionConnector}
169+
errors={{ index: [] }}
170+
editActionConfig={() => {}}
171+
editActionSecrets={() => {}}
172+
http={deps!.http}
173+
/>
187174
);
188175

189176
await act(async () => {

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/es_index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import {
3333
getIndexPatterns,
3434
} from '../../../common/index_controls';
3535
import { AddMessageVariables } from '../add_message_variables';
36-
import { useActionsConnectorsContext } from '../../context/actions_connectors_context';
3736

3837
export function getActionType(): ActionTypeModel {
3938
return {
@@ -79,8 +78,7 @@ export function getActionType(): ActionTypeModel {
7978

8079
const IndexActionConnectorFields: React.FunctionComponent<ActionConnectorFieldsProps<
8180
EsIndexActionConnector
82-
>> = ({ action, editActionConfig, errors }) => {
83-
const { http } = useActionsConnectorsContext();
81+
>> = ({ action, editActionConfig, errors, http }) => {
8482
const { index, refresh, executionTimeField } = action.config;
8583
const [hasTimeFieldCheckbox, setTimeFieldCheckboxState] = useState<boolean>(
8684
executionTimeField != null

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.test.tsx

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import React, { FunctionComponent } from 'react';
77
import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers';
88
import { act } from 'react-dom/test-utils';
9-
import { coreMock } from '../../../../../../../src/core/public/mocks';
109
import { TypeRegistry } from '../../type_registry';
1110
import { registerBuiltInActionTypes } from './index';
1211
import { ActionTypeModel, ActionParamsProps } from '../../../types';
@@ -16,7 +15,6 @@ import {
1615
SeverityActionOptions,
1716
PagerDutyActionConnector,
1817
} from './types';
19-
import { ActionsConnectorsContextProvider } from '../../context/actions_connectors_context';
2018

2119
const ACTION_TYPE_ID = '.pagerduty';
2220
let actionTypeModel: ActionTypeModel;
@@ -29,24 +27,7 @@ beforeAll(async () => {
2927
if (getResult !== null) {
3028
actionTypeModel = getResult;
3129
}
32-
const mocks = coreMock.createSetup();
33-
const [
34-
{
35-
application: { capabilities },
36-
},
37-
] = await mocks.getStartServices();
3830
deps = {
39-
toastNotifications: mocks.notifications.toasts,
40-
http: mocks.http,
41-
capabilities: {
42-
...capabilities,
43-
actions: {
44-
delete: true,
45-
save: true,
46-
show: true,
47-
},
48-
},
49-
actionTypeRegistry: actionTypeRegistry as any,
5031
docLinks: { ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' },
5132
};
5233
});
@@ -148,25 +129,13 @@ describe('PagerDutyActionConnectorFields renders', () => {
148129
},
149130
} as PagerDutyActionConnector;
150131
const wrapper = mountWithIntl(
151-
<ActionsConnectorsContextProvider
152-
value={{
153-
http: deps!.http,
154-
actionTypeRegistry: deps!.actionTypeRegistry,
155-
capabilities: deps!.capabilities,
156-
toastNotifications: deps!.toastNotifications,
157-
reloadConnectors: () => {
158-
return new Promise<void>(() => {});
159-
},
160-
docLinks: deps!.docLinks,
161-
}}
162-
>
163-
<ConnectorFields
164-
action={actionConnector}
165-
errors={{ index: [], routingKey: [] }}
166-
editActionConfig={() => {}}
167-
editActionSecrets={() => {}}
168-
/>
169-
</ActionsConnectorsContextProvider>
132+
<ConnectorFields
133+
action={actionConnector}
134+
errors={{ index: [], routingKey: [] }}
135+
editActionConfig={() => {}}
136+
editActionSecrets={() => {}}
137+
docLinks={deps!.docLinks}
138+
/>
170139
);
171140

172141
await act(async () => {

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/pagerduty.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import { PagerDutyActionParams, PagerDutyActionConnector } from './types';
2525
import pagerDutySvg from './pagerduty.svg';
2626
import { AddMessageVariables } from '../add_message_variables';
2727
import { hasMustacheTokens } from '../../lib/has_mustache_tokens';
28-
import { useActionsConnectorsContext } from '../../context/actions_connectors_context';
2928

3029
export function getActionType(): ActionTypeModel {
3130
return {
@@ -105,8 +104,7 @@ export function getActionType(): ActionTypeModel {
105104

106105
const PagerDutyActionConnectorFields: React.FunctionComponent<ActionConnectorFieldsProps<
107106
PagerDutyActionConnector
108-
>> = ({ errors, action, editActionConfig, editActionSecrets }) => {
109-
const { docLinks } = useActionsConnectorsContext();
107+
>> = ({ errors, action, editActionConfig, editActionSecrets, docLinks }) => {
110108
const { apiUrl } = action.config;
111109
const { routingKey } = action.secrets;
112110
return (

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/slack.test.tsx

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
import React, { FunctionComponent } from 'react';
77
import { mountWithIntl, nextTick } from 'test_utils/enzyme_helpers';
88
import { act } from 'react-dom/test-utils';
9-
import { coreMock } from '../../../../../../../src/core/public/mocks';
109
import { TypeRegistry } from '../../type_registry';
1110
import { registerBuiltInActionTypes } from './index';
1211
import { ActionTypeModel, ActionParamsProps } from '../../../types';
1312
import { SlackActionParams, SlackActionConnector } from './types';
14-
import { ActionsConnectorsContextProvider } from '../../context/actions_connectors_context';
1513

1614
const ACTION_TYPE_ID = '.slack';
1715
let actionTypeModel: ActionTypeModel;
@@ -25,24 +23,7 @@ beforeAll(async () => {
2523
if (getResult !== null) {
2624
actionTypeModel = getResult;
2725
}
28-
const mocks = coreMock.createSetup();
29-
const [
30-
{
31-
application: { capabilities },
32-
},
33-
] = await mocks.getStartServices();
3426
deps = {
35-
toastNotifications: mocks.notifications.toasts,
36-
http: mocks.http,
37-
capabilities: {
38-
...capabilities,
39-
actions: {
40-
delete: true,
41-
save: true,
42-
show: true,
43-
},
44-
},
45-
actionTypeRegistry: actionTypeRegistry as any,
4627
docLinks: { ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' },
4728
};
4829
});
@@ -119,25 +100,13 @@ describe('SlackActionFields renders', () => {
119100
config: {},
120101
} as SlackActionConnector;
121102
const wrapper = mountWithIntl(
122-
<ActionsConnectorsContextProvider
123-
value={{
124-
http: deps!.http,
125-
actionTypeRegistry: deps!.actionTypeRegistry,
126-
capabilities: deps!.capabilities,
127-
toastNotifications: deps!.toastNotifications,
128-
reloadConnectors: () => {
129-
return new Promise<void>(() => {});
130-
},
131-
docLinks: deps!.docLinks,
132-
}}
133-
>
134-
<ConnectorFields
135-
action={actionConnector}
136-
errors={{ index: [], webhookUrl: [] }}
137-
editActionConfig={() => {}}
138-
editActionSecrets={() => {}}
139-
/>
140-
</ActionsConnectorsContextProvider>
103+
<ConnectorFields
104+
action={actionConnector}
105+
errors={{ index: [], webhookUrl: [] }}
106+
editActionConfig={() => {}}
107+
editActionSecrets={() => {}}
108+
docLinks={deps!.docLinks}
109+
/>
141110
);
142111

143112
await act(async () => {

x-pack/plugins/triggers_actions_ui/public/application/components/builtin_action_types/slack.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
} from '../../../types';
1616
import { SlackActionParams, SlackActionConnector } from './types';
1717
import { AddMessageVariables } from '../add_message_variables';
18-
import { useActionsConnectorsContext } from '../../context/actions_connectors_context';
1918

2019
export function getActionType(): ActionTypeModel {
2120
return {
@@ -76,8 +75,7 @@ export function getActionType(): ActionTypeModel {
7675

7776
const SlackActionFields: React.FunctionComponent<ActionConnectorFieldsProps<
7877
SlackActionConnector
79-
>> = ({ action, editActionSecrets, errors }) => {
80-
const { docLinks } = useActionsConnectorsContext();
78+
>> = ({ action, editActionSecrets, errors, docLinks }) => {
8179
const { webhookUrl } = action.secrets;
8280

8381
return (

x-pack/plugins/triggers_actions_ui/public/application/context/alerts_context.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export const AlertsContextProvider = ({
4949
export const useAlertsContext = () => {
5050
const ctx = useContext(AlertsContext);
5151
if (!ctx) {
52-
throw new Error('ActionsConnectorsContext has not been set.');
52+
throw new Error('AlertsContext has not been set.');
5353
}
5454
return ctx;
5555
};

x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_connector_form.test.tsx

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,14 @@ import { coreMock } from '../../../../../../../src/core/public/mocks';
99
import { actionTypeRegistryMock } from '../../action_type_registry.mock';
1010
import { ValidationResult, ActionConnector } from '../../../types';
1111
import { ActionConnectorForm } from './action_connector_form';
12-
import { ActionsConnectorsContextProvider } from '../../context/actions_connectors_context';
1312
const actionTypeRegistry = actionTypeRegistryMock.create();
1413

1514
describe('action_connector_form', () => {
1615
let deps: any;
1716
beforeAll(async () => {
1817
const mocks = coreMock.createSetup();
19-
const [
20-
{
21-
application: { capabilities },
22-
},
23-
] = await mocks.getStartServices();
2418
deps = {
25-
toastNotifications: mocks.notifications.toasts,
2619
http: mocks.http,
27-
capabilities: {
28-
...capabilities,
29-
actions: {
30-
delete: true,
31-
save: true,
32-
show: true,
33-
},
34-
},
3520
actionTypeRegistry: actionTypeRegistry as any,
3621
docLinks: { ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' },
3722
};
@@ -63,25 +48,15 @@ describe('action_connector_form', () => {
6348
let wrapper;
6449
if (deps) {
6550
wrapper = mountWithIntl(
66-
<ActionsConnectorsContextProvider
67-
value={{
68-
http: deps!.http,
69-
actionTypeRegistry: deps!.actionTypeRegistry,
70-
capabilities: deps!.capabilities,
71-
toastNotifications: deps!.toastNotifications,
72-
reloadConnectors: () => {
73-
return new Promise<void>(() => {});
74-
},
75-
docLinks: deps!.docLinks,
76-
}}
77-
>
78-
<ActionConnectorForm
79-
actionTypeName={'my-action-type-name'}
80-
connector={initialConnector}
81-
dispatch={() => {}}
82-
errors={{ name: [] }}
83-
/>
84-
</ActionsConnectorsContextProvider>
51+
<ActionConnectorForm
52+
actionTypeName={'my-action-type-name'}
53+
connector={initialConnector}
54+
dispatch={() => {}}
55+
errors={{ name: [] }}
56+
http={deps!.http}
57+
actionTypeRegistry={deps!.actionTypeRegistry}
58+
docLinks={deps!.docLinks}
59+
/>
8560
);
8661
}
8762
const connectorNameField = wrapper?.find('[data-test-subj="nameInput"]');

x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/action_connector_form.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ import {
1515
} from '@elastic/eui';
1616
import { i18n } from '@kbn/i18n';
1717
import { FormattedMessage } from '@kbn/i18n/react';
18+
import { HttpSetup, DocLinksStart } from 'kibana/public';
1819
import { ReducerAction } from './connector_reducer';
19-
import { ActionConnector, IErrorObject } from '../../../types';
20-
import { useActionsConnectorsContext } from '../../context/actions_connectors_context';
20+
import { ActionConnector, IErrorObject, ActionTypeModel } from '../../../types';
21+
import { TypeRegistry } from '../../type_registry';
2122

2223
export function validateBaseProperties(actionObject: ActionConnector) {
2324
const validationResult = { errors: {} };
@@ -46,6 +47,9 @@ interface ActionConnectorProps {
4647
body: { message: string; error: string };
4748
};
4849
errors: IErrorObject;
50+
http: HttpSetup;
51+
actionTypeRegistry: TypeRegistry<ActionTypeModel>;
52+
docLinks: DocLinksStart;
4953
}
5054

5155
export const ActionConnectorForm = ({
@@ -54,8 +58,10 @@ export const ActionConnectorForm = ({
5458
actionTypeName,
5559
serverError,
5660
errors,
61+
http,
62+
actionTypeRegistry,
63+
docLinks,
5764
}: ActionConnectorProps) => {
58-
const { actionTypeRegistry, docLinks } = useActionsConnectorsContext();
5965
const setActionProperty = (key: string, value: any) => {
6066
dispatch({ command: { type: 'setProperty' }, payload: { key, value } });
6167
};
@@ -150,6 +156,8 @@ export const ActionConnectorForm = ({
150156
errors={errors}
151157
editActionConfig={setActionConfigProperty}
152158
editActionSecrets={setActionSecretsProperty}
159+
http={http}
160+
docLinks={docLinks}
153161
/>
154162
) : null}
155163
</EuiForm>

x-pack/plugins/triggers_actions_ui/public/application/sections/action_connector_form/connector_add_flyout.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export const ConnectorAddFlyout = ({
5252
capabilities,
5353
actionTypeRegistry,
5454
reloadConnectors,
55+
docLinks,
5556
} = useActionsConnectorsContext();
5657
const [actionType, setActionType] = useState<ActionType | undefined>(undefined);
5758
const [hasActionsUpgradeableByTrial, setHasActionsUpgradeableByTrial] = useState<boolean>(false);
@@ -114,6 +115,9 @@ export const ConnectorAddFlyout = ({
114115
connector={connector}
115116
dispatch={dispatch}
116117
errors={errors}
118+
actionTypeRegistry={actionTypeRegistry}
119+
http={http}
120+
docLinks={docLinks}
117121
/>
118122
);
119123
}

0 commit comments

Comments
 (0)