feat: add minInterval in provider
This commit is contained in:
parent
ffa2cce2a6
commit
3512ad1997
@ -32,9 +32,11 @@ export const MonitorInfoEditor: React.FC<MonitorInfoEditorProps> = React.memo(
|
|||||||
const initialValues = props.initialValues ?? defaultValues;
|
const initialValues = props.initialValues ?? defaultValues;
|
||||||
const isEdit = Boolean(initialValues.id);
|
const isEdit = Boolean(initialValues.id);
|
||||||
|
|
||||||
const formEl = useMemo(() => {
|
const provider = useMemo(() => {
|
||||||
const provider = getMonitorProvider(typeValue);
|
return getMonitorProvider(typeValue);
|
||||||
|
}, [typeValue]);
|
||||||
|
|
||||||
|
const formEl = useMemo(() => {
|
||||||
if (!provider) {
|
if (!provider) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -42,7 +44,7 @@ export const MonitorInfoEditor: React.FC<MonitorInfoEditorProps> = React.memo(
|
|||||||
const Component = provider.form;
|
const Component = provider.form;
|
||||||
|
|
||||||
return <Component />;
|
return <Component />;
|
||||||
}, [typeValue]);
|
}, [provider]);
|
||||||
|
|
||||||
const handleSubmit = useEvent((values) => {
|
const handleSubmit = useEvent((values) => {
|
||||||
props.onSave({
|
props.onSave({
|
||||||
@ -81,7 +83,11 @@ export const MonitorInfoEditor: React.FC<MonitorInfoEditorProps> = React.memo(
|
|||||||
name="interval"
|
name="interval"
|
||||||
rules={[{ required: true }]}
|
rules={[{ required: true }]}
|
||||||
>
|
>
|
||||||
<InputNumber min={5} max={10000} step={10} />
|
<InputNumber
|
||||||
|
min={provider?.minInterval ?? 5}
|
||||||
|
max={10000}
|
||||||
|
step={10}
|
||||||
|
/>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
|
||||||
{formEl}
|
{formEl}
|
||||||
|
@ -57,4 +57,5 @@ export const openaiProvider: MonitorProvider = {
|
|||||||
overview: [MonitorOpenaiOverview],
|
overview: [MonitorOpenaiOverview],
|
||||||
valueLabel: 'Balance',
|
valueLabel: 'Balance',
|
||||||
valueFormatter: (value) => `$${value / 100}`,
|
valueFormatter: (value) => `$${value / 100}`,
|
||||||
|
minInterval: 300, // min allow request in 5 minute, avoid to pressure for chatgpt
|
||||||
};
|
};
|
||||||
|
@ -6,8 +6,24 @@ export interface MonitorProvider {
|
|||||||
link?: (info: MonitorInfo) => React.ReactNode;
|
link?: (info: MonitorInfo) => React.ReactNode;
|
||||||
form: React.ComponentType;
|
form: React.ComponentType;
|
||||||
overview?: MonitorOverviewComponent[];
|
overview?: MonitorOverviewComponent[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom chart value label name
|
||||||
|
*/
|
||||||
valueLabel?: string;
|
valueLabel?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom chart value label number display
|
||||||
|
*/
|
||||||
valueFormatter?: (value: number) => string;
|
valueFormatter?: (value: number) => string;
|
||||||
|
/**
|
||||||
|
* Minimum value of this provider
|
||||||
|
*
|
||||||
|
* Helps reduce pressure on third-party services
|
||||||
|
*
|
||||||
|
* unit: second
|
||||||
|
*/
|
||||||
|
minInterval?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type MonitorOverviewComponent = React.ComponentType<{
|
export type MonitorOverviewComponent = React.ComponentType<{
|
||||||
|
Loading…
Reference in New Issue
Block a user