Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41589,10 +41589,7 @@
"xpack.stackConnectors.components.slack_api.error.requiredSlackMessageText": "Nachricht ist erforderlich.",
"xpack.stackConnectors.components.slack_api.error.slackBlockkitBlockRequired": "JSON muss das Feld „blocks“ enthalten.",
"xpack.stackConnectors.components.slack_api.error.slackBlockkitJsonRequired": "Das Block-Kit muss ein gültiges JSON sein.",
"xpack.stackConnectors.components.slack_api.errorInvalidChannelsText": "Die Kanal-ID \"{channels}\" kann nicht validiert werden. Bitte überprüfen Sie die Gültigkeit Ihres Tokens und/oder der Kanal-ID.",
"xpack.stackConnectors.components.slack_api.errorValidChannelsText": "Kanäle können nicht validiert werden, bitte überprüfen Sie die Gültigkeit Ihres Tokens oder Ihres Kanals",
"xpack.stackConnectors.components.slack_api.selectMessageText": "Senden Sie Nachrichten an Slack-Kanäle.",
"xpack.stackConnectors.components.slack_api.successFetchChannelsText": "Alle Kanäle abrufen",
"xpack.stackConnectors.components.slack_api.tokenTextFieldLabel": "API-Token",
"xpack.stackConnectors.components.slack_api.webApi": "Web-API",
"xpack.stackConnectors.components.slack..error.requiredSlackMessageText": "Nachricht ist erforderlich.",
Expand Down Expand Up @@ -41868,9 +41865,7 @@
"xpack.stackConnectors.slack.errorPostingRetryDateErrorMessage": "Fehler beim Posten einer Slack-Nachricht – versuchen Sie es erneut um {retryString}",
"xpack.stackConnectors.slack.errorPostingRetryLaterErrorMessage": "Fehler beim Posten einer Slack-Nachricht, bitte später erneut versuchen",
"xpack.stackConnectors.slack.params.blockkitLabel": "Block-Kit",
"xpack.stackConnectors.slack.params.channelIdComboBoxLabel": "Kanal-ID",
"xpack.stackConnectors.slack.params.channelsComboBoxLabel": "Kanal",
"xpack.stackConnectors.slack.params.componentError.validChannelsRequestFailed": "{validChannelId} ist kein gültiger Slack-Kanal.",
"xpack.stackConnectors.slack.params.textLabel": "Text",
"xpack.stackConnectors.slack.unexpectedHttpResponseErrorMessage": "unerwartete HTTP-Reaktion von Slack: {httpStatus} {httpStatusText}",
"xpack.stackConnectors.slack.unexpectedNullResponseErrorMessage": "unerwartete Null-Reaktion von Slack",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41996,10 +41996,7 @@
"xpack.stackConnectors.components.slack_api.error.requiredSlackMessageText": "Le message est requis.",
"xpack.stackConnectors.components.slack_api.error.slackBlockkitBlockRequired": "L'objet JSON doit contenir des \"blocs\" de champs.",
"xpack.stackConnectors.components.slack_api.error.slackBlockkitJsonRequired": "Le kit de blocs doit être un objet JSON valide.",
"xpack.stackConnectors.components.slack_api.errorInvalidChannelsText": "Impossible de valider l'ID \"{channels}\" du canal. Nous vous invitons à vérifier la validité de votre token ou l'ID du canal",
"xpack.stackConnectors.components.slack_api.errorValidChannelsText": "Impossible de valider les canaux, veuillez vérifier la validité de votre token ou de votre canal",
"xpack.stackConnectors.components.slack_api.selectMessageText": "Envoyer des messages aux canaux Slack.",
"xpack.stackConnectors.components.slack_api.successFetchChannelsText": "Récupérer tous les canaux",
"xpack.stackConnectors.components.slack_api.tokenTextFieldLabel": "Token d'API",
"xpack.stackConnectors.components.slack_api.webApi": "API web",
"xpack.stackConnectors.components.slack..error.requiredSlackMessageText": "Le message est requis.",
Expand Down Expand Up @@ -42272,9 +42269,7 @@
"xpack.stackConnectors.slack.errorPostingRetryDateErrorMessage": "erreur lors de la publication d'un message slack, réessayer à cette date/heure : {retryString}",
"xpack.stackConnectors.slack.errorPostingRetryLaterErrorMessage": "erreur lors de la publication d'un message slack, réessayer ultérieurement",
"xpack.stackConnectors.slack.params.blockkitLabel": "Kit de blocs",
"xpack.stackConnectors.slack.params.channelIdComboBoxLabel": "ID canal",
"xpack.stackConnectors.slack.params.channelsComboBoxLabel": "Canal",
"xpack.stackConnectors.slack.params.componentError.validChannelsRequestFailed": "{validChannelId} n'est pas un canal Slack valide",
"xpack.stackConnectors.slack.params.textLabel": "Texte",
"xpack.stackConnectors.slack.unexpectedHttpResponseErrorMessage": "réponse http inattendue de Slack : {httpStatus} {httpStatusText}",
"xpack.stackConnectors.slack.unexpectedNullResponseErrorMessage": "réponse nulle inattendue de Slack",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42037,10 +42037,7 @@
"xpack.stackConnectors.components.slack_api.error.requiredSlackMessageText": "メッセージが必要です。",
"xpack.stackConnectors.components.slack_api.error.slackBlockkitBlockRequired": "JSONには\"blocks\"フィールドを含める必要があります。",
"xpack.stackConnectors.components.slack_api.error.slackBlockkitJsonRequired": "Block kitは有効なJSONでなければなりません。",
"xpack.stackConnectors.components.slack_api.errorInvalidChannelsText": "チャンネルID \"{channels}\"を検証できません。トークンまたはチャンネルIDの有効性を確認してください。",
"xpack.stackConnectors.components.slack_api.errorValidChannelsText": "有効なチャンネルではありません。トークンまたはチャンネルの有効期限を確認してください",
"xpack.stackConnectors.components.slack_api.selectMessageText": "メッセージをSlackチャンネルに送信します。",
"xpack.stackConnectors.components.slack_api.successFetchChannelsText": "すべてのチャンネルを取得",
"xpack.stackConnectors.components.slack_api.tokenTextFieldLabel": "APIトークン",
"xpack.stackConnectors.components.slack_api.webApi": "Web API",
"xpack.stackConnectors.components.slack..error.requiredSlackMessageText": "メッセージが必要です。",
Expand Down Expand Up @@ -42313,9 +42310,7 @@
"xpack.stackConnectors.slack.errorPostingRetryDateErrorMessage": "slack メッセージの投稿エラー、 {retryString} で再試行",
"xpack.stackConnectors.slack.errorPostingRetryLaterErrorMessage": "slack メッセージの投稿エラー、後ほど再試行",
"xpack.stackConnectors.slack.params.blockkitLabel": "Block Kit",
"xpack.stackConnectors.slack.params.channelIdComboBoxLabel": "チャンネルID",
"xpack.stackConnectors.slack.params.channelsComboBoxLabel": "チャンネル",
"xpack.stackConnectors.slack.params.componentError.validChannelsRequestFailed": "{validChannelId}は有効なSlackチャンネルではありません。",
"xpack.stackConnectors.slack.params.textLabel": "Text",
"xpack.stackConnectors.slack.unexpectedHttpResponseErrorMessage": "slack からの予期せぬ http 応答:{httpStatus} {httpStatusText}",
"xpack.stackConnectors.slack.unexpectedNullResponseErrorMessage": "Slack から予期せぬ null 応答",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42018,10 +42018,7 @@
"xpack.stackConnectors.components.slack_api.error.requiredSlackMessageText": "“消息”必填。",
"xpack.stackConnectors.components.slack_api.error.slackBlockkitBlockRequired": "JSON 必须包含字段“块”。",
"xpack.stackConnectors.components.slack_api.error.slackBlockkitJsonRequired": "Block Kit 必须为有效 JSON。",
"xpack.stackConnectors.components.slack_api.errorInvalidChannelsText": "无法验证频道 ID“{channels}”,请检查您的令牌和/或频道 ID 的有效性",
"xpack.stackConnectors.components.slack_api.errorValidChannelsText": "无法使频道生效,请检查您的令牌或频道的有效性",
"xpack.stackConnectors.components.slack_api.selectMessageText": "向 Slack 频道发送消息。",
"xpack.stackConnectors.components.slack_api.successFetchChannelsText": "提取所有频道",
"xpack.stackConnectors.components.slack_api.tokenTextFieldLabel": "API 令牌",
"xpack.stackConnectors.components.slack_api.webApi": "Web API",
"xpack.stackConnectors.components.slack..error.requiredSlackMessageText": "“消息”必填。",
Expand Down Expand Up @@ -42294,9 +42291,7 @@
"xpack.stackConnectors.slack.errorPostingRetryDateErrorMessage": "发布 Slack 消息时出错,在 {retryString} 重试",
"xpack.stackConnectors.slack.errorPostingRetryLaterErrorMessage": "发布 slack 消息时出错,稍后重试",
"xpack.stackConnectors.slack.params.blockkitLabel": "Block Kit",
"xpack.stackConnectors.slack.params.channelIdComboBoxLabel": "频道 ID",
"xpack.stackConnectors.slack.params.channelsComboBoxLabel": "频道",
"xpack.stackConnectors.slack.params.componentError.validChannelsRequestFailed": "{validChannelId} 不是有效的 Slack 频道",
"xpack.stackConnectors.slack.params.textLabel": "文本",
"xpack.stackConnectors.slack.unexpectedHttpResponseErrorMessage": "来自 slack 的非预期 http 响应:{httpStatus} {httpStatusText}",
"xpack.stackConnectors.slack.unexpectedNullResponseErrorMessage": "来自 slack 的异常空响应",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { TypeRegistry } from '@kbn/triggers-actions-ui-plugin/public/application/type_registry';
import type { ActionTypeModel as ConnectorTypeModel } from '@kbn/triggers-actions-ui-plugin/public/types';
import { registerConnectorTypes } from '..';
import { experimentalFeaturesMock, registrationServicesMock } from '../../mocks';
import { CONNECTOR_ID } from '@kbn/connector-schemas/slack_api/constants';
import { ExperimentalFeaturesService } from '../../common/experimental_features_service';

let connectorTypeModel: ConnectorTypeModel;

beforeAll(async () => {
const connectorTypeRegistry = new TypeRegistry<ConnectorTypeModel>();
ExperimentalFeaturesService.init({ experimentalFeatures: experimentalFeaturesMock });
registerConnectorTypes({ connectorTypeRegistry, services: registrationServicesMock });

const getResult = connectorTypeRegistry.get(CONNECTOR_ID);

if (getResult !== null) {
connectorTypeModel = getResult;
}
});

describe('deserializer', () => {
it('should deserialize the config as expected', () => {
const data = {
id: '1',
name: 'slack api',
isPreconfigured: false,
isDeprecated: false,
isSystemAction: false,
actionTypeId: CONNECTOR_ID,
config: { allowedChannels: [{ name: 'general' }, { name: '#random' }] },
secrets: {},
};

const deserializer = connectorTypeModel.connectorForm?.deserializer!;
const result = deserializer(data);

expect(result).toEqual({
...data,
config: {
...data.config,
allowedChannels: ['#general', '#random'],
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { ConnectorFormSchema, InternalConnectorForm } from '@kbn/alerts-ui-shared';
import type { SlackApiConfig } from '@kbn/connector-schemas/slack_api';

export const deserializer = (data: ConnectorFormSchema): InternalConnectorForm => {
const allowedChannels = (data.config?.allowedChannels as SlackApiConfig['allowedChannels']) ?? [];
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The casting is needed because the TS types do not support templates, as they assume the data is the same for all connectors. I opened this issue: #246390.


const formattedChannels =
allowedChannels.map((channel) => {
if (channel.name.startsWith('#')) {
return channel.name;
}

return `#${channel.name}`;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how can this happen? Did we miss a schema validation to check that channel.name starts with # ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old code always put names without #. We can do the same but I thought users are more used to the # on front of channels and it will make it easier to distinguish channel names for channel IDs.

}) ?? [];

return {
...data,
config: { ...data.config, allowedChannels: formattedChannels },
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { TypeRegistry } from '@kbn/triggers-actions-ui-plugin/public/application/type_registry';
import type { ActionTypeModel as ConnectorTypeModel } from '@kbn/triggers-actions-ui-plugin/public/types';
import { registerConnectorTypes } from '..';
import { experimentalFeaturesMock, registrationServicesMock } from '../../mocks';
import { CONNECTOR_ID } from '@kbn/connector-schemas/slack_api/constants';
import { ExperimentalFeaturesService } from '../../common/experimental_features_service';

let connectorTypeModel: ConnectorTypeModel;

beforeAll(async () => {
const connectorTypeRegistry = new TypeRegistry<ConnectorTypeModel>();
ExperimentalFeaturesService.init({ experimentalFeatures: experimentalFeaturesMock });
registerConnectorTypes({ connectorTypeRegistry, services: registrationServicesMock });

const getResult = connectorTypeRegistry.get(CONNECTOR_ID);

if (getResult !== null) {
connectorTypeModel = getResult;
}
});

describe('serializer', () => {
it('should serialize the config as expected', () => {
const data = {
id: '1',
name: 'slack api',
isPreconfigured: false,
isDeprecated: false,
isSystemAction: false,
actionTypeId: CONNECTOR_ID,
config: { allowedChannels: ['#general', '#random'] },
secrets: {},
};

const serializer = connectorTypeModel.connectorForm?.serializer!;

const result = serializer(data);

expect(result).toEqual({
...data,
config: {
...data.config,
allowedChannels: [{ name: '#general' }, { name: '#random' }],
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { ConnectorFormSchema, InternalConnectorForm } from '@kbn/alerts-ui-shared';

export const serializer = (data: InternalConnectorForm): ConnectorFormSchema => {
const formAllowedChannels = (data.config?.allowedChannels as string[]) ?? [];
const allowedChannels = formAllowedChannels.map((option) => ({ name: option })) ?? [];

return {
...data,
config: { ...data.config, allowedChannels },
};
};
Loading