mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-12 16:28:59 +08:00
added min-max values check in latency (#158)
* added min-max values check in latency * error handling antd way * separated rules validation logic into functions
This commit is contained in:
parent
a118c3c8a1
commit
72f5688194
@ -1,6 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Modal, Form, InputNumber, Col, Row } from "antd";
|
import { Modal, Form, InputNumber, Col, Row } from "antd";
|
||||||
import { Store } from "antd/lib/form/interface";
|
import { NamePath, Store } from "antd/lib/form/interface";
|
||||||
|
|
||||||
interface LatencyModalFormProps {
|
interface LatencyModalFormProps {
|
||||||
onCreate: (values: Store) => void; //Store is defined in antd forms library
|
onCreate: (values: Store) => void; //Store is defined in antd forms library
|
||||||
@ -14,6 +14,25 @@ const LatencyModalForm: React.FC<LatencyModalFormProps> = ({
|
|||||||
latencyFilterValues,
|
latencyFilterValues,
|
||||||
}) => {
|
}) => {
|
||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
|
|
||||||
|
const validateMinValue = ({ getFieldValue }: {getFieldValue: (name: NamePath) => any}) => ({
|
||||||
|
validator(_, value: any) {
|
||||||
|
if (value < getFieldValue('max')) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error('Min value should be less than Max value'));
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const validateMaxValue = ({ getFieldValue }: {getFieldValue: (name: NamePath) => any}) => ({
|
||||||
|
validator(_, value: any) {
|
||||||
|
if (value > getFieldValue('min')) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
return Promise.reject(new Error('Max value should be greater than Min value'));
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal
|
||||||
visible={true}
|
visible={true}
|
||||||
@ -45,13 +64,18 @@ const LatencyModalForm: React.FC<LatencyModalFormProps> = ({
|
|||||||
<Form.Item
|
<Form.Item
|
||||||
name="min"
|
name="min"
|
||||||
label="Min (in ms)"
|
label="Min (in ms)"
|
||||||
|
rules={[validateMinValue]}
|
||||||
// rules={[{ required: true, message: 'Please input the title of collection!' }]}
|
// rules={[{ required: true, message: 'Please input the title of collection!' }]}
|
||||||
>
|
>
|
||||||
<InputNumber />
|
<InputNumber />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
<Col span={12}>
|
<Col span={12}>
|
||||||
<Form.Item name="max" label="Max (in ms)">
|
<Form.Item
|
||||||
|
name="max"
|
||||||
|
label="Max (in ms)"
|
||||||
|
rules = {[validateMaxValue]}
|
||||||
|
>
|
||||||
<InputNumber />
|
<InputNumber />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user