Skip to content

Commit 480af6e

Browse files
committed
update req.txt file and ruff
1 parent 61e6229 commit 480af6e

File tree

10 files changed

+51
-111
lines changed

10 files changed

+51
-111
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
2-
reflex==0.7.8a1
1+
reflex>=0.7.8a1

retail_analytics_dashboard/retail_analytics_dashboard/components/billing_cycle.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import reflex as rx
2-
from retail_analytics_dashbaord.states.dashboard_state import DashboardState
32
from retail_analytics_dashbaord.components.progress_bar import (
4-
progress_bar,
53
cost_progress_bar,
4+
progress_bar,
65
)
6+
from retail_analytics_dashbaord.states.dashboard_state import DashboardState
77

88

99
def billing_cycle_stats() -> rx.Component:
@@ -40,9 +40,7 @@ def billing_workspace_stats() -> rx.Component:
4040

4141
def billing_costs() -> rx.Component:
4242
"""Renders billing costs."""
43-
return cost_progress_bar(
44-
items=DashboardState.billing_costs_items
45-
)
43+
return cost_progress_bar(items=DashboardState.billing_costs_items)
4644

4745

4846
def billing_cycle() -> rx.Component:
@@ -100,4 +98,4 @@ def billing_cycle() -> rx.Component:
10098
),
10199
class_name="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",
102100
),
103-
)
101+
)

retail_analytics_dashboard/retail_analytics_dashboard/components/customize_charts_dialog.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import reflex as rx
2+
from retail_analytics_dashbaord.components.overview_chart import overview_chart
23
from retail_analytics_dashbaord.states.dashboard_state import (
34
DashboardState,
45
OverviewMetric,
56
)
6-
from retail_analytics_dashbaord.components.overview_chart import overview_chart
77

88

99
def customize_chart_item(
@@ -14,12 +14,8 @@ def customize_chart_item(
1414
overview_chart(metric),
1515
rx.el.input(
1616
type="checkbox",
17-
checked=DashboardState.temp_chart_visibility[
18-
metric["id"]
19-
],
20-
on_click=lambda: DashboardState.toggle_temp_chart_visibility(
21-
metric["id"]
22-
),
17+
checked=DashboardState.temp_chart_visibility[metric["id"]],
18+
on_click=lambda: DashboardState.toggle_temp_chart_visibility(metric["id"]),
2319
class_name="absolute top-3 right-3 h-5 w-5 text-indigo-600 focus:ring-indigo-500 border-gray-300 rounded cursor-pointer",
2420
),
2521
class_name="relative bg-white rounded-md shadow-sm border border-gray-200",
@@ -68,5 +64,5 @@ def customize_charts_dialog() -> rx.Component:
6864
),
6965
class_name="fixed inset-0 z-50 overflow-hidden",
7066
),
71-
rx.el.div()
72-
)
67+
rx.el.div(),
68+
)

retail_analytics_dashboard/retail_analytics_dashboard/components/overview_chart.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from typing import List
2+
13
import reflex as rx
24
from retail_analytics_dashbaord.states.dashboard_state import (
35
TOOLTIP_PROPS,
46
ChartDataPoint,
57
OverviewMetric,
68
)
7-
from typing import List, Dict, Union
89

910

1011
def overview_chart(
@@ -21,8 +22,7 @@ def overview_chart(
2122
metric["change"],
2223
class_name="ml-2 text-xs font-medium px-1.5 py-0.5 rounded-full "
2324
+ rx.cond(
24-
metric["change_color"]
25-
== "text-green-600",
25+
metric["change_color"] == "text-green-600",
2626
"bg-green-100 text-green-600",
2727
"bg-red-100 text-red-600",
2828
),
@@ -47,9 +47,7 @@ def overview_chart(
4747
vertical=False,
4848
class_name="opacity-50",
4949
),
50-
rx.recharts.graphing_tooltip(
51-
**TOOLTIP_PROPS
52-
),
50+
rx.recharts.graphing_tooltip(**TOOLTIP_PROPS),
5351
rx.recharts.line(
5452
data_key="value1",
5553
stroke="#8884d8",
@@ -76,9 +74,7 @@ def overview_chart(
7674
tick_line=False,
7775
domain=["auto", "auto"],
7876
),
79-
data=metric["chart_data"].to(
80-
List[ChartDataPoint]
81-
),
77+
data=metric["chart_data"].to(List[ChartDataPoint]),
8278
height=120,
8379
margin={
8480
"top": 5,
@@ -91,4 +87,4 @@ def overview_chart(
9187
class_name="mt-3 -mb-2 -ml-2 -mr-2",
9288
),
9389
class_name="p-4",
94-
)
90+
)

retail_analytics_dashboard/retail_analytics_dashboard/components/overview_section.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import reflex as rx
2-
from retail_analytics_dashbaord.states.dashboard_state import DashboardState
32
from retail_analytics_dashbaord.components.overview_chart import overview_chart
3+
from retail_analytics_dashbaord.states.dashboard_state import DashboardState
44

55

66
def overview_section() -> rx.Component:
@@ -32,4 +32,4 @@ def overview_section() -> rx.Component:
3232
),
3333
class_name="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6",
3434
),
35-
)
35+
)

retail_analytics_dashboard/retail_analytics_dashboard/components/progress_bar.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ def progress_bar(
1111
"""A simple progress bar component."""
1212
return rx.el.div(
1313
rx.el.div(
14-
rx.el.p(
15-
label, class_name="text-sm text-gray-600"
16-
),
14+
rx.el.p(label, class_name="text-sm text-gray-600"),
1715
rx.el.p(
1816
f"{value} / {total}",
1917
class_name="text-sm font-medium text-gray-800",
@@ -23,9 +21,7 @@ def progress_bar(
2321
rx.el.div(
2422
rx.el.div(
2523
class_name="bg-indigo-600 h-2 rounded-full",
26-
style={
27-
"width": percentage.to_string() + "%"
28-
},
24+
style={"width": percentage.to_string() + "%"},
2925
),
3026
class_name="w-full bg-gray-200 rounded-full h-2",
3127
),
@@ -43,12 +39,7 @@ def cost_progress_bar(
4339
lambda item: rx.el.div(
4440
class_name=item["color"]
4541
+ " h-2 first:rounded-l-full last:rounded-r-full",
46-
style={
47-
"width": item[
48-
"percentage"
49-
].to_string()
50-
+ "%"
51-
},
42+
style={"width": item["percentage"].to_string() + "%"},
5243
),
5344
),
5445
class_name="flex w-full bg-gray-200 rounded-full h-2 overflow-hidden",
@@ -57,10 +48,7 @@ def cost_progress_bar(
5748
rx.foreach(
5849
items,
5950
lambda item: rx.el.div(
60-
rx.el.span(
61-
class_name="w-2 h-2 rounded-full mr-2 "
62-
+ item["color"]
63-
),
51+
rx.el.span(class_name="w-2 h-2 rounded-full mr-2 " + item["color"]),
6452
rx.el.span(
6553
f"{item['label']} ({item['value']} / {item['percentage']}%)",
6654
class_name="text-xs text-gray-600",
@@ -79,4 +67,4 @@ def cost_progress_bar(
7967
DashboardState.total_budget.to_string(),
8068
class_name="text-xs text-gray-500 mt-2 text-right",
8169
),
82-
)
70+
)

retail_analytics_dashboard/retail_analytics_dashboard/components/sidebar.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@
55
def sidebar_nav_item(item: rx.Var[dict]) -> rx.Component:
66
"""Renders a single navigation item in the sidebar."""
77
return rx.el.a(
8-
rx.icon(
9-
tag=item["icon"], class_name="w-5 h-5 mr-3"
10-
),
8+
rx.icon(tag=item["icon"], class_name="w-5 h-5 mr-3"),
119
item["name"],
1210
href="#",
13-
on_click=lambda: DashboardState.set_active_nav(
14-
item["name"]
15-
),
11+
on_click=lambda: DashboardState.set_active_nav(item["name"]),
1612
class_name=rx.cond(
1713
item["active"],
1814
"flex items-center px-4 py-2 text-sm font-medium text-indigo-700 bg-indigo-100 rounded-md transition-colors duration-150",
@@ -111,4 +107,4 @@ def sidebar() -> rx.Component:
111107
class_name="flex flex-col h-full",
112108
),
113109
class_name="hidden lg:flex w-64 border-r border-gray-200 flex-shrink-0 sticky top-0 h-screen overflow-y-auto",
114-
)
110+
)

retail_analytics_dashboard/retail_analytics_dashboard/retail_analytics_dashbaord.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import reflex as rx
2-
from retail_analytics_dashbaord.states.dashboard_state import DashboardState
3-
from retail_analytics_dashbaord.components.sidebar import sidebar
42
from retail_analytics_dashbaord.components.billing_cycle import billing_cycle
5-
from retail_analytics_dashbaord.components.overview_section import overview_section
63
from retail_analytics_dashbaord.components.customize_charts_dialog import (
74
customize_charts_dialog,
85
)
6+
from retail_analytics_dashbaord.components.overview_section import overview_section
7+
from retail_analytics_dashbaord.components.sidebar import sidebar
98

109

1110
def index() -> rx.Component:
@@ -24,4 +23,4 @@ def index() -> rx.Component:
2423

2524

2625
app = rx.App(theme=rx.theme(appearance="light"))
27-
app.add_page(index)
26+
app.add_page(index)

retail_analytics_dashboard/retail_analytics_dashboard/states/dashboard_state.py

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import reflex as rx
2-
from typing import TypedDict, List, Union, Dict, Any
3-
import random
41
import datetime
2+
import random
3+
from typing import Dict, List, TypedDict
4+
5+
import reflex as rx
56

67
TOOLTIP_PROPS = {
78
"content_style": {
@@ -84,24 +85,16 @@ def generate_chart_data(
8485
max_val2: int = 150,
8586
) -> List[ChartDataPoint]:
8687
data: List[ChartDataPoint] = []
87-
start_date = datetime.datetime.strptime(
88-
start_date_str, "%d/%m/%Y"
89-
)
90-
end_date = datetime.datetime.strptime(
91-
end_date_str, "%d/%m/%Y"
92-
)
88+
start_date = datetime.datetime.strptime(start_date_str, "%d/%m/%Y")
89+
end_date = datetime.datetime.strptime(end_date_str, "%d/%m/%Y")
9390
date_delta = (end_date - start_date) / (num_points - 1)
9491
for i in range(num_points):
9592
current_date = start_date + date_delta * i
9693
data.append(
9794
{
9895
"date": current_date.strftime("%d/%m/%Y"),
99-
"value1": random.randint(
100-
min_val1, max_val1
101-
),
102-
"value2": random.randint(
103-
min_val2, max_val2
104-
),
96+
"value1": random.randint(min_val1, max_val1),
97+
"value2": random.randint(min_val2, max_val2),
10598
}
10699
)
107100
return data
@@ -327,25 +320,17 @@ class DashboardState(rx.State):
327320
"color": "bg-gray-400",
328321
},
329322
]
330-
overview_metrics: List[OverviewMetric] = (
331-
overview_metrics_data
332-
)
323+
overview_metrics: List[OverviewMetric] = overview_metrics_data
333324
chart_visibility: Dict[str, bool] = {
334-
metric["id"]: True
335-
for metric in overview_metrics_data
325+
metric["id"]: True for metric in overview_metrics_data
336326
}
337327
temp_chart_visibility: Dict[str, bool] = {}
338328
show_customize_dialog: bool = False
339329

340330
@rx.var
341331
def current_total_cost(self) -> float:
342332
"""Calculates the current total cost from the breakdown items."""
343-
return sum(
344-
(
345-
item["value_num"]
346-
for item in self.billing_costs_items
347-
)
348-
)
333+
return sum((item["value_num"] for item in self.billing_costs_items))
349334

350335
@rx.var
351336
def remaining_budget_value(self) -> float:
@@ -357,22 +342,13 @@ def remaining_budget_percentage(self) -> float:
357342
"""Calculates the remaining budget percentage."""
358343
if self.total_budget == 0:
359344
return 0.0
360-
percentage = (
361-
self.remaining_budget_value
362-
/ self.total_budget
363-
* 100
364-
)
345+
percentage = self.remaining_budget_value / self.total_budget * 100
365346
return round(percentage * 10) / 10
366347

367348
@rx.var
368349
def total_cost_percentage(self) -> float:
369350
"""Calculates the total percentage used based on cost items."""
370-
return sum(
371-
(
372-
item["percentage"]
373-
for item in self.billing_costs_items
374-
)
375-
)
351+
return sum((item["percentage"] for item in self.billing_costs_items))
376352

377353
@rx.var
378354
def visible_overview_metrics(
@@ -382,9 +358,7 @@ def visible_overview_metrics(
382358
return [
383359
metric
384360
for metric in self.overview_metrics
385-
if self.chart_visibility.get(
386-
metric["id"], False
387-
)
361+
if self.chart_visibility.get(metric["id"], False)
388362
]
389363

390364
@rx.event
@@ -399,31 +373,25 @@ def set_active_nav(self, item_name: str):
399373
@rx.event
400374
def toggle_customize_dialog(self):
401375
"""Toggles the customize charts dialog and initializes temporary visibility."""
402-
self.show_customize_dialog = (
403-
not self.show_customize_dialog
404-
)
376+
self.show_customize_dialog = not self.show_customize_dialog
405377
if self.show_customize_dialog:
406-
self.temp_chart_visibility = (
407-
self.chart_visibility.copy()
408-
)
378+
self.temp_chart_visibility = self.chart_visibility.copy()
409379

410380
@rx.event
411381
def toggle_temp_chart_visibility(self, chart_id: str):
412382
"""Toggles the visibility of a specific chart in the temporary state."""
413383
if chart_id in self.temp_chart_visibility:
414-
self.temp_chart_visibility[chart_id] = (
415-
not self.temp_chart_visibility[chart_id]
416-
)
384+
self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[
385+
chart_id
386+
]
417387

418388
@rx.event
419389
def apply_chart_visibility(self):
420390
"""Applies the temporary visibility settings to the actual state and closes the dialog."""
421-
self.chart_visibility = (
422-
self.temp_chart_visibility.copy()
423-
)
391+
self.chart_visibility = self.temp_chart_visibility.copy()
424392
self.show_customize_dialog = False
425393

426394
@rx.event
427395
def cancel_chart_visibility(self):
428396
"""Closes the dialog without applying changes."""
429-
self.show_customize_dialog = False
397+
self.show_customize_dialog = False
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
import reflex as rx
22

3-
config = rx.Config(app_name="retail_analytics_dashboard")
3+
config = rx.Config(app_name="retail_analytics_dashboard")

0 commit comments

Comments
 (0)