Skip to content

Commit 821e050

Browse files
committed
Fixing action form not rendering pre selected action
1 parent 9dff0db commit 821e050

2 files changed

Lines changed: 25 additions & 25 deletions

File tree

x-pack/plugins/triggers_actions_ui/public/application/components/health_check.tsx

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66

77
import React, { Fragment } from 'react';
8+
import { Option, none, some, fold } from 'fp-ts/lib/Option';
9+
import { pipe } from 'fp-ts/lib/pipeable';
810
import { FormattedMessage } from '@kbn/i18n/react';
911

1012
import { EuiLink, EuiLoadingSpinner } from '@elastic/eui';
@@ -33,41 +35,35 @@ export const HealthCheck: React.FunctionComponent<Props> = ({
3335
waitForCheck = true,
3436
}) => {
3537
const { setLoadingHealthCheck } = useHealthContext();
36-
const [alertingHealth, setAlertingHealth] = React.useState<AlertingFrameworkHealth | null>(null);
38+
const [alertingHealth, setAlertingHealth] = React.useState<Option<AlertingFrameworkHealth>>(none);
3739

38-
/**
39-
* if waitForCheck && no response from server, loading
40-
if waitForcheck && response from server, go through logic
41-
if !waitForCheck && no response from server, return child
42-
if !waitForCheck && response from server, go through logic
43-
*/
4440
React.useEffect(() => {
4541
(async function () {
4642
setLoadingHealthCheck(true);
47-
setAlertingHealth(await health({ http }));
43+
setAlertingHealth(some(await health({ http })));
4844
setLoadingHealthCheck(false);
4945
})();
5046
}, [http, setLoadingHealthCheck]);
5147

5248
const className = inFlyout ? 'alertingFlyoutHealthCheck' : 'alertingHealthCheck';
5349

54-
const healthLoadedButNotSecure =
55-
alertingHealth &&
56-
(!alertingHealth.isSufficientlySecure || !alertingHealth.hasPermanentEncryptionKey);
57-
58-
if (healthLoadedButNotSecure) {
59-
return !alertingHealth?.isSufficientlySecure && !alertingHealth?.hasPermanentEncryptionKey ? (
60-
<TlsAndEncryptionError docLinks={docLinks} className={className} />
61-
) : !alertingHealth?.hasPermanentEncryptionKey ? (
62-
<EncryptionError docLinks={docLinks} className={className} />
63-
) : (
64-
<TlsError docLinks={docLinks} className={className} />
65-
);
66-
} else if (waitForCheck && !alertingHealth) {
67-
return <EuiLoadingSpinner size="m" />;
68-
}
69-
70-
return <Fragment>{children}</Fragment>;
50+
return pipe(
51+
alertingHealth,
52+
fold(
53+
() => (waitForCheck ? <EuiLoadingSpinner size="m" /> : <Fragment>{children}</Fragment>),
54+
(healthCheck) => {
55+
return healthCheck?.isSufficientlySecure && healthCheck?.hasPermanentEncryptionKey ? (
56+
<Fragment>{children}</Fragment>
57+
) : !healthCheck.isSufficientlySecure && !healthCheck.hasPermanentEncryptionKey ? (
58+
<TlsAndEncryptionError docLinks={docLinks} className={className} />
59+
) : !healthCheck.hasPermanentEncryptionKey ? (
60+
<EncryptionError docLinks={docLinks} className={className} />
61+
) : (
62+
<TlsError docLinks={docLinks} className={className} />
63+
);
64+
}
65+
)
66+
);
7167
};
7268

7369
type PromptErrorProps = Pick<Props, 'docLinks'> & {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,10 @@ export const AlertForm = ({
149149
// eslint-disable-next-line react-hooks/exhaustive-deps
150150
}, []);
151151

152+
useEffect(() => {
153+
setAlertTypeModel(alert.alertTypeId ? alertTypeRegistry.get(alert.alertTypeId) : null);
154+
}, [alert, alertTypeRegistry]);
155+
152156
const setAlertProperty = (key: string, value: any) => {
153157
dispatch({ command: { type: 'setProperty' }, payload: { key, value } });
154158
};

0 commit comments

Comments
 (0)