Skip to content

Commit 2276ffa

Browse files
committed
Remove toast notifications and simplify dashboard UI
1 parent a771c4e commit 2276ffa

File tree

2 files changed

+59
-113
lines changed

2 files changed

+59
-113
lines changed

dashboard/components.py

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,22 @@ def create_batch_card(batch_name: str, stats: dict) -> Card:
207207
return Card(
208208
DivLAligned(
209209
Div(
210-
H4(batch_name, cls="mb-2"),
210+
Button(
211+
batch_name,
212+
hx_get=f"/batch/{batch_name}",
213+
hx_push_url=f"/batch/{batch_name}",
214+
hx_target="#main-content",
215+
hx_indicator="#loading",
216+
cls=ButtonT.primary,
217+
),
211218
DivLAligned(
212219
Div(
213220
DivLAligned(
214221
UkIcon("activity", cls="text-blue-500"),
215-
P(f"{stats['unique_metrics']} metrics", cls=TextPresets.muted_sm),
222+
P(
223+
f"{stats['unique_metrics']} metrics",
224+
cls=TextPresets.muted_sm,
225+
),
216226
cls="space-x-2",
217227
),
218228
DivLAligned(
@@ -222,30 +232,28 @@ def create_batch_card(batch_name: str, stats: dict) -> Card:
222232
),
223233
DivLAligned(
224234
UkIcon("bar-chart", cls="text-purple-500"),
225-
P(f"Avg Score: {stats['avg_score']:.1%}", cls=TextPresets.muted_sm),
235+
P(
236+
f"Avg Score: {stats['avg_score']:.1%}",
237+
cls=TextPresets.muted_sm,
238+
),
226239
cls="space-x-2",
227240
),
228241
DivLAligned(
229242
UkIcon("alert-circle", cls="text-red-500"),
230-
P(f"{stats['alert_count']} alerts", cls=TextPresets.muted_sm),
243+
P(
244+
f"{stats['alert_count']} alerts",
245+
cls=TextPresets.muted_sm,
246+
),
231247
cls="space-x-2",
232248
),
233-
cls="space-y-2",
249+
cls="space-y-1",
234250
)
235251
),
236252
),
237-
Button(
238-
"View Metrics",
239-
hx_get=f"/batch/{batch_name}",
240-
hx_push_url=f"/batch/{batch_name}",
241-
hx_target="#main-content",
242-
hx_indicator="#loading",
243-
cls=ButtonT.primary,
244-
),
245253
style="justify-content: space-between;",
246254
cls="flex-row items-center",
247255
),
248-
cls="p-6 hover:border-primary transition-colors duration-200",
256+
cls="p-2 hover:border-primary transition-colors duration-200",
249257
)
250258

251259

dashboard/routes.py

Lines changed: 37 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,21 @@ def post(request: Request):
2424
"""
2525
Refresh all batch data.
2626
"""
27-
# Add loading toast
28-
loading_toast = add_toast("Refreshing all batch data...", "info")
29-
27+
3028
try:
3129
# Clear all batch caches
3230
app.state.df_cache.clear()
3331
app.state.stats_cache.clear()
3432
app.state.chart_cache.clear()
35-
33+
3634
# Get the updated content
3735
response = index(request)
38-
39-
# Add success toast
40-
success_toast = add_toast("Successfully refreshed all batch data", "success")
41-
42-
return [loading_toast, response, success_toast]
43-
36+
37+
return [response]
38+
4439
except Exception as e:
45-
# Add error toast
46-
error_toast = add_toast(f"Error refreshing batch data: {str(e)}", "error")
47-
return [loading_toast, error_toast]
40+
log.error(f"Error refreshing all batch data: {e}")
41+
return []
4842

4943

5044
@rt
@@ -64,41 +58,21 @@ def index(request: Request):
6458
"""
6559
)
6660

67-
# Add toast container for notifications
68-
toast_container = Div(id="toast-container", cls=(ToastHT.end, ToastVT.top))
69-
7061
# Calculate batch stats
7162
batch_stats = {}
7263
for batch_name in app.state.metric_batches:
7364
if batch_name not in app.state.df_cache:
7465
try:
75-
# Add loading toast
76-
loading_toast = Toast(
77-
f"Loading data for batch {batch_name}...",
78-
alert_cls=AlertT.info,
79-
cls=(ToastHT.end, ToastVT.top)
80-
)
81-
66+
8267
df = get_data(
8368
app.state.specs_enabled[batch_name], max_n=DEFAULT_ALERT_MAX_N
8469
)
85-
86-
# Add success toast
87-
success_toast = Toast(
88-
f"Successfully loaded data for {batch_name}",
89-
alert_cls=AlertT.success,
90-
cls=(ToastHT.end, ToastVT.top)
91-
)
92-
70+
9371
except Exception as e:
9472
log.error(f"Error getting data for batch {batch_name}: {e}")
95-
# Add error toast
96-
error_toast = Toast(
97-
f"Error loading data for {batch_name}: {str(e)}",
98-
alert_cls=AlertT.error,
99-
cls=(ToastHT.end, ToastVT.top)
73+
df = pd.DataFrame(
74+
data=[], columns=["metric_name", "metric_timestamp", "metric_value"]
10075
)
101-
df = pd.DataFrame(data=[], columns=['metric_name', 'metric_timestamp', 'metric_value'])
10276
app.state.df_cache[batch_name] = df
10377
else:
10478
df = app.state.df_cache[batch_name]
@@ -117,8 +91,8 @@ def index(request: Request):
11791
filtered_batches.keys(),
11892
key=lambda x: (
11993
-filtered_batches[x]["alert_count"], # Negative for descending order
120-
-filtered_batches[x]["avg_score"] # Negative for descending order
121-
)
94+
-filtered_batches[x]["avg_score"], # Negative for descending order
95+
),
12296
)
12397

12498
main_content = Div(
@@ -127,25 +101,22 @@ def index(request: Request):
127101
H2("Anomstack", cls="text-2xl font-bold pl-2"),
128102
DivLAligned(
129103
Button(
130-
DivLAligned(
131-
UkIcon("refresh-ccw"),
132-
cls="space-x-2"
133-
),
104+
DivLAligned(UkIcon("refresh-ccw"), cls="space-x-2"),
134105
cls=ButtonT.ghost, # Using ghost style to match header aesthetics
135106
hx_post="/refresh-all",
136107
hx_target="#main-content",
137108
hx_indicator="#loading",
138-
uk_tooltip="Refresh all"
109+
uk_tooltip="Refresh all",
139110
),
140111
A(
141112
UkIcon("github"),
142113
href="https://github.com/andrewm4894/anomstack",
143114
cls=ButtonT.ghost,
144-
uk_tooltip="View the source code on GitHub"
115+
uk_tooltip="View the source code on GitHub",
145116
),
146-
cls="space-x-2"
117+
cls="space-x-2",
147118
),
148-
cls="flex justify-between items-center mb-6"
119+
cls="flex justify-between items-center mb-6",
149120
),
150121
# Show warning if no metric batches
151122
(
@@ -156,18 +127,21 @@ def index(request: Request):
156127
"No metric batches found. Is Dagster running?",
157128
cls=TextPresets.muted_sm,
158129
),
159-
cls="space-x-2 p-4 bg-yellow-50 text-yellow-700 rounded-md",
130+
cls="space-x-2 p-2 bg-yellow-50 text-yellow-700 rounded-md",
160131
),
161132
cls="mb-6",
162133
)
163134
if not app.state.metric_batches
164135
else Grid(
165-
*[create_batch_card(name, batch_stats[name]) for name in sorted_batch_names],
166-
cols=3,
167-
gap=4,
136+
*[
137+
create_batch_card(name, batch_stats[name])
138+
for name in sorted_batch_names
139+
],
140+
cols=4,
141+
gap=2,
168142
)
169143
),
170-
cls="p-6",
144+
cls="p-2",
171145
),
172146
id="main-content",
173147
)
@@ -176,11 +150,10 @@ def index(request: Request):
176150
if is_htmx:
177151
return main_content
178152

179-
# For full page loads, return the complete layout with toast container
153+
# For full page loads, return the complete layout
180154
return (
181155
Title("Anomstack"),
182156
script,
183-
toast_container, # Add toast container
184157
Div(
185158
Safe('<span class="htmx-indicator">Loading...</span>'),
186159
id="loading",
@@ -304,23 +277,18 @@ def get(batch_name: str, session):
304277
"""
305278
Refresh the batch view for a given batch name.
306279
"""
307-
# Add loading toast
308-
loading_toast = add_toast(f"Refreshing data for {batch_name}...", "info")
309-
280+
310281
try:
311282
app.state.clear_batch_cache(batch_name)
312-
response = get_batch_view(batch_name, session, initial_load=DEFAULT_LOAD_N_CHARTS)
313-
314-
# Add success toast
315-
success_toast = add_toast(f"Successfully refreshed {batch_name}", "success")
316-
317-
# Return both the response and the toasts
318-
return [loading_toast, response, success_toast]
319-
283+
response = get_batch_view(
284+
batch_name, session, initial_load=DEFAULT_LOAD_N_CHARTS
285+
)
286+
287+
# Return the response
288+
return [response]
289+
320290
except Exception as e:
321-
# Add error toast
322-
error_toast = add_toast(f"Error refreshing {batch_name}: {str(e)}", "error")
323-
return [loading_toast, error_toast]
291+
return []
324292

325293

326294
@rt("/batch/{batch_name}/load-more/{start_index}")
@@ -483,39 +451,9 @@ def post(batch_name: str, session=None):
483451
"""
484452
Toggle between narrow (1px) and normal (2px) line width.
485453
"""
486-
app.state.narrow_lines = not getattr(app.state, 'narrow_lines', False)
454+
app.state.narrow_lines = not getattr(app.state, "narrow_lines", False)
487455
app.state.line_width = 1 if app.state.narrow_lines else 2
488456
app.state.chart_cache.clear() # Clear cache to regenerate charts
489457
return get_batch_view(
490458
batch_name, session=session, initial_load=DEFAULT_LOAD_N_CHARTS
491459
)
492-
493-
494-
# Add helper function to create toast messages for other routes
495-
def add_toast(message: str, type: str = "info") -> Toast:
496-
"""Create a toast notification"""
497-
alert_types = {
498-
"info": AlertT.info,
499-
"success": AlertT.success,
500-
"warning": AlertT.warning,
501-
"error": AlertT.error
502-
}
503-
return Toast(
504-
message,
505-
alert_cls=alert_types.get(type, AlertT.info),
506-
cls=(ToastHT.end, ToastVT.top),
507-
hx_swap_oob="beforeend",
508-
hx_target="#toast-container"
509-
)
510-
511-
512-
# Add new test toast route
513-
@rt("/test-toast")
514-
def post(request: Request):
515-
"""Test route to trigger different types of toasts."""
516-
return [
517-
add_toast("This is an info toast", "info"),
518-
add_toast("This is a success toast", "success"),
519-
add_toast("This is a warning toast", "warning"),
520-
add_toast("This is an error toast", "error")
521-
]

0 commit comments

Comments
 (0)