bbgo_origin/apps/backtest-report/components/ReportNavigator.tsx

79 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-05-17 17:53:48 +00:00
import React, {useEffect, useState} from 'react';
2022-05-18 17:00:45 +00:00
import {List, ThemeIcon} from '@mantine/core';
import {CircleCheck} from 'tabler-icons-react';
2022-05-17 17:53:48 +00:00
import {ReportEntry, ReportIndex} from '../types';
function fetchIndex(basePath: string, setter: (data: any) => void) {
return fetch(
`${basePath}/index.json`,
)
.then((res) => res.json())
.then((data) => {
console.log("reportIndex", data);
setter(data);
})
.catch((e) => {
console.error("failed to fetch index", e)
});
}
interface ReportNavigatorProps {
onSelect: (reportEntry: ReportEntry) => void;
}
const ReportNavigator = (props: ReportNavigatorProps) => {
const [isLoading, setLoading] = useState(false)
const [reportIndex, setReportIndex] = useState<ReportIndex>({runs: []});
useEffect(() => {
setLoading(true)
fetchIndex('/output', setReportIndex).then(() => {
setLoading(false);
})
}, []);
if (isLoading) {
return <div>Loading...</div>;
}
if (reportIndex.runs.length == 0) {
return <div>No back-test report data</div>
}
2022-05-18 17:00:45 +00:00
return <div className={"report-navigator"}>
<List
spacing="xs"
size="xs"
center
icon={
<ThemeIcon color="teal" size={24} radius="xl">
<CircleCheck size={16}/>
</ThemeIcon>
}
>
{
reportIndex.runs.map((entry) => {
return <List.Item key={entry.id} onClick={() => {
if (props.onSelect) {
props.onSelect(entry);
}
}}>
2022-05-18 17:07:08 +00:00
<div style={{
"textOverflow": "ellipsis",
"overflow": "hidden",
"inlineSize": "190px",
}}>
2022-05-18 17:00:45 +00:00
{entry.id}
2022-05-18 17:07:08 +00:00
</div>
2022-05-18 17:00:45 +00:00
</List.Item>
})
}
</List>
2022-05-17 17:53:48 +00:00
</div>;
};
export default ReportNavigator;