Skip to content

Commit

Permalink
handle optional alerting plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Mar 17, 2020
1 parent 4564004 commit 186b31e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface AppDeps {
dataPlugin: DataPublicPluginStart;
charts: ChartsPluginStart;
chrome: ChromeStart;
alerting: AlertingStart;
alerting?: AlertingStart;
navigateToApp: CoreStart['application']['navigateToApp'];
docLinks: DocLinksStart;
toastNotifications: ToastsSetup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe('alert_details', () => {
expect(component!.find('button').prop('disabled')).toBe(true);
expect(component!.text()).toBe('View in app');

expect(alerting.getNavigation).toBeCalledWith(alert.id);
expect(alerting!.getNavigation).toBeCalledWith(alert.id);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import React, { useState, useEffect } from 'react';
import { EuiButtonEmpty } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { CoreStart } from 'kibana/public';
import { fromNullable, fold } from 'fp-ts/lib/Option';
import { pipe } from 'fp-ts/lib/pipeable';
import { useAppDependencies } from '../../../app_context';

import {
Expand All @@ -26,17 +28,28 @@ const NO_NAVIGATION = false;
type AlertNavigationLoadingState = AlertNavigation | false | null;

export const ViewInApp: React.FunctionComponent<ViewInAppProps> = ({ alert }) => {
const { navigateToApp, alerting } = useAppDependencies();
const { navigateToApp, alerting: maybeAlerting } = useAppDependencies();

const [alertNavigation, setAlertNavigation] = useState<AlertNavigationLoadingState>(null);
useEffect(() => {
alerting
.getNavigation(alert.id)
.then(nav => (nav ? setAlertNavigation(nav) : setAlertNavigation(NO_NAVIGATION)))
.catch(() => {
setAlertNavigation(NO_NAVIGATION);
});
}, [alert.id, alerting]);
pipe(
fromNullable(maybeAlerting),
fold(
/**
* If the alerting plugin is disabled,
* navigation isn't supported
*/
() => setAlertNavigation(NO_NAVIGATION),
alerting =>
alerting
.getNavigation(alert.id)
.then(nav => (nav ? setAlertNavigation(nav) : setAlertNavigation(NO_NAVIGATION)))
.catch(() => {
setAlertNavigation(NO_NAVIGATION);
})
)
);
}, [alert.id, maybeAlerting]);

return (
<EuiButtonEmpty
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/triggers_actions_ui/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface PluginsStart {
data: DataPublicPluginStart;
charts: ChartsPluginStart;
management: ManagementStart;
alerting: AlertingStart;
alerting?: AlertingStart;
navigateToApp: CoreStart['application']['navigateToApp'];
}

Expand Down

0 comments on commit 186b31e

Please sign in to comment.