Skip to content

Commit 7f0b087

Browse files
committed
rafactor componenets to seperate files
1 parent 6bed197 commit 7f0b087

File tree

8 files changed

+271
-252
lines changed

8 files changed

+271
-252
lines changed

dashboard/components.py

Lines changed: 0 additions & 252 deletions
This file was deleted.

dashboard/components/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
Components module initialization.
3+
"""
4+
from .toolbar import create_toolbar_buttons
5+
from .search import create_search_form, create_last_n_form
6+
from .batch import create_batch_card
7+
from .settings import create_settings_dropdown
8+
from .header import create_header
9+
from .common import create_controls
10+
11+
__all__ = [
12+
'create_toolbar_buttons',
13+
'create_search_form',
14+
'create_last_n_form',
15+
'create_batch_card',
16+
'create_settings_dropdown',
17+
'create_header',
18+
'create_controls',
19+
]

dashboard/components/batch.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
"""
2+
Batch-related components.
3+
"""
4+
from fasthtml.common import *
5+
from monsterui.all import *
6+
from dashboard.state import get_state
7+
8+
def create_batches_dropdown(batch_name: str) -> DropDownNavContainer:
9+
"""Create the metric batches dropdown menu."""
10+
state = get_state()
11+
return DropDownNavContainer(
12+
NavHeaderLi("metric batches"),
13+
*[
14+
Li(
15+
A(
16+
name,
17+
hx_get=f"/batch/{name}",
18+
hx_push_url=f"/batch/{name}",
19+
hx_target="#main-content",
20+
hx_indicator="#loading",
21+
cls=f"{'uk-active' if name == batch_name else ''}",
22+
)) for name in state.metric_batches
23+
],
24+
uk_dropdown="pos: bottom-right; boundary: window; shift: true; flip: true;")
25+
26+
def create_batch_card(batch_name: str, stats: dict) -> Card:
27+
"""Create a card displaying batch information."""
28+
metric_info = [
29+
(UkIcon("activity", cls="text-blue-500"), f"{stats['unique_metrics']} metrics"),
30+
(UkIcon("clock", cls="text-green-500"), f"{stats['latest_timestamp']}"),
31+
(UkIcon("bar-chart", cls="text-purple-500"), f"Avg Score: {stats['avg_score']:.1%}"),
32+
(UkIcon("alert-circle", cls="text-red-500"), f"{stats['alert_count']} alerts"),
33+
]
34+
35+
metric_divs = [
36+
DivLAligned(
37+
icon,
38+
P(text, cls=TextPresets.muted_sm),
39+
cls="space-x-2",
40+
) for icon, text in metric_info
41+
]
42+
43+
return Card(
44+
DivLAligned(
45+
Div(
46+
Button(batch_name,
47+
hx_get=f"/batch/{batch_name}",
48+
hx_push_url=f"/batch/{batch_name}",
49+
hx_target="#main-content",
50+
hx_indicator="#loading",
51+
cls=(ButtonT.primary, "w-full")),
52+
DividerLine(),
53+
DivLAligned(Div(*metric_divs, cls="space-y-1"), ),
54+
cls="w-full",
55+
),
56+
cls="w-full",
57+
),
58+
cls="px-2 py-0.5 hover:border-primary transition-colors duration-200",
59+
)

dashboard/components/common.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Common components shared across the dashboard.
3+
"""
4+
from fasthtml.common import *
5+
from monsterui.all import *
6+
from .search import create_search_form, create_last_n_form
7+
from .toolbar import create_toolbar_buttons
8+
9+
def create_controls(batch_name: str) -> Card:
10+
"""Create the main controls for the dashboard."""
11+
return Card(
12+
DivFullySpaced(
13+
Div(
14+
Div(
15+
Div(
16+
create_toolbar_buttons(batch_name),
17+
Div(
18+
create_search_form(batch_name),
19+
create_last_n_form(batch_name),
20+
cls="flex flex-col space-y-2 md:flex-row md:space-y-0 md:space-x-4 mt-4",
21+
),
22+
cls="flex flex-col w-full",
23+
), ),
24+
cls="w-full",
25+
), ),
26+
cls="mb-4 uk-padding-small py-2 shadow-sm",
27+
)

dashboard/components/header.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"""
2+
Header components.
3+
"""
4+
from fasthtml.common import *
5+
from monsterui.all import *
6+
7+
def create_header() -> Div:
8+
"""Create the dashboard header."""
9+
return DivLAligned(
10+
H2(
11+
"Anomstack",
12+
P(
13+
"Painless open source anomaly detection for your metrics 📈📉🚀",
14+
cls=TextPresets.muted_sm,
15+
),
16+
cls="mb-2",
17+
),
18+
A(
19+
DivLAligned(UkIcon("github")),
20+
href="https://github.com/andrewm4894/anomstack",
21+
target="_blank",
22+
cls="uk-button uk-button-secondary",
23+
uk_tooltip="View on GitHub",
24+
),
25+
style="justify-content: space-between;",
26+
cls="mb-6",
27+
)

0 commit comments

Comments
 (0)