Skip to content

Commit

Permalink
feat(frontend): 告警通知优化 TencentBlueKing#8366
Browse files Browse the repository at this point in the history
  • Loading branch information
3octaves committed Jan 16, 2025
1 parent 56f1877 commit cfb7797
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
4 changes: 2 additions & 2 deletions dbm-ui/frontend/patch/user-selector/selector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,9 @@
}
try {
loading.value = true;
const pasteStr = event.clipboardData.getData('text').replace(/\s/g, '');
const pasteStr = event.clipboardData.getData('text').replace(/[^\S\r\n]/g, '');
const values = pasteStr
.split(/,|;/)
.split(/\s*[||,,;;、\t/\s]\s*/g)
.map((value) => pasteFormatter.value(value))
.filter((value) => value.length);
const uniqueValues = [...new Set(values)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,11 @@
].join('\n'),
};

const InputMessageTypeMap: Record<string, string> = {
'wxwork-bot': MessageTypes.WECOM_ROBOT,
[MessageTypes.WECOM_ROBOT]: 'wxwork-bot',
};

let head: TableHead[] = [
{
label: t('告警级别'),
Expand Down Expand Up @@ -472,14 +477,16 @@
const inputArr = _.cloneDeep(panelInitData.inputArr);

configItem.notice_ways.forEach((wayItem) => {
if (InputMessageTypes.includes(wayItem.name)) {
const idx = inputArr.findIndex((inputItem) => inputItem.type === wayItem.name);
// 转为消息类型对应值
const conversionType = InputMessageTypeMap[wayItem.name] || wayItem.name;
if (InputMessageTypes.includes(conversionType)) {
const idx = inputArr.findIndex((inputItem) => inputItem.type === conversionType);

if (idx > -1) {
inputArr[idx].value = (wayItem.receivers || []).join(',');
}
} else {
const idx = checkboxArr.findIndex((checkboxItem) => checkboxItem.type === wayItem.name);
const idx = checkboxArr.findIndex((checkboxItem) => checkboxItem.type === conversionType);

if (idx > -1) {
checkboxArr[idx].checked = true;
Expand Down Expand Up @@ -625,7 +632,7 @@
(prev, current) => {
if (current.value !== '') {
prev.push({
name: current.type,
name: InputMessageTypeMap[current.type] || current.type, // 转为映射值
receivers: current.value.split(','),
});
}
Expand Down Expand Up @@ -697,10 +704,9 @@

.table-row-item {
display: flex;
min-width: 120px;
width: 110px;
padding: 0 12px;
border-bottom: 1px solid #dcdee5;
flex: 1;
align-items: center;
justify-content: center;
flex-shrink: 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
:default-alternate="defaultAlternate"
:disabled="disabled"
:fuzzy-search-method="fuzzySearchMethod"
:paste-validator="pasteValidator"
:render-list="renderList"
:render-tag="renderTag"
:search-from-default-alternate="false"
Expand Down Expand Up @@ -227,6 +228,13 @@
userSelectorRef.value.search();
};

const pasteValidator = (values: string[]) =>
getUserList({
exact_lookups: values.join(','),
offset: 0,
limit: -1,
}).then((userResult) => userResult.results.map((userItem) => userItem.username));

defineExpose<Exposes>({
getSelectedReceivers() {
return modelValue.value.map((modelValueItem) => ({
Expand Down

0 comments on commit cfb7797

Please sign in to comment.