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

[Refactor][admin,web] Refactor alertinstance (#1892)

* refactor alert instance * refactor alert instance dingtalk * refactor alert instance feishu * refactor alert instance wechat * refactor alert instance email * 优化常量 * 优化代码 * 优化代码1 * spotless:apply * change datetime gettype * coding op
parent 4435bfc1
......@@ -26,4 +26,6 @@ public class BaseConstant {
/** default batch insert size */
public static final Integer DEFAULT_BATCH_INSERT_SIZE = 1000;
public static final String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
}
......@@ -25,6 +25,7 @@ import org.dinky.common.result.ProTableResult;
import org.dinky.common.result.Result;
import org.dinky.model.AlertInstance;
import org.dinky.service.AlertInstanceService;
import org.dinky.utils.MessageResolverUtils;
import java.util.List;
......@@ -34,6 +35,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.databind.JsonNode;
......@@ -41,11 +43,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
/**
* AlertInstanceController
*
* @since 2022/2/24 19:54
*/
/** AlertInstanceController */
@Slf4j
@RestController
@RequestMapping("/api/alertInstance")
......@@ -54,51 +52,117 @@ public class AlertInstanceController {
private final AlertInstanceService alertInstanceService;
/** 新增或者更新 */
/**
* saveOrUpdate
*
* @param alertInstance {@link AlertInstance}
* @return {@link Result} of {@link Void}
* @throws Exception {@link Exception}
*/
@PutMapping
public Result<Void> saveOrUpdate(@RequestBody AlertInstance alertInstance) throws Exception {
if (alertInstanceService.saveOrUpdate(alertInstance)) {
AlertPool.remove(alertInstance.getName());
return Result.succeed("新增成功");
return Result.succeed(MessageResolverUtils.getMessage("save.success"));
} else {
return Result.failed("新增失败");
return Result.failed(MessageResolverUtils.getMessage("save.failed"));
}
}
/** 动态查询列表 */
/**
* listAlertInstances
*
* @param para {@link JsonNode}
* @return {@link ProTableResult} of {@link AlertInstance}
*/
@PostMapping
public ProTableResult<AlertInstance> listAlertInstances(@RequestBody JsonNode para) {
return alertInstanceService.selectForProTable(para);
}
/** 批量删除 */
/**
* bactchDelete AlertInstance, this method is {@link Deprecated} and will be removed in the
* future, please use {@link #deleteInstanceById(Integer)} instead.
*
* @param para
* @return
*/
@DeleteMapping
@Deprecated
public Result<Void> deleteMul(@RequestBody JsonNode para) {
return alertInstanceService.deleteAlertInstance(para);
}
/** 获取指定ID的信息 */
/**
* delete AlertInstance by id
*
* @param id {@link Integer}
* @return {@link Result} of {@link Void}
*/
@DeleteMapping("/delete")
public Result<Void> deleteInstanceById(@RequestParam("id") Integer id) {
if (alertInstanceService.removeById(id)) {
return Result.succeed(MessageResolverUtils.getMessage("delete.success"));
} else {
return Result.failed(MessageResolverUtils.getMessage("delete.failed"));
}
}
/**
* delete AlertInstance by id
*
* @param id {@link Integer}
* @return {@link Result} of {@link Void}
*/
@PutMapping("/enable")
public Result<Void> enable(@RequestParam("id") Integer id) {
if (alertInstanceService.enable(id)) {
return Result.succeed(MessageResolverUtils.getMessage("modify.success"));
} else {
return Result.failed(MessageResolverUtils.getMessage("modify.failed"));
}
}
/**
* get AlertInstance info by id
*
* @param alertInstance {@link AlertInstance}
* @return {@link Result} of {@link AlertInstance}
* @throws Exception {@link Exception}
*/
@PostMapping("/getOneById")
public Result<AlertInstance> getOneById(@RequestBody AlertInstance alertInstance)
throws Exception {
alertInstance = alertInstanceService.getById(alertInstance.getId());
return Result.succeed(alertInstance, "获取成功");
return Result.succeed(
alertInstance, MessageResolverUtils.getMessage("response.get.success"));
}
/** 获取可用的报警实例列表 */
/**
* get all enabled AlertInstance
*
* @return {@link Result} of {@link AlertInstance}
*/
@GetMapping("/listEnabledAll")
public Result<List<AlertInstance>> listEnabledAll() {
return Result.succeed(alertInstanceService.listEnabledAll(), "获取成功");
return Result.succeed(
alertInstanceService.listEnabledAll(),
MessageResolverUtils.getMessage("response.get.success"));
}
/** 发送告警实例的测试信息 */
/**
* send test alert message
*
* @param alertInstance {@link AlertInstance}
* @return {@link Result} of {@link Void}
*/
@PostMapping("/sendTest")
public Result<Void> sendTest(@RequestBody AlertInstance alertInstance) {
AlertResult alertResult = alertInstanceService.testAlert(alertInstance);
if (alertResult.getSuccess()) {
return Result.succeed("发送成功");
return Result.succeed(MessageResolverUtils.getMessage("send.success"));
} else {
return Result.failed("发送失败");
return Result.failed(MessageResolverUtils.getMessage("send.failed"));
}
}
}
......@@ -24,20 +24,45 @@ import org.dinky.common.result.Result;
import org.dinky.db.service.ISuperService;
import org.dinky.model.AlertInstance;
import java.io.Serializable;
import java.util.List;
import com.fasterxml.jackson.databind.JsonNode;
/**
* AlertInstanceService
*
* @since 2022/2/24 19:52
*/
/** AlertInstanceService */
public interface AlertInstanceService extends ISuperService<AlertInstance> {
/**
* list all enabled alert instance
*
* @return {@link List<AlertInstance>}
*/
List<AlertInstance> listEnabledAll();
/**
* test one alert instance
*
* @param alertInstance {@link AlertInstance}
* @return {@link AlertResult}
*/
AlertResult testAlert(AlertInstance alertInstance);
/**
* batch delete alert instance , this method is{@link Deprecated} , will be removed in the
* future, please use {@link
* com.baomidou.mybatisplus.core.mapper.BaseMapper#deleteById(Serializable id)} instead
*
* @param para {@link JsonNode}
* @return {@link Result<Void>}
*/
@Deprecated
Result<Void> deleteAlertInstance(JsonNode para);
/**
* enable or disable alert instance
*
* @param id {@link Integer}
* @return {@link Boolean}
*/
Boolean enable(Integer id);
}
......@@ -25,6 +25,7 @@ import org.dinky.alert.AlertMsg;
import org.dinky.alert.AlertResult;
import org.dinky.alert.ShowType;
import org.dinky.common.result.Result;
import org.dinky.constant.BaseConstant;
import org.dinky.db.service.impl.SuperServiceImpl;
import org.dinky.mapper.AlertInstanceMapper;
import org.dinky.model.AlertGroup;
......@@ -37,10 +38,9 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
......@@ -53,17 +53,12 @@ import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.JsonNode;
import cn.hutool.core.util.StrUtil;
import lombok.RequiredArgsConstructor;
/**
* AlertInstanceServiceImpl
*
* @since 2022/2/24 19:53
*/
/** AlertInstanceServiceImpl */
@Service
@RequiredArgsConstructor
public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapper, AlertInstance>
......@@ -73,7 +68,7 @@ public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapp
@Override
public List<AlertInstance> listEnabledAll() {
return list(new QueryWrapper<AlertInstance>().eq("enabled", 1));
return list(new LambdaQueryWrapper<AlertInstance>().eq(AlertInstance::getEnabled, 1));
}
@Override
......@@ -84,9 +79,11 @@ public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapp
alertInstance.getType(),
JSONUtil.toMap(alertInstance.getParams()));
Alert alert = Alert.buildTest(alertConfig);
String currentDateTime =
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
.format(Calendar.getInstance().getTime());
LocalDateTime.now()
.format(DateTimeFormatter.ofPattern(BaseConstant.YYYY_MM_DD_HH_MM_SS));
String uuid = UUID.randomUUID().toString();
AlertMsg alertMsg = new AlertMsg();
......@@ -137,6 +134,13 @@ public class AlertInstanceServiceImpl extends SuperServiceImpl<AlertInstanceMapp
}
}
@Override
public Boolean enable(Integer id) {
AlertInstance alertInstance = getById(id);
alertInstance.setEnabled(!alertInstance.getEnabled());
return updateById(alertInstance);
}
private void writeBackGroupInformation(Map<Integer, Set<Integer>> alertGroupInformation) {
if (MapUtils.isEmpty(alertGroupInformation)) {
return;
......
......@@ -29,6 +29,8 @@ create.success=\u65B0\u589E\u6210\u529F
create.failed=\u65B0\u589E\u5931\u8D25
save.success=\u4FDD\u5B58\u6210\u529F
save.failed=\u4FDD\u5B58\u5931\u8D25
send.success=\u53D1\u9001\u6210\u529F
send.failed=\u53D1\u9001\u5931\u8D25
# response messages
request.params.error=\u8BF7\u6C42\u53C2\u6570\u9519\u8BEF
......
......@@ -28,6 +28,8 @@ create.success=Add successfully
create.failed=Create failed
save.success=Save successfully
save.failed=Save failed
send.success=Send successfully
send.failed=Send failed
# response messages
request.params.error=Request parameter error
......
......@@ -29,7 +29,8 @@ create.success=\u65B0\u589E\u6210\u529F
create.failed=\u65B0\u589E\u5931\u8D25
save.success=\u4FDD\u5B58\u6210\u529F
save.failed=\u4FDD\u5B58\u5931\u8D25
send.success=\u53D1\u9001\u6210\u529F
send.failed=\u53D1\u9001\u5931\u8D25
# response messages
request.params.error=\u8BF7\u6C42\u53C2\u6570\u9519\u8BEF
......
......@@ -183,4 +183,5 @@ export default defineConfig({
strategy: 'normal',
},
requestRecord: {},
dva: {},
});
......@@ -128,12 +128,12 @@ export default [
{
path: '/registration/alert/instance',
name: 'instance',
// component: './RegistrationCenter/AlertManage/AlertInstance',
component: './RegCenter/Alert/AlertInstance',
},
{
path: '/registration/alert/group',
name: 'group',
// component: './RegistrationCenter/AlertManage/AlertGroup',
// component: './RegistrationCenter/Alert/AlertGroup',
},
],
},
......
......@@ -66,7 +66,8 @@
"react-dom": "^18.0.0",
"react-draggable": "^4.4.5",
"react-helmet-async": "^1.3.0",
"screenfull": "^6.0.2"
"screenfull": "^6.0.2",
"rc-resize-observer": "1.3.1"
},
"devDependencies": {
"@ant-design/pro-cli": "^3.0.1",
......
This diff is collapsed.
......@@ -77,6 +77,7 @@ ol {
background-color: rgba(79, 79, 79, 0.04);
width: 100%;
height: 100%;
overflow: hidden;
}
.blue-icon {
......@@ -97,3 +98,7 @@ ol {
padding: 0;
height: max-content;
}
.hidden-overflow {
overflow: hidden;
}
......@@ -508,86 +508,80 @@ export default {
'rc.clusterConfig.help.kubernets.taskManagerMemory': 'Optional,taskManagerMemory memory',
'rc.alert.instanceManagement': 'Alarm Instance Management',
'rc.alert.instance.name': 'Name',
'rc.alert.instance.namePleaseHolder': 'please enter alarm instance name',
'rc.alert.instance.type': 'Type',
'rc.alert.instance.delete': 'Delete the Alarm Instance ',
'rc.alert.instance.create': 'Create Alarm Instance',
'rc.alert.instance.modify': 'Modify Alarm Instance',
'rc.alert.instance.deleteConfirm': 'Are you sure to delete the selected Alarm Instance? ',
'rc.alert.instance.enable': 'Enable Alarm Instance ',
'rc.alert.instance.enableConfirm': 'Are you sure you want to enable this Alarm Instance? ',
'rc.alert.instance.disable': 'Disable the Alarm Instance ',
'rc.alert.instance.disableConfirm': 'Are you sure you want to disable this Alarm Instance? ',
'rc.alert.instance.disableTotalOf': 'Total Of {total} Alarm Instance Is Disabled',
'rc.alert.instance.dingTalk': 'DingDingTalk Config',
'rc.alert.instance.email': 'Email Config',
'rc.alert.instance.feishu': 'FeiShu Config',
'rc.alert.instance.wechat': 'WeChat Config',
'rc.alert.instance.webhookPleaseHolder': 'please enter webhook url',
'rc.alert.instance.keywordPleaseHolder': 'please enter keyword',
'rc.alert.instance.secretPleaseHolder': 'please enter secret',
'rc.alert.instance.proxyPleaseHolder': 'please enter proxy',
'rc.alert.instance.portPleaseHolder': 'please enter port',
'rc.alert.instance.userPleaseHolder': 'please enter user',
'rc.alert.instance.atUsersPleaseHolder': 'Please enter the user ID (user ID of Feishu background is required), separated by multiple commas!',
'rc.alert.instance.passwordPleaseHolder': 'please enter password',
'rc.alert.instance.atMobilesPleaseHolder': 'Please enter the members that need @, multiple use, separated by numbers',
'rc.alert.instance.msgtypePleaseHolder': 'please choose message Send Type`',
'rc.alert.instance.corpIdPleaseHolder': 'Please enter CorpId',
'rc.alert.instance.wechatAtUsersPleaseHolder': 'Please enter the @user ID (enterprise and micro user name spelled out), separated by multiple commas!',
'rc.alert.instance.sendTypePleaseHolder' : 'Please choose Send Type',
'rc.alert.instance.agentIdPleaseHolder': 'Please enter AgentId',
'rc.alert.instance.receiversPleaseHolder': 'Please enter recipient email address! Separate multiple commas',
'rc.alert.instance.receiverCcsPleaseHolder': 'Please enter the receiverCcs email address! Separate multiple commas!',
'rc.alert.instance.serverHostPleaseHolder': 'Mail server host',
'rc.alert.instance.serverPortPleaseHolder': 'Please enter the mail server port',
'rc.alert.instance.senderPleaseHolder': 'Please enter the mail server sender sender',
'rc.alert.instance.emailUserPleaseHolder': 'Please enter your email username',
'rc.alert.instance.emailPasswordPleaseHolder': 'Please enter the email password! Note: the password is the authorization code',
'rc.alert.instance.smtpSslTrustPleaseHolder': 'Please enter a trusted domain',
'rc.alert.instance.xls.file.pathPleaseHolder': 'Please enter the XLS storage directory! The default is /tmp/xls',
'rc.alert.instance.webhook': 'WebHook Url',
'rc.alert.instance.keyword': 'KeyWord',
'rc.alert.instance.secret': 'Secret',
'rc.alert.instance.isEnableProxy': 'IsEnableProxy',
'rc.alert.instance.proxy': 'Proxy',
'rc.alert.instance.port': 'Port',
'rc.alert.instance.user': 'User',
'rc.alert.instance.password': 'Password',
'rc.alert.instance.isAtAll': 'IsAtAll',
'rc.alert.instance.corpId': 'CorpId',
'rc.alert.instance.atMobiles': 'At Mobiles',
'rc.alert.instance.sendType': 'Send Type',
'rc.alert.instance.agentId': 'AgentId',
'rc.alert.instance.atUsers': 'At Users',
'rc.alert.instance.receivers': 'Receivers',
'rc.alert.instance.receiverCcs': 'ReceiverCcs',
'rc.alert.instance.serverHost': 'Mail server Host',
'rc.alert.instance.serverPort': 'Mail server Port',
'rc.alert.instance.sender': 'Sender nickname',
'rc.alert.instance.enableSmtpAuth': 'Enable SmtpAuth',
'rc.alert.instance.emailUser': 'Email user',
'rc.alert.instance.emailPassword': 'Email password',
'rc.alert.instance.starttlsEnable': 'Start Tls Enable',
'rc.alert.instance.sslEnable': 'Ssl Enable',
'rc.alert.instance.smtpSslTrust': 'Smtp Ssl Trust',
'rc.alert.instance.xls.file.path': 'XLS storage directory',
'rc.alert.instance.msgtype': 'Send Message Type',
'rc.alert.instance.sendType.app': 'Application',
'rc.alert.instance.sendType.wechat': 'WeChat',
'rc.alert.instance.markdown': 'MarkDown',
'rc.alert.instance.text': 'Text',
'rc.alert.instance.post': 'Post',
'rc.alert.instance.table': 'Table',
'rc.alert.instance.attachment': 'Attachment',
'rc.alert.instance.tableAttachment': 'Table And Attachment',
'rc.ai.management': 'Alarm Instance Management',
'rc.ai.name': 'Name',
'rc.ai.namePleaseHolder': 'please enter alarm instance name',
'rc.ai.type': 'Type',
'rc.ai.delete': 'Delete the Alarm Instance ',
'rc.ai.create': 'Create Alarm Instance',
'rc.ai.modify': 'Modify Alarm Instance',
'rc.ai.deleteConfirm': 'Are you sure to delete the selected Alarm Instance? ',
'rc.ai.dingTalk': 'DingDingTalk Config',
'rc.ai.email': 'Email Config',
'rc.ai.feishu': 'FeiShu Config',
'rc.ai.wechat': 'WeChat Config',
'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.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',
'rc.ai.msgtypePleaseHolder': 'please choose message Send Type`',
'rc.ai.corpIdPleaseHolder': 'Please enter CorpId',
'rc.ai.wechatAtUsersPleaseHolder': 'Please enter the @user ID (enterprise and micro user name spelled out), separated by multiple commas!',
'rc.ai.sendTypePleaseHolder' : 'Please choose Send Type',
'rc.ai.agentIdPleaseHolder': 'Please enter AgentId',
'rc.ai.receiversPleaseHolder': 'Please enter recipient email address! Separate multiple commas',
'rc.ai.receiverCcsPleaseHolder': 'Please enter the receiverCcs email address! Separate multiple commas!',
'rc.ai.serverHostPleaseHolder': 'Mail server host',
'rc.ai.serverPortPleaseHolder': 'Please enter the mail server port',
'rc.ai.senderPleaseHolder': 'Please enter the mail server sender Nickname',
'rc.ai.emailUserPleaseHolder': 'Please enter your email username',
'rc.ai.emailPasswordPleaseHolder': 'Please enter the email password! Note: the password is the authorization code',
'rc.ai.smtpSslTrustPleaseHolder': 'Please enter a trusted domain',
'rc.ai.xls.file.pathPleaseHolder': 'Please enter the XLS storage directory! The default is /tmp/xls',
'rc.ai.webhook': 'WebHook Url',
'rc.ai.keyword': 'KeyWord',
'rc.ai.secret': 'Secret',
'rc.ai.isEnableProxy': 'IsEnableProxy',
'rc.ai.proxy': 'Proxy',
'rc.ai.port': 'Port',
'rc.ai.user': 'User',
'rc.ai.password': 'Password',
'rc.ai.isAtAll': 'IsAtAll',
'rc.ai.corpId': 'CorpId',
'rc.ai.atMobiles': 'At Mobiles',
'rc.ai.sendType': 'Send Type',
'rc.ai.agentId': 'AgentId',
'rc.ai.atUsers': 'At Users',
'rc.ai.receivers': 'Receivers',
'rc.ai.receiverCcs': 'ReceiverCcs',
'rc.ai.serverHost': 'Mail server Host',
'rc.ai.serverPort': 'Mail server Port',
'rc.ai.sender': 'Sender Nickname',
'rc.ai.enableSmtpAuth': 'Enable SmtpAuth',
'rc.ai.emailUser': 'Email user',
'rc.ai.emailPassword': 'Email password',
'rc.ai.starttlsEnable': 'Start Tls Enable',
'rc.ai.sslEnable': 'Ssl Enable',
'rc.ai.smtpSslTrust': 'Smtp Ssl Trust',
'rc.ai.xls.file.path': 'XLS storage directory',
'rc.ai.msgtype': 'Send Message Type',
'rc.ai.sendType.app': 'Application',
'rc.ai.sendType.wechat': 'WeChat',
'rc.ai.markdown': 'MarkDown',
'rc.ai.text': 'Text',
'rc.ai.post': 'Post',
'rc.ai.table': 'Table',
'rc.ai.attachment': 'Attachment',
'rc.ai.tableAttachment': 'Table And Attachment',
'rc.alert.groupManagement': 'Alarm Group Management ',
'rc.alert.group.name': 'Alarm Group Name',
......
......@@ -504,82 +504,77 @@ export default {
'rc.clusterConfig.help.kubernets.jobManagerMemory': '可选,JobManager 的内存配置',
'rc.clusterConfig.help.kubernets.taskManagerMemory': '可选,taskManagerMemory 的内存配置',
'rc.alert.instanceManagement': '报警实例管理',
'rc.alert.instance.name': '名称',
'rc.alert.instance.namePleaseHolder': '请输入告警实例名称',
'rc.alert.instance.type': '类型',
'rc.alert.instance.delete': '删除报警实例',
'rc.alert.instance.create': '创建告警实例',
'rc.alert.instance.modify': '修改告警实例',
'rc.alert.instance.deleteConfirm': '确定删除选中的报警实例吗?',
'rc.alert.instance.enable': '启用报警实例',
'rc.alert.instance.enableConfirm': '您确定要启用此报警实例吗?',
'rc.alert.instance.disable': '禁用报警实例',
'rc.alert.instance.disableConfirm': '您确定要禁用此报警实例吗?',
'rc.alert.instance.disableTotalOf': '被禁用的报警实例共 {total} 个',
'rc.alert.instance.dingTalk': '钉钉告警配置',
'rc.alert.instance.email': '邮箱告警配置',
'rc.alert.instance.feishu': '飞书告警配置',
'rc.alert.instance.wechat': '企业微信告警配置',
'rc.alert.instance.webhookPleaseHolder': '请输入 webhook 地址',
'rc.alert.instance.keywordPleaseHolder': '请输入关键词',
'rc.alert.instance.secretPleaseHolder': '请输入 密令',
'rc.alert.instance.proxyPleaseHolder': '请输入代理主机',
'rc.alert.instance.portPleaseHolder': '请输入代理端口',
'rc.alert.instance.userPleaseHolder': '请输入代理用户',
'rc.alert.instance.atUsersPleaseHolder': '请输入被@用户ID(需要飞书后台的用户ID),多个逗号隔开!',
'rc.alert.instance.passwordPleaseHolder': '请输入密码',
'rc.alert.instance.atMobilesPleaseHolder': '请输入@手机号 多个使用英文逗号分开 ',
'rc.alert.instance.msgtypePleaseHolder': '请选择消息发送类型',
'rc.alert.instance.corpIdPleaseHolder': '请输入 企业Id',
'rc.alert.instance.wechatAtUsersPleaseHolder': '请输入被@用户ID(企微用户名全拼),多个逗号隔开!',
'rc.alert.instance.sendTypePleaseHolder' : '请选择发送方式!',
'rc.alert.instance.agentIdPleaseHolder': '请输入 AgentId',
'rc.alert.instance.receiversPleaseHolder': '请输入收件人邮箱!多个英文逗号隔开',
'rc.alert.instance.receiverCcsPleaseHolder': '请输入抄送人邮箱!多个英文逗号隔开!',
'rc.alert.instance.serverHostPleaseHolder': '邮件服务器主机',
'rc.alert.instance.serverPortPleaseHolder': '请输入邮件服务器端口',
'rc.alert.instance.senderPleaseHolder': '请输入邮件服务器发送者sender',
'rc.alert.instance.emailUserPleaseHolder': '请输入邮箱用户名',
'rc.alert.instance.emailPasswordPleaseHolder': '请输入邮箱密码! 注意:密码为授权码',
'rc.alert.instance.smtpSslTrustPleaseHolder': '请输入受信任域',
'rc.alert.instance.xls.file.pathPleaseHolder': '请输入XLS存放目录! 默认为 /tmp/xls',
'rc.alert.instance.webhook': 'WebHook 地址',
'rc.alert.instance.keyword': '关键词',
'rc.alert.instance.secret': '密令',
'rc.alert.instance.isEnableProxy': '是否启用代理',
'rc.alert.instance.proxy': '代理',
'rc.alert.instance.port': '端口',
'rc.alert.instance.user': '用户名',
'rc.alert.instance.password': '密码',
'rc.alert.instance.isAtAll': '是否@全部',
'rc.alert.instance.corpId': '企业Id',
'rc.alert.instance.atMobiles': '@手机号',
'rc.alert.instance.sendType': '发送方式',
'rc.alert.instance.agentId': '代理ID',
'rc.alert.instance.atUsers': '被@用户',
'rc.alert.instance.receivers': '收件人',
'rc.alert.instance.receiverCcs': '抄送人',
'rc.alert.instance.serverHost': '邮件服务器Host',
'rc.alert.instance.serverPort': '邮件服务器Port',
'rc.alert.instance.sender': '发送者sender昵称',
'rc.alert.instance.enableSmtpAuth': '是否开启邮箱验证',
'rc.alert.instance.emailUser': '邮箱用户名',
'rc.alert.instance.emailPassword': '邮箱密码',
'rc.alert.instance.starttlsEnable': '是否开启tls证书验证',
'rc.alert.instance.sslEnable': '是否开启SSL验证',
'rc.alert.instance.smtpSslTrust': '受信任域',
'rc.alert.instance.xls.file.path': 'XLS存放目录',
'rc.alert.instance.msgtype': '展示方式',
'rc.alert.instance.sendType.app': '应用',
'rc.alert.instance.sendType.wechat': '群聊',
'rc.alert.instance.markdown': 'MarkDown',
'rc.alert.instance.text': '普通文本',
'rc.alert.instance.post': '富文本',
'rc.alert.instance.table': '表格',
'rc.alert.instance.attachment': '附件',
'rc.alert.instance.tableAttachment': '表格和附件',
// alert
'rc.ai.management': '报警实例管理',
'rc.ai.type': '类型',
'rc.ai.name': '名称',
'rc.ai.namePleaseHolder': '请输入告警实例名称',
'rc.ai.delete': '删除报警实例',
'rc.ai.create': '创建告警实例',
'rc.ai.modify': '修改告警实例',
'rc.ai.deleteConfirm': '确定删除选中的报警实例吗?',
'rc.ai.dingTalk': '钉钉告警配置',
'rc.ai.email': '邮箱告警配置',
'rc.ai.feishu': '飞书告警配置',
'rc.ai.wechat': '企业微信告警配置',
'rc.ai.webhookPleaseHolder': '请输入 webhook 地址',
'rc.ai.keywordPleaseHolder': '请输入关键词',
'rc.ai.secretPleaseHolder': '请输入 密令',
'rc.ai.proxyPleaseHolder': '请输入代理主机',
'rc.ai.portPleaseHolder': '请输入代理端口',
'rc.ai.userPleaseHolder': '请输入代理用户',
'rc.ai.atUsersPleaseHolder': '请输入被@用户ID(需要飞书后台的用户ID),多个逗号隔开!',
'rc.ai.passwordPleaseHolder': '请输入密码',
'rc.ai.atMobilesPleaseHolder': '请输入@手机号 多个使用英文逗号分开 ',
'rc.ai.msgtypePleaseHolder': '请选择消息发送类型',
'rc.ai.corpIdPleaseHolder': '请输入 企业Id',
'rc.ai.wechatAtUsersPleaseHolder': '请输入被@用户ID(企微用户名全拼),多个逗号隔开!',
'rc.ai.sendTypePleaseHolder' : '请选择发送方式!',
'rc.ai.agentIdPleaseHolder': '请输入 AgentId',
'rc.ai.receiversPleaseHolder': '请输入收件人邮箱!多个英文逗号隔开',
'rc.ai.receiverCcsPleaseHolder': '请输入抄送人邮箱!多个英文逗号隔开!',
'rc.ai.serverHostPleaseHolder': '邮件服务器主机',
'rc.ai.serverPortPleaseHolder': '请输入邮件服务器端口',
'rc.ai.senderPleaseHolder': '请输入邮件服务器发送者昵称',
'rc.ai.emailUserPleaseHolder': '请输入邮箱用户名',
'rc.ai.emailPasswordPleaseHolder': '请输入邮箱密码! 注意:密码为授权码',
'rc.ai.smtpSslTrustPleaseHolder': '请输入受信任域',
'rc.ai.xls.file.pathPleaseHolder': '请输入XLS存放目录! 默认为 /tmp/xls',
'rc.ai.webhook': 'WebHook 地址',
'rc.ai.keyword': '关键词',
'rc.ai.secret': '密令',
'rc.ai.isEnableProxy': '是否启用代理',
'rc.ai.proxy': '代理',
'rc.ai.port': '端口',
'rc.ai.user': '用户名',
'rc.ai.password': '密码',
'rc.ai.isAtAll': '是否@全部',
'rc.ai.corpId': '企业Id',
'rc.ai.atMobiles': '@手机号',
'rc.ai.sendType': '发送方式',
'rc.ai.agentId': '代理ID',
'rc.ai.atUsers': '被@用户',
'rc.ai.receivers': '收件人',
'rc.ai.receiverCcs': '抄送人',
'rc.ai.serverHost': '邮件服务器Host',
'rc.ai.serverPort': '邮件服务器Port',
'rc.ai.sender': '发送者昵称',
'rc.ai.enableSmtpAuth': '开启邮箱验证',
'rc.ai.emailUser': '邮箱用户名',
'rc.ai.emailPassword': '邮箱密码',
'rc.ai.starttlsEnable': '开启tls证书',
'rc.ai.sslEnable': '开启SSL',
'rc.ai.smtpSslTrust': '受信任域',
'rc.ai.xls.file.path': 'XLS存放目录',
'rc.ai.msgtype': '展示方式',
'rc.ai.sendType.app': '应用',
'rc.ai.sendType.wechat': '群聊',
'rc.ai.markdown': 'MarkDown',
'rc.ai.text': '普通文本',
'rc.ai.post': '富文本',
'rc.ai.table': '表格',
'rc.ai.attachment': '附件',
'rc.ai.tableAttachment': '表格和附件',
'rc.alert.groupManagement': '报警组管理',
'rc.alert.group.name': '报警组名称',
......
......@@ -22,7 +22,7 @@ import React, {useState} from "react";
import {Form, Modal} from "antd";
import {l} from "@/utils/intl";
import {ProForm, ProFormSwitch, ProFormText} from "@ant-design/pro-components";
import {FORM_LAYOUT_PUBLIC, NORMAL_MODAL_OPTIONS} from "@/services/constants";
import {FORM_LAYOUT_PUBLIC, NORMAL_MODAL_OPTIONS, SWITCH_OPTIONS} from "@/services/constants";
export type UserFormProps = {
onCancel: (flag?: boolean) => void;
......@@ -110,9 +110,8 @@ const UserForm: React.FC<UserFormProps> = (props) => {
<ProFormSwitch
name="enabled"
{...SWITCH_OPTIONS()}
label={l("global.table.isEnable")}
checkedChildren={l("button.enable")}
unCheckedChildren={l("button.disable")}
/>
</>
);
......
......@@ -29,7 +29,13 @@ import TableTransferFrom from "@/pages/AuthCenter/User/components/UserTransfer";
import {l} from "@/utils/intl";
import {handleAddOrUpdate, handleOption, handlePutData, handleRemoveById, updateEnabled} from "@/services/BusinessCrud";
import {queryList} from "@/services/api";
import {API_CONSTANTS, PROTABLE_OPTIONS_PUBLIC, STATUS_ENUM, STATUS_MAPPING} from "@/services/constants";
import {
API_CONSTANTS,
PROTABLE_OPTIONS_PUBLIC,
STATUS_ENUM,
STATUS_MAPPING,
SWITCH_OPTIONS
} from "@/services/constants";
import {useAccess} from "@@/exports";
import {DangerDeleteIcon} from "@/components/Icons/CustomIcons";
......@@ -202,8 +208,7 @@ const UserTableList: React.FC = () => {
<Space>
<Switch
key={record.id}
checkedChildren={l("status.enabled")}
unCheckedChildren={l("status.disabled")}
{...SWITCH_OPTIONS()}
checked={record.enabled}
onChange={() => handleChangeEnable(record)}/>
</Space>
......
/*
* 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 {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";
/**
* update form props
*/
type UpdateFormProps = {
onCancel: (flag?: boolean, formVals?: Partial<Alert.AlertInstance>) => void;
onSubmit: (values: Partial<Alert.AlertInstance>) => void;
modalVisible: boolean;
values: Partial<Alert.AlertInstance>;
};
const AlertTypeChoose: React.FC<UpdateFormProps> = (props) => {
/**
* state
*/
const [alertType, setAlertType] = useState<string>();
/**
* extract props
*/
const {
onSubmit: handleUpdate,
onCancel: handleChooseModalVisible,
modalVisible,
values
} = props;
/**
* choose one type
* @param item
*/
const chooseAlertType = (item: AlertConfig) => {
setAlertType(item.type);
};
/**
* 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
*/
const onTest = async (value: any) => {
await sendTest(value);
};
/**
* cancel choose
*/
const handleCancel = () => {
setAlertType(undefined);
handleChooseModalVisible();
};
/**
* render card item
* @param item
*/
const renderCardItem = (item: AlertConfig) => {
return (
<List.Item onClick={() => {
chooseAlertType(item);
}}>
<Card>{getAlertIcon(item.type)}</Card>
</List.Item>
);
};
/**
* 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)}
/>
</>;
};
/**
* choose modal props
*/
const chooseProps = {
onCancel: handleCancel,
modalVisible: modalVisible,
values: values,
onSubmit: (value: any) => onSubmit(value),
onTest: (value: any) => onTest(value)
};
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>
</>
);
};
export default connect(({Alert}: { Alert: AlertStateType }) => ({
instance: Alert.instance,
}))(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.atUsersPleaseHolder")}]}
placeholder={l("rc.ai.atUsersPleaseHolder")}
/>
</>
}
</>:
(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;
/*
* 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} from "@/types/RegCenter/data";
/**
* 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>;
};
/*
* 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 {DefaultSvg, DingTalkSvg, EmailSvg, FeiShuSvg, WeChatSvg} from "@/components/Icons/AlertIcon";
/**
* get json data to alert instance
* @param values
*/
export const getJSONData = (values: Partial<Alert.AlertInstance>) => {
if (!values.params || values.params === "") {
return values;
}
let data = JSON.parse(values.params);
return {...data, ...values};
};
/**
* build json data to alert instance
* @param values
* @param params
*/
export const buildJSONData = (values: Partial<Alert.AlertInstance>, params: any) => {
let newValue = values;
if (params.name) {
newValue.name = params.name;
delete params.name;
}
if (params.enabled) {
newValue.enabled = params.enabled;
delete params.enabled;
}
let data: string = JSON.stringify(params);
return {...newValue, params: data};
};
/**
* get alert icon
* @param type alert type
* @param size icon size
*/
export const getAlertIcon = (type: string, size?: number) => {
switch (type) {
case ALERT_TYPE.DINGTALK:
return <DingTalkSvg size={size}/>;
case ALERT_TYPE.WECHAT:
return <WeChatSvg size={size}/>;
case ALERT_TYPE.FEISHU:
return <FeiShuSvg size={size}/>;
case ALERT_TYPE.EMAIL:
return <EmailSvg size={size}/>;
default:
return <DefaultSvg size={size}/>;
}
};
/*
* 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, 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, 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";
const PRO_LIST_CARD_META = {
title: {},
subTitle: {},
type: {},
avatar: {},
content: {},
actions: {
cardActionProps: "actions"
},
};
const PRO_LIST_CARD_OPTIONS = {
search: false,
metas: PRO_LIST_CARD_META,
grid: {gutter: 24, column: 6}
};
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[]>([]);
/**
* execute query alert instance list
* set alert instance list
*/
const queryAlertInstanceList = async () => {
await queryList(API_CONSTANTS.ALERT_INSTANCE).then(res => {
setAlertInstanceList(res.data);
});
};
/**
* 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 handleRemoveById(API_CONSTANTS.ALERT_INSTANCE_DELETE, id);
await queryAlertInstanceList();
}
});
};
/**
* handle enable alert instance
* @param item
*/
const handleEnable = async (item: Alert.AlertInstance) => {
await updateEnabled(API_CONSTANTS.ALERT_INSTANCE_ENABLE, {id: item.id});
await queryAlertInstanceList();
};
/**
* 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(false);
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}
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;
/*
* 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 {Reducer} from "umi";
import {Alert} from "@/types/RegCenter/data.d";
export type AlertStateType = {
instance:Alert.AlertInstance[],
group:Alert.AlertGroup[]
};
export type AlertModelType = {
namespace: string;
state: AlertStateType;
effects: {
};
reducers: {
saveInstance: Reducer<AlertStateType>;
saveGroup: Reducer<AlertStateType>;
};
};
const AlertModel: AlertModelType = {
namespace: 'Alert',
state: {
instance:[],
group:[],
},
effects: {
},
reducers: {
saveInstance(state, {payload}) {
return {
...state,
instance: payload,
};
},
saveGroup(state, {payload}) {
return {
...state,
group: payload,
};
},
},
};
export default AlertModel;
/*
* 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 {l} from "@/utils/intl";
import {handleAddOrUpdate} from "@/services/BusinessCrud";
import {Alert} from "@/types/RegCenter/data.d";
import {postAll} from "@/services/api";
import {ErrorMessage, LoadingMessageAsync, SuccessMessage, WarningMessage} from "@/utils/messages";
import {RESPONSE_CODE} from "@/services/constants";
export async function createOrModifyAlertInstance(alertInstance: Alert.AlertInstance) {
return handleAddOrUpdate("/api/alertInstance", alertInstance);
}
export async function sendTest(alertInstance: Alert.AlertInstance) {
await LoadingMessageAsync(l("app.request.test.alert.msg"));
try {
const {code, msg} = await postAll("/api/alertInstance/sendTest", alertInstance);
if (code === RESPONSE_CODE.SUCCESS) {
SuccessMessage(msg);
return true;
} else {
WarningMessage(msg);
return false;
}
} catch (error) {
ErrorMessage(l("app.request.failed"));
return false;
}
}
......@@ -35,7 +35,13 @@ import {
DOCUMENT_FUNCTION_ENUMS,
DOCUMENT_FUNCTION_TYPE, DOCUMENT_SUBTYPE, DOCUMENT_SUBTYPE_ENUMS
} from "@/pages/RegCenter/Document/constans";
import {API_CONSTANTS, PROTABLE_OPTIONS_PUBLIC, STATUS_ENUM, STATUS_MAPPING} from "@/services/constants";
import {
API_CONSTANTS,
PROTABLE_OPTIONS_PUBLIC,
STATUS_ENUM,
STATUS_MAPPING,
SWITCH_OPTIONS
} from "@/services/constants";
import CodeShow from "@/components/CustomMonacoEditor/CodeShow";
import {DangerDeleteIcon} from "@/components/Icons/CustomIcons";
import {handleAddOrUpdate, handleRemoveById, updateEnabled} from "@/services/BusinessCrud";
......@@ -177,8 +183,7 @@ const DocumentTableList: React.FC = (props: any) => {
<Space>
<Switch
key={record.id}
checkedChildren={l("status.enabled")}
unCheckedChildren={l("status.disabled")}
{...SWITCH_OPTIONS()}
checked={record.enabled}
onChange={() => handleChangeEnable(record)}/>
</Space>
......@@ -216,6 +221,7 @@ const DocumentTableList: React.FC = (props: any) => {
}}
/>,
<Popconfirm
key={'DocumentDelete'}
placement="topRight"
title={l("button.delete")}
description={l("rc.doc.deleteConfirm")}
......
......@@ -18,7 +18,7 @@
*/
import {EditTwoTone, PlusOutlined} from '@ant-design/icons';
import {Button, Drawer, Form, Popconfirm, Space, Switch} from 'antd';
import {Button, Drawer, Popconfirm, Space, Switch} from 'antd';
import React, {useRef, useState} from 'react';
import {PageContainer} from '@ant-design/pro-layout';
import type {ActionType, ProColumns} from '@ant-design/pro-table';
......@@ -26,7 +26,13 @@ import ProTable from '@ant-design/pro-table';
import ProDescriptions from '@ant-design/pro-descriptions';
import {l} from "@/utils/intl";
import {GlobalVar} from "@/types/RegCenter/data";
import {API_CONSTANTS, PROTABLE_OPTIONS_PUBLIC, STATUS_ENUM, STATUS_MAPPING} from "@/services/constants";
import {
API_CONSTANTS,
PROTABLE_OPTIONS_PUBLIC,
STATUS_ENUM,
STATUS_MAPPING,
SWITCH_OPTIONS
} from "@/services/constants";
import {DangerDeleteIcon} from "@/components/Icons/CustomIcons";
import {handleAddOrUpdate, handleRemoveById, updateEnabled} from "@/services/BusinessCrud";
import GlobalVarForm from "@/pages/RegCenter/GlobalVar/components/GlobalVarForm";
......@@ -131,8 +137,7 @@ const GlobalVarList: React.FC = (props: any) => {
<Space>
<Switch
key={record.id}
checkedChildren={l("status.enabled")}
unCheckedChildren={l("status.disabled")}
{...SWITCH_OPTIONS()}
checked={record.enabled}
onChange={() => handleChangeEnable(record)}/>
</Space>
......@@ -174,6 +179,7 @@ const GlobalVarList: React.FC = (props: any) => {
}}
/>,
<Popconfirm
key={'GlobalVarDelete'}
placement="topRight"
title={l("button.delete")}
description={l("rc.gv.deleteConfirm")}
......
......@@ -79,6 +79,15 @@ export const API_CONSTANTS = {
// document enable or disable
DOCUMENT_ENABLE: "/api/document/enable",
// ---- alert instance ----
// alert instance list
ALERT_INSTANCE: "/api/alertInstance",
// delete alert instance by id
ALERT_INSTANCE_DELETE: "/api/alertInstance/delete",
// alert instance enable or disable
ALERT_INSTANCE_ENABLE: "/api/alertInstance/enable",
};
......@@ -147,6 +156,19 @@ export const FORM_LAYOUT_PUBLIC = {
wrapperCol: {span: 15},
};
/**
* the modal form layout of public
*/
export const MODAL_FORM_STYLE: any = {
width: "40%",
style: {
maxHeight: "70vh",
overflowY: "auto",
},
};
/**
* the protable layout of public
*/
......@@ -185,7 +207,15 @@ export const NORMAL_TABLE_OPTIONS = {
export const SCROLLBAR_OPTIONS = {
style: {
height: '520px',
width: '100%',
height: "520px",
width: "100%",
}
};
export const SWITCH_OPTIONS =() => {
return {
checkedChildren: l("status.enabled"),
unCheckedChildren: l("status.disabled"),
};
}
......@@ -46,6 +46,30 @@ declare namespace Alert {
};
}
export type AlertConfig = {
type: string,
}
export const ALERT_TYPE = {
DINGTALK: "DingTalk",
WECHAT: "WeChat",
FEISHU: "FeiShu",
EMAIL: "Email",
};
export const ALERT_CONFIG_LIST: AlertConfig[] = [{
type: ALERT_TYPE.DINGTALK,
}, {
type: ALERT_TYPE.WECHAT,
}, {
type: ALERT_TYPE.FEISHU,
}, {
type: ALERT_TYPE.EMAIL,
}
];
/**
* about flink cluster
*/
......
......@@ -82,7 +82,8 @@ const AlertInstanceChooseForm: React.FC<UpdateFormProps> = (props) => {
maskClosable={false}
destroyOnClose={true}
footer={null}
>{
>
{
(!alertType && !values?.id) && (<List
grid={{
gutter: 16,
......
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