@@ -43,6 +43,8 @@ Table of Contents
4343 - [ Action type model definition] ( #action-type-model-definition )
4444 - [ Register action type model] ( #register-action-type-model )
4545 - [ Create and register new action type UI example] ( #reate-and-register-new-action-type-ui-example )
46+ - [ Embed the Create Connector flyout within any Kibana plugin] ( #embed-the-create-connector-flyout-within-any-kibana-plugin )
47+ - [ Embed the Edit Connector flyout within any Kibana plugin] ( #embed-the-edit-connector-flyout-within-any-kibana-plugin )
4648
4749## Built-in Alert Types
4850
@@ -667,6 +669,7 @@ const [alertFlyoutVisible, setAlertFlyoutVisibility] = useState<boolean>(false);
667669 uiSettings,
668670 charts,
669671 dataFieldsFormats,
672+ metadata: { test: 'some value', fields: ['test'] },
670673 }}
671674>
672675 <AlertAdd consumer={'watcher'} />
@@ -690,7 +693,7 @@ interface AlertAddProps {
690693
691694AlertsContextProvider value options:
692695```
693- export interface AlertsContextValue {
696+ export interface AlertsContextValue<MetaData = Record<string, any>> {
694697 addFlyoutVisible: boolean;
695698 setAddFlyoutVisibility: React.Dispatch<React.SetStateAction<boolean>>;
696699 reloadAlerts?: () => Promise<void>;
@@ -704,6 +707,7 @@ export interface AlertsContextValue {
704707 >;
705708 charts?: ChartsPluginSetup;
706709 dataFieldsFormats?: Pick<FieldFormatsRegistry, 'register'>;
710+ metadata?: MetaData;
707711}
708712```
709713
@@ -719,6 +723,7 @@ export interface AlertsContextValue {
719723| toastNotifications| Optional toast messages.|
720724| charts| Optional property, which is needed to display visualization of alert type expression. Will be changed after visualization refactoring.|
721725| dataFieldsFormats| Optional property, which is needed to display visualization of alert type expression. Will be changed after visualization refactoring.|
726+ | metadata| Optional generic property, which allows to define component specific metadata. This metadata can be used for passing down preloaded data for Alert type expression component.|
722727
723728## Build and register Action Types
724729
@@ -1198,3 +1203,213 @@ Clicking on the select card for `Example Action Type` will open the action type
11981203
11991204or create a new connector:
12001205![ Example Action Type with empty connectors list] ( https://i.imgur.com/EamA9Xv.png )
1206+
1207+ ## Embed the Create Connector flyout within any Kibana plugin
1208+
1209+ Follow the instructions bellow to embed the Create Connector flyout within any Kibana plugin:
1210+ 1 . Add TriggersAndActionsUIPublicPluginSetup and TriggersAndActionsUIPublicPluginStart to Kibana plugin setup dependencies:
1211+
1212+ ```
1213+ import {
1214+ TriggersAndActionsUIPublicPluginSetup,
1215+ TriggersAndActionsUIPublicPluginStart,
1216+ } from '../../../../../x-pack/plugins/triggers_actions_ui/public';
1217+
1218+ triggers_actions_ui: TriggersAndActionsUIPublicPluginSetup;
1219+ ...
1220+
1221+ triggers_actions_ui: TriggersAndActionsUIPublicPluginStart;
1222+ ```
1223+ Then this dependency will be used to embed Create Connector flyout or register new action type.
1224+
1225+ 2 . Add Create Connector flyout to React component:
1226+ ```
1227+ // import section
1228+ import { ActionsConnectorsContextProvider, ConnectorAddFlyout } from '../../../../../../../triggers_actions_ui/public';
1229+
1230+ // in the component state definition section
1231+ const [addFlyoutVisible, setAddFlyoutVisibility] = useState<boolean>(false);
1232+
1233+ // load required dependancied
1234+ const { http, triggers_actions_ui, toastNotifications, capabilities } = useKibana().services;
1235+
1236+ const connector = {
1237+ secrets: {},
1238+ id: 'test',
1239+ actionTypeId: '.index',
1240+ actionType: 'Index',
1241+ name: 'action-connector',
1242+ referencedByCount: 0,
1243+ config: {},
1244+ };
1245+
1246+ // UI control item for open flyout
1247+ <EuiButton
1248+ fill
1249+ iconType="plusInCircle"
1250+ iconSide="left"
1251+ onClick={() => setAddFlyoutVisibility(true)}
1252+ >
1253+ <FormattedMessage
1254+ id="emptyButton"
1255+ defaultMessage="Create connector"
1256+ />
1257+ </EuiButton>
1258+
1259+ // in render section of component
1260+ <ActionsConnectorsContextProvider
1261+ value={{
1262+ http: http,
1263+ toastNotifications: toastNotifications,
1264+ actionTypeRegistry: triggers_actions_ui.actionTypeRegistry,
1265+ capabilities: capabilities,
1266+ }}
1267+ >
1268+ <ConnectorAddFlyout
1269+ addFlyoutVisible={addFlyoutVisible}
1270+ setAddFlyoutVisibility={setAddFlyoutVisibility}
1271+ actionTypes={[
1272+ {
1273+ id: '.index',
1274+ enabled: true,
1275+ name: 'Index',
1276+ },
1277+ ]}
1278+ />
1279+ </ActionsConnectorsContextProvider>
1280+ ```
1281+
1282+ ConnectorAddFlyout Props definition:
1283+ ```
1284+ export interface ConnectorAddFlyoutProps {
1285+ addFlyoutVisible: boolean;
1286+ setAddFlyoutVisibility: React.Dispatch<React.SetStateAction<boolean>>;
1287+ actionTypes?: ActionType[];
1288+ }
1289+ ```
1290+
1291+ | Property| Description|
1292+ | ---| ---|
1293+ | addFlyoutVisible| Visibility state of the Create Connector flyout.|
1294+ | setAddFlyoutVisibility| Function for changing visibility state of the Create Connector flyout.|
1295+ | actionTypes| Optional property, that allows to define only specific action types list which is available for a current plugin.|
1296+
1297+ ActionsConnectorsContextValue options:
1298+ ```
1299+ export interface ActionsConnectorsContextValue {
1300+ http: HttpSetup;
1301+ actionTypeRegistry: TypeRegistry<ActionTypeModel>;
1302+ toastNotifications: Pick<
1303+ ToastsApi,
1304+ 'get$' | 'add' | 'remove' | 'addSuccess' | 'addWarning' | 'addDanger' | 'addError'
1305+ >;
1306+ capabilities: ApplicationStart['capabilities'];
1307+ reloadConnectors?: () => Promise<void>;
1308+ }
1309+ ```
1310+
1311+ | Property| Description|
1312+ | ---| ---|
1313+ | http| HttpSetup needed for executing API calls.|
1314+ | actionTypeRegistry| Registry for action types.|
1315+ | capabilities| Property, which is defining action current user usage capabilities like canSave or canDelete.|
1316+ | toastNotifications| Toast messages.|
1317+ | reloadConnectors| Optional function, which will be executed if connector was saved sucsessfuly, like reload list of connecotrs.|
1318+
1319+
1320+ ## Embed the Edit Connector flyout within any Kibana plugin
1321+
1322+ Follow the instructions bellow to embed the Edit Connector flyout within any Kibana plugin:
1323+ 1 . Add TriggersAndActionsUIPublicPluginSetup and TriggersAndActionsUIPublicPluginStart to Kibana plugin setup dependencies:
1324+
1325+ ```
1326+ import {
1327+ TriggersAndActionsUIPublicPluginSetup,
1328+ TriggersAndActionsUIPublicPluginStart,
1329+ } from '../../../../../x-pack/plugins/triggers_actions_ui/public';
1330+
1331+ triggers_actions_ui: TriggersAndActionsUIPublicPluginSetup;
1332+ ...
1333+
1334+ triggers_actions_ui: TriggersAndActionsUIPublicPluginStart;
1335+ ```
1336+ Then this dependency will be used to embed Edit Connector flyout.
1337+
1338+ 2 . Add Create Connector flyout to React component:
1339+ ```
1340+ // import section
1341+ import { ActionsConnectorsContextProvider, ConnectorEditFlyout } from '../../../../../../../triggers_actions_ui/public';
1342+
1343+ // in the component state definition section
1344+ const [editFlyoutVisible, setEditFlyoutVisibility] = useState<boolean>(false);
1345+
1346+ // load required dependancied
1347+ const { http, triggers_actions_ui, toastNotifications, capabilities } = useKibana().services;
1348+
1349+ // UI control item for open flyout
1350+ <EuiButton
1351+ fill
1352+ iconType="plusInCircle"
1353+ iconSide="left"
1354+ onClick={() => setEditFlyoutVisibility(true)}
1355+ >
1356+ <FormattedMessage
1357+ id="emptyButton"
1358+ defaultMessage="Edit connector"
1359+ />
1360+ </EuiButton>
1361+
1362+ // in render section of component
1363+ <ActionsConnectorsContextProvider
1364+ value={{
1365+ http: http,
1366+ toastNotifications: toastNotifications,
1367+ actionTypeRegistry: triggers_actions_ui.actionTypeRegistry,
1368+ capabilities: capabilities,
1369+ }}
1370+ >
1371+ <ConnectorEditFlyout
1372+ initialConnector={connector}
1373+ editFlyoutVisible={editFlyoutVisible}
1374+ setEditFlyoutVisibility={setEditFlyoutVisibility}
1375+ />
1376+ </ActionsConnectorsContextProvider>
1377+
1378+ ```
1379+
1380+ ConnectorEditFlyout Props definition:
1381+ ```
1382+ export interface ConnectorEditProps {
1383+ initialConnector: ActionConnectorTableItem;
1384+ editFlyoutVisible: boolean;
1385+ setEditFlyoutVisibility: React.Dispatch<React.SetStateAction<boolean>>;
1386+ }
1387+ ```
1388+
1389+ | Property| Description|
1390+ | ---| ---|
1391+ | initialConnector| Property, that allows to define the initial state of edited connector.|
1392+ | editFlyoutVisible| Visibility state of the Edit Connector flyout.|
1393+ | setEditFlyoutVisibility| Function for changing visibility state of the Edit Connector flyout.|
1394+
1395+ ActionsConnectorsContextValue options:
1396+ ```
1397+ export interface ActionsConnectorsContextValue {
1398+ http: HttpSetup;
1399+ actionTypeRegistry: TypeRegistry<ActionTypeModel>;
1400+ toastNotifications: Pick<
1401+ ToastsApi,
1402+ 'get$' | 'add' | 'remove' | 'addSuccess' | 'addWarning' | 'addDanger' | 'addError'
1403+ >;
1404+ capabilities: ApplicationStart['capabilities'];
1405+ reloadConnectors?: () => Promise<void>;
1406+ }
1407+ ```
1408+
1409+ | Property| Description|
1410+ | ---| ---|
1411+ | http| HttpSetup needed for executing API calls.|
1412+ | actionTypeRegistry| Registry for action types.|
1413+ | capabilities| Property, which is defining action current user usage capabilities like canSave or canDelete.|
1414+ | toastNotifications| Toast messages.|
1415+ | reloadConnectors| Optional function, which will be executed if connector was saved sucsessfuly, like reload list of connecotrs.|
0 commit comments