feat: monitor list add upPercent

This commit is contained in:
moonrailgun 2023-10-14 00:26:31 +08:00
parent 7e03bd5ee4
commit 0ba0f4a080

View File

@ -27,11 +27,28 @@ export const MonitorList: React.FC = React.memo(() => {
return null; return null;
}, []); }, []);
const [beats, setBeats] = useState<
{
value: number;
createdAt: string;
}[]
>([]);
const [selectedMonitorId, setSelectedMonitorId] = useState<string | null>( const [selectedMonitorId, setSelectedMonitorId] = useState<string | null>(
initMonitorId initMonitorId
); );
const upPercent = useMemo(() => {
let up = 0;
beats.forEach((b) => {
if (b.value >= 0) {
up++;
}
});
return parseFloat(((up / beats.length) * 100).toFixed(1));
}, [beats]);
if (!currentWorkspaceId) { if (!currentWorkspaceId) {
return <NoWorkspaceTip />; return <NoWorkspaceTip />;
} }
@ -59,11 +76,11 @@ export const MonitorList: React.FC = React.memo(() => {
} }
> >
{/* {monitor.monthOnlineRate * 100}% */} {/* {monitor.monthOnlineRate * 100}% */}
80% {upPercent}%
</span> </span>
</div> </div>
<div className="flex-1 pl-2"> <div className="flex-1 pl-2">
<div className="text-base mb-2">{monitor.name}</div> <div className="text-base">{monitor.name}</div>
{/* <div> {/* <div>
{monitor.tags.map((tag) => ( {monitor.tags.map((tag) => (
<span <span
@ -77,7 +94,10 @@ export const MonitorList: React.FC = React.memo(() => {
</div> </div>
<div className="flex items-center"> <div className="flex items-center">
<MonitorHealthBar monitorId={monitor.id} /> <MonitorHealthBar
monitorId={monitor.id}
onBeatsItemUpdate={setBeats}
/>
</div> </div>
</div> </div>
))} ))}