feat: add value format for data metrics

This commit is contained in:
moonrailgun 2023-12-23 01:04:02 +08:00
parent a579b678cc
commit f749f720db

View File

@ -17,8 +17,13 @@ export const MonitorDataMetrics: React.FC<{
workspaceId, workspaceId,
monitorId, monitorId,
}); });
const provider = useMemo(
() => getMonitorProvider(monitorType),
[monitorType]
);
const providerOverview = useMemo(() => { const providerOverview = useMemo(() => {
const provider = getMonitorProvider(monitorType);
if (!provider || !provider.overview) { if (!provider || !provider.overview) {
return null; return null;
} }
@ -30,7 +35,11 @@ export const MonitorDataMetrics: React.FC<{
))} ))}
</> </>
); );
}, [monitorId, monitorType]); }, [monitorId, provider]);
const formatterFn = provider?.valueFormatter
? provider?.valueFormatter
: (value: number) => `${value}ms`;
if (isLoading) { if (isLoading) {
return <Loading />; return <Loading />;
@ -46,14 +55,14 @@ export const MonitorDataMetrics: React.FC<{
<MonitorStatsBlock <MonitorStatsBlock
title="Response" title="Response"
desc="(Current)" desc="(Current)"
text={`${currectResponse} ms`} text={formatterFn(currectResponse)}
/> />
)} )}
<MonitorStatsBlock <MonitorStatsBlock
title="Avg. Response" title="Avg. Response"
desc="(24 hour)" desc="(24 hour)"
text={`${parseFloat(data.recent1DayAvg.toFixed(0))} ms`} text={formatterFn(parseFloat(data.recent1DayAvg.toFixed(0)))}
/> />
<MonitorStatsBlock <MonitorStatsBlock
title="Uptime" title="Uptime"