-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7301ebd
commit c7cab6c
Showing
110 changed files
with
11,508 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { Legacy } from 'kibana'; | ||
import { Root } from 'joi'; | ||
import { resolve } from 'path'; | ||
|
||
export function triggersActionsUI(kibana: any) { | ||
return new kibana.Plugin({ | ||
id: 'triggers_actions_ui', | ||
configPrefix: 'xpack.triggers_actions_ui', | ||
isEnabled(config: Legacy.KibanaConfig) { | ||
return ( | ||
config.get('xpack.triggers_actions_ui.enabled') && | ||
(config.get('xpack.actions.enabled') || config.get('xpack.alerting.enabled')) | ||
); | ||
}, | ||
publicDir: resolve(__dirname, 'public'), | ||
require: ['kibana'], | ||
config(Joi: Root) { | ||
return Joi.object() | ||
.keys({ | ||
enabled: Joi.boolean().default(false), | ||
createAlertUiEnabled: Joi.boolean().default(false), | ||
}) | ||
.default(); | ||
}, | ||
uiExports: { | ||
home: ['plugins/triggers_actions_ui/hacks/register'], | ||
managementSections: ['plugins/triggers_actions_ui/legacy'], | ||
styleSheetPaths: resolve(__dirname, 'public/index.scss'), | ||
injectDefaultVars(server: Legacy.Server) { | ||
const serverConfig = server.config(); | ||
return { | ||
createAlertUiEnabled: serverConfig.get('xpack.triggers_actions_ui.createAlertUiEnabled'), | ||
}; | ||
}, | ||
}, | ||
}); | ||
} |
6 changes: 6 additions & 0 deletions
6
x-pack/legacy/plugins/triggers_actions_ui/np_ready/kibana.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"id": "triggers_actions_ui", | ||
"version": "kibana", | ||
"server": false, | ||
"ui": true | ||
} |
21 changes: 21 additions & 0 deletions
21
...gacy/plugins/triggers_actions_ui/np_ready/public/application/action_type_registry.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { ActionTypeRegistryContract } from '../types'; | ||
|
||
const createActionTypeRegistryMock = () => { | ||
const mocked: jest.Mocked<ActionTypeRegistryContract> = { | ||
has: jest.fn(x => true), | ||
register: jest.fn(), | ||
get: jest.fn(), | ||
list: jest.fn(), | ||
}; | ||
return mocked; | ||
}; | ||
|
||
export const actionTypeRegistryMock = { | ||
create: createActionTypeRegistryMock, | ||
}; |
21 changes: 21 additions & 0 deletions
21
...egacy/plugins/triggers_actions_ui/np_ready/public/application/alert_type_registry.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { AlertTypeRegistryContract } from '../types'; | ||
|
||
const createAlertTypeRegistryMock = () => { | ||
const mocked: jest.Mocked<AlertTypeRegistryContract> = { | ||
has: jest.fn(), | ||
register: jest.fn(), | ||
get: jest.fn(), | ||
list: jest.fn(), | ||
}; | ||
return mocked; | ||
}; | ||
|
||
export const alertTypeRegistryMock = { | ||
create: createAlertTypeRegistryMock, | ||
}; |
64 changes: 64 additions & 0 deletions
64
x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/app.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import React from 'react'; | ||
import { Switch, Route, Redirect, HashRouter } from 'react-router-dom'; | ||
import { | ||
ChromeStart, | ||
DocLinksStart, | ||
ToastsSetup, | ||
HttpSetup, | ||
IUiSettingsClient, | ||
} from 'kibana/public'; | ||
import { BASE_PATH, Section } from './constants'; | ||
import { TriggersActionsUIHome } from './home'; | ||
import { AppContextProvider, useAppDependencies } from './app_context'; | ||
import { hasShowAlertsCapability } from './lib/capabilities'; | ||
import { LegacyDependencies, ActionTypeModel, AlertTypeModel } from '../types'; | ||
import { TypeRegistry } from './type_registry'; | ||
|
||
export interface AppDeps { | ||
chrome: ChromeStart; | ||
docLinks: DocLinksStart; | ||
toastNotifications: ToastsSetup; | ||
injectedMetadata: any; | ||
http: HttpSetup; | ||
uiSettings: IUiSettingsClient; | ||
legacy: LegacyDependencies; | ||
actionTypeRegistry: TypeRegistry<ActionTypeModel>; | ||
alertTypeRegistry: TypeRegistry<AlertTypeModel>; | ||
} | ||
|
||
export const App = (appDeps: AppDeps) => { | ||
const sections: Section[] = ['alerts', 'connectors']; | ||
|
||
const sectionsRegex = sections.join('|'); | ||
|
||
return ( | ||
<HashRouter> | ||
<AppContextProvider appDeps={appDeps}> | ||
<AppWithoutRouter sectionsRegex={sectionsRegex} /> | ||
</AppContextProvider> | ||
</HashRouter> | ||
); | ||
}; | ||
|
||
export const AppWithoutRouter = ({ sectionsRegex }: any) => { | ||
const { | ||
legacy: { capabilities }, | ||
} = useAppDependencies(); | ||
const canShowAlerts = hasShowAlertsCapability(capabilities.get()); | ||
const DEFAULT_SECTION: Section = canShowAlerts ? 'alerts' : 'connectors'; | ||
return ( | ||
<Switch> | ||
<Route | ||
exact | ||
path={`${BASE_PATH}/:section(${sectionsRegex})`} | ||
component={TriggersActionsUIHome} | ||
/> | ||
<Redirect from={`${BASE_PATH}`} to={`${BASE_PATH}/${DEFAULT_SECTION}`} /> | ||
</Switch> | ||
); | ||
}; |
30 changes: 30 additions & 0 deletions
30
x-pack/legacy/plugins/triggers_actions_ui/np_ready/public/application/app_context.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { createContext, useContext } from 'react'; | ||
import { AppDeps } from './app'; | ||
|
||
const AppContext = createContext<AppDeps | null>(null); | ||
|
||
export const AppContextProvider = ({ | ||
children, | ||
appDeps, | ||
}: { | ||
appDeps: AppDeps | null; | ||
children: React.ReactNode; | ||
}) => { | ||
return appDeps ? <AppContext.Provider value={appDeps}>{children}</AppContext.Provider> : null; | ||
}; | ||
|
||
export const useAppDependencies = (): AppDeps => { | ||
const ctx = useContext(AppContext); | ||
if (!ctx) { | ||
throw new Error( | ||
'The app dependencies Context has not been set. Use the "setAppDependencies()" method when bootstrapping the app.' | ||
); | ||
} | ||
return ctx; | ||
}; |
Oops, something went wrong.