feat: add minInterval in provider

This commit is contained in:
moonrailgun 2023-12-20 17:53:17 +00:00
parent ffa2cce2a6
commit 3512ad1997
3 changed files with 27 additions and 4 deletions

View File

@ -32,9 +32,11 @@ export const MonitorInfoEditor: React.FC<MonitorInfoEditorProps> = React.memo(
const initialValues = props.initialValues ?? defaultValues;
const isEdit = Boolean(initialValues.id);
const formEl = useMemo(() => {
const provider = getMonitorProvider(typeValue);
const provider = useMemo(() => {
return getMonitorProvider(typeValue);
}, [typeValue]);
const formEl = useMemo(() => {
if (!provider) {
return null;
}
@ -42,7 +44,7 @@ export const MonitorInfoEditor: React.FC<MonitorInfoEditorProps> = React.memo(
const Component = provider.form;
return <Component />;
}, [typeValue]);
}, [provider]);
const handleSubmit = useEvent((values) => {
props.onSave({
@ -81,7 +83,11 @@ export const MonitorInfoEditor: React.FC<MonitorInfoEditorProps> = React.memo(
name="interval"
rules={[{ required: true }]}
>
<InputNumber min={5} max={10000} step={10} />
<InputNumber
min={provider?.minInterval ?? 5}
max={10000}
step={10}
/>
</Form.Item>
{formEl}

View File

@ -57,4 +57,5 @@ export const openaiProvider: MonitorProvider = {
overview: [MonitorOpenaiOverview],
valueLabel: 'Balance',
valueFormatter: (value) => `$${value / 100}`,
minInterval: 300, // min allow request in 5 minute, avoid to pressure for chatgpt
};

View File

@ -6,8 +6,24 @@ export interface MonitorProvider {
link?: (info: MonitorInfo) => React.ReactNode;
form: React.ComponentType;
overview?: MonitorOverviewComponent[];
/**
* Custom chart value label name
*/
valueLabel?: string;
/**
* Custom chart value label number display
*/
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<{