Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed alert Edit flyout shows the error message when one of this actions has a preconfigured action type #64742

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ export const ActionForm = ({
index[actionTypeItem.id] = actionTypeItem;
}
setActionTypesIndex(index);
const hasActionsDisabled = actions.some(action => !index[action.actionTypeId].enabled);
if (setHasActionsDisabled) {
setHasActionsDisabled(hasActionsDisabled);
}
} catch (e) {
toastNotifications.addDanger({
title: i18n.translate(
Expand All @@ -129,7 +125,11 @@ export const ActionForm = ({
(async () => {
try {
setIsLoadingConnectors(true);
setConnectors(await loadConnectors({ http }));
const loadedConnectors = await loadConnectors({ http });
setConnectors(loadedConnectors);
setActionTypesAvalilability(
loadedConnectors.filter(connector => connector.isPreconfigured)
);
} catch (e) {
toastNotifications.addDanger({
title: i18n.translate(
Expand All @@ -146,6 +146,21 @@ export const ActionForm = ({
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const setActionTypesAvalilability = (preconfiguredConnectors: ActionConnector[]) => {
const hasActionsDisabled = actions.some(
action =>
actionTypesIndex &&
!actionTypesIndex[action.actionTypeId].enabled &&
!checkActionFormActionTypeEnabled(
actionTypesIndex[action.actionTypeId],
preconfiguredConnectors
).isEnabled
);
if (setHasActionsDisabled) {
setHasActionsDisabled(hasActionsDisabled);
}
};

const preconfiguredMessage = i18n.translate(
'xpack.triggersActionsUI.sections.actionForm.preconfiguredTitleMessage',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ export const AlertEdit = ({
size="s"
color="danger"
iconType="alert"
data-test-subj="hasActionsDisabled"
title={i18n.translate(
'xpack.triggersActionsUI.sections.alertEdit.disabledActionsWarningTitle',
{ defaultMessage: 'This alert has actions that are disabled' }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,14 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const alert = await alerting.alerts.createAlertWithActions(
testRunUuid,
'.index-threshold',
params
params,
[
{
group: 'threshold met',
id: 'my-server-log',
params: { level: 'info', message: ' {{context.message}}' },
},
]
);
// refresh to see alert
await browser.refresh();
Expand All @@ -183,6 +190,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

const editButton = await testSubjects.find('openEditAlertFlyoutButton');
await editButton.click();
expect(await testSubjects.exists('hasActionsDisabled')).to.eql(false);

const updatedAlertName = `Changed Alert Name ${uuid.v4()}`;
await testSubjects.setValue('alertNameInput', updatedAlertName, {
Expand Down
21 changes: 21 additions & 0 deletions x-pack/test/functional_with_es_ssl/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@ import { FtrConfigProviderContext } from '@kbn/test/types/ftr';
import { services } from './services';
import { pageObjects } from './page_objects';

// .server-log is specifically not enabled
const enabledActionTypes = [
'.email',
'.index',
'.pagerduty',
'.servicenow',
'.slack',
'.webhook',
'test.authorization',
'test.failing',
'test.index-record',
'test.noop',
'test.rate-limit',
];

// eslint-disable-next-line import/no-default-export
export default async function({ readConfigFile }: FtrConfigProviderContext) {
const xpackFunctionalConfig = await readConfigFile(require.resolve('../functional/config.js'));
Expand Down Expand Up @@ -50,6 +65,7 @@ export default async function({ readConfigFile }: FtrConfigProviderContext) {
`--elasticsearch.hosts=https://${servers.elasticsearch.hostname}:${servers.elasticsearch.port}`,
`--elasticsearch.ssl.certificateAuthorities=${CA_CERT_PATH}`,
`--plugin-path=${join(__dirname, 'fixtures', 'plugins', 'alerts')}`,
`--xpack.actions.enabledActionTypes=${JSON.stringify(enabledActionTypes)}`,
`--xpack.actions.preconfigured=${JSON.stringify([
{
id: 'my-slack1',
Expand All @@ -59,6 +75,11 @@ export default async function({ readConfigFile }: FtrConfigProviderContext) {
webhookUrl: 'https://hooks.slack.com/services/abcd/efgh/ijklmnopqrstuvwxyz',
},
},
{
id: 'my-server-log',
actionTypeId: '.server-log',
name: 'Serverlog#xyz',
},
])}`,
],
},
Expand Down