Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6171bf6

Browse files
Copilotmo-esmp
andcommitted
Add frontend dashboard component with charts and navigation
Co-authored-by: mo-esmp <1659032+mo-esmp@users.noreply.github.com>
1 parent65cbd47 commit6171bf6

File tree

11 files changed

+963
-7
lines changed

11 files changed

+963
-7
lines changed

‎src/Serilog.Ui.Web/package-lock.json‎

Lines changed: 372 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎src/Serilog.Ui.Web/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"react-dom":"^18.3.1",
2828
"react-hook-form":"^7.55.0",
2929
"react-router":"^7.5.2",
30+
"recharts":"^3.0.2",
3031
"xml-formatter":"^3.6.5"
3132
},
3233
"devDependencies": {
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
import{Box,Card,Grid,Text,Title,Group,Stack}from'@mantine/core';
2+
import{IconActivity,IconAlertTriangle,IconCalendar,IconChartBar}from'@tabler/icons-react';
3+
import{BarChart,Bar,XAxis,YAxis,CartesianGrid,Tooltip,ResponsiveContainer,PieChart,Pie,Cell}from'recharts';
4+
importuseQueryDashboardfrom'../hooks/useQueryDashboard';
5+
6+
constLEVEL_COLORS={
7+
Verbose:'#868e96',
8+
Debug:'#4c6ef5',
9+
Information:'#12b886',
10+
Warning:'#fd7e14',
11+
Error:'#fa5252',
12+
Fatal:'#c92a2a',
13+
Unknown:'#adb5bd',
14+
};
15+
16+
constStatCard=({ icon, title, value, color}:{
17+
icon:React.ReactNode;
18+
title:string;
19+
value:number;
20+
color:string;
21+
})=>(
22+
<Cardshadow="sm"padding="lg"radius="md"withBorder>
23+
<Groupjustify="space-between">
24+
<Stackgap="xs">
25+
<Textsize="sm"c="dimmed">
26+
{title}
27+
</Text>
28+
<Textsize="xl"fw={700}c={color}>
29+
{value.toLocaleString()}
30+
</Text>
31+
</Stack>
32+
<Boxc={color}>
33+
{icon}
34+
</Box>
35+
</Group>
36+
</Card>
37+
);
38+
39+
exportconstDashboard=()=>{
40+
const{data:dashboard, isLoading, error}=useQueryDashboard();
41+
42+
if(isLoading){
43+
return(
44+
<Boxp="md">
45+
<Text>Loading dashboard...</Text>
46+
</Box>
47+
);
48+
}
49+
50+
if(error||!dashboard){
51+
return(
52+
<Boxp="md">
53+
<Textc="red">Error loading dashboard data</Text>
54+
</Box>
55+
);
56+
}
57+
58+
// Prepare data for charts
59+
constlevelData=Object.entries(dashboard.logsByLevel).map(([level,count])=>({
60+
level,
61+
count,
62+
color:LEVEL_COLORS[levelaskeyoftypeofLEVEL_COLORS]||LEVEL_COLORS.Unknown,
63+
}));
64+
65+
return(
66+
<Boxp="md">
67+
<Titleorder={2}mb="lg">
68+
Log Dashboard
69+
</Title>
70+
71+
{/* Stats Cards */}
72+
<Gridgutter="md"mb="xl">
73+
<Grid.Colspan={{base:12,md:3}}>
74+
<StatCard
75+
icon={<IconChartBarsize={32}/>}
76+
title="Total Logs"
77+
value={dashboard.totalLogs}
78+
color="blue"
79+
/>
80+
</Grid.Col>
81+
<Grid.Colspan={{base:12,md:3}}>
82+
<StatCard
83+
icon={<IconCalendarsize={32}/>}
84+
title="Today's Logs"
85+
value={dashboard.todayLogs}
86+
color="green"
87+
/>
88+
</Grid.Col>
89+
<Grid.Colspan={{base:12,md:3}}>
90+
<StatCard
91+
icon={<IconAlertTrianglesize={32}/>}
92+
title="Today's Errors"
93+
value={dashboard.todayErrorLogs}
94+
color="red"
95+
/>
96+
</Grid.Col>
97+
<Grid.Colspan={{base:12,md:3}}>
98+
<StatCard
99+
icon={<IconActivitysize={32}/>}
100+
title="Log Levels"
101+
value={Object.keys(dashboard.logsByLevel).length}
102+
color="grape"
103+
/>
104+
</Grid.Col>
105+
</Grid>
106+
107+
{/* Charts */}
108+
<Gridgutter="md">
109+
<Grid.Colspan={{base:12,md:8}}>
110+
<Cardshadow="sm"padding="lg"radius="md"withBorder>
111+
<Titleorder={4}mb="md">
112+
Logs by Level
113+
</Title>
114+
<Boxh={300}>
115+
<ResponsiveContainerwidth="100%"height="100%">
116+
<BarChartdata={levelData}>
117+
<CartesianGridstrokeDasharray="3 3"/>
118+
<XAxisdataKey="level"/>
119+
<YAxis/>
120+
<Tooltip/>
121+
<BardataKey="count"fill="#4c6ef5"/>
122+
</BarChart>
123+
</ResponsiveContainer>
124+
</Box>
125+
</Card>
126+
</Grid.Col>
127+
<Grid.Colspan={{base:12,md:4}}>
128+
<Cardshadow="sm"padding="lg"radius="md"withBorder>
129+
<Titleorder={4}mb="md">
130+
Level Distribution
131+
</Title>
132+
<Boxh={300}>
133+
<ResponsiveContainerwidth="100%"height="100%">
134+
<PieChart>
135+
<Pie
136+
data={levelData}
137+
cx="50%"
138+
cy="50%"
139+
labelLine={false}
140+
label={({ level, percent})=>`${level}${((percent||0)*100).toFixed(0)}%`}
141+
outerRadius={80}
142+
fill="#8884d8"
143+
dataKey="count"
144+
>
145+
{levelData.map((entry,index)=>(
146+
<Cellkey={`cell-${index}`}fill={entry.color}/>
147+
))}
148+
</Pie>
149+
<Tooltip/>
150+
</PieChart>
151+
</ResponsiveContainer>
152+
</Box>
153+
</Card>
154+
</Grid.Col>
155+
</Grid>
156+
</Box>
157+
);
158+
};
159+
160+
exportdefaultDashboard;

‎src/Serilog.Ui.Web/src/app/components/Index.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useSerilogUiProps } from 'app/hooks/useSerilogUiProps';
1010
import{Suspense,lazy}from'react';
1111
import{Navigate}from'react-router';
1212

13-
constAppBody=lazy(()=>import('./AppBody'));
13+
constAppBody=lazy(()=>import('./TabbedAppBody'));
1414
constHead=lazy(()=>import('./ShellStructure/Header'));
1515
constSidebar=lazy(()=>import('./ShellStructure/Sidebar'));
1616

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import{Box,Tabs}from'@mantine/core';
2+
import{IconChartBar,IconTable}from'@tabler/icons-react';
3+
import{useJwtTimeout}from'app/hooks/useJwtTimeout';
4+
import{useState,Suspense,lazy}from'react';
5+
importclassesfrom'style/table.module.css';
6+
7+
constSearch=lazy(()=>import('./Search/Search'));
8+
constPaging=lazy(()=>import('./Search/Paging'));
9+
constSerilogResults=lazy(()=>import('./Table/SerilogResults'));
10+
constSerilogResultsMobile=lazy(()=>import('./Table/SerilogResultsMobile'));
11+
constDashboard=lazy(()=>import('./Dashboard'));
12+
13+
constTabbedAppBody=({ hideMobileResults}:{hideMobileResults?:boolean})=>{
14+
useJwtTimeout();
15+
const[activeTab,setActiveTab]=useState<string|null>('logs');
16+
17+
return(
18+
<Boxp="md">
19+
<Tabsvalue={activeTab}onChange={setActiveTab}>
20+
<Tabs.List>
21+
<Tabs.Tabvalue="logs"leftSection={<IconTablesize={16}/>}>
22+
Logs
23+
</Tabs.Tab>
24+
<Tabs.Tabvalue="dashboard"leftSection={<IconChartBarsize={16}/>}>
25+
Dashboard
26+
</Tabs.Tab>
27+
</Tabs.List>
28+
29+
<Tabs.Panelvalue="logs">
30+
<Boxmt="md">
31+
<BoxvisibleFrom="lg">
32+
<Suspense>
33+
<Search/>
34+
</Suspense>
35+
</Box>
36+
<Box
37+
display={hideMobileResults ?'none' :'block'}
38+
hiddenFrom="md"
39+
className={classes.mobileTableWrapper}
40+
>
41+
<Suspense>
42+
<SerilogResultsMobile/>
43+
</Suspense>
44+
</Box>
45+
<Box>
46+
<BoxvisibleFrom="md"m="xl">
47+
<Suspense>
48+
<SerilogResults/>
49+
</Suspense>
50+
</Box>
51+
<Suspense>
52+
<Paging/>
53+
</Suspense>
54+
</Box>
55+
</Box>
56+
</Tabs.Panel>
57+
58+
<Tabs.Panelvalue="dashboard">
59+
<Boxmt="md">
60+
<Suspense>
61+
<Dashboard/>
62+
</Suspense>
63+
</Box>
64+
</Tabs.Panel>
65+
</Tabs>
66+
</Box>
67+
);
68+
};
69+
70+
exportdefaultTabbedAppBody;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import{useQuery}from'@tanstack/react-query';
2+
import{useAuthProperties}from'./useAuthProperties';
3+
import{fetchDashboard}from'../queries/dashboard';
4+
5+
constuseQueryDashboard=()=>{
6+
const{ fetchInfo, isHeaderReady}=useAuthProperties();
7+
8+
returnuseQuery({
9+
enabled:isHeaderReady,
10+
queryKey:['get-dashboard'],
11+
queryFn:async()=>{
12+
if(!isHeaderReady)returnnull;
13+
returnawaitfetchDashboard(fetchInfo.headers,fetchInfo.routePrefix);
14+
},
15+
refetchOnMount:false,
16+
refetchOnWindowFocus:false,
17+
retry:false,
18+
});
19+
};
20+
21+
exportdefaultuseQueryDashboard;
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import{determineHost,send403Notification,sendUnexpectedNotification}from'../util/queries';
2+
import{UiApiError}from'./errors';
3+
4+
exportinterfaceDashboardData{
5+
totalLogs:number;
6+
logsByLevel:Record<string,number>;
7+
todayLogs:number;
8+
todayErrorLogs:number;
9+
}
10+
11+
constdefaultDashboard:DashboardData={
12+
totalLogs:0,
13+
logsByLevel:{},
14+
todayLogs:0,
15+
todayErrorLogs:0,
16+
};
17+
18+
exportconstfetchDashboard=async(
19+
fetchOptions:RequestInit,
20+
routePrefix?:string,
21+
):Promise<DashboardData>=>{
22+
try{
23+
consturl=`${determineHost(routePrefix)}/api/dashboard`;
24+
constreq=awaitfetch(url,fetchOptions);
25+
26+
if(req.ok)returnawait(req.json()asPromise<DashboardData>);
27+
28+
returnawaitPromise.reject(newUiApiError(req.status,'Failed to fetch dashboard'));
29+
}catch(error:unknown){
30+
consterr=errorasUiApiError;
31+
if(err?.code===403){
32+
send403Notification();
33+
}else{
34+
sendUnexpectedNotification(err.message);
35+
}
36+
37+
returndefaultDashboard;
38+
}
39+
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp