Unverified Commit a4737678 authored by zhu-mingye's avatar zhu-mingye Committed by GitHub

[refactor] [alert] alter instance && support sms(web) (#1999)

* refactor alert instance && support sms(web) * fix some bug * format code * fix some bug * fix some bug * fix some bug * USE enum support switch * added sms config * added sms config
parent 4eec3d59
......@@ -121,6 +121,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>${scope.runtime}</scope>
</dependency>
<!-- postgresql -->
<dependency>
......
......@@ -109,9 +109,14 @@ public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapp
String exceptionUrl = "http://cdh1:8081/#/job/" + uuid + "/exceptions";
Map<String, String> map = JSONUtil.toMap(alertInstance.getParams());
if (map.get("msgtype").equals(ShowType.MARKDOWN.getValue())) {
alertMsgBuilder.linkUrl("[跳转至该任务的 FlinkWeb](" + linkUrl + ")");
alertMsgBuilder.exceptionUrl("[点击查看该任务的异常日志](" + exceptionUrl + ")");
if (!alertInstance.getType().equals("Sms")) {
if (map.get("msgtype").equals(ShowType.MARKDOWN.getValue())) {
alertMsgBuilder.linkUrl("[跳转至该任务的 FlinkWeb](" + linkUrl + ")");
alertMsgBuilder.exceptionUrl("[点击查看该任务的异常日志](" + exceptionUrl + ")");
} else {
alertMsgBuilder.linkUrl(linkUrl);
alertMsgBuilder.exceptionUrl(exceptionUrl);
}
} else {
alertMsgBuilder.linkUrl(linkUrl);
alertMsgBuilder.exceptionUrl(exceptionUrl);
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one or more
~ contributor license agreements. See the NOTICE file distributed with
~ this work for additional information regarding copyright ownership.
~ The ASF licenses this file to You under the Apache License, Version 2.0
~ (the "License"); you may not use this file except in compliance with
~ the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.dinky</groupId>
<artifactId>dinky-alert</artifactId>
<version>0.8.0</version>
</parent>
<artifactId>dinky-alert-sms</artifactId>
<name>Dinky : Alter : SMS</name>
<dependencies>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-alert-base</artifactId>
</dependency>
<dependency>
<groupId>org.dromara.sms4j</groupId>
<artifactId>sms4j-spring-boot-starter</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.alert.sms;
import org.dinky.alert.AbstractAlert;
import org.dinky.alert.AlertResult;
import cn.hutool.json.JSONUtil;
/** SmsAlert */
public class SmsAlert extends AbstractAlert {
@Override
public String getType() {
return SmsConstants.TYPE;
}
@Override
public AlertResult send(String title, String content) {
SmsSender sender = new SmsSender(JSONUtil.toJsonStr(getConfig().getParam()));
return sender.send(title, content);
}
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.alert.sms;
/** SmsConstants */
public class SmsConstants {
public static final String TYPE = "Sms";
public static final String MANU_FACTURERS = "manufacturers";
public static final String ACCESS_KEY_ID = "accessKeyId";
public static final String ACCESS_KEY_SECRET = "accessKeySecret";
public static final String TEMPLATE_ID = "templateId";
public static final String SIGNATURE = "signature";
public static final String TEMPLATE_NAME = "templateName";
public static final String REQUEST_URL = "requestUrl";
public static final String REGION_ID = "regionId";
public static final String ACTION = "action";
public static final String VERSION = "version";
public static final String APP_KEY = "appKey";
public static final String APP_SECRET = "appSecret";
public static final String SENDER = "sender";
public static final String STATUS_CALLBACK = "statusCallBack";
public static final String URL = "url";
public static final String SDK_APP_ID = "sdkAppId";
public static final String TERRITORY = "territory";
public static final String CONN_TIMEOUT = "connTimeout";
public static final String IS_SIMPLE = "is-simple";
public static final String REGION = "region";
public static final String APP_ID = "appId";
public static final String BASE_URL = "baseUrl";
public static final String SECRET_KEY = "secretKey";
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.alert.sms;
import static java.util.Objects.requireNonNull;
import org.dinky.alert.AlertResult;
import org.dinky.alert.sms.config.SmsConfigLoader;
import org.dinky.alert.sms.enums.ManuFacturers;
import java.util.Arrays;
import java.util.LinkedHashMap;
import org.dromara.sms4j.api.SmsBlend;
import org.dromara.sms4j.api.universal.SupplierConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import cn.hutool.json.JSONUtil;
/** SmsSender todo: https://wind.kim/doc/start/springboot.html */
public class SmsSender {
private static final Logger logger = LoggerFactory.getLogger(SmsSender.class);
private static SupplierConfig configLoader = null;
private static SmsBlend smsSendFactory = null;
/** manufacturers of sms */
private Integer manufacturers;
SmsSender(String config) {
int manufacturersId =
Integer.parseInt(JSONUtil.parseObj(config).getStr(SmsConstants.MANU_FACTURERS));
this.manufacturers = manufacturersId;
requireNonNull(manufacturers, "manufacturers is null");
configLoader = SmsConfigLoader.getConfigLoader(config, manufacturers);
smsSendFactory = SmsConfigLoader.getSmsFactory(manufacturersId);
logger.info("you choose {} manufacturers", ManuFacturers.getManuFacturers(manufacturersId));
}
public AlertResult send(String title, String content) {
AlertResult alertResult = new AlertResult();
logger.info("send sms, title: {}, content: {}", title, content);
// todo: 1. support multi sms manufacturers send
// 使用自定义模板群发短信 || use custom template mass texting
smsSendFactory.massTexting(Arrays.asList("17722226666"), "110", new LinkedHashMap<>());
// todo: 2. validate sms send result
return alertResult;
}
}
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.dinky.alert.sms.enums;
public enum ManuFacturers {
/** 阿里云 */
ALIBABA(1, "阿里云短信"),
/** 华为云 */
HUAWEI(2, "华为云短信"),
/** 云片 */
YUNPIAN(3, "云片短信"),
/** 腾讯云 */
TENCENT(4, "腾讯云短信"),
/** 合一短信 */
UNI_SMS(5, "合一短信"),
/** 京东云短信 */
JD_CLOUD(6, "京东云短信"),
/** 容联云短信 */
CLOOPEN(7, "容联云短信"),
/** 亿美软通短信 */
EMAY(8, "亿美软通短信"),
/** 天翼云短信 */
CTYUN(9, "天翼云短信"),
;
private final Integer code;
private final String type;
ManuFacturers(Integer code, String type) {
this.code = code;
this.type = type;
}
public Integer getCode() {
return this.code;
}
public String getType() {
return this.type;
}
public static ManuFacturers getManuFacturers(Integer code) {
for (ManuFacturers manuFacturers : ManuFacturers.values()) {
if (manuFacturers.getCode().equals(code)) {
return manuFacturers;
}
}
return null;
}
}
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
org.dinky.alert.sms.SmsAlert
\ No newline at end of file
......@@ -41,7 +41,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>provided</scope>
<scope>test</scope>
</dependency>
</dependencies>
</project>
......@@ -25,8 +25,8 @@ package org.dinky.alert.wechat;
* @since 2022/2/23 21:36
*/
public enum WeChatType {
APP(1, "应用"),
CHAT(2, "群聊");
APP(1, "app"),
CHAT(2, "wechat");
private final int code;
private final String value;
......
......@@ -35,6 +35,7 @@
<module>dinky-alert-wechat</module>
<module>dinky-alert-feishu</module>
<module>dinky-alert-email</module>
<module>dinky-alert-sms</module>
</modules>
</project>
......@@ -218,6 +218,14 @@
<include>dinky-alert-feishu-${project.version}.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.parent.basedir}/dinky-alert/dinky-alert-sms/target
</directory>
<outputDirectory>lib</outputDirectory>
<includes>
<include>dinky-alert-sms-${project.version}.jar</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.parent.basedir}/dinky-alert/dinky-alert-wechat/target
</directory>
......
......@@ -54,6 +54,11 @@
<artifactId>dinky-alert-feishu</artifactId>
<scope>${scope.runtime}</scope>
</dependency>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-alert-sms</artifactId>
<scope>${scope.runtime}</scope>
</dependency>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-alert-email</artifactId>
......
......@@ -24,17 +24,19 @@ import React from "react";
type ShowLogBtnProps = {
onClick: () => void;
disabled?: boolean;
}
export const ShowLogBtn: React.FC<ShowLogBtnProps> = ( props) => {
const {onClick} = props;
const {onClick,disabled=false} = props;
return <>
<Button
className={"options-button"}
title={l("button.showLog")}
disabled={disabled}
icon={<ShowLogIcon/>}
onClick={() => onClick()}
/>
</>
}
\ No newline at end of file
}
......@@ -16,11 +16,11 @@
*/
import Icon from "@ant-design/icons";
import Icon from '@ant-design/icons';
const defaultSvgSize = "100%";
const defaultSvgSize = '100%';
const style = {overflow: "hidden"};
const style = {overflow: 'hidden'};
export const DingTalkSvg = (props: any) => {
const size = props.size || defaultSvgSize;
......@@ -117,6 +117,52 @@ export const EmailSvg = (props: any) => {
};
export const SmsSvg = (props: any) => {
const size = props.size || defaultSvgSize;
return <>
<Icon style={style} component={
() => (
<svg className="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"
width={size} height={size}>
<path
d="M102.4 143.36h368.64c12.288 0 20.48 8.192 20.48 20.48v696.32c0 12.288-8.192 20.48-20.48 20.48H102.4c-12.288 0-20.48-8.192-20.48-20.48V163.84c0-12.288 8.192-20.48 20.48-20.48z"
fill="#FFFFFF" ></path>
<path
d="M491.52 921.6H81.92c-22.528 0-40.96-18.432-40.96-40.96V143.36c0-22.528 18.432-40.96 40.96-40.96h409.6c22.528 0 40.96 18.432 40.96 40.96v737.28c0 22.528-18.432 40.96-40.96 40.96zM81.92 143.36v737.28h409.6V143.36H81.92z"
fill="#13173C" ></path>
<path d="M102.4 204.8h368.64v552.96H102.4z" fill="#579AFF" ></path>
<path d="M286.72 819.2m-40.96 0a40.96 40.96 0 1 0 81.92 0 40.96 40.96 0 1 0-81.92 0Z" fill="#C5C5C5"
></path>
<path
d="M194.56 163.84h102.4c6.144 0 10.24 4.096 10.24 10.24s-4.096 10.24-10.24 10.24h-102.4c-6.144 0-10.24-4.096-10.24-10.24s4.096-10.24 10.24-10.24zM337.92 163.84h20.48c6.144 0 10.24 4.096 10.24 10.24s-4.096 10.24-10.24 10.24h-20.48c-6.144 0-10.24-4.096-10.24-10.24s4.096-10.24 10.24-10.24z"
fill="#C5C5C5" ></path>
<path
d="M450.56 368.64h491.52v325.632h-178.176c-8.192 0-16.384 6.144-24.576 10.24l-102.4 75.776 2.048-63.488c0-12.288-10.24-22.528-22.528-22.528h-169.984V368.64h4.096z"
fill="#8DCC4A" ></path>
<path
d="M616.448 839.68c-4.096 0-6.144 0-8.192-2.048-6.144-4.096-12.288-10.24-12.288-18.432v-83.968H430.08c-12.288 0-20.48-8.192-20.48-20.48V348.16c0-12.288 8.192-20.48 20.48-20.48h532.48c12.288 0 20.48 8.192 20.48 20.48v366.592c0 12.288-8.192 20.48-20.48 20.48h-198.656l-135.168 100.352c-4.096 2.048-8.192 4.096-12.288 4.096zM450.56 694.272h165.888c12.288 0 20.48 8.192 20.48 20.48V778.24l108.544-79.872c4.096-2.048 8.192-4.096 12.288-4.096h184.32V368.64H450.56v325.632z"
fill="#13173C" ></path>
<path d="M593.92 512m-40.96 0a40.96 40.96 0 1 0 81.92 0 40.96 40.96 0 1 0-81.92 0Z" fill="#FFFFFF"
></path>
<path d="M798.72 512m-40.96 0a40.96 40.96 0 1 0 81.92 0 40.96 40.96 0 1 0-81.92 0Z" fill="#FFFFFF"
></path>
<path
d="M174.08 286.72h163.84c16.384 0 30.72 14.336 30.72 30.72s-14.336 30.72-30.72 30.72h-163.84c-16.384 0-30.72-14.336-30.72-30.72S157.696 286.72 174.08 286.72z"
fill="#FFFFFF" ></path>
<path
d="M174.08 430.08h61.44c16.384 0 30.72 14.336 30.72 30.72s-14.336 30.72-30.72 30.72h-61.44c-16.384 0-30.72-14.336-30.72-30.72S157.696 430.08 174.08 430.08z"
fill="#FFFFFF" ></path>
</svg>
)
}/>
</>;
};
/**
* random rgb color
*/
......
......@@ -221,16 +221,17 @@ export default {
'rc.ai.create': 'Create Alert Instance',
'rc.ai.modify': 'Modify Alert Instance',
'rc.ai.deleteConfirm': 'Are you sure to delete the selected Alert Instance? ',
'rc.ai.dingTalk': 'DingTalk Config',
'rc.ai.email': 'Email Config',
'rc.ai.feishu': 'FeiShu Config',
'rc.ai.wechat': 'WeChat Config',
'rc.ai.dingTalk': 'DingTalk',
'rc.ai.email': 'Email',
'rc.ai.feishu': 'FeiShu',
'rc.ai.wechat': 'WeChat',
'rc.ai.sms': 'Sms',
'rc.ai.webhookPleaseHolder': 'please enter webhook url',
'rc.ai.keywordPleaseHolder': 'please enter keyword',
'rc.ai.secretPleaseHolder': 'please enter secret',
'rc.ai.proxyPleaseHolder': 'please enter proxy',
'rc.ai.portPleaseHolder': 'please enter port',
'rc.ai.userPleaseHolder': 'please enter user',
'rc.ai.proxyPleaseHolder': 'enter proxy',
'rc.ai.portPleaseHolder': 'enter port',
'rc.ai.userPleaseHolder': 'enter user',
'rc.ai.atUsersPleaseHolder': 'Please enter the user ID (user ID of FeiShu background is required), separated by multiple commas!',
'rc.ai.passwordPleaseHolder': 'please enter password',
'rc.ai.atMobilesPleaseHolder': 'Please enter the members that need @, multiple use, separated by numbers',
......@@ -283,6 +284,62 @@ export default {
'rc.ai.table': 'Table',
'rc.ai.attachment': 'Attachment',
'rc.ai.tableAttachment': 'Table And Attachment',
'rc.ai.manufacturers': 'SMS manufacturers',
'rc.ai.manufacturersPleaseHolder': 'Please select a SMS manufacturer',
'rc.ai.signature': 'SMS signature',
'rc.ai.signaturePleaseHolder': 'Please enter the SMS signature',
'rc.ai.accessKeyId': 'AccessKeyId',
'rc.ai.accessKeyIdPleaseHolder': 'Please enter AccessKeyId',
'rc.ai.accessKeySecret': 'AccessKeySecret',
'rc.ai.accessKeySecretPleaseHolder': 'Please enter AccessKeySecret',
'rc.ai.templateId': 'SMS Template ID',
'rc.ai.templateIdPleaseHolder': 'Please enter the SMS template ID',
'rc.ai.templateName': 'Template variable',
'rc.ai.templateNamePleaseHolder': 'Please enter the SMS template variable',
'rc.ai.requestUrl': 'Request URL',
'rc.ai.requestUrlPleaseHolder': 'Please enter the request URL',
'rc.ai.regionId': 'Regional Information',
'rc.ai.regionIdPleaseHolder': 'Please enter the region information',
'rc.ai.action': 'Interface method',
'rc.ai.actionPleaseHolder': 'Please enter the interface method',
'rc.ai.version': 'version number',
'rc.ai.versionPleaseHolder': 'Please enter the version number',
'rc.ai.appKey': 'App Key',
'rc.ai.appKeyPleaseHolder': 'Please enter App Key',
'rc.ai.appSecret': 'App Secret',
'rc.ai.appSecretPleaseHolder': 'Please enter App Secret',
'rc.ai.senders': 'Domestic SMS signature channel number',
'rc.ai.sendersPleaseHolder': 'Please enter the domestic SMS signature channel number',
'rc.ai.url': 'APP access address',
'rc.ai.urlPleaseHolder': 'Please enter the APP access address, the address obtained after creating the SMS application',
'rc.ai.statusCallBack': 'Domestic SMS status report destination',
'rc.ai.statusCallBackPleaseHolder': 'Please enter the recipient of the domestic SMS status report',
'rc.ai.apikey': 'Account unique identifier',
'rc.ai.apikeyPleaseHolder': 'Please enter the unique ID of the account',
'rc.ai.callbackUrl': 'Official callback address',
'rc.ai.callbackUrlPleaseHolder': 'Please enter the official callback address',
'rc.ai.sdkAppId': 'Account unique ID',
'rc.ai.sdkAppIdPleaseHolder': 'Please enter the unique ID of the account',
'rc.ai.connTimeout': 'Request timeout',
'rc.ai.connTimeoutPleaseHolder': 'Please enter the request timeout',
'rc.ai.isSimple': 'Is Simple Mode',
'rc.ai.isSimple.yes': 'Yes',
'rc.ai.isSimple.no': 'No',
'rc.ai.appId': 'App ID',
'rc.ai.appIdPleaseHolder': 'Please enter the application ID',
'rc.ai.baseUrl': 'REST API Base URL',
'rc.ai.baseUrlPleaseHolder': 'Please enter the REST API Base URL',
'rc.ai.secretKey': 'Access key secret',
'rc.ai.secretKeyPleaseHolder': 'Please enter the access key secret',
'rc.ai.mf.alibaba': 'Aliyun SMS',
'rc.ai.mf.huawei': 'Huawei Cloud Domestic SMS',
'rc.ai.mf.yunpian': 'Yunpian SMS',
'rc.ai.mf.tencent': 'Tencent Cloud SMS',
'rc.ai.mf.uni': 'Uni SMS',
'rc.ai.mf.jdcloud': 'JD Cloud Domestic SMS',
'rc.ai.mf.cloopen': 'CloOpen cloud domestic SMS',
'rc.ai.mf.emay': 'Emay Softcom Domestic SMS',
'rc.ai.mf.ctyun': 'Tianyi Cloud SMS',
// alert group
'rc.ag.management': 'Alert Group Management ',
......
......@@ -220,16 +220,18 @@ export default {
'rc.ai.create': '创建告警实例',
'rc.ai.modify': '修改告警实例',
'rc.ai.deleteConfirm': '确定删除选中的告警实例吗?',
'rc.ai.dingTalk': '钉钉告警配置',
'rc.ai.email': '邮箱告警配置',
'rc.ai.feishu': '飞书告警配置',
'rc.ai.wechat': '企业微信告警配置',
'rc.ai.choosetype': '请选择告警类型',
'rc.ai.dingTalk': '钉钉',
'rc.ai.email': '邮箱',
'rc.ai.feishu': '飞书',
'rc.ai.wechat': '企业微信',
'rc.ai.sms': '短信',
'rc.ai.webhookPleaseHolder': '请输入 webhook 地址',
'rc.ai.keywordPleaseHolder': '请输入关键词',
'rc.ai.secretPleaseHolder': '请输入 密令',
'rc.ai.proxyPleaseHolder': '请输入代理主机',
'rc.ai.portPleaseHolder': '请输入代理端口',
'rc.ai.userPleaseHolder': '请输入代理用户',
'rc.ai.proxyPleaseHolder': '代理主机',
'rc.ai.portPleaseHolder': '代理端口',
'rc.ai.userPleaseHolder': '代理用户',
'rc.ai.atUsersPleaseHolder': '请输入被@用户ID(需要飞书后台的用户ID),多个逗号隔开!',
'rc.ai.passwordPleaseHolder': '请输入密码',
'rc.ai.atMobilesPleaseHolder': '请输入@手机号 多个使用英文逗号分开 ',
......@@ -282,6 +284,64 @@ export default {
'rc.ai.table': '表格',
'rc.ai.attachment': '附件',
'rc.ai.tableAttachment': '表格和附件',
// sms
'rc.ai.manufacturers': '短信厂商',
'rc.ai.manufacturersPleaseHolder': '请选择短信厂商',
'rc.ai.signature': '短信签名',
'rc.ai.signaturePleaseHolder': '请输入短信签名',
'rc.ai.accessKeyId': 'AccessKeyId',
'rc.ai.accessKeyIdPleaseHolder': '请输入AccessKeyId',
'rc.ai.accessKeySecret': 'AccessKeySecret',
'rc.ai.accessKeySecretPleaseHolder': '请输入AccessKeySecret',
'rc.ai.templateId': '短信模板ID',
'rc.ai.templateIdPleaseHolder': '请输入短信模板ID',
'rc.ai.templateName': '模板变量',
'rc.ai.templateNamePleaseHolder': '请输入短信模板变量',
'rc.ai.requestUrl': '请求地址',
'rc.ai.requestUrlPleaseHolder': '请输入请求地址',
'rc.ai.regionId': '地域信息',
'rc.ai.regionIdPleaseHolder': '请输入地域信息',
'rc.ai.action': '接口方法',
'rc.ai.actionPleaseHolder': '请输入接口方法',
'rc.ai.version': '版本号',
'rc.ai.versionPleaseHolder': '请输入版本号',
'rc.ai.appKey': 'App Key',
'rc.ai.appKeyPleaseHolder': '请输入App Key',
'rc.ai.appSecret': 'App Secret',
'rc.ai.appSecretPleaseHolder': '请输入App Secret',
'rc.ai.senders': '国内短信签名通道号',
'rc.ai.sendersPleaseHolder': '请输入国内短信签名通道号',
'rc.ai.url': 'APP接入地址',
'rc.ai.urlPleaseHolder': '请输入APP接入地址,建立短信应用后获取到的地址',
'rc.ai.statusCallBack': '国内短信状态报告接收地',
'rc.ai.statusCallBackPleaseHolder': '请输入国内短信状态报告接收地址',
'rc.ai.apikey': '账号唯一标识',
'rc.ai.apikeyPleaseHolder': '请输入账号唯一标识',
'rc.ai.callbackUrl': '官方回调地址',
'rc.ai.callbackUrlPleaseHolder': '请输入官方回调地址',
'rc.ai.sdkAppId': '账号唯一标识',
'rc.ai.sdkAppIdPleaseHolder': '请输入账号唯一标识',
'rc.ai.connTimeout': '请求超时时间',
'rc.ai.connTimeoutPleaseHolder': '请输入请求超时时间',
'rc.ai.isSimple': '是否为简易模式',
'rc.ai.isSimple.yes': '是',
'rc.ai.isSimple.no': '否',
'rc.ai.appId': '应用 ID',
'rc.ai.appIdPleaseHolder': '请输入应用 ID',
'rc.ai.baseUrl': 'REST API Base URL',
'rc.ai.baseUrlPleaseHolder': '请输入 REST API Base URL',
'rc.ai.secretKey': '访问键秘钥',
'rc.ai.secretKeyPleaseHolder': '请输入访问键秘钥',
'rc.ai.mf.alibaba': '阿里云短信',
'rc.ai.mf.huawei': '华为云国内短信',
'rc.ai.mf.yunpian': '云片短信',
'rc.ai.mf.tencent': '腾讯云短信',
'rc.ai.mf.uni': '合一短信',
'rc.ai.mf.jdcloud': '京东云国内短信',
'rc.ai.mf.cloopen': '容联云国内短信',
'rc.ai.mf.emay': '亿美软通国内短信',
'rc.ai.mf.ctyun': '天翼云短信',
// alert group
'rc.ag.management': '告警组管理',
......
......@@ -241,12 +241,15 @@ const AlertGroupTableList: React.FC = (props: any) => {
modalVisible={modalVisible}
values={{}}
/>
<AlertGroupForm
onSubmit={handleSubmit}
onCancel={handleCleanState}
modalVisible={updateModalVisible}
values={formValues}
/>
{
( formValues && Object.keys(formValues).length>0) &&
<AlertGroupForm
onSubmit={handleSubmit}
onCancel={handleCleanState}
modalVisible={updateModalVisible}
values={formValues}
/>
}
</PageContainer>
);
......
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, {useEffect, useRef, useState} from 'react';
import {EditTwoTone} from '@ant-design/icons';
import {ActionType} from '@ant-design/pro-table';
import {Button, Descriptions, Modal, Space, Switch, Tag, Tooltip} from 'antd';
import {l} from '@/utils/intl';
import {Alert} from '@/types/RegCenter/data.d';
import {queryList} from '@/services/api';
import {handleRemoveById, updateEnabled} from '@/services/BusinessCrud';
import {ProList} from '@ant-design/pro-components';
import {API_CONSTANTS, PRO_LIST_CARD_OPTIONS, PROTABLE_OPTIONS_PUBLIC, SWITCH_OPTIONS} from '@/services/constants';
import {DangerDeleteIcon} from '@/components/Icons/CustomIcons';
import {getAlertIcon, getJSONData, getSmsType} from '@/pages/RegCenter/Alert/AlertInstance/function';
import DescriptionsItem from 'antd/es/descriptions/Item';
import AlertTypeChoose from '../AlertTypeChoose';
import {CreateBtn} from '@/components/CallBackButton/CreateBtn';
import {createOrModifyAlertInstance, sendTest} from '@/pages/RegCenter/Alert/AlertInstance/service';
const AlertInstanceList: React.FC = () => {
/**
* status
*/
const actionRef = useRef<ActionType>();
const [formValues, setFormValues] = useState<Partial<Alert.AlertInstance>>();
const [addVisible, handleAddVisible] = useState<boolean>(false);
const [updateVisible, handleUpdateVisible] = useState<boolean>(false);
const [alertInstanceList, setAlertInstanceList] = useState<Alert.AlertInstance[]>([]);
const [loading, setLoading] = useState<boolean>(false);
/**
* execute query alert instance list
* set alert instance list
*/
const queryAlertInstanceList = async () => {
await queryList(API_CONSTANTS.ALERT_INSTANCE).then(res => {
setAlertInstanceList(res.data);
});
};
const executeAndCallbackRefresh = async (callback: () => void) => {
setLoading(true);
await callback();
await queryAlertInstanceList();
setLoading(false);
};
/**
* handle delete alert instance
* @param id
*/
const handleDeleteSubmit = async (id: number) => {
Modal.confirm({
title: l('rc.ai.delete'),
content: l('rc.ai.deleteConfirm'),
okText: l('button.confirm'),
cancelText: l('button.cancel'),
onOk: async () => {
await executeAndCallbackRefresh(async () => {
await handleRemoveById(API_CONSTANTS.ALERT_INSTANCE_DELETE, id);
});
}
});
};
/**
* handle enable alert instance
* @param item
*/
const handleEnable = async (item: Alert.AlertInstance) => {
await executeAndCallbackRefresh(async () => {
await updateEnabled(API_CONSTANTS.ALERT_INSTANCE_ENABLE, {id: item.id});
});
};
/**
* query alert instance list
*/
useEffect(() => {
queryAlertInstanceList();
}, [addVisible, updateVisible]);
/**
* render alert instance sub title
* @param item
*/
const renderAlertInstanceSubTitle = (item: Alert.AlertInstance) => {
return (
<Descriptions size={'small'} layout={'vertical'} column={1}>
<DescriptionsItem
className={'hidden-overflow'}
key={item.id}>
<Tooltip key={item.name} title={item.name}>{item.name}</Tooltip>
</DescriptionsItem>
</Descriptions>
);
};
/**
* edit click callback
* @param item
*/
const editClick = (item: Alert.AlertInstance) => {
setFormValues(item);
handleUpdateVisible(!updateVisible);
};
/**
* render alert instance action button
* @param item
*/
const renderAlertInstanceActionButton = (item: Alert.AlertInstance) => {
return [
<Button
className={'options-button'}
key={'AlertInstanceEdit'}
icon={<EditTwoTone/>}
title={l('button.edit')}
onClick={() => editClick(item)}
/>,
<Button
className={'options-button'}
key={'DeleteAlertInstanceIcon'}
icon={<DangerDeleteIcon/>}
onClick={() => handleDeleteSubmit(item.id)}
/>,
];
};
const renderSubType = (item: Alert.AlertInstance) => {
if (JSON.parse(item.params).manufacturers) {
return ` - ${getSmsType(JSON.parse(item.params).manufacturers)}`;
}
};
/**
* render alert instance action button
* @param item
*/
const renderAlertInstanceContent = (item: Alert.AlertInstance) => {
return (
<Space className={'hidden-overflow'}>
<Tag color="#5BD8A6">
{item.type} {renderSubType(item)}
</Tag>
<Switch
key={item.id}
{...SWITCH_OPTIONS()}
checked={item.enabled}
onChange={() => handleEnable(item)}
/>
</Space>
);
};
/**
* render data source
*/
const renderDataSource = alertInstanceList.map((item) => ({
subTitle: renderAlertInstanceSubTitle(item),
actions: renderAlertInstanceActionButton(item),
avatar: getAlertIcon(item.type, 60),
content: renderAlertInstanceContent(item),
}));
/**
* render right tool bar
*/
const renderToolBar = () => {
return () => [
<CreateBtn key={'CreateAlertInstanceBtn'} onClick={() => handleAddVisible(true)}/>
];
};
/**
* click cancel button callback
*/
const cancelHandler = () => {
handleAddVisible(false);
handleUpdateVisible(false);
actionRef.current?.reload();
setFormValues(undefined);
};
/**
* submit form
* @param values
*/
const handleSubmit = async (values: any) => {
const success = await createOrModifyAlertInstance(getJSONData(values));
if (success) {
cancelHandler();
}
};
/**
* test alert msg
* @param values
*/
const handleTestSend = async (values: any) => {
await sendTest(getJSONData(values));
};
/**
* render main list
*/
return <>
{/* alert instance list */}
<ProList<Alert.AlertInstance>
{...PROTABLE_OPTIONS_PUBLIC}
{...PRO_LIST_CARD_OPTIONS as any}
loading={loading}
actionRef={actionRef}
headerTitle={l('rc.ai.management')}
toolBarRender={renderToolBar()}
dataSource={renderDataSource}
/>
{/* added */}
{addVisible && <AlertTypeChoose onTest={handleTestSend} onCancel={cancelHandler} modalVisible={addVisible}
onSubmit={handleSubmit}
values={{}}/>}
{/* modify */}
{updateVisible &&
<AlertTypeChoose onTest={handleTestSend} onCancel={cancelHandler} modalVisible={updateVisible}
onSubmit={handleSubmit}
values={formValues}/>}
</>;
};
export default AlertInstanceList;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import {Radio} from 'antd';
import {l} from '@/utils/intl';
import {
ProForm,
ProFormDigit,
ProFormRadio,
ProFormSwitch,
ProFormText,
ProFormTextArea
} from '@ant-design/pro-components';
import {SWITCH_OPTIONS} from '@/services/constants';
const DingTalk = (props: any) => {
const {values} = props;
return <>
{/* base columns */}
<ProForm.Group>
<ProFormTextArea
width="lg"
allowClear
name="webhook"
label={l('rc.ai.webhook')}
rules={[{required: true, message: l('rc.ai.webhookPleaseHolder')}]}
placeholder={l('rc.ai.webhookPleaseHolder')}
/>
<ProFormTextArea
width="md"
name="keyword"
label={l('rc.ai.keyword')}
placeholder={l('rc.ai.keywordPleaseHolder')}
/>
<ProFormText.Password
width="lg"
allowClear
name="secret"
label={l('rc.ai.secret')}
placeholder={l('rc.ai.secretPleaseHolder')}
/>
{/* advanced columns */}
<ProFormRadio.Group
name="msgtype"
width={'xs'}
label={l('rc.ai.msgtype')}
rules={[{required: true, message: l('rc.ai.msgtypePleaseHolder')}]}
>
<Radio.Group>
<Radio value="markdown">{l('rc.ai.markdown')}</Radio>
<Radio value="text">{l('rc.ai.text')}</Radio>
</Radio.Group>
</ProFormRadio.Group>
</ProForm.Group>
<ProForm.Group>
<ProFormSwitch
width="xs"
name="isEnableProxy"
label={l('rc.ai.isEnableProxy')}
{...SWITCH_OPTIONS()}
/>
<ProFormSwitch
width="xs"
name="isAtAll"
label={l('rc.ai.isAtAll')}
{...SWITCH_OPTIONS()}
/>
<ProFormSwitch
width="xs"
name="enabled"
label={l('global.table.isEnable')}
{...SWITCH_OPTIONS()}
/>
{/* if not Enable At All this group do render */}
{!values.isAtAll &&
<>
<ProFormTextArea
width="xl"
name="atMobiles"
label={l('rc.ai.atMobiles')}
rules={[{required: true, message: l('rc.ai.atMobilesPleaseHolder')}]}
placeholder={l('rc.ai.atMobilesPleaseHolder')}
/>
</>
}
</ProForm.Group>
{/* if Enable Proxy this group do render */}
<ProForm.Group>
{values.isEnableProxy && <>
<ProFormText
width="md"
name="proxy"
label={l('rc.ai.proxy')}
rules={[{required: true, message: l('rc.ai.proxyPleaseHolder')}]}
placeholder={l('rc.ai.proxyPleaseHolder')}
/>
<ProFormDigit
width="lg"
name="port"
label={l('rc.ai.port')}
rules={[{required: true, message: l('rc.ai.portPleaseHolder')}]}
placeholder={l('rc.ai.portPleaseHolder')}
/>
<ProFormText
width="md"
name="user"
label={l('rc.ai.user')}
rules={[{required: true, message: l('rc.ai.userPleaseHolder')}]}
placeholder={l('rc.ai.userPleaseHolder')}
/>
<ProFormText.Password
width={'lg'}
name="password"
label={l('rc.ai.password')}
rules={[{required: true, message: l('rc.ai.passwordPleaseHolder')}]}
placeholder={l('rc.ai.passwordPleaseHolder')}
/>
</>
}
</ProForm.Group>
</>;
};
export default DingTalk;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import {Form, Radio} from 'antd';
import {l} from '@/utils/intl';
import {ProForm, ProFormDigit, ProFormSwitch, ProFormText, ProFormTextArea} from '@ant-design/pro-components';
import {SWITCH_OPTIONS} from '@/services/constants';
const Email = (props: any) => {
const {values} = props;
return <>
<>
{/* base columns */}
<ProForm.Group>
<ProFormText
width="lg"
name="serverHost"
label={l('rc.ai.serverHost')}
rules={[{required: true, message: l('rc.ai.serverHostPleaseHolder')}]}
placeholder={l('rc.ai.serverHostPleaseHolder')}
/>
<ProFormDigit
width="md"
name="serverPort"
label={l('rc.ai.serverPort')}
rules={[{required: true, message: l('rc.ai.serverPortPleaseHolder')}]}
placeholder={l('rc.ai.serverPortPleaseHolder')}
/>
<ProFormTextArea
width="xs"
name="sender"
label={l('rc.ai.sender')}
rules={[{required: true, message: l('rc.ai.senderPleaseHolder')}]}
placeholder={l('rc.ai.senderPleaseHolder')}
/>
<ProFormTextArea
width="md"
name="receivers"
label={l('rc.ai.receivers')}
rules={[{required: true, message: l('rc.ai.receiversPleaseHolder')}]}
placeholder={l('rc.ai.receiversPleaseHolder')}
/>
<ProFormTextArea
width="md"
name="receiverCcs"
label={l('rc.ai.receiverCcs')}
placeholder={l('rc.ai.receiverCcsPleaseHolder')}
/>
</ProForm.Group>
{/* switch */}
<ProForm.Group>
<ProFormSwitch
width="xs"
name="enableSmtpAuth"
label={l('rc.ai.enableSmtpAuth')}
{...SWITCH_OPTIONS()}
/>
<ProFormSwitch
width="xs"
name="starttlsEnable"
label={l('rc.ai.starttlsEnable')}
{...SWITCH_OPTIONS()}
/>
<ProFormSwitch
width="xs"
name="sslEnable"
label={l('rc.ai.sslEnable')}
{...SWITCH_OPTIONS()}
/>
<ProFormSwitch
width="xs"
name="enabled"
label={l('global.table.isEnable')}
{...SWITCH_OPTIONS()}
/>
{/* msgtype */}
<Form.Item
name="msgtype"
label={l('rc.ai.msgtype')}
rules={[{required: true, message: l('rc.ai.msgtypePleaseHolder')}]}
>
<Radio.Group>
<Radio value="text">{l('rc.ai.text')}</Radio>
<Radio value="table">{l('rc.ai.table')}</Radio>
<Radio value="attachment">{l('rc.ai.attachment')}</Radio>
<Radio value="table attachment">{l('rc.ai.tableAttachment')}</Radio>
</Radio.Group>
</Form.Item>
</ProForm.Group>
{/* proxy */}
<ProForm.Group>
{values.enableSmtpAuth &&
<>
<ProFormText
name="User"
width={'md'}
label={l('rc.ai.emailUser')}
rules={[{required: true, message: l('rc.ai.emailUserPleaseHolder')}]}
allowClear placeholder={l('rc.ai.emailUserPleaseHolder')}
/>
<ProFormText.Password
name="Password"
width={'lg'}
label={l('rc.ai.emailPassword')}
rules={[{required: true, message: l('rc.ai.emailPasswordPleaseHolder')}]}
allowClear placeholder={l('rc.ai.emailPasswordPleaseHolder')}
/>
</>}
</ProForm.Group>
<ProForm.Group>
{/* if choose attachment || table attachment , this input is render */}
{(values.msgtype === 'attachment' || values.msgtype === 'table attachment') &&
<ProFormText
name="xls.file.path"
width={'md'}
label={l('rc.ai.xls.file.path')}
placeholder={l('rc.ai.xls.file.pathPleaseHolder')} allowClear
/>}
{/* ssl */}
{(values.sslEnable) &&
<ProFormText
name="smtpSslTrust"
width={'lg'}
label={l('rc.ai.smtpSslTrust')}
rules={[{required: true, message: l('rc.ai.smtpSslTrustPleaseHolder')}]}
placeholder={l('rc.ai.smtpSslTrustPleaseHolder')}
/>
}
</ProForm.Group>
</>
</>;
};
export default Email;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { Radio} from "antd";
import {l} from "@/utils/intl";
import {
ProForm, ProFormDigit,
ProFormRadio,
ProFormSwitch,
ProFormText,
ProFormTextArea
} from "@ant-design/pro-components";
import {SWITCH_OPTIONS} from "@/services/constants";
const FeiShu = (props:any) => {
const {values} = props;
console.log("FeiShu props", props);
/**
* render
*/
return <>
<ProForm.Group>
<ProFormTextArea
width="lg"
allowClear
name="webhook"
label={l("rc.ai.webhook")}
rules={[{required: true, message: l("rc.ai.webhookPleaseHolder")}]}
placeholder={l("rc.ai.webhookPleaseHolder")}
/>
<ProFormTextArea
width="md"
name="keyword"
label={l("rc.ai.keyword")}
placeholder={l("rc.ai.keywordPleaseHolder")}
/>
<ProFormText.Password
width="lg"
allowClear
name="secret"
label={l("rc.ai.secret")}
placeholder={l("rc.ai.secretPleaseHolder")}
/>
<ProFormRadio.Group
name="msgtype"
width={"xs"}
label={l("rc.ai.msgtype")}
rules={[{required: true, message: l("rc.ai.msgtypePleaseHolder")}]}
>
<Radio.Group>
<Radio value='post'>{l('rc.ai.post')}</Radio>
<Radio value='text'>{l('rc.ai.text')}</Radio>
</Radio.Group>
</ProFormRadio.Group>
</ProForm.Group>
{/* advanced columns */}
<ProForm.Group>
<ProFormSwitch
width="xs"
name="isEnableProxy"
label={l("rc.ai.isEnableProxy")}
{...SWITCH_OPTIONS()}
/>
<ProFormSwitch
width="xs"
name="isAtAll"
label={l("rc.ai.isAtAll")}
{...SWITCH_OPTIONS()}
/>
<ProFormSwitch
width="xs"
name="enabled"
label={l("global.table.isEnable")}
{...SWITCH_OPTIONS()}
/>
{/* if not Enable At All this group do render */}
{!values.isAtAll &&
<>
<ProFormTextArea
width="xl"
name="users"
label={l('rc.ai.atUsers')}
rules={[{required: true, message: l('rc.ai.atUsersPleaseHolder')}]}
placeholder={l("rc.ai.atUsersPleaseHolder")}
/>
</>
}
</ProForm.Group>
{/* if Enable Proxy this group do render */}
<ProForm.Group>
{values.isEnableProxy && <>
<ProFormText
width="lg"
name="proxy"
label={l("rc.ai.proxy")}
rules={[{required: true, message: l("rc.ai.proxyPleaseHolder")}]}
placeholder={l("rc.ai.proxyPleaseHolder")}
/>
<ProFormDigit
width="md"
name="port"
label={l("rc.ai.port")}
rules={[{required: true, message: l("rc.ai.portPleaseHolder")}]}
placeholder={l("rc.ai.portPleaseHolder")}
/>
<ProFormText
width="lg"
name="user"
label={l("rc.ai.user")}
rules={[{required: true, message: l("rc.ai.userPleaseHolder")}]}
placeholder={l("rc.ai.userPleaseHolder")}
/>
<ProFormText.Password
width={"md"}
name="password"
label={l("rc.ai.password")}
rules={[{required: true, message: l("rc.ai.passwordPleaseHolder")}]}
placeholder={l("rc.ai.passwordPleaseHolder")}
/>
</>
}
</ProForm.Group>
</>
};
export default FeiShu;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, {useCallback} from 'react';
import {l} from '@/utils/intl';
import {ProForm, ProFormSelect, ProFormSwitch} from '@ant-design/pro-components';
import {SWITCH_OPTIONS} from '@/services/constants';
import {
renderAlibabaSmsForm,
renderCloopenSmsForm,
renderCtyunForm,
renderEmaySmsForm,
renderHuaWeiSmsForm,
renderJDSmsForm,
renderTencentSmsForm,
renderUniSmsForm,
renderYunpianSmsForm
} from '@/pages/RegCenter/Alert/AlertInstance/components/AlertTypeChoose/InstanceForm/Sms/function';
import {MANU_FACTURERS, SMS_TYPE} from '@/pages/RegCenter/Alert/AlertInstance/constans';
const Sms = (props: any) => {
const {values} = props;
/**
* render form by sms type
*/
const renderFormBySmsType = useCallback((smsType: number) => {
switch (smsType) {
case SMS_TYPE.ALIBABA:
return renderAlibabaSmsForm();
case SMS_TYPE.HUAWEI:
return renderHuaWeiSmsForm();
case SMS_TYPE.YUNPIAN:
return renderYunpianSmsForm();
case SMS_TYPE.TENCENT:
return renderTencentSmsForm();
case SMS_TYPE.UNI:
return renderUniSmsForm();
case SMS_TYPE.JDCLOUD:
return renderJDSmsForm();
case SMS_TYPE.CLOOPEN:
return renderCloopenSmsForm();
case SMS_TYPE.EMAY:
return renderEmaySmsForm();
case SMS_TYPE.CTYUN:
return renderCtyunForm();
default:
return undefined;
}
}, [values.manufacturers]);
/**
* render
*/
return <>
<ProForm.Group>
<ProFormSelect
name="manufacturers"
label={l('rc.ai.manufacturers')}
width={'md'}
options={MANU_FACTURERS}
rules={[{required: true, message: l('rc.ai.manufacturersPleaseHolder')}]}
placeholder={l('rc.ai.manufacturersPleaseHolder')}
/>
<ProFormSwitch
name="enabled"
label={l('global.table.isEnable')}
{...SWITCH_OPTIONS()}
/>
</ProForm.Group>
<ProForm.Group>
{renderFormBySmsType(values.manufacturers)}
</ProForm.Group>
</>;
};
export default Sms;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from "react";
import {Radio} from "antd";
import {l} from "@/utils/intl";
import {
ProForm, ProFormDigit,
ProFormRadio,
ProFormSwitch,
ProFormText,
ProFormTextArea
} from "@ant-design/pro-components";
import {SWITCH_OPTIONS} from "@/services/constants";
const WeChat = (props:any) => {
const {values} = props;
/**
* render
*/
return <>
<ProForm.Group>
<ProFormRadio.Group
name="msgtype"
label={l("rc.ai.msgtype")}
rules={[{required: true, message: l("rc.ai.msgtypePleaseHolder")}]}
>
<Radio.Group>
<Radio value="markdown">{l("rc.ai.markdown")}</Radio>
<Radio value="text">{l("rc.ai.text")}</Radio>
</Radio.Group>
</ProFormRadio.Group>
<ProFormRadio.Group
name="sendType"
label={l("rc.ai.sendType")}
rules={[{required: true, message: l("rc.ai.sendTypePleaseHolder")}]}
>
<Radio.Group>
<Radio value="app">{l("rc.ai.sendType.app")}</Radio>
<Radio value="wechat">{l("rc.ai.sendType.wechat")}</Radio>
</Radio.Group>
</ProFormRadio.Group>
<ProFormSwitch
name="enabled"
label={l("global.table.isEnable")}
{...SWITCH_OPTIONS()}
/>
{(values.sendType === "wechat") &&
// if sendType is wechat render this switch group
<ProFormSwitch
name="isAtAll"
label={l("rc.ai.isAtAll")}
{...SWITCH_OPTIONS()}
/>
}
</ProForm.Group>
<ProForm.Group>
{(values.sendType === "wechat") ?
// if sendType is wechat
<>
<ProFormTextArea
width="xl"
allowClear
name="webhook"
label={l("rc.ai.webhook")}
rules={[{required: true, message: l("rc.ai.webhookPleaseHolder")}]}
placeholder={l("rc.ai.webhookPleaseHolder")}
/>
<ProFormTextArea
width="sm"
name="keyword"
label={l("rc.ai.keyword")}
placeholder={l("rc.ai.keywordPleaseHolder")}
/>
{/* if not Enable At All this group do render */}
{!values.isAtAll &&
<>
<ProFormTextArea
width="xl"
name="users"
label={l("rc.ai.atUsers")}
rules={[{required: true, message: l("rc.ai.wechatAtUsersPleaseHolder")}]}
placeholder={l("rc.ai.wechatAtUsersPleaseHolder")}
/>
</>
}
</>:
(values.sendType === "app") &&
// if sendType is app
<>
<ProFormText
width="md"
name="corpId"
label={l("rc.ai.corpId")}
rules={[{required: true, message: l("rc.ai.corpIdPleaseHolder")}]}
placeholder={l("rc.ai.corpIdPleaseHolder")}
/>
<ProFormText.Password
width="lg"
name="secret"
label={l("rc.ai.secret")}
rules={[{required: true, message: l("rc.ai.secretPleaseHolder")}]}
placeholder={l("rc.ai.secretPleaseHolder")}
/>
<ProFormDigit
width="md"
name="agentId"
label={l("rc.ai.agentId")}
rules={[{required: true, message: l("rc.ai.agentIdPleaseHolder")}]}
placeholder={l("rc.ai.agentIdPleaseHolder")}
/>
<ProFormText
width="lg"
name="users"
label={l("rc.ai.user")}
rules={[{required: true, message: l("rc.ai.userPleaseHolder")}]}
placeholder={l("rc.ai.userPleaseHolder")}
/>
</>
}
</ProForm.Group>
</>;
};
export default WeChat;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {Alert, ALERT_TYPE} from '@/types/RegCenter/data.d';
import DingTalk from './DingTalk';
import {buildJSONData, getJSONData} from '@/pages/RegCenter/Alert/AlertInstance/function';
import {ProForm, ProFormSelect, ProFormText} from '@ant-design/pro-components';
import React, {useState} from 'react';
import {FormInstance} from 'antd/es/form/hooks/useForm';
import {Values} from 'async-validator';
import {MODAL_FORM_OPTIONS} from '@/services/constants';
import {l} from '@/utils/intl';
import {ALERT_TYPE_LIST_OPTIONS} from '@/pages/RegCenter/Alert/AlertInstance/constans';
import FeiShu from '@/pages/RegCenter/Alert/AlertInstance/components/AlertTypeChoose/InstanceForm/FeiShu';
import WeChat from '@/pages/RegCenter/Alert/AlertInstance/components/AlertTypeChoose/InstanceForm/WeChat';
import Email from '@/pages/RegCenter/Alert/AlertInstance/components/AlertTypeChoose/InstanceForm/Email';
import Sms from '@/pages/RegCenter/Alert/AlertInstance/components/AlertTypeChoose/InstanceForm/Sms';
type InstanceFormProps = {
values: Partial<Alert.AlertInstance>;
form: FormInstance<Values>
}
const InstanceForm: React.FC<InstanceFormProps> = (props) => {
const {values, form} = props;
const [alertType, setAlertType] = useState<string>(values.type || ALERT_TYPE.DINGTALK);
const [data, setData] = useState<any>(
values ? getJSONData(values) : {}
);// 保存表单数据
const renderPreForm = () => {
return <>
<ProFormText
width="lg"
name="name"
label={l('rc.ai.name')}
rules={[{required: true, message: l('rc.ai.namePleaseHolder')}]}
placeholder={l('rc.ai.namePleaseHolder')}
/>
<ProFormSelect
width="md"
name="type"
label={l('rc.ai.type')}
rules={[{required: true, message: l('rc.ai.choosetype')}]}
placeholder={l('rc.ai.choosetype')}
options={ALERT_TYPE_LIST_OPTIONS}
initialValue={alertType}
/>
</>;
};
const renderFormByType = () => {
switch (alertType) {
case ALERT_TYPE.DINGTALK:
return <DingTalk values={getJSONData(data)}/>;
case ALERT_TYPE.FEISHU:
return <FeiShu values={getJSONData(data)}/>;
case ALERT_TYPE.WECHAT:
return <WeChat values={getJSONData(data)}/>;
case ALERT_TYPE.EMAIL:
return <Email values={getJSONData(data)}/>;
case ALERT_TYPE.SMS:
return <Sms values={getJSONData(data)}/>;
}
};
const handleValuesChange = async (changedValues: any) => {
const fields = await form.getFieldsValue();
setData(fields);
if (changedValues.type) {
setAlertType(changedValues.type);
}
};
return <>
<ProForm
{...MODAL_FORM_OPTIONS}
form={form}
submitter={false}
initialValues={getJSONData(values)}
onValuesChange={handleValuesChange}
>
<ProForm.Group>
{renderPreForm()}
{renderFormByType()}
</ProForm.Group>
</ProForm>
</>;
};
export default InstanceForm;
......@@ -16,20 +16,16 @@
*/
import React, {useState} from "react";
import {Card, List, Modal} from "antd";
import {connect} from "umi";
import {l} from "@/utils/intl";
import {Alert, ALERT_CONFIG_LIST, ALERT_TYPE, AlertConfig} from "@/types/RegCenter/data.d";
import {createOrModifyAlertInstance, sendTest} from "@/pages/RegCenter/Alert/AlertInstance/service";
import {AlertStateType} from "@/pages/RegCenter/Alert/AlertInstance/model";
import {getAlertIcon} from "@/pages/RegCenter/Alert/AlertInstance/function";
import {NORMAL_MODAL_OPTIONS} from "@/services/constants";
import DingTalk from "../DingTalk";
import WeChat from "../WeChat";
import FeiShu from "../FeiShu";
import Email from "../Email";
import React, {useEffect} from 'react';
import {Button, Form} from 'antd';
import {l} from '@/utils/intl';
import {Alert} from '@/types/RegCenter/data.d';
import {NORMAL_MODAL_OPTIONS} from '@/services/constants';
import {ModalForm} from '@ant-design/pro-components';
import {FormContextValue} from '@/components/Context/FormContext';
import InstanceForm from '@/pages/RegCenter/Alert/AlertInstance/components/AlertTypeChoose/InstanceForm';
import {buildJSONData, getJSONData} from '@/pages/RegCenter/Alert/AlertInstance/function';
/**
* update form props
......@@ -37,136 +33,87 @@ import Email from "../Email";
type UpdateFormProps = {
onCancel: (flag?: boolean, formVals?: Partial<Alert.AlertInstance>) => void;
onSubmit: (values: Partial<Alert.AlertInstance>) => void;
onTest: (values: Partial<Alert.AlertInstance>) => void;
modalVisible: boolean;
values: Partial<Alert.AlertInstance>;
values: Partial<Alert.AlertInstance> ;
};
const AlertTypeChoose: React.FC<UpdateFormProps> = (props) => {
/**
* state
*/
const [alertType, setAlertType] = useState<string>();
/**
* extract props
*/
const {
onSubmit: handleUpdate,
onCancel: handleChooseModalVisible,
onSubmit: handleSubmit,
onCancel: handleCancelVisible,
onTest: handleTest,
modalVisible,
values
} = props;
/**
* choose one type
* @param item
* init form
*/
const chooseAlertType = (item: AlertConfig) => {
setAlertType(item.type);
};
const [form] = Form.useForm();
/**
* submit form
* @param value
*/
const onSubmit = async (value: any) => {
const success = await createOrModifyAlertInstance(value);
if (success) {
handleChooseModalVisible();
setAlertType(undefined);
handleUpdate(value);
}
};
/**
* test alert msg
* @param value
* init form context
*/
const onTest = async (value: any) => {
await sendTest(value);
};
const formContext = React.useMemo<FormContextValue>(() => ({
resetForm: () => form.resetFields(), // 定义 resetForm 方法
}), [form]);
/**
* cancel choose
*/
const handleCancel = () => {
setAlertType(undefined);
handleChooseModalVisible();
handleCancelVisible();
formContext.resetForm();
};
/**
* render card item
* @param item
* when modalVisible or values changed, set form values
*/
const renderCardItem = (item: AlertConfig) => {
return (
<List.Item onClick={() => {
chooseAlertType(item);
}}>
<Card>{getAlertIcon(item.type)}</Card>
</List.Item>
);
useEffect(() => {
form.setFieldsValue(getJSONData(values));
}, [modalVisible, values, form]);
const testSend = async () => {
const validateFields = await form.validateFields();
const data = buildJSONData(values, validateFields);
await handleTest(data);
};
/**
* get alert type
* @param assertsType
*/
const getAlertType = (assertsType: string) => {
return values?.type === assertsType || alertType === assertsType;
};
/**
* card list
*/
const renderChooseTypesCardList = () => {
return <>
<List
grid={{gutter: 24, column: 4}}
dataSource={ALERT_CONFIG_LIST}
renderItem={(item: AlertConfig) => renderCardItem(item)}
/>
</>;
const submit = async () => {
const validateFields = await form.validateFields();
const data = buildJSONData(values, validateFields);
await handleSubmit(data);
handleCancel();
};
/**
* choose modal props
*/
const chooseProps = {
onCancel: handleCancel,
modalVisible: modalVisible,
values: values,
onSubmit: (value: any) => onSubmit(value),
onTest: (value: any) => onTest(value)
const renderFooter = () => {
return [
<Button key={'AlertCancel'} onClick={handleCancel}>{l('button.cancel')}</Button>,
<Button key={'AlertTest'} type="primary" onClick={testSend}>{l('button.test')}</Button>,
<Button key={'AlertFinish'} type="primary" onClick={submit}>{l('button.finish')}</Button>,
];
};
return (
<>
<Modal
{...NORMAL_MODAL_OPTIONS}
title={values?.id ? l("rc.ai.modify") : l("rc.ai.create")}
open={modalVisible}
onCancel={handleCancel}
footer={null}
>
{/* render card list*/}
{(!alertType && !values?.id) && renderChooseTypesCardList()}
{/* Renders the alert component form based on the selected alert type */}
{getAlertType(ALERT_TYPE.DINGTALK) && <DingTalk{...chooseProps}/>}
{getAlertType(ALERT_TYPE.WECHAT) && <WeChat{...chooseProps}/>}
{getAlertType(ALERT_TYPE.FEISHU) && <FeiShu{...chooseProps}/>}
{getAlertType(ALERT_TYPE.EMAIL) && <Email{...chooseProps}/>}
</Modal>
</>
);
return <>
<ModalForm
{...NORMAL_MODAL_OPTIONS}
title={values?.id ? l('rc.ai.modify') : l('rc.ai.create')}
open={modalVisible}
form={form}
modalProps={{onCancel: handleCancel,...NORMAL_MODAL_OPTIONS}}
submitter={{render: () => [...renderFooter()]}}
>
<InstanceForm form={form} values={values}/>
</ModalForm>
</>;
};
export default connect(({Alert}: { Alert: AlertStateType }) => ({
instance: Alert.instance,
}))(AlertTypeChoose);
export default AlertTypeChoose;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, {useState} from "react";
import {Button, Divider, Form, Radio, Space} from "antd";
import {l} from "@/utils/intl";
import {Alert, ALERT_TYPE} from "@/types/RegCenter/data.d";
import {buildJSONData, getJSONData} from "@/pages/RegCenter/Alert/AlertInstance/function";
import {
ModalForm,
ProForm, ProFormDigit, ProFormRadio,
ProFormSwitch,
ProFormText,
ProFormTextArea
} from "@ant-design/pro-components";
import {MODAL_FORM_STYLE, SWITCH_OPTIONS} from "@/services/constants";
import {AlertInstanceFormProps} from "@/pages/RegCenter/Alert/AlertInstance/constans";
const DingTalk: React.FC<AlertInstanceFormProps> = (props) => {
/**
* status of form
*/
const [form] = Form.useForm();
const [formVals, setFormVals] = useState<Partial<Alert.AlertInstance>>({
id: props.values?.id,
name: props.values?.name,
type: ALERT_TYPE.DINGTALK,
params: props.values?.params,
enabled: props.values?.enabled,
});
/**
* extract props
*/
const {
onSubmit: handleSubmit,
onCancel: handleModalVisible,
onTest: handleTest,
modalVisible,
} = props;
/**
* on values change
* @param change
*/
const onValuesChange = (change: any) => {
setFormVals({...formVals, ...change});
};
/**
* send test msg to dingtalk
*/
const sendTestForm = async () => {
const fieldsValue = await form.validateFields();
setFormVals(buildJSONData(formVals, fieldsValue));
handleTest(buildJSONData(formVals, fieldsValue));
};
/**
* submit form data
*/
const submitForm = async () => {
const fieldsValue = await form.validateFields();
setFormVals(buildJSONData(formVals, fieldsValue));
handleSubmit(buildJSONData(formVals, fieldsValue));
};
/**
* render dingtalk form
* @param vals
*/
const renderDingTalkForm = (vals: any) => {
return (
<>
<Divider>{l("rc.ai.dingTalk")}</Divider>
{/* base columns */}
<ProForm.Group>
<ProFormText
width="md"
name="name"
label={l("rc.ai.name")}
rules={[{required: true, message: l("rc.ai.namePleaseHolder")}]}
placeholder={l("rc.ai.namePleaseHolder")}
/>
<ProFormText
width="md"
name="keyword"
label={l("rc.ai.keyword")}
placeholder={l("rc.ai.keywordPleaseHolder")}
/>
<ProFormTextArea
width="md"
allowClear
name="webhook"
label={l("rc.ai.webhook")}
rules={[{required: true, message: l("rc.ai.webhookPleaseHolder")}]}
placeholder={l("rc.ai.webhookPleaseHolder")}
/>
<ProFormText.Password
width="md"
allowClear
name="secret"
label={l("rc.ai.secret")}
placeholder={l("rc.ai.secretPleaseHolder")}
/>
</ProForm.Group>
{/* advanced columns */}
<ProForm.Group>
<ProFormRadio.Group
name="msgtype"
width={"xs"}
label={l("rc.ai.msgtype")}
rules={[{required: true, message: l("rc.ai.msgtypePleaseHolder")}]}
>
<Radio.Group>
<Radio value="markdown">{l("rc.ai.markdown")}</Radio>
<Radio value="text">{l("rc.ai.text")}</Radio>
</Radio.Group>
</ProFormRadio.Group>
<ProFormSwitch
width="xs"
name="isEnableProxy"
label={l("rc.ai.isEnableProxy")}
{...SWITCH_OPTIONS()}
/>
<ProFormSwitch
width="xs"
name="isAtAll"
label={l("rc.ai.isAtAll")}
{...SWITCH_OPTIONS()}
/>
<ProFormSwitch
width="xs"
name="enabled"
label={l("global.table.isEnable")}
{...SWITCH_OPTIONS()}
/>
</ProForm.Group>
{/* if Enable Proxy this group do render */}
<ProForm.Group>
{vals.isEnableProxy && <>
<ProFormText
width="md"
name="proxy"
label={l("rc.ai.proxy")}
rules={[{required: true, message: l("rc.ai.proxyPleaseHolder")}]}
placeholder={l("rc.ai.proxyPleaseHolder")}
/>
<ProFormDigit
width="md"
name="port"
label={l("rc.ai.port")}
rules={[{required: true, message: l("rc.ai.portPleaseHolder")}]}
placeholder={l("rc.ai.portPleaseHolder")}
/>
<ProFormText
width="md"
name="user"
label={l("rc.ai.user")}
rules={[{required: true, message: l("rc.ai.userPleaseHolder")}]}
placeholder={l("rc.ai.userPleaseHolder")}
/>
<ProFormText.Password
width={"md"}
name="password"
label={l("rc.ai.password")}
rules={[{required: true, message: l("rc.ai.passwordPleaseHolder")}]}
placeholder={l("rc.ai.passwordPleaseHolder")}
/>
</>
}
</ProForm.Group>
{/* if not Enable At All this group do render */}
<ProForm.Group>
{!vals.isAtAll &&
<>
<ProFormTextArea
width="md"
name="atMobiles"
label={l("rc.ai.atMobiles")}
rules={[{required: true, message: l("rc.ai.atMobilesPleaseHolder")}]}
placeholder={l("rc.ai.atMobilesPleaseHolder")}
/>
</>
}
</ProForm.Group>
</>
);
};
const renderFooter = () => {
return [
<Button key={"AlertCancel"} onClick={() => handleModalVisible(false)}>{l("button.cancel")}</Button>,
<Button key={"AlertTest"} type="primary" onClick={() => sendTestForm()}>{l("button.test")}</Button>,
<Button key={"AlertFinish"} type="primary" onClick={() => submitForm()}>{l("button.finish")}</Button>,
];
};
return (
<Space>
<ModalForm<Alert.AlertInstance>
{...MODAL_FORM_STYLE}
title={formVals.id ? l("rc.ai.modify") : l("rc.ai.create")}
open={modalVisible}
submitter={{render: () => [...renderFooter()]}}
>
<ProForm
form={form}
initialValues={getJSONData(formVals)}
onValuesChange={onValuesChange}
submitter={false}
>
{renderDingTalkForm(getJSONData(formVals))}
</ProForm>
</ModalForm>
</Space>
);
};
export default DingTalk;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, {useState} from "react";
import {Button, Divider, Form, Radio, Space} from "antd";
import {l} from "@/utils/intl";
import {Alert, ALERT_TYPE} from "@/types/RegCenter/data.d";
import {buildJSONData, getJSONData} from "@/pages/RegCenter/Alert/AlertInstance/function";
import {
ModalForm,
ProForm,
ProFormDigit, ProFormSwitch,
ProFormText,
ProFormTextArea
} from "@ant-design/pro-components";
import {MODAL_FORM_STYLE, SWITCH_OPTIONS} from "@/services/constants";
import {AlertInstanceFormProps} from "@/pages/RegCenter/Alert/AlertInstance/constans";
const Email: React.FC<AlertInstanceFormProps> = (props) => {
/**
* state
*/
const [form] = Form.useForm();
const [formVals, setFormVals] = useState<Partial<Alert.AlertInstance>>({
id: props.values?.id,
name: props.values?.name,
type: ALERT_TYPE.EMAIL,
params: props.values?.params,
enabled: props.values?.enabled,
});
/**
* extract props
*/
const {
onSubmit: handleSubmit,
onCancel: handleModalVisible,
onTest: handleTest,
modalVisible,
} = props;
/**
* values change callback
* @param change
*/
const onValuesChange = (change: any) => {
setFormVals({...formVals, ...change});
};
/**
* send test email callback
*/
const sendTestMsg = async () => {
const fieldsValue = await form.validateFields();
setFormVals(buildJSONData(formVals, fieldsValue));
handleTest(buildJSONData(formVals, fieldsValue));
};
/**
* submit form callback
*/
const submitForm = async () => {
const fieldsValue = await form.validateFields();
setFormVals(buildJSONData(formVals, fieldsValue));
handleSubmit(buildJSONData(formVals, fieldsValue));
};
/**
* render email content
* @param vals
*/
const renderEmailForm = (vals: any) => {
return (
<>
<Divider>{l("rc.ai.email")}</Divider>
{/* base columns */}
<ProForm.Group>
<ProFormText
width="md"
name="name"
label={l("rc.ai.name")}
rules={[{required: true, message: l("rc.ai.namePleaseHolder")}]}
placeholder={l("rc.ai.namePleaseHolder")}
/>
<ProFormText
width="md"
name="serverHost"
label={l("rc.ai.serverHost")}
rules={[{required: true, message: l("rc.ai.serverHostPleaseHolder")}]}
placeholder={l("rc.ai.serverHostPleaseHolder")}
/>
<ProFormDigit
width="md"
name="serverPort"
label={l("rc.ai.serverPort")}
rules={[{required: true, message: l("rc.ai.serverPortPleaseHolder")}]}
placeholder={l("rc.ai.serverPortPleaseHolder")}
/>
<ProFormText
width="md"
name="sender"
label={l("rc.ai.sender")}
rules={[{required: true, message: l("rc.ai.senderPleaseHolder")}]}
placeholder={l("rc.ai.senderPleaseHolder")}
/>
<ProFormTextArea
width="md"
name="receivers"
label={l("rc.ai.receivers")}
rules={[{required: true, message: l("rc.ai.receiversPleaseHolder")}]}
placeholder={l("rc.ai.receiversPleaseHolder")}
/>
<ProFormTextArea
width="md"
name="receiverCcs"
label={l("rc.ai.receiverCcs")}
placeholder={l("rc.ai.receiverCcsPleaseHolder")}
/>
</ProForm.Group>
{/* switch */}
<ProForm.Group>
<ProFormSwitch
width="xs"
name="enableSmtpAuth"
label={l("rc.ai.enableSmtpAuth")}
{...SWITCH_OPTIONS()}
/>
<ProFormSwitch
width="xs"
name="starttlsEnable"
label={l("rc.ai.starttlsEnable")}
{...SWITCH_OPTIONS()}
/>
<ProFormSwitch
width="xs"
name="sslEnable"
label={l("rc.ai.sslEnable")}
{...SWITCH_OPTIONS()}
/>
<ProFormSwitch
width="xs"
name="enabled"
label={l("global.table.isEnable")}
{...SWITCH_OPTIONS()}
/>
{/* ssl */}
{(vals.sslEnable) &&
<ProFormText
name="smtpSslTrust"
width={"sm"}
label={l("rc.ai.smtpSslTrust")}
rules={[{required: true, message: l("rc.ai.smtpSslTrustPleaseHolder")}]}
placeholder={l("rc.ai.smtpSslTrustPleaseHolder")}
/>
}
{/* msgtype */}
<Form.Item
name="msgtype"
label={l("rc.ai.msgtype")}
rules={[{required: true, message: l("rc.ai.msgtypePleaseHolder")}]}
>
<Radio.Group>
<Radio value="text">{l("rc.ai.text")}</Radio>
<Radio value="table">{l("rc.ai.table")}</Radio>
<Radio value="attachment">{l("rc.ai.attachment")}</Radio>
<Radio value="table attachment">{l("rc.ai.tableAttachment")}</Radio>
</Radio.Group>
</Form.Item>
{/* if choose attachment || table attachment , this input is render */}
{(vals.msgtype === "attachment" || vals.msgtype === "table attachment") &&
<ProFormText
name="xls.file.path"
width={"md"}
label={l("rc.ai.xls.file.path")}
placeholder={l("rc.ai.xls.file.pathPleaseHolder")} allowClear
/>}
</ProForm.Group>
{/* proxy */}
<ProForm.Group>
{vals.enableSmtpAuth &&
<>
<ProFormText
name="User"
width={"md"}
label={l("rc.ai.emailUser")}
rules={[{required: true, message: l("rc.ai.emailUserPleaseHolder")}]}
allowClear placeholder={l("rc.ai.emailUserPleaseHolder")}
/>
<ProFormText.Password
name="Password"
width={"md"}
label={l("rc.ai.emailPassword")}
rules={[{required: true, message: l("rc.ai.emailPasswordPleaseHolder")}]}
allowClear placeholder={l("rc.ai.emailPasswordPleaseHolder")}
/>
</>}
</ProForm.Group>
</>
);
};
/**
* render footer button
*/
const renderFooter = () => {
return [
<Button key={"AlertCancel"} onClick={() => handleModalVisible(false)}>{l("button.cancel")}</Button>,
<Button key={"AlertTest"} type="primary" onClick={() => sendTestMsg()}>{l("button.test")}</Button>,
<Button key={"AlertFinish"} type="primary" onClick={() => submitForm()}>{l("button.finish")}</Button>,
];
};
return (
<Space>
<ModalForm<Alert.AlertInstance>
{...MODAL_FORM_STYLE}
title={formVals.id ? l("rc.ai.modify") : l("rc.ai.create")}
open={modalVisible}
submitter={{render: () => [...renderFooter()]}}
>
<ProForm
form={form}
initialValues={getJSONData(formVals)}
onValuesChange={onValuesChange}
submitter={false}
>
{renderEmailForm(getJSONData(formVals))}
</ProForm>
</ModalForm>
</Space>
);
};
export default Email;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, {useState} from 'react';
import {Button, Divider, Form, Radio, Space} from "antd";
import {l} from "@/utils/intl";
import {Alert, ALERT_TYPE} from "@/types/RegCenter/data.d";
import {buildJSONData, getJSONData} from "@/pages/RegCenter/Alert/AlertInstance/function";
import {
ModalForm,
ProForm, ProFormDigit,
ProFormRadio,
ProFormSwitch,
ProFormText,
ProFormTextArea
} from "@ant-design/pro-components";
import {MODAL_FORM_STYLE, SWITCH_OPTIONS} from "@/services/constants";
import {AlertInstanceFormProps} from "@/pages/RegCenter/Alert/AlertInstance/constans";
const FeiShu: React.FC<AlertInstanceFormProps> = (props) => {
/**
* status of form
*/
const [form] = Form.useForm();
const [formVals, setFormVals] = useState<Partial<Alert.AlertInstance>>({
id: props.values?.id,
name: props.values?.name,
type: ALERT_TYPE.FEISHU,
params: props.values?.params,
enabled: props.values?.enabled,
});
/**
* extract props
*/
const {
onSubmit: handleSubmit,
onTest: handleTest,
onCancel: handleModalVisible,
modalVisible,
} = props;
/**
* on values change
* @param change
*/
const onValuesChange = (change: any) => {
setFormVals({...formVals, ...change});
};
/**
* submit form
*/
const submitForm = async () => {
const fieldsValue = await form.validateFields();
setFormVals(buildJSONData(formVals, fieldsValue));
handleSubmit(buildJSONData(formVals, fieldsValue));
};
/**
* send test msg
*/
const sendTestMsg = async () => {
const fieldsValue = await form.getFieldsValue();
setFormVals(buildJSONData(formVals, fieldsValue));
handleTest(buildJSONData(formVals, fieldsValue));
};
/**
* render content
* @param vals
*/
const renderFeiShuForm = (vals: any) => {
return (
<>
<Divider>{l('rc.ai.feishu')}</Divider>
<ProForm.Group>
<ProFormText
width="md"
name="name"
label={l('rc.ai.name')}
rules={[{required: true, message: l('rc.ai.namePleaseHolder')}]}
placeholder={l("rc.ai.namePleaseHolder")}
/>
<ProFormText
width="md"
name="keyword"
label={l("rc.ai.keyword")}
placeholder={l("rc.ai.keywordPleaseHolder")}
/>
<ProFormTextArea
width="md"
allowClear
name="webhook"
label={l("rc.ai.webhook")}
rules={[{required: true, message: l("rc.ai.webhookPleaseHolder")}]}
placeholder={l("rc.ai.webhookPleaseHolder")}
/>
<ProFormText.Password
width="md"
allowClear
name="secret"
label={l("rc.ai.secret")}
placeholder={l("rc.ai.secretPleaseHolder")}
/>
</ProForm.Group>
{/* advanced columns */}
<ProForm.Group>
<ProFormRadio.Group
name="msgtype"
width={"xs"}
label={l("rc.ai.msgtype")}
rules={[{required: true, message: l("rc.ai.msgtypePleaseHolder")}]}
>
<Radio.Group>
<Radio value='post'>{l('rc.ai.post')}</Radio>
<Radio value='text'>{l('rc.ai.text')}</Radio>
</Radio.Group>
</ProFormRadio.Group>
<ProFormSwitch
width="xs"
name="isEnableProxy"
label={l("rc.ai.isEnableProxy")}
{...SWITCH_OPTIONS()}
/>
<ProFormSwitch
width="xs"
name="isAtAll"
label={l("rc.ai.isAtAll")}
{...SWITCH_OPTIONS()}
/>
<ProFormSwitch
width="xs"
name="enabled"
label={l("global.table.isEnable")}
{...SWITCH_OPTIONS()}
/>
</ProForm.Group>
{/* if Enable Proxy this group do render */}
<ProForm.Group>
{vals.isEnableProxy && <>
<ProFormText
width="md"
name="proxy"
label={l("rc.ai.proxy")}
rules={[{required: true, message: l("rc.ai.proxyPleaseHolder")}]}
placeholder={l("rc.ai.proxyPleaseHolder")}
/>
<ProFormDigit
width="md"
name="port"
label={l("rc.ai.port")}
rules={[{required: true, message: l("rc.ai.portPleaseHolder")}]}
placeholder={l("rc.ai.portPleaseHolder")}
/>
<ProFormText
width="md"
name="user"
label={l("rc.ai.user")}
rules={[{required: true, message: l("rc.ai.userPleaseHolder")}]}
placeholder={l("rc.ai.userPleaseHolder")}
/>
<ProFormText.Password
width={"md"}
name="password"
label={l("rc.ai.password")}
rules={[{required: true, message: l("rc.ai.passwordPleaseHolder")}]}
placeholder={l("rc.ai.passwordPleaseHolder")}
/>
</>
}
</ProForm.Group>
{/* if not Enable At All this group do render */}
<ProForm.Group>
{!vals.isAtAll &&
<>
<ProFormTextArea
width="md"
name="users"
label={l('rc.ai.atUsers')}
rules={[{required: true, message: l('rc.ai.atUsersPleaseHolder')}]}
placeholder={l("rc.ai.atUsersPleaseHolder")}
/>
</>
}
</ProForm.Group>
</>
);
};
/**
* render footer button
*/
const renderFooter = () => {
return [
<Button key={"AlertCancel"} onClick={() => handleModalVisible(false)}>{l("button.cancel")}</Button>,
<Button key={"AlertTest"} type="primary" onClick={() => sendTestMsg()}>{l("button.test")}</Button>,
<Button key={"AlertFinish"} type="primary" onClick={() => submitForm()}>{l("button.finish")}</Button>,
];
};
/**
* render
*/
return (
<Space>
<ModalForm<Alert.AlertInstance>
{...MODAL_FORM_STYLE}
title={formVals.id ? l('rc.ai.modify') : l('rc.ai.create')}
open={modalVisible}
submitter={{render: () => [...renderFooter()]}}
>
<ProForm
form={form}
initialValues={getJSONData(formVals)}
onValuesChange={onValuesChange}
submitter={false}
>
{renderFeiShuForm(getJSONData(formVals))}
</ProForm>
</ModalForm>
</Space>
);
};
export default FeiShu;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React, {useState} from "react";
import {Button, Divider, Form, Radio, Space} from "antd";
import {l} from "@/utils/intl";
import {Alert, ALERT_TYPE} from "@/types/RegCenter/data.d";
import {buildJSONData, getJSONData} from "@/pages/RegCenter/Alert/AlertInstance/function";
import {
ModalForm,
ProForm, ProFormDigit,
ProFormRadio,
ProFormSwitch,
ProFormText,
ProFormTextArea
} from "@ant-design/pro-components";
import {MODAL_FORM_STYLE, SWITCH_OPTIONS} from "@/services/constants";
import {AlertInstanceFormProps} from "@/pages/RegCenter/Alert/AlertInstance/constans";
const WeChat: React.FC<AlertInstanceFormProps> = (props) => {
/**
* status of form
*/
const [form] = Form.useForm();
const [formVals, setFormVals] = useState<Partial<Alert.AlertInstance>>({
id: props.values?.id,
name: props.values?.name,
type: ALERT_TYPE.WECHAT,
params: props.values?.params,
enabled: props.values?.enabled,
});
/**
* extract props
*/
const {
onSubmit: handleSubmit,
onCancel: handleModalVisible,
onTest: handleTest,
modalVisible,
} = props;
/**
* on values change
* @param change
*/
const onValuesChange = (change: any) => {
setFormVals({...formVals, ...change});
};
/**
* send test message
*/
const sendTestMsg = async () => {
const fieldsValue = await form.validateFields();
setFormVals(buildJSONData(formVals, fieldsValue));
handleTest(buildJSONData(formVals, fieldsValue));
};
/**
* submit form
*/
const submitForm = async () => {
const fieldsValue = await form.validateFields();
setFormVals(buildJSONData(formVals, fieldsValue));
handleSubmit(buildJSONData(formVals, fieldsValue));
};
/**
* render form
* @param vals
*/
const renderWeChatForm = (vals: any) => {
return (
<>
<Divider>{l("rc.ai.wechat")}</Divider>
<ProForm.Group>
<ProFormText
width="md"
name="name"
label={l("rc.ai.name")}
rules={[{required: true, message: l("rc.ai.namePleaseHolder")}]}
placeholder={l("rc.ai.namePleaseHolder")}
/>
<ProFormRadio.Group
name="msgtype"
label={l("rc.ai.msgtype")}
rules={[{required: true, message: l("rc.ai.msgtypePleaseHolder")}]}
>
<Radio.Group>
<Radio value="markdown">{l("rc.ai.markdown")}</Radio>
<Radio value="text">{l("rc.ai.text")}</Radio>
</Radio.Group>
</ProFormRadio.Group>
<ProForm.Item
name="sendType"
validateTrigger={["onChange", "onBlur"]}
label={l("rc.ai.sendType")}
rules={[{required: true, message: l("rc.ai.sendTypePleaseHolder")}]}
>
<Radio.Group>
<Radio value="app">{l("rc.ai.sendType.app")}</Radio>
<Radio value="wechat">{l("rc.ai.sendType.wechat")}</Radio>
</Radio.Group>
</ProForm.Item>
<ProFormSwitch
name="enabled"
label={l("global.table.isEnable")}
{...SWITCH_OPTIONS()}
/>
{(vals.sendType === "wechat") &&
// if sendType is wechat render this switch group
<ProFormSwitch
name="isAtAll"
label={l("rc.ai.isAtAll")}
{...SWITCH_OPTIONS()}
/>
}
</ProForm.Group>
<ProForm.Group>
{(vals.sendType === "wechat") ?
// if sendType is wechat
<>
<ProFormTextArea
width="md"
allowClear
name="webhook"
label={l("rc.ai.webhook")}
rules={[{required: true, message: l("rc.ai.webhookPleaseHolder")}]}
placeholder={l("rc.ai.webhookPleaseHolder")}
/>
<ProFormText
width="md"
name="keyword"
label={l("rc.ai.keyword")}
placeholder={l("rc.ai.keywordPleaseHolder")}
/>
{/* if not Enable At All this group do render */}
{!vals.isAtAll &&
<>
<ProFormTextArea
width="md"
name="users"
label={l("rc.ai.atUsers")}
rules={[{required: true, message: l("rc.ai.wechatAtUsersPleaseHolder")}]}
placeholder={l("rc.ai.wechatAtUsersPleaseHolder")}
/>
</>
}
</>:
(vals.sendType === "app") &&
// if sendType is app
<>
<ProFormText
width="sm"
name="corpId"
label={l("rc.ai.corpId")}
rules={[{required: true, message: l("rc.ai.corpIdPleaseHolder")}]}
placeholder={l("rc.ai.corpIdPleaseHolder")}
/>
<ProFormText.Password
width="sm"
name="secret"
label={l("rc.ai.secret")}
rules={[{required: true, message: l("rc.ai.secretPleaseHolder")}]}
placeholder={l("rc.ai.secretPleaseHolder")}
/>
<ProFormDigit
width="sm"
name="agentId"
label={l("rc.ai.agentId")}
rules={[{required: true, message: l("rc.ai.agentIdPleaseHolder")}]}
placeholder={l("rc.ai.agentIdPleaseHolder")}
/>
<ProFormTextArea
width="xl"
name="users"
label={l("rc.ai.user")}
rules={[{required: true, message: l("rc.ai.userPleaseHolder")}]}
placeholder={l("rc.ai.userPleaseHolder")}
/>
</>
}
</ProForm.Group>
</>
);
};
/**
* render footer button
*/
const renderFooter = () => {
return [
<Button key={"AlertCancel"} onClick={() => handleModalVisible(false)}>{l("button.cancel")}</Button>,
<Button key={"AlertTest"} type="primary" onClick={() => sendTestMsg()}>{l("button.test")}</Button>,
<Button key={"AlertFinish"} type="primary" onClick={() => submitForm()}>{l("button.finish")}</Button>,
];
};
/**
* render
*/
return (
<Space>
<ModalForm<Alert.AlertInstance>
{...MODAL_FORM_STYLE}
title={formVals.id ? l("rc.ai.modify") : l("rc.ai.create")}
open={modalVisible}
submitter={{render: () => [...renderFooter()]}}
>
<ProForm
form={form}
initialValues={getJSONData(formVals)}
onValuesChange={onValuesChange}
submitter={false}
>
{renderWeChatForm(getJSONData(formVals))}
</ProForm>
</ModalForm>
</Space>
);
};
export default WeChat;
......@@ -16,15 +16,87 @@
*/
import {Alert} from '@/types/RegCenter/data';
import {ALERT_TYPE} from '@/types/RegCenter/data.d';
import {l} from '@/utils/intl';
import {DefaultOptionType} from 'rc-select/es/Select';
/**
* AlertInstanceFormProps
*/
export type AlertInstanceFormProps = {
onCancel: (flag?: boolean) => void;
onSubmit: (values: Partial<Alert.AlertInstance>) => void;
onTest: (values: Partial<Alert.AlertInstance>) => void;
modalVisible: boolean;
values: Partial<Alert.AlertInstance>;
};
export const ALERT_TYPE_LIST_OPTIONS: DefaultOptionType[] = [
{
label: l('rc.ai.dingTalk'),
value: ALERT_TYPE.DINGTALK,
disabled: false,
},
{
label: l('rc.ai.wechat'),
value: ALERT_TYPE.WECHAT,
disabled: false,
},
{
label: l('rc.ai.feishu'),
value: ALERT_TYPE.FEISHU,
disabled: false,
},
{
label: l('rc.ai.email'),
value: ALERT_TYPE.EMAIL,
disabled: false,
},
{
label: l('rc.ai.sms'),
value: ALERT_TYPE.SMS,
disabled: false,
}
];
export const MANU_FACTURERS = [
{
label: l('rc.ai.mf.alibaba'),
value: 1,
},
{
label: l('rc.ai.mf.huawei'),
value: 2,
},
{
label: l('rc.ai.mf.yunpian'),
value: 3,
},
{
label: l('rc.ai.mf.tencent'),
value: 4,
},
{
label: l('rc.ai.mf.uni'),
value: 5,
},
{
label: l('rc.ai.mf.jdcloud'),
value: 6,
},
{
label: l('rc.ai.mf.cloopen'),
value: 7,
},
{
label: l('rc.ai.mf.emay'),
value: 8,
},
{
label: l('rc.ai.mf.ctyun'),
value: 9,
},
];
export enum SMS_TYPE {
ALIBABA = 1,
HUAWEI = 2,
YUNPIAN = 3,
TENCENT = 4,
UNI = 5,
JDCLOUD = 6,
CLOOPEN = 7,
EMAY = 8,
CTYUN = 9,
}
......@@ -17,7 +17,16 @@
import {Alert, ALERT_TYPE} from "@/types/RegCenter/data.d";
import {AlertGroupSvg, DefaultSvg, DingTalkSvg, EmailSvg, FeiShuSvg, WeChatSvg} from "@/components/Icons/AlertIcon";
import {
AlertGroupSvg,
DefaultSvg,
DingTalkSvg,
EmailSvg,
FeiShuSvg,
SmsSvg,
WeChatSvg
} from '@/components/Icons/AlertIcon';
import {MANU_FACTURERS} from '@/pages/RegCenter/Alert/AlertInstance/constans';
/**
* get json data to alert instance
......@@ -46,6 +55,10 @@ export const buildJSONData = (values: Partial<Alert.AlertInstance>, params: any)
newValue.enabled = params.enabled;
delete params.enabled;
}
if (params.type) {
newValue.type = params.type;
delete params.type;
}
let data: string = JSON.stringify(params);
return {...newValue, params: data};
};
......@@ -63,6 +76,8 @@ export const getAlertIcon = (type: string, size?: number) => {
return <WeChatSvg size={size}/>;
case ALERT_TYPE.FEISHU:
return <FeiShuSvg size={size}/>;
case ALERT_TYPE.SMS:
return <SmsSvg size={size}/>;
case ALERT_TYPE.EMAIL:
return <EmailSvg size={size}/>;
case ALERT_TYPE.GROUP:
......@@ -71,3 +86,7 @@ export const getAlertIcon = (type: string, size?: number) => {
return <DefaultSvg size={size}/>;
}
};
export const getSmsType = (type: number) => {
return MANU_FACTURERS.find((item) => item.value === type)?.label;
}
......@@ -16,216 +16,14 @@
*/
import React, {useEffect, useRef, useState} from "react";
import {EditTwoTone, PlusOutlined} from "@ant-design/icons";
import {ActionType} from "@ant-design/pro-table";
import {Button, Descriptions, Modal, Space, Switch, Tag, Tooltip} from "antd";
import {PageContainer} from "@ant-design/pro-layout";
import {l} from "@/utils/intl";
import {Alert} from "@/types/RegCenter/data.d";
import {queryList} from "@/services/api";
import {handleRemoveById, updateEnabled} from "@/services/BusinessCrud";
import {ProList} from "@ant-design/pro-components";
import {API_CONSTANTS, PRO_LIST_CARD_OPTIONS, PROTABLE_OPTIONS_PUBLIC, SWITCH_OPTIONS} from "@/services/constants";
import {DangerDeleteIcon} from "@/components/Icons/CustomIcons";
import {getAlertIcon} from "@/pages/RegCenter/Alert/AlertInstance/function";
import DescriptionsItem from "antd/es/descriptions/Item";
import AlertTypeChoose from "./components/AlertTypeChoose";
import React from 'react';
import AlertInstanceList from '@/pages/RegCenter/Alert/AlertInstance/components/AlertInstanceList';
import {PageContainer} from '@ant-design/pro-components';
const AlertInstanceTableList: React.FC = () => {
/**
* status
*/
const actionRef = useRef<ActionType>();
const [formValues, setFormValues] = useState<Alert.AlertInstance>();
const [modalVisible, handleModalVisible] = useState<boolean>(false);
const [alertInstanceList, setAlertInstanceList] = useState<Alert.AlertInstance[]>([]);
const [loading, setLoading] = useState<boolean>(false);
export default () => {
return <PageContainer title={false}>
<AlertInstanceList/>
</PageContainer>;
}
/**
* execute query alert instance list
* set alert instance list
*/
const queryAlertInstanceList = async () => {
await queryList(API_CONSTANTS.ALERT_INSTANCE).then(res => {
setAlertInstanceList(res.data);
});
};
const executeAndCallbackRefresh = async (callback: () => void) => {
setLoading(true);
await callback();
await queryAlertInstanceList();
setLoading(false);
}
/**
* handle delete alert instance
* @param id
*/
const handleDeleteSubmit = async (id: number) => {
Modal.confirm({
title: l("rc.ai.delete"),
content: l("rc.ai.deleteConfirm"),
okText: l("button.confirm"),
cancelText: l("button.cancel"),
onOk: async () => {
await executeAndCallbackRefresh(async () => {
await handleRemoveById(API_CONSTANTS.ALERT_INSTANCE_DELETE, id);
})
}
});
};
/**
* handle enable alert instance
* @param item
*/
const handleEnable = async (item: Alert.AlertInstance) => {
await executeAndCallbackRefresh(async () => {
await updateEnabled(API_CONSTANTS.ALERT_INSTANCE_ENABLE, {id: item.id});
})
};
/**
* query alert instance list
*/
useEffect(() => {
queryAlertInstanceList();
}, [modalVisible]);
/**
* render alert instance sub title
* @param item
*/
const renderAlertInstanceSubTitle = (item: Alert.AlertInstance) => {
return (
<Descriptions size={"small"} layout={"vertical"} column={1}>
<DescriptionsItem
className={"hidden-overflow"}
key={item.id}>
<Tooltip key={item.name} title={item.name}>{item.name}</Tooltip>
</DescriptionsItem>
</Descriptions>
);
};
/**
* edit click callback
* @param item
*/
const editClick = (item: Alert.AlertInstance) => {
setFormValues(item);
handleModalVisible(!modalVisible);
};
/**
* render alert instance action button
* @param item
*/
const renderAlertInstanceActionButton = (item: Alert.AlertInstance) => {
return [
<Button
className={"options-button"}
key={"AlertInstanceEdit"}
icon={<EditTwoTone/>}
title={l("button.edit")}
onClick={() => editClick(item)}
/>,
<Button
className={"options-button"}
key={"DeleteAlertInstanceIcon"}
icon={<DangerDeleteIcon/>}
onClick={() => handleDeleteSubmit(item.id)}
/>,
];
};
/**
* render alert instance action button
* @param item
*/
const renderAlertInstanceContent = (item: Alert.AlertInstance) => {
return (
<Space className={"hidden-overflow"}>
<Tag color="#5BD8A6">{item.type}</Tag>
<Switch
key={item.id}
{...SWITCH_OPTIONS()}
checked={item.enabled}
onChange={() => handleEnable(item)}
/>
</Space>
);
};
/**
* render data source
*/
const renderDataSource = alertInstanceList.map((item) => ({
subTitle: renderAlertInstanceSubTitle(item),
actions: renderAlertInstanceActionButton(item),
avatar: getAlertIcon(item.type, 60),
content: renderAlertInstanceContent(item),
}));
/**
* render right tool bar
*/
const renderToolBar = () => {
return () => [
<Button key={"CreateAlertInstance"} type="primary" onClick={() => handleModalVisible(true)}>
<PlusOutlined/> {l("button.create")}
</Button>,
];
};
/**
* click cancel button callback
*/
const cancelHandler = () => {
handleModalVisible(!modalVisible);
setFormValues(undefined);
};
/**
* click submit button callback
*/
const chooseSubmitHandler = () => {
actionRef.current?.reloadAndRest?.();
};
/**
* render main list
*/
return (
<PageContainer title={false}>
{/* alert instance list */}
<ProList<Alert.AlertInstance>
{...PROTABLE_OPTIONS_PUBLIC}
{...PRO_LIST_CARD_OPTIONS as any}
loading={loading}
actionRef={actionRef}
headerTitle={l("rc.ai.management")}
toolBarRender={renderToolBar()}
dataSource={renderDataSource}
/>
{/* render choose alert type list */}
<AlertTypeChoose
onCancel={cancelHandler}
modalVisible={modalVisible}
onSubmit={chooseSubmitHandler}
values={formValues}
/>
</PageContainer>
);
};
export default AlertInstanceTableList;
......@@ -21,7 +21,6 @@
import {Modal} from "antd";
import React, {useEffect, useState} from "react";
import {GitProject} from "@/types/RegCenter/data";
import {l} from "@/utils/intl";
import {AutoSteps, BuildMsgData} from "@/pages/RegCenter/GitProject/components/BuildSteps/AutoSteps";
import {JavaSteps, PythonSteps} from "@/pages/RegCenter/GitProject/components/BuildSteps/constants";
import {API_CONSTANTS} from "@/services/constants";
......@@ -34,8 +33,8 @@ import {BuildStepsState} from '@/pages/RegCenter/GitProject/data.d';
* props
*/
type BuildStepsProps = {
onCancel: (flag?: boolean) => void;
modalVisible: boolean;
onCancel: (flag?: boolean) => void
title: string;
values: Partial<GitProject>;
};
......@@ -46,7 +45,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => {
*/
const {
onCancel: handleModalVisible,
modalVisible,
title,
values,
} = props;
let [logList, setLogList] = useState<Record<number, string[]>>({});
......@@ -174,7 +173,7 @@ export const BuildSteps: React.FC<BuildStepsProps> = (props) => {
return <>
<Modal
title={l("rc.gp.build")}
title={title}
width={"85%"}
open={true}
maskClosable={false}
......
......@@ -21,9 +21,7 @@ import React, {useRef, useState} from "react";
import ProTable, {ActionType, ProColumns} from "@ant-design/pro-table";
import {GitProject} from "@/types/RegCenter/data";
import {
getDataByParams,
handleAddOrUpdate, handleData,
handlePutDataByParams,
handleAddOrUpdate, handlePutDataByParams,
handleRemoveById,
updateEnabled
} from "@/services/BusinessCrud";
......@@ -44,9 +42,8 @@ import {
renderBranchesTagColor
} from "@/pages/RegCenter/GitProject/constans";
import {ShowCodeTreeIcon} from "@/components/Icons/CustomIcons";
import {getData, queryList} from "@/services/api";
import {queryList} from "@/services/api";
import {BuildSteps} from "@/pages/RegCenter/GitProject/components/BuildSteps";
import {ShowLog} from "@/pages/RegCenter/GitProject/components/ShowLog";
import {CodeTree} from "@/pages/RegCenter/GitProject/components/CodeTree";
import {CreateBtn} from "@/components/CallBackButton/CreateBtn";
import ProjectModal from "@/pages/RegCenter/GitProject/components/ProjectModal";
......@@ -227,7 +224,7 @@ const ProjectProTable: React.FC = () => {
valueType: "option",
width: "10vw",
render: (text, record) => [
<ShowLogBtn key={`${record.id}_showLog`} onClick={() => handleShowLog(record)}/>,
<ShowLogBtn disabled={record.buildStep === 0} key={`${record.id}_showLog`} onClick={() => handleShowLog(record)}/>,
<Button
key={`${record.id}_code`}
className={"options-button"}
......@@ -301,12 +298,10 @@ const ProjectProTable: React.FC = () => {
modalVisible={updateModalVisible}
values={formValues}/>
{/* build steps modal */}
{buildModalVisible && <BuildSteps onCancel={handleCancel} modalVisible={buildModalVisible}
values={formValues}/>}
{buildModalVisible && <BuildSteps title={l('rc.gp.build')} onCancel={handleCancel} values={formValues}/>}
{/* show build log modal */}
{/*{logModalVisible && <ShowLog modalVisible={logModalVisible} onCancel={handleCancel} values={formValues}/>}*/}
{logModalVisible && <BuildSteps onCancel={handleCancel} modalVisible={buildModalVisible}
values={formValues}/>}
{logModalVisible && <BuildSteps title={l('rc.gp.log')} onCancel={handleCancel} values={formValues}/>}
{/* show code tree modal */}
<CodeTree modalVisible={codeTreeModalVisible} onCancel={handleCancel} values={formValues}/>
</>;
......
/*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
import CodeShow from "@/components/CustomEditor/CodeShow";
import {Modal} from "antd";
import {l} from "@/utils/intl";
import {GitProject} from "@/types/RegCenter/data";
import React, {useEffect} from "react";
import {handleData} from "@/services/BusinessCrud";
import {API_CONSTANTS} from "@/services/constants";
type ShowLogProps = {
onCancel: (flag?: boolean) => void;
modalVisible: boolean;
values: Partial<GitProject>;
};
/**
* code edit props
*/
const CodeEditProps = {
height: "60vh",
width: "100%",
lineNumbers: "on",
language: "java",
};
export const ShowLog: React.FC<ShowLogProps> = (props) => {
/**
* props
*/
const {values, modalVisible, onCancel} = props;
const [log, setLog] = React.useState<string>("");
/**
* query all step logs
* @returns {Promise<void>}
*/
const queryAllStepLogs = async () => {
const result = await handleData(API_CONSTANTS.GIT_PROJECT_BUILD_ALL_LOGS, values.id);
setLog(result);
};
/**
* effect
*/
useEffect(() => {
queryAllStepLogs();
}, []);
/**
* render
*/
return (
<Modal
title={l("rc.gp.log")}
width={"80%"}
open={modalVisible}
onCancel={() => onCancel()}
cancelText={l("button.close")}
okButtonProps={{style: {display: "none"}}}
>
<CodeShow
{...CodeEditProps}
code={log}
showFloatButton={true}
refreshLogCallback={queryAllStepLogs}
/>
</Modal>
);
};
......@@ -48,6 +48,7 @@ export const ALERT_TYPE = {
WECHAT: 'WeChat',
FEISHU: 'FeiShu',
EMAIL: 'Email',
SMS: 'Sms',
GROUP: 'Group',
};
......@@ -59,6 +60,8 @@ export const ALERT_CONFIG_LIST: AlertConfig[] = [{
type: ALERT_TYPE.FEISHU,
}, {
type: ALERT_TYPE.EMAIL,
}, {
type: ALERT_TYPE.SMS,
}
];
......@@ -71,7 +74,7 @@ declare namespace Cluster {
* flink cluster instance
* mainly used for `yarn session` `standalone`
*/
export type ClusterInstance = BaseBeanColumns & {
export type Instance = BaseBeanColumns & {
alias: string,
type: string,
hosts: string,
......@@ -86,7 +89,7 @@ declare namespace Cluster {
* flink cluster config
* mainly used for `projob` `application` `k8s` and start a new session cluster
*/
export type ClusterConfig = BaseBeanColumns & {
export type Config = BaseBeanColumns & {
type: string,
config: any,
configJson: string,
......
......@@ -495,6 +495,11 @@
<artifactId>dinky-alert-feishu</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-alert-sms</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.dinky</groupId>
<artifactId>dinky-alert-email</artifactId>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment