Skip to content

Commit

Permalink
Dealing with some details (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
yang1666204 authored Jun 11, 2024
1 parent cb95d39 commit d897c5e
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 22 deletions.
9 changes: 7 additions & 2 deletions ui/src/pages/Alert/AlarmFilter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export default function AlarmFilter({ form, type, depend }: AlarmFilterProps) {
>
<Select
style={{ width: '100%' }}
allowClear
options={getOptionsFromType(
getFieldValue(['instance', 'type']),
)}
Expand All @@ -250,10 +251,14 @@ export default function AlarmFilter({ form, type, depend }: AlarmFilterProps) {
<Select
allowClear
placeholder="请选择"
options={LEVER_OPTIONS_ALARM?.map((item) => ({
options={LEVER_OPTIONS_ALARM!.map((item) => ({
value: item.value,
label: (
<Tag color={SEVERITY_MAP[item.value]?.color}>
<Tag
color={
SEVERITY_MAP[item.value as Alert.AlarmLevel]?.color
}
>
{item.label}
</Tag>
),
Expand Down
18 changes: 4 additions & 14 deletions ui/src/pages/Alert/Rules/RuleDrawerForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,12 @@ import { alert } from '@/api';
import type { CommonKVPair, RuleRule } from '@/api/generated';
import AlertDrawer from '@/components/AlertDrawer';
import InputLabelComp from '@/components/InputLabelComp';
import InputTimeComp from '@/components/InputTimeComp';
import { LEVER_OPTIONS_ALARM, SEVERITY_MAP } from '@/constants';
import { QuestionCircleOutlined } from '@ant-design/icons';
import InputTimeComp from '@/components/InputTimeComp';
import { useRequest } from 'ahooks';
import type { DrawerProps } from 'antd';
import {
Col,
Form,
Input,
Radio,
Row,
Select,
Tag,
message,
} from 'antd';
import { Col, Form, Input, Radio, Row, Select, Tag, message } from 'antd';
import { useEffect } from 'react';
import { validateLabelValues } from '../helper';

Expand Down Expand Up @@ -46,8 +37,8 @@ export default function RuleDrawerForm({
instanceType: 'obcluster',
};
const submit = (values: RuleRule) => {
values.type = 'customized';
if (!values.labels) values.labels = [];
values.labels = values.labels.filter((label) => label.key && label.value);
alert.createOrUpdateRule(values).then(({ successful }) => {
if (successful) {
message.success('操作成功!');
Expand Down Expand Up @@ -84,10 +75,9 @@ export default function RuleDrawerForm({
validateTrigger="onBlur"
form={form}
>
<Row gutter={[24, 24]}>
<Row gutter={[24, 0]}>
<Col span={24}>
<Form.Item
style={{ marginBottom: 0 }}
rules={[
{
required: true,
Expand Down
3 changes: 2 additions & 1 deletion ui/src/pages/Alert/Rules/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Button, Card, Form, Space, Table, Tag, Typography } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import { useState } from 'react';
import AlarmFilter from '../AlarmFilter';
import { formatDuration } from '../helper';
import RuleDrawerForm from './RuleDrawerForm';

const { Text } = Typography;
Expand Down Expand Up @@ -54,7 +55,7 @@ export default function Rules() {
title: '持续时间',
dataIndex: 'duration',
key: 'duration',
render: (value) => <Text>{value}分钟</Text>,
render: (value) => <Text>{formatDuration(value)}</Text>,
},
{
title: '对象类型',
Expand Down
3 changes: 3 additions & 0 deletions ui/src/pages/Alert/Shield/ShieldDrawerForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export default function ShieldDrawerForm({

const submit = (values: Alert.ShieldDrawerForm) => {
if (!values.matchers) values.matchers = [];
values.matchers = values.matchers.filter(
(matcher) => matcher.name && matcher.value,
);
const _clusterList = getSelectList(
clusterList!,
values.instances.type,
Expand Down
1 change: 1 addition & 0 deletions ui/src/pages/Alert/Shield/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export default function Shield() {
<Button
onClick={() => editShield(record.id)}
style={{ paddingLeft: 0 }}
disabled={record.status.state === 'expired'}
type="link"
>
编辑
Expand Down
3 changes: 3 additions & 0 deletions ui/src/pages/Alert/Subscriptions/SubscripDrawerForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export default function SubscripDrawerForm({
const listReceivers = listReceiversRes?.data;
const submit = async (values: RouteRoute) => {
if (!values.matchers) values.matchers = [];
values.matchers = values.matchers.filter(
(matcher) => matcher.name && matcher.value,
);
const { successful } = await alert.createOrUpdateRoute(values);
if (successful) {
message.success(`${isEdit ? '修改' : '创建'}成功!`);
Expand Down
3 changes: 3 additions & 0 deletions ui/src/pages/Alert/Subscriptions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Button, Card, Table } from 'antd';
import type { ColumnsType } from 'antd/es/table';
import { useState } from 'react';
import ChannelDrawer from '../Channel/ChannelDrawer';
import { formatDuration } from '../helper';
import SubscripDrawerForm from './SubscripDrawerForm';

export default function Subscriptions() {
Expand Down Expand Up @@ -74,10 +75,12 @@ export default function Subscriptions() {
title: '聚合配置',
dataIndex: 'aggregateLabels',
key: 'aggregateLabels',
render: (labels) => <span>{labels.join(',')}</span>,
},
{
title: '推送周期',
dataIndex: 'repeatInterval',
render: (repeatIntervel) => <span>{formatDuration(repeatIntervel)}</span>,
},
{
title: '操作',
Expand Down
23 changes: 20 additions & 3 deletions ui/src/pages/Alert/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ export const getInstancesFromRes = (
* @description
* Sort alarms by status and time
*/
const sortAlarm = (alarms: AlertAlert[] | SilenceSilencerResponse[], map) => {
const sortAlarm = (
alarms: AlertAlert[] | SilenceSilencerResponse[],
map: { [T: string]: { text: string; color: string; weight: number } },
) => {
if (!alarms || !alarms.length) return [];
const types = uniq(alarms.map((item) => item.status.state));
types.sort((pre, cur) => map[cur].weight - map[pre].weight);
Expand Down Expand Up @@ -190,10 +193,10 @@ export const validateLabelValues = (
) => {
for (const labelValue of labelValues) {
const tempArr = Object.keys(labelValue).map((key) =>
Boolean(labelValue[key]),
Boolean(labelValue[key as keyof (AlarmMatcher | CommonKVPair)]),
);
const stautsArr = tempArr.filter((item) => item === true);
if (stautsArr.length === 1) return false;
if (stautsArr.length === 1) return false;
if (
stautsArr.length === 2 &&
tempArr.length > 2 &&
Expand All @@ -204,3 +207,17 @@ export const validateLabelValues = (
}
return true;
};

/**
*
* @param duration The unit is seconds
*/
export const formatDuration = (duration: number) => {
if (Math.floor(duration / 60) > 180) {
return `${Math.floor(duration / 3600)}小时`;
}
if (duration > 600) {
return `${Math.floor(duration / 60)}分钟`;
}
return `${duration}秒`;
};
6 changes: 4 additions & 2 deletions ui/src/type/alert.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AlarmMatcher, OceanbaseOBInstanceType } from '@/api/generated';
import type { AlarmMatcher } from '@/api/generated';
import type { Dayjs } from 'dayjs';

declare namespace Alert {
Expand All @@ -9,8 +9,9 @@ declare namespace Alert {
rules?: string[];
};
type InstancesKey = 'obcluster' | 'observer' | 'obtenant';
type AlarmLevel = 'critical' | 'warning' | 'caution' | 'info';
type InstancesType = {
type: OceanbaseOBInstanceType;
type: InstancesKey;
obcluster: string[];
observer?: string[];
obtenant?: string[];
Expand All @@ -23,6 +24,7 @@ declare namespace Alert {
value?: string;
}[];
endsAt: Dayjs;
rules: string[];
id?: string;
comment: string;
};
Expand Down

0 comments on commit d897c5e

Please sign in to comment.