instruction
stringlengths
0
1k
input
stringlengths
1
1k
output
stringlengths
10
6.51k
from typing import List, TypedDict class NavItem(TypedDict): name: str icon: str active: bool
class BillingStat(TypedDict): label: str value: str total: str percentage: float class CostItem(TypedDict): label: str value: str value_num: float percentage: float color: str class ChartDataPoint(TypedDict): date: str value1: int value2: int class OverviewMetric(TypedDict): id: str title: str change: str change_color: str value: str previous_value: str chart_data: List[ChartDataPoint]
class ShortcutItem(TypedDict): name: str icon: str
import reflex as rx from retail_analytics_dashboard.models.models import ( BillingStat, CostItem, NavItem, OverviewMetric, ShortcutItem, ) from retail_analytics_dashboard.states.data import overview_metrics_data class DashboardState(rx.State): nav_items: List[NavItem] = [ { "name": "Overview", "icon": "home", "active": True, }, { "name": "Details", "icon": "list", "active": False, }, { "name": "Settings", "icon": "settings", "active": False, }, ] shortcuts: List[ShortcutItem] = [ {"name": "Add new user", "icon": "link"}, {"name": "Workspace usage", "icon": "link"}, {"name": "Cost spend control", "icon": "link"}, {"name": "Overview - Rows written", "icon": "link"}, ] billing_usage_stats: List[BillingStat] = [ { "label": "Rows read",
from typing import Dict, List
from typing import Dict, List
from retail_analytics_dashboard.models.models import ( BillingStat, CostItem, NavItem, OverviewMetric, ShortcutItem, ) from retail_analytics_dashboard.states.data import overview_metrics_data class DashboardState(rx.State): nav_items: List[NavItem] = [ { "name": "Overview", "icon": "home", "active": True, }, { "name": "Details", "icon": "list", "active": False, }, { "name": "Settings", "icon": "settings", "active": False, }, ] shortcuts: List[ShortcutItem] = [ {"name": "Add new user", "icon": "link"}, {"name": "Workspace usage", "icon": "link"}, {"name": "Cost spend control", "icon": "link"}, {"name": "Overview - Rows written", "icon": "link"}, ] billing_usage_stats: List[BillingStat] = [ { "label": "Rows read", "value": "48.1
import reflex as rx
from typing import Dict, List import reflex as rx
from retail_analytics_dashboard.states.data import overview_metrics_data class DashboardState(rx.State): nav_items: List[NavItem] = [ { "name": "Overview", "icon": "home", "active": True, }, { "name": "Details", "icon": "list", "active": False, }, { "name": "Settings", "icon": "settings", "active": False, }, ] shortcuts: List[ShortcutItem] = [ {"name": "Add new user", "icon": "link"}, {"name": "Workspace usage", "icon": "link"}, {"name": "Cost spend control", "icon": "link"}, {"name": "Overview - Rows written", "icon": "link"}, ] billing_usage_stats: List[BillingStat] = [ { "label": "Rows read", "value": "48.1M", "total": "100M", "percentage": 48.1, }, { "label": "Rows written", "valu
from retail_analytics_dashboard.models.models import ( BillingStat, CostItem, NavItem, OverviewMetric, ShortcutItem, )
from typing import Dict, List import reflex as rx from retail_analytics_dashboard.models.models import ( BillingStat, CostItem, NavItem, OverviewMetric, ShortcutItem, )
class DashboardState(rx.State): nav_items: List[NavItem] = [ { "name": "Overview", "icon": "home", "active": True, }, { "name": "Details", "icon": "list", "active": False, }, { "name": "Settings", "icon": "settings", "active": False, }, ] shortcuts: List[ShortcutItem] = [ {"name": "Add new user", "icon": "link"}, {"name": "Workspace usage", "icon": "link"}, {"name": "Cost spend control", "icon": "link"}, {"name": "Overview - Rows written", "icon": "link"}, ] billing_usage_stats: List[BillingStat] = [ { "label": "Rows read", "value": "48.1M", "total": "100M", "percentage": 48.1, }, { "label": "Rows written", "value": "78.3M", "total": "100M", "percentage": 78.3,
from retail_analytics_dashboard.states.data import overview_metrics_data
"total": "100%", "percentage": 98.3, }, ] total_budget: float = 328.0 billing_costs_items: List[CostItem] = [ { "label": "Base tier", "value": "$200", "value_num": 200.0, "percentage": 68.1, "color": "bg-indigo-600", }, { "label": "On-demand charges", "value": "$61.1", "value_num": 61.1, "percentage": 20.8, "color": "bg-purple-600", }, { "label": "Caching", "value": "$31.9", "value_num": 31.9, "percentage": 11.1, "color": "bg-gray-400", }, ] overview_metrics: List[OverviewMetric] = overview_metrics_data chart_visibility: Dict[str, bool] = { metric["id"]: True for metric in overview_metrics_data } temp_chart_visibility: Dict[str, bool] = {} show_customize_dialog: bool = False @rx.var
@rx.var def remaining_budget_value(self) -> float: """Calculates the remaining budget value.""" return self.total_budget - self.current_total_cost @rx.var def remaining_budget_percentage(self) -> float: """Calculates the remaining budget percentage.""" if self.total_budget == 0: return 0.0 percentage = self.remaining_budget_value / self.total_budget * 100 return round(percentage * 10) / 10 @rx.var def total_cost_percentage(self) -> float: """Calculates the total percentage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items)) @rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False)
def current_total_cost(self) -> float: """Calculates the current total cost from the breakdown items.""" return sum((item["value_num"] for item in self.billing_costs_items))
arges", "value": "$61.1", "value_num": 61.1, "percentage": 20.8, "color": "bg-purple-600", }, { "label": "Caching", "value": "$31.9", "value_num": 31.9, "percentage": 11.1, "color": "bg-gray-400", }, ] overview_metrics: List[OverviewMetric] = overview_metrics_data chart_visibility: Dict[str, bool] = { metric["id"]: True for metric in overview_metrics_data } temp_chart_visibility: Dict[str, bool] = {} show_customize_dialog: bool = False @rx.var def current_total_cost(self) -> float: """Calculates the current total cost from the breakdown items.""" return sum((item["value_num"] for item in self.billing_costs_items)) @rx.var def remaining_budget_value(self) -> float: """Calculates the remaining budget value.""" return self.total_budget - self.current_total_cost @rx.var
@rx.var def total_cost_percentage(self) -> float: """Calculates the total percentage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items)) @rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_cus
def remaining_budget_percentage(self) -> float: """Calculates the remaining budget percentage.""" if self.total_budget == 0: return 0.0 percentage = self.remaining_budget_value / self.total_budget * 100 return round(percentage * 10) / 10
color": "bg-purple-600", }, { "label": "Caching", "value": "$31.9", "value_num": 31.9, "percentage": 11.1, "color": "bg-gray-400", }, ] overview_metrics: List[OverviewMetric] = overview_metrics_data chart_visibility: Dict[str, bool] = { metric["id"]: True for metric in overview_metrics_data } temp_chart_visibility: Dict[str, bool] = {} show_customize_dialog: bool = False @rx.var def current_total_cost(self) -> float: """Calculates the current total cost from the breakdown items.""" return sum((item["value_num"] for item in self.billing_costs_items)) @rx.var def remaining_budget_value(self) -> float: """Calculates the remaining budget value.""" return self.total_budget - self.current_total_cost @rx.var def remaining_budget_percentage(self) -> float: """Calculates the remaining budget percentage."""
percentage = self.remaining_budget_value / self.total_budget * 100 return round(percentage * 10) / 10 @rx.var def total_cost_percentage(self) -> float: """Calculates the total percentage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items)) @rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialo
if self.total_budget == 0: return 0.0
"label": "Caching", "value": "$31.9", "value_num": 31.9, "percentage": 11.1, "color": "bg-gray-400", }, ] overview_metrics: List[OverviewMetric] = overview_metrics_data chart_visibility: Dict[str, bool] = { metric["id"]: True for metric in overview_metrics_data } temp_chart_visibility: Dict[str, bool] = {} show_customize_dialog: bool = False @rx.var def current_total_cost(self) -> float: """Calculates the current total cost from the breakdown items.""" return sum((item["value_num"] for item in self.billing_costs_items)) @rx.var def remaining_budget_value(self) -> float: """Calculates the remaining budget value.""" return self.total_budget - self.current_total_cost @rx.var def remaining_budget_percentage(self) -> float: """Calculates the remaining budget percentage.""" if self.total_budget == 0: return 0.0
return round(percentage * 10) / 10 @rx.var def total_cost_percentage(self) -> float: """Calculates the total percentage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items)) @rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes tem
percentage = self.remaining_budget_value / self.total_budget * 100
olor": "bg-gray-400", }, ] overview_metrics: List[OverviewMetric] = overview_metrics_data chart_visibility: Dict[str, bool] = { metric["id"]: True for metric in overview_metrics_data } temp_chart_visibility: Dict[str, bool] = {} show_customize_dialog: bool = False @rx.var def current_total_cost(self) -> float: """Calculates the current total cost from the breakdown items.""" return sum((item["value_num"] for item in self.billing_costs_items)) @rx.var def remaining_budget_value(self) -> float: """Calculates the remaining budget value.""" return self.total_budget - self.current_total_cost @rx.var def remaining_budget_percentage(self) -> float: """Calculates the remaining budget percentage.""" if self.total_budget == 0: return 0.0 percentage = self.remaining_budget_value / self.total_budget * 100 return round(percentage * 10) / 10 @rx.var
@rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event def toggle_temp_chart_visibility(s
def total_cost_percentage(self) -> float: """Calculates the total percentage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items))
a } temp_chart_visibility: Dict[str, bool] = {} show_customize_dialog: bool = False @rx.var def current_total_cost(self) -> float: """Calculates the current total cost from the breakdown items.""" return sum((item["value_num"] for item in self.billing_costs_items)) @rx.var def remaining_budget_value(self) -> float: """Calculates the remaining budget value.""" return self.total_budget - self.current_total_cost @rx.var def remaining_budget_percentage(self) -> float: """Calculates the remaining budget percentage.""" if self.total_budget == 0: return 0.0 percentage = self.remaining_budget_value / self.total_budget * 100 return round(percentage * 10) / 10 @rx.var def total_cost_percentage(self) -> float: """Calculates the total percentage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items)) @rx.var
@rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ] @rx.event def apply_chart_visibility(self):
def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ]
ning_budget_value(self) -> float: """Calculates the remaining budget value.""" return self.total_budget - self.current_total_cost @rx.var def remaining_budget_percentage(self) -> float: """Calculates the remaining budget percentage.""" if self.total_budget == 0: return 0.0 percentage = self.remaining_budget_value / self.total_budget * 100 return round(percentage * 10) / 10 @rx.var def total_cost_percentage(self) -> float: """Calculates the total percentage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items)) @rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event
@rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ] @rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.copy() self.show_customize_dialog = False @rx.event def cancel_chart_visibility(self): """Closes the dialog without
def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items
lates the remaining budget value.""" return self.total_budget - self.current_total_cost @rx.var def remaining_budget_percentage(self) -> float: """Calculates the remaining budget percentage.""" if self.total_budget == 0: return 0.0 percentage = self.remaining_budget_value / self.total_budget * 100 return round(percentage * 10) / 10 @rx.var def total_cost_percentage(self) -> float: """Calculates the total percentage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items)) @rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str):
for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ] @rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the
new_nav_items = []
value.""" return self.total_budget - self.current_total_cost @rx.var def remaining_budget_percentage(self) -> float: """Calculates the remaining budget percentage.""" if self.total_budget == 0: return 0.0 percentage = self.remaining_budget_value / self.total_budget * 100 return round(percentage * 10) / 10 @rx.var def total_cost_percentage(self) -> float: """Calculates the total percentage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items)) @rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = []
self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ] @rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.copy() self.show_customize_dialog = False @rx.event def cancel_chart_visibility(self)
for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item)
et - self.current_total_cost @rx.var def remaining_budget_percentage(self) -> float: """Calculates the remaining budget percentage.""" if self.total_budget == 0: return 0.0 percentage = self.remaining_budget_value / self.total_budget * 100 return round(percentage * 10) / 10 @rx.var def total_cost_percentage(self) -> float: """Calculates the total percentage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items)) @rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items:
new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ] @rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.
new_item = item.copy()
get percentage.""" if self.total_budget == 0: return 0.0 percentage = self.remaining_budget_value / self.total_budget * 100 return round(percentage * 10) / 10 @rx.var def total_cost_percentage(self) -> float: """Calculates the total percentage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items)) @rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item)
@rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ] @rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.copy() self.show_customize_dialog = False @rx.event def cancel_chart_visibility(self): """Closes the dialog without
self.nav_items = new_nav_items
0: return 0.0 percentage = self.remaining_budget_value / self.total_budget * 100 return round(percentage * 10) / 10 @rx.var def total_cost_percentage(self) -> float: """Calculates the total percentage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items)) @rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event
@rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ] @rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.copy() self.show_customize_dialog = False @rx.event def cancel_chart_visibility(self): """Closes the dialog without applying changes.""" self.show_customize_dialog = False
def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy()
ge * 10) / 10 @rx.var def total_cost_percentage(self) -> float: """Calculates the total percentage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items)) @rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility."""
if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ] @rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.copy() self.show_customize_dialog = False @rx.event def cancel_chart_visibility(self): """Closes the dialog without applying changes.""" self.show_customize_dialog = False
self.show_customize_dialog = not self.show_customize_dialog
oat: """Calculates the total percentage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items)) @rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog
@rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ] @rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.copy() self.show_customize_dialog = False @rx.event def cancel_chart_visibility(self): """Closes the dialog without applying changes.""" self.show_customize_dialog = False
if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy()
tage used based on cost items.""" return sum((item["percentage"] for item in self.billing_costs_items)) @rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog:
@rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ] @rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.copy() self.show_customize_dialog = False @rx.event def cancel_chart_visibility(self): """Closes the dialog without applying changes.""" self.show_customize_dialog = False
self.temp_chart_visibility = self.chart_visibility.copy()
item in self.billing_costs_items)) @rx.var def visible_overview_metrics( self, ) -> List[OverviewMetric]: """Returns the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event
@rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.copy() self.show_customize_dialog = False @rx.event def cancel_chart_visibility(self): """Closes the dialog without applying changes.""" self.show_customize_dialog = False
def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ]
s the list of overview metrics that are marked as visible.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state."""
@rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.copy() self.show_customize_dialog = False @rx.event def cancel_chart_visibility(self): """Closes the dialog without applying changes.""" self.show_customize_dialog = False
if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ]
le.""" return [ metric for metric in self.overview_metrics if self.chart_visibility.get(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility:
@rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.copy() self.show_customize_dialog = False @rx.event def cancel_chart_visibility(self): """Closes the dialog without applying changes.""" self.show_customize_dialog = False
self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ]
et(metric["id"], False) ] @rx.event def set_active_nav(self, item_name: str): new_nav_items = [] for item in self.nav_items: new_item = item.copy() new_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ] @rx.event
@rx.event def cancel_chart_visibility(self): """Closes the dialog without applying changes.""" self.show_customize_dialog = False
def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.copy() self.show_customize_dialog = False
w_item["active"] = item["name"] == item_name new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ] @rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.copy()
@rx.event def cancel_chart_visibility(self): """Closes the dialog without applying changes.""" self.show_customize_dialog = False
self.show_customize_dialog = False
new_nav_items.append(new_item) self.nav_items = new_nav_items @rx.event def toggle_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ] @rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.copy() self.show_customize_dialog = False @rx.event
def cancel_chart_visibility(self): """Closes the dialog without applying changes.""" self.show_customize_dialog = False
e_customize_dialog(self): """Toggles the customize charts dialog and initializes temporary visibility.""" self.show_customize_dialog = not self.show_customize_dialog if self.show_customize_dialog: self.temp_chart_visibility = self.chart_visibility.copy() @rx.event def toggle_temp_chart_visibility(self, chart_id: str): """Toggles the visibility of a specific chart in the temporary state.""" if chart_id in self.temp_chart_visibility: self.temp_chart_visibility[chart_id] = not self.temp_chart_visibility[ chart_id ] @rx.event def apply_chart_visibility(self): """Applies the temporary visibility settings to the actual state and closes the dialog.""" self.chart_visibility = self.temp_chart_visibility.copy() self.show_customize_dialog = False @rx.event def cancel_chart_visibility(self): """Closes the dialog without applying changes."""
self.show_customize_dialog = False
from retail_analytics_dashboard.models.models import OverviewMetric from retail_analytics_dashboard.states.utils import generate_chart_data TOOLTIP_PROPS = { "content_style": { "background": "white", "borderColor": "#E8E8E8", "borderRadius": "0.75rem", "boxShadow": "0px 24px 12px 0px light-dark(rgba(28, 32, 36, 0.02), rgba(0, 0, 0, 0.00)), 0px 8px 8px 0px light-dark(rgba(28, 32, 36, 0.02), rgba(0, 0, 0, 0.00)), 0px 2px 6px 0px light-dark(rgba(28, 32, 36, 0.02), rgba(0, 0, 0, 0.00))", "fontFamily": "sans-serif", "fontSize": "0.875rem", "lineHeight": "1.25rem", "fontWeight": "500", "minWidth": "8rem", "padding": "0.375rem 0.625rem", "position": "relative", }, "item_style": { "display": "flex", "paddingBottom": "0px", "position": "relative", "paddingTop": "2px", }, "label_style": { "color": "black", "fontWeight": "500", "ali
from typing import List
from typing import List
from retail_analytics_dashboard.states.utils import generate_chart_data TOOLTIP_PROPS = { "content_style": { "background": "white", "borderColor": "#E8E8E8", "borderRadius": "0.75rem", "boxShadow": "0px 24px 12px 0px light-dark(rgba(28, 32, 36, 0.02), rgba(0, 0, 0, 0.00)), 0px 8px 8px 0px light-dark(rgba(28, 32, 36, 0.02), rgba(0, 0, 0, 0.00)), 0px 2px 6px 0px light-dark(rgba(28, 32, 36, 0.02), rgba(0, 0, 0, 0.00))", "fontFamily": "sans-serif", "fontSize": "0.875rem", "lineHeight": "1.25rem", "fontWeight": "500", "minWidth": "8rem", "padding": "0.375rem 0.625rem", "position": "relative", }, "item_style": { "display": "flex", "paddingBottom": "0px", "position": "relative", "paddingTop": "2px", }, "label_style": { "color": "black", "fontWeight": "500", "alignSelf": "flex-end", }, "separator": "", } overview_metrics
from retail_analytics_dashboard.models.models import OverviewMetric
from typing import List from retail_analytics_dashboard.models.models import OverviewMetric
TOOLTIP_PROPS = { "content_style": { "background": "white", "borderColor": "#E8E8E8", "borderRadius": "0.75rem", "boxShadow": "0px 24px 12px 0px light-dark(rgba(28, 32, 36, 0.02), rgba(0, 0, 0, 0.00)), 0px 8px 8px 0px light-dark(rgba(28, 32, 36, 0.02), rgba(0, 0, 0, 0.00)), 0px 2px 6px 0px light-dark(rgba(28, 32, 36, 0.02), rgba(0, 0, 0, 0.00))", "fontFamily": "sans-serif", "fontSize": "0.875rem", "lineHeight": "1.25rem", "fontWeight": "500", "minWidth": "8rem", "padding": "0.375rem 0.625rem", "position": "relative", }, "item_style": { "display": "flex", "paddingBottom": "0px", "position": "relative", "paddingTop": "2px", }, "label_style": { "color": "black", "fontWeight": "500", "alignSelf": "flex-end", }, "separator": "", } overview_metrics_data: List[OverviewMetric] = [ { "id": "rows_read",
from retail_analytics_dashboard.states.utils import generate_chart_data
import random from typing import List from retail_analytics_dashboard.models.models import ChartDataPoint def generate_chart_data( start_date_str: str, end_date_str: str, num_points: int = 30, min_val1: int = 50, max_val1: int = 200, min_val2: int = 30, max_val2: int = 150, ) -> List[ChartDataPoint]: data: List[ChartDataPoint] = [] start_date = datetime.datetime.strptime(start_date_str, "%d/%m/%Y") end_date = datetime.datetime.strptime(end_date_str, "%d/%m/%Y") date_delta = (end_date - start_date) / (num_points - 1) for i in range(num_points): current_date = start_date + date_delta * i data.append( { "date": current_date.strftime("%d/%m/%Y"), "value1": random.randint(min_val1, max_val1), "value2": random.randint(min_val2, max_val2), } ) return data
import datetime
import datetime
from typing import List from retail_analytics_dashboard.models.models import ChartDataPoint def generate_chart_data( start_date_str: str, end_date_str: str, num_points: int = 30, min_val1: int = 50, max_val1: int = 200, min_val2: int = 30, max_val2: int = 150, ) -> List[ChartDataPoint]: data: List[ChartDataPoint] = [] start_date = datetime.datetime.strptime(start_date_str, "%d/%m/%Y") end_date = datetime.datetime.strptime(end_date_str, "%d/%m/%Y") date_delta = (end_date - start_date) / (num_points - 1) for i in range(num_points): current_date = start_date + date_delta * i data.append( { "date": current_date.strftime("%d/%m/%Y"), "value1": random.randint(min_val1, max_val1), "value2": random.randint(min_val2, max_val2), } ) return data
import random
import datetime import random
from retail_analytics_dashboard.models.models import ChartDataPoint def generate_chart_data( start_date_str: str, end_date_str: str, num_points: int = 30, min_val1: int = 50, max_val1: int = 200, min_val2: int = 30, max_val2: int = 150, ) -> List[ChartDataPoint]: data: List[ChartDataPoint] = [] start_date = datetime.datetime.strptime(start_date_str, "%d/%m/%Y") end_date = datetime.datetime.strptime(end_date_str, "%d/%m/%Y") date_delta = (end_date - start_date) / (num_points - 1) for i in range(num_points): current_date = start_date + date_delta * i data.append( { "date": current_date.strftime("%d/%m/%Y"), "value1": random.randint(min_val1, max_val1), "value2": random.randint(min_val2, max_val2), } ) return data
from typing import List
import datetime import random from typing import List
def generate_chart_data( start_date_str: str, end_date_str: str, num_points: int = 30, min_val1: int = 50, max_val1: int = 200, min_val2: int = 30, max_val2: int = 150, ) -> List[ChartDataPoint]: data: List[ChartDataPoint] = [] start_date = datetime.datetime.strptime(start_date_str, "%d/%m/%Y") end_date = datetime.datetime.strptime(end_date_str, "%d/%m/%Y") date_delta = (end_date - start_date) / (num_points - 1) for i in range(num_points): current_date = start_date + date_delta * i data.append( { "date": current_date.strftime("%d/%m/%Y"), "value1": random.randint(min_val1, max_val1), "value2": random.randint(min_val2, max_val2), } ) return data
from retail_analytics_dashboard.models.models import ChartDataPoint
import datetime import random from typing import List from retail_analytics_dashboard.models.models import ChartDataPoint def generate_chart_data( start_date_str: str, end_date_str: str, num_points: int = 30, min_val1: int = 50, max_val1: int = 200, min_val2: int = 30, max_val2: int = 150, ) -> List[ChartDataPoint]: data: List[ChartDataPoint] = []
end_date = datetime.datetime.strptime(end_date_str, "%d/%m/%Y") date_delta = (end_date - start_date) / (num_points - 1) for i in range(num_points): current_date = start_date + date_delta * i data.append( { "date": current_date.strftime("%d/%m/%Y"), "value1": random.randint(min_val1, max_val1), "value2": random.randint(min_val2, max_val2), } ) return data
start_date = datetime.datetime.strptime(start_date_str, "%d/%m/%Y")
import datetime import random from typing import List from retail_analytics_dashboard.models.models import ChartDataPoint def generate_chart_data( start_date_str: str, end_date_str: str, num_points: int = 30, min_val1: int = 50, max_val1: int = 200, min_val2: int = 30, max_val2: int = 150, ) -> List[ChartDataPoint]: data: List[ChartDataPoint] = [] start_date = datetime.datetime.strptime(start_date_str, "%d/%m/%Y")
date_delta = (end_date - start_date) / (num_points - 1) for i in range(num_points): current_date = start_date + date_delta * i data.append( { "date": current_date.strftime("%d/%m/%Y"), "value1": random.randint(min_val1, max_val1), "value2": random.randint(min_val2, max_val2), } ) return data
end_date = datetime.datetime.strptime(end_date_str, "%d/%m/%Y")
import datetime import random from typing import List from retail_analytics_dashboard.models.models import ChartDataPoint def generate_chart_data( start_date_str: str, end_date_str: str, num_points: int = 30, min_val1: int = 50, max_val1: int = 200, min_val2: int = 30, max_val2: int = 150, ) -> List[ChartDataPoint]: data: List[ChartDataPoint] = [] start_date = datetime.datetime.strptime(start_date_str, "%d/%m/%Y") end_date = datetime.datetime.strptime(end_date_str, "%d/%m/%Y")
for i in range(num_points): current_date = start_date + date_delta * i data.append( { "date": current_date.strftime("%d/%m/%Y"), "value1": random.randint(min_val1, max_val1), "value2": random.randint(min_val2, max_val2), } ) return data
date_delta = (end_date - start_date) / (num_points - 1)
import datetime import random from typing import List from retail_analytics_dashboard.models.models import ChartDataPoint def generate_chart_data( start_date_str: str, end_date_str: str, num_points: int = 30, min_val1: int = 50, max_val1: int = 200, min_val2: int = 30, max_val2: int = 150, ) -> List[ChartDataPoint]: data: List[ChartDataPoint] = [] start_date = datetime.datetime.strptime(start_date_str, "%d/%m/%Y") end_date = datetime.datetime.strptime(end_date_str, "%d/%m/%Y") date_delta = (end_date - start_date) / (num_points - 1) for i in range(num_points):
data.append( { "date": current_date.strftime("%d/%m/%Y"), "value1": random.randint(min_val1, max_val1), "value2": random.randint(min_val2, max_val2), } ) return data
current_date = start_date + date_delta * i
import reflex as rx from retail_dashboard.components.sidebar import sidebar from retail_dashboard.pages.details_page import details_page_layout from retail_dashboard.states.dashboard_state import DashboardState def page_with_sidebar( content_func: Callable[[], rx.Component], ) -> rx.Component: """Main page layout with sidebar and content area.""" return rx.el.div( sidebar(), rx.el.main( content_func(), class_name="flex-1 overflow-y-auto bg-gray-50 p-0", ), rx.el.div( class_name=rx.cond( DashboardState.show_status_filter | DashboardState.show_country_filter | DashboardState.show_costs_filter, "fixed inset-0 bg-black bg-opacity-20 z-20", "hidden", ), on_click=DashboardState.close_filter_dropdowns, ), class_name="flex h-screen font-['Inter']", ) def details_route() -> rx.Component:
from typing import Callable
from typing import Callable
from retail_dashboard.components.sidebar import sidebar from retail_dashboard.pages.details_page import details_page_layout from retail_dashboard.states.dashboard_state import DashboardState def page_with_sidebar( content_func: Callable[[], rx.Component], ) -> rx.Component: """Main page layout with sidebar and content area.""" return rx.el.div( sidebar(), rx.el.main( content_func(), class_name="flex-1 overflow-y-auto bg-gray-50 p-0", ), rx.el.div( class_name=rx.cond( DashboardState.show_status_filter | DashboardState.show_country_filter | DashboardState.show_costs_filter, "fixed inset-0 bg-black bg-opacity-20 z-20", "hidden", ), on_click=DashboardState.close_filter_dropdowns, ), class_name="flex h-screen font-['Inter']", ) def details_route() -> rx.Component: """Route for the
import reflex as rx
from typing import Callable import reflex as rx
from retail_dashboard.pages.details_page import details_page_layout from retail_dashboard.states.dashboard_state import DashboardState def page_with_sidebar( content_func: Callable[[], rx.Component], ) -> rx.Component: """Main page layout with sidebar and content area.""" return rx.el.div( sidebar(), rx.el.main( content_func(), class_name="flex-1 overflow-y-auto bg-gray-50 p-0", ), rx.el.div( class_name=rx.cond( DashboardState.show_status_filter | DashboardState.show_country_filter | DashboardState.show_costs_filter, "fixed inset-0 bg-black bg-opacity-20 z-20", "hidden", ), on_click=DashboardState.close_filter_dropdowns, ), class_name="flex h-screen font-['Inter']", ) def details_route() -> rx.Component: """Route for the Details page.""" return page_with_sidebar(details_pa
from retail_dashboard.components.sidebar import sidebar
from typing import Callable import reflex as rx from retail_dashboard.components.sidebar import sidebar
from retail_dashboard.states.dashboard_state import DashboardState def page_with_sidebar( content_func: Callable[[], rx.Component], ) -> rx.Component: """Main page layout with sidebar and content area.""" return rx.el.div( sidebar(), rx.el.main( content_func(), class_name="flex-1 overflow-y-auto bg-gray-50 p-0", ), rx.el.div( class_name=rx.cond( DashboardState.show_status_filter | DashboardState.show_country_filter | DashboardState.show_costs_filter, "fixed inset-0 bg-black bg-opacity-20 z-20", "hidden", ), on_click=DashboardState.close_filter_dropdowns, ), class_name="flex h-screen font-['Inter']", ) def details_route() -> rx.Component: """Route for the Details page.""" return page_with_sidebar(details_page_layout) def index() -> rx.Component: """Default route, now
from retail_dashboard.pages.details_page import details_page_layout
from typing import Callable import reflex as rx from retail_dashboard.components.sidebar import sidebar from retail_dashboard.pages.details_page import details_page_layout
def page_with_sidebar( content_func: Callable[[], rx.Component], ) -> rx.Component: """Main page layout with sidebar and content area.""" return rx.el.div( sidebar(), rx.el.main( content_func(), class_name="flex-1 overflow-y-auto bg-gray-50 p-0", ), rx.el.div( class_name=rx.cond( DashboardState.show_status_filter | DashboardState.show_country_filter | DashboardState.show_costs_filter, "fixed inset-0 bg-black bg-opacity-20 z-20", "hidden", ), on_click=DashboardState.close_filter_dropdowns, ), class_name="flex h-screen font-['Inter']", ) def details_route() -> rx.Component: """Route for the Details page.""" return page_with_sidebar(details_page_layout) def index() -> rx.Component: """Default route, now pointing to details page.""" return details_route() app = rx.
from retail_dashboard.states.dashboard_state import DashboardState
from typing import Callable import reflex as rx from retail_dashboard.components.sidebar import sidebar from retail_dashboard.pages.details_page import details_page_layout from retail_dashboard.states.dashboard_state import DashboardState def page_with_sidebar( content_func: Callable[[], rx.Component], ) -> rx.Component: """Main page layout with sidebar and content area.""" return rx.el.div( sidebar(), rx.el.main( content_func(), class_name="flex-1 overflow-y-auto bg-gray-50 p-0", ), rx.el.div( class_name=rx.cond( DashboardState.show_status_filter | DashboardState.show_country_filter | DashboardState.show_costs_filter, "fixed inset-0 bg-black bg-opacity-20 z-20", "hidden", ), on_click=DashboardState.close_filter_dropdowns, ), class_name="flex h-screen font-['Inter']", )
def index() -> rx.Component: """Default route, now pointing to details page.""" return details_route() app = rx.App( theme=rx.theme(appearance="light"), head_components=[ rx.el.link( rel="preconnect", href="https://fonts.googleapis.com", ), rx.el.link( rel="preconnect", href="https://fonts.gstatic.com", crossorigin="", ), rx.el.link( href="https://fonts.googleapis.com/css2?family=Inter:wght@400..700&display=swap", rel="stylesheet", ), ], ) app.add_page(index, route="/")
def details_route() -> rx.Component: """Route for the Details page.""" return page_with_sidebar(details_page_layout)
dashboard.pages.details_page import details_page_layout from retail_dashboard.states.dashboard_state import DashboardState def page_with_sidebar( content_func: Callable[[], rx.Component], ) -> rx.Component: """Main page layout with sidebar and content area.""" return rx.el.div( sidebar(), rx.el.main( content_func(), class_name="flex-1 overflow-y-auto bg-gray-50 p-0", ), rx.el.div( class_name=rx.cond( DashboardState.show_status_filter | DashboardState.show_country_filter | DashboardState.show_costs_filter, "fixed inset-0 bg-black bg-opacity-20 z-20", "hidden", ), on_click=DashboardState.close_filter_dropdowns, ), class_name="flex h-screen font-['Inter']", ) def details_route() -> rx.Component: """Route for the Details page.""" return page_with_sidebar(details_page_layout)
app = rx.App( theme=rx.theme(appearance="light"), head_components=[ rx.el.link( rel="preconnect", href="https://fonts.googleapis.com", ), rx.el.link( rel="preconnect", href="https://fonts.gstatic.com", crossorigin="", ), rx.el.link( href="https://fonts.googleapis.com/css2?family=Inter:wght@400..700&display=swap", rel="stylesheet", ), ], ) app.add_page(index, route="/")
def index() -> rx.Component: """Default route, now pointing to details page.""" return details_route()
from retail_dashboard.states.dashboard_state import DashboardState def status_badge(status: rx.Var[str]) -> rx.Component: """Creates a colored status badge.""" return rx.el.span( rx.el.span( class_name=rx.match( status, ( "Live", "h-1.5 w-1.5 rounded-full bg-emerald-500 mr-1.5", ), ( "Inactive", "h-1.5 w-1.5 rounded-full bg-amber-500 mr-1.5", ), ( "Archived", "h-1.5 w-1.5 rounded-full bg-slate-500 mr-1.5", ), "h-1.5 w-1.5 rounded-full bg-slate-400 mr-1.5", ) ), status, class_name=rx.match( status, ( "Live", "inline-flex items-center px-2.5 py-1 rounded-md text-xs font-medium bg-emerald-100 text-emerald-700",
import reflex as rx
import reflex as rx
def status_badge(status: rx.Var[str]) -> rx.Component: """Creates a colored status badge.""" return rx.el.span( rx.el.span( class_name=rx.match( status, ( "Live", "h-1.5 w-1.5 rounded-full bg-emerald-500 mr-1.5", ), ( "Inactive", "h-1.5 w-1.5 rounded-full bg-amber-500 mr-1.5", ), ( "Archived", "h-1.5 w-1.5 rounded-full bg-slate-500 mr-1.5", ), "h-1.5 w-1.5 rounded-full bg-slate-400 mr-1.5", ) ), status, class_name=rx.match( status, ( "Live", "inline-flex items-center px-2.5 py-1 rounded-md text-xs font-medium bg-emerald-100 text-emerald-700", ), ( "Inactive", "inline
from retail_dashboard.states.dashboard_state import DashboardState
import reflex as rx from reflex.event import EventSpec from retail_dashboard.states.dashboard_state import DashboardState def filter_checkbox_item( label: str, is_checked: rx.Var[bool], on_change: Callable[[str], None], show_flag: bool = False, ) -> rx.Component: """Component for a single checkbox item in a filter dropdown.""" return rx.el.label( rx.el.input( type="checkbox", checked=is_checked, on_change=lambda: on_change(label), class_name="mr-2.5 h-4 w-4 border-gray-300 rounded text-neutral-600 focus:ring-neutral-500 cursor-pointer", ), rx.fragment( rx.image( src=f"https://countryflagsapi.netlify.app/flag/{label}.svg", class_name="rounded-[2px] w-4 mr-2.5", alt=label + " Flag", ) if show_flag else None, label, ), class_name="flex items-center text-sm text-gray-7
from typing import Callable
from typing import Callable
from reflex.event import EventSpec from retail_dashboard.states.dashboard_state import DashboardState def filter_checkbox_item( label: str, is_checked: rx.Var[bool], on_change: Callable[[str], None], show_flag: bool = False, ) -> rx.Component: """Component for a single checkbox item in a filter dropdown.""" return rx.el.label( rx.el.input( type="checkbox", checked=is_checked, on_change=lambda: on_change(label), class_name="mr-2.5 h-4 w-4 border-gray-300 rounded text-neutral-600 focus:ring-neutral-500 cursor-pointer", ), rx.fragment( rx.image( src=f"https://countryflagsapi.netlify.app/flag/{label}.svg", class_name="rounded-[2px] w-4 mr-2.5", alt=label + " Flag", ) if show_flag else None, label, ), class_name="flex items-center text-sm text-gray-700 p-2.5 hover:bg-gra
import reflex as rx
from typing import Callable import reflex as rx
from retail_dashboard.states.dashboard_state import DashboardState def filter_checkbox_item( label: str, is_checked: rx.Var[bool], on_change: Callable[[str], None], show_flag: bool = False, ) -> rx.Component: """Component for a single checkbox item in a filter dropdown.""" return rx.el.label( rx.el.input( type="checkbox", checked=is_checked, on_change=lambda: on_change(label), class_name="mr-2.5 h-4 w-4 border-gray-300 rounded text-neutral-600 focus:ring-neutral-500 cursor-pointer", ), rx.fragment( rx.image( src=f"https://countryflagsapi.netlify.app/flag/{label}.svg", class_name="rounded-[2px] w-4 mr-2.5", alt=label + " Flag", ) if show_flag else None, label, ), class_name="flex items-center text-sm text-gray-700 p-2.5 hover:bg-gray-50 cursor-pointer rounded-md",
from reflex.event import EventSpec
from typing import Callable import reflex as rx from reflex.event import EventSpec
def filter_checkbox_item( label: str, is_checked: rx.Var[bool], on_change: Callable[[str], None], show_flag: bool = False, ) -> rx.Component: """Component for a single checkbox item in a filter dropdown.""" return rx.el.label( rx.el.input( type="checkbox", checked=is_checked, on_change=lambda: on_change(label), class_name="mr-2.5 h-4 w-4 border-gray-300 rounded text-neutral-600 focus:ring-neutral-500 cursor-pointer", ), rx.fragment( rx.image( src=f"https://countryflagsapi.netlify.app/flag/{label}.svg", class_name="rounded-[2px] w-4 mr-2.5", alt=label + " Flag", ) if show_flag else None, label, ), class_name="flex items-center text-sm text-gray-700 p-2.5 hover:bg-gray-50 cursor-pointer rounded-md", ) def filter_dropdown_base( title: str, show_var: rx.Var
from retail_dashboard.states.dashboard_state import DashboardState
-gray-500 px-3 pt-2.5 pb-1.5", ), content, rx.el.div( rx.el.button( "Reset", on_click=reset_action, class_name="px-3.5 py-2 text-sm text-gray-700 hover:bg-gray-100 rounded-lg focus:outline-none focus:ring-1 focus:ring-gray-300", ), rx.el.button( "Apply", on_click=apply_action, class_name="px-3.5 py-2 text-sm text-white bg-neutral-600 hover:bg-neutral-700 rounded-lg focus:outline-none focus:ring-2 focus:ring-offset-1 focus:ring-neutral-500", ), class_name="flex justify-end space-x-2.5 p-2.5 border-t border-gray-200 bg-gray-50 rounded-b-lg", ), class_name=f"absolute top-full left-0 mt-2 {width_class} border border-gray-200 rounded-lg z-30 bg-white shadow-lg", hidden=~show_var, ) def status_filter_dropdown() -> rx.Component: """Dropdown component for filtering by Status."""
return filter_dropdown_base( "Filter by Status", DashboardState.show_status_filter, content, DashboardState.reset_status_filter, DashboardState.apply_status_filter, ) def country_filter_dropdown() -> rx.Component: """Dropdown component for filtering by Country.""" content = rx.el.div( rx.foreach( DashboardState.unique_countries, lambda country: filter_checkbox_item( label=country, is_checked=DashboardState.temp_selected_countries.contains(country), on_change=DashboardState.toggle_temp_country, show_flag=True, ), ), class_name="max-h-48 overflow-y-auto p-2", ) return filter_dropdown_base( "Filter by Country", DashboardState.show_country_filter, content, DashboardState.reset_country_filter, DashboardState.apply_country_filter, ) def costs_filter_dropdown(
content = rx.el.div( rx.foreach( DashboardState.unique_statuses, lambda status: filter_checkbox_item( label=status, is_checked=DashboardState.temp_selected_statuses.contains(status), on_change=DashboardState.toggle_temp_status, ), ), class_name="max-h-48 overflow-y-auto p-2", )
nded-b-lg", ), class_name=f"absolute top-full left-0 mt-2 {width_class} border border-gray-200 rounded-lg z-30 bg-white shadow-lg", hidden=~show_var, ) def status_filter_dropdown() -> rx.Component: """Dropdown component for filtering by Status.""" content = rx.el.div( rx.foreach( DashboardState.unique_statuses, lambda status: filter_checkbox_item( label=status, is_checked=DashboardState.temp_selected_statuses.contains(status), on_change=DashboardState.toggle_temp_status, ), ), class_name="max-h-48 overflow-y-auto p-2", ) return filter_dropdown_base( "Filter by Status", DashboardState.show_status_filter, content, DashboardState.reset_status_filter, DashboardState.apply_status_filter, ) def country_filter_dropdown() -> rx.Component: """Dropdown component for filtering by Country."""
return filter_dropdown_base( "Filter by Country", DashboardState.show_country_filter, content, DashboardState.reset_country_filter, DashboardState.apply_country_filter, ) def costs_filter_dropdown() -> rx.Component: """Dropdown component for filtering by Costs.""" content = rx.el.div( rx.el.input( placeholder="Min cost", on_change=DashboardState.set_temp_min_cost, class_name="w-full p-2.5 border border-gray-300 rounded-lg text-sm mb-2.5 focus:outline-none focus:ring-1 focus:ring-neutral-500 focus:border-neutral-500", default_value=DashboardState.temp_min_cost_str, type="number", step="0.01", ), rx.el.input( placeholder="Max cost", on_change=DashboardState.set_temp_max_cost, class_name="w-full p-2.5 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-1 focus:ring-neutral-500 focu
content = rx.el.div( rx.foreach( DashboardState.unique_countries, lambda country: filter_checkbox_item( label=country, is_checked=DashboardState.temp_selected_countries.contains(country), on_change=DashboardState.toggle_temp_country, show_flag=True, ), ), class_name="max-h-48 overflow-y-auto p-2", )
-500 focus:border-neutral-500", default_value=DashboardState.temp_min_cost_str, type="number", step="0.01", ), rx.el.input( placeholder="Max cost", on_change=DashboardState.set_temp_max_cost, class_name="w-full p-2.5 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-1 focus:ring-neutral-500 focus:border-neutral-500", default_value=DashboardState.temp_max_cost_str, type="number", step="0.01", ), class_name="p-3", ) return filter_dropdown_base( "Filter by Costs", DashboardState.show_costs_filter, content, DashboardState.reset_costs_filter, DashboardState.apply_costs_filter, width_class="w-52", ) def filter_button( label: str, on_click: EventSpec, is_active: rx.Var[bool], has_filter: rx.Var[bool], ) -> rx.Component: """Generic filter button."""
active_class = f"{base_class} border-neutral-500 bg-neutral-50 text-neutral-700 ring-neutral-400" inactive_class = f"{base_class} border-gray-300 text-gray-700 hover:border-gray-400 hover:bg-gray-50 ring-gray-400" return rx.el.button( rx.el.span(label, class_name="flex items-center"), rx.icon(tag="chevron_down", size=16, class_name="ml-2"), on_click=on_click, class_name=rx.cond(has_filter, active_class, inactive_class), aria_expanded=is_active, )
base_class = "flex items-center px-3.5 py-2 border rounded-lg text-sm font-medium focus:outline-none focus:ring-1 focus:ring-offset-1"
01", ), rx.el.input( placeholder="Max cost", on_change=DashboardState.set_temp_max_cost, class_name="w-full p-2.5 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-1 focus:ring-neutral-500 focus:border-neutral-500", default_value=DashboardState.temp_max_cost_str, type="number", step="0.01", ), class_name="p-3", ) return filter_dropdown_base( "Filter by Costs", DashboardState.show_costs_filter, content, DashboardState.reset_costs_filter, DashboardState.apply_costs_filter, width_class="w-52", ) def filter_button( label: str, on_click: EventSpec, is_active: rx.Var[bool], has_filter: rx.Var[bool], ) -> rx.Component: """Generic filter button.""" base_class = "flex items-center px-3.5 py-2 border rounded-lg text-sm font-medium focus:outline-none focus:ring-1 focus:ring-offset-1"
inactive_class = f"{base_class} border-gray-300 text-gray-700 hover:border-gray-400 hover:bg-gray-50 ring-gray-400" return rx.el.button( rx.el.span(label, class_name="flex items-center"), rx.icon(tag="chevron_down", size=16, class_name="ml-2"), on_click=on_click, class_name=rx.cond(has_filter, active_class, inactive_class), aria_expanded=is_active, )
active_class = f"{base_class} border-neutral-500 bg-neutral-50 text-neutral-700 ring-neutral-400"
rdState.set_temp_max_cost, class_name="w-full p-2.5 border border-gray-300 rounded-lg text-sm focus:outline-none focus:ring-1 focus:ring-neutral-500 focus:border-neutral-500", default_value=DashboardState.temp_max_cost_str, type="number", step="0.01", ), class_name="p-3", ) return filter_dropdown_base( "Filter by Costs", DashboardState.show_costs_filter, content, DashboardState.reset_costs_filter, DashboardState.apply_costs_filter, width_class="w-52", ) def filter_button( label: str, on_click: EventSpec, is_active: rx.Var[bool], has_filter: rx.Var[bool], ) -> rx.Component: """Generic filter button.""" base_class = "flex items-center px-3.5 py-2 border rounded-lg text-sm font-medium focus:outline-none focus:ring-1 focus:ring-offset-1" active_class = f"{base_class} border-neutral-500 bg-neutral-50 text-neutral-700 ring-neutral-400"
return rx.el.button( rx.el.span(label, class_name="flex items-center"), rx.icon(tag="chevron_down", size=16, class_name="ml-2"), on_click=on_click, class_name=rx.cond(has_filter, active_class, inactive_class), aria_expanded=is_active, )
inactive_class = f"{base_class} border-gray-300 text-gray-700 hover:border-gray-400 hover:bg-gray-50 ring-gray-400"
from retail_dashboard.components.filter_dropdown import ( costs_filter_dropdown, country_filter_dropdown, filter_button, status_filter_dropdown, ) from retail_dashboard.states.dashboard_state import DashboardState def header() -> rx.Component: """The header component with title, filters, and actions.""" return rx.el.div( rx.el.div( rx.el.h1( "Dashboard", class_name="text-2xl font-semibold text-gray-800", ), rx.el.p( "Manage and analyze your retail data entries.", class_name="text-sm text-gray-500 mt-1.5", ), ), rx.el.div( rx.el.div( rx.el.div( filter_button( "Status", on_click=DashboardState.toggle_status_filter, is_active=DashboardState.show_status_filter, has_filter=DashboardState.
import reflex as rx
import reflex as rx
from retail_dashboard.states.dashboard_state import DashboardState def header() -> rx.Component: """The header component with title, filters, and actions.""" return rx.el.div( rx.el.div( rx.el.h1( "Dashboard", class_name="text-2xl font-semibold text-gray-800", ), rx.el.p( "Manage and analyze your retail data entries.", class_name="text-sm text-gray-500 mt-1.5", ), ), rx.el.div( rx.el.div( rx.el.div( filter_button( "Status", on_click=DashboardState.toggle_status_filter, is_active=DashboardState.show_status_filter, has_filter=DashboardState.selected_statuses.length() > 0, ), status_filter_dropdown(), class_name="relative", ),
from retail_dashboard.components.filter_dropdown import ( costs_filter_dropdown, country_filter_dropdown, filter_button, status_filter_dropdown, )
import reflex as rx from retail_dashboard.components.filter_dropdown import ( costs_filter_dropdown, country_filter_dropdown, filter_button, status_filter_dropdown, )
def header() -> rx.Component: """The header component with title, filters, and actions.""" return rx.el.div( rx.el.div( rx.el.h1( "Dashboard", class_name="text-2xl font-semibold text-gray-800", ), rx.el.p( "Manage and analyze your retail data entries.", class_name="text-sm text-gray-500 mt-1.5", ), ), rx.el.div( rx.el.div( rx.el.div( filter_button( "Status", on_click=DashboardState.toggle_status_filter, is_active=DashboardState.show_status_filter, has_filter=DashboardState.selected_statuses.length() > 0, ), status_filter_dropdown(), class_name="relative", ), rx.el.div( filter_button(
from retail_dashboard.states.dashboard_state import DashboardState
from retail_dashboard.states.dashboard_state import DashboardState def nav_link( text: str, icon_name: str, href: str | None = None, on_click: rx.event.EventHandler | None = None, ) -> rx.Component: """A reusable navigation link component.""" current_path_check = rx.cond(href, DashboardState.router.page.path == href, False) base_class = "flex items-center px-3.5 py-2.5 text-sm rounded-lg" active_class = f"{base_class} font-medium text-neutral-700 bg-neutral-100" inactive_class = f"{base_class} text-gray-600 hover:bg-gray-100 hover:text-gray-800" icon_active_class = "text-neutral-700" icon_inactive_class = "text-gray-400 group-hover:text-gray-500" link_content = rx.el.span( rx.icon( tag=icon_name, size=18, class_name=rx.cond( current_path_check, icon_active_class, icon_inactive_class, ) + " mr-3.5", ), tex
import reflex as rx
import reflex as rx
def nav_link( text: str, icon_name: str, href: str | None = None, on_click: rx.event.EventHandler | None = None, ) -> rx.Component: """A reusable navigation link component.""" current_path_check = rx.cond(href, DashboardState.router.page.path == href, False) base_class = "flex items-center px-3.5 py-2.5 text-sm rounded-lg" active_class = f"{base_class} font-medium text-neutral-700 bg-neutral-100" inactive_class = f"{base_class} text-gray-600 hover:bg-gray-100 hover:text-gray-800" icon_active_class = "text-neutral-700" icon_inactive_class = "text-gray-400 group-hover:text-gray-500" link_content = rx.el.span( rx.icon( tag=icon_name, size=18, class_name=rx.cond( current_path_check, icon_active_class, icon_inactive_class, ) + " mr-3.5", ), text, class_name=rx.cond(current_path_check, active_class, inac
from retail_dashboard.states.dashboard_state import DashboardState
import reflex as rx from retail_dashboard.states.dashboard_state import DashboardState def nav_link( text: str, icon_name: str, href: str | None = None, on_click: rx.event.EventHandler | None = None, ) -> rx.Component: """A reusable navigation link component."""
base_class = "flex items-center px-3.5 py-2.5 text-sm rounded-lg" active_class = f"{base_class} font-medium text-neutral-700 bg-neutral-100" inactive_class = f"{base_class} text-gray-600 hover:bg-gray-100 hover:text-gray-800" icon_active_class = "text-neutral-700" icon_inactive_class = "text-gray-400 group-hover:text-gray-500" link_content = rx.el.span( rx.icon( tag=icon_name, size=18, class_name=rx.cond( current_path_check, icon_active_class, icon_inactive_class, ) + " mr-3.5", ), text, class_name=rx.cond(current_path_check, active_class, inactive_class) + " group w-full", on_click=rx.cond(on_click, on_click, rx.noop()), ) if href: return rx.el.a( link_content, href=href, class_name="cursor-pointer", ) else: return rx.el.button(
current_path_check = rx.cond(href, DashboardState.router.page.path == href, False)
import reflex as rx from retail_dashboard.states.dashboard_state import DashboardState def nav_link( text: str, icon_name: str, href: str | None = None, on_click: rx.event.EventHandler | None = None, ) -> rx.Component: """A reusable navigation link component.""" current_path_check = rx.cond(href, DashboardState.router.page.path == href, False)
active_class = f"{base_class} font-medium text-neutral-700 bg-neutral-100" inactive_class = f"{base_class} text-gray-600 hover:bg-gray-100 hover:text-gray-800" icon_active_class = "text-neutral-700" icon_inactive_class = "text-gray-400 group-hover:text-gray-500" link_content = rx.el.span( rx.icon( tag=icon_name, size=18, class_name=rx.cond( current_path_check, icon_active_class, icon_inactive_class, ) + " mr-3.5", ), text, class_name=rx.cond(current_path_check, active_class, inactive_class) + " group w-full", on_click=rx.cond(on_click, on_click, rx.noop()), ) if href: return rx.el.a( link_content, href=href, class_name="cursor-pointer", ) else: return rx.el.button( link_content, class_name="w-full text-left cursor-poi
base_class = "flex items-center px-3.5 py-2.5 text-sm rounded-lg"
import reflex as rx from retail_dashboard.states.dashboard_state import DashboardState def nav_link( text: str, icon_name: str, href: str | None = None, on_click: rx.event.EventHandler | None = None, ) -> rx.Component: """A reusable navigation link component.""" current_path_check = rx.cond(href, DashboardState.router.page.path == href, False) base_class = "flex items-center px-3.5 py-2.5 text-sm rounded-lg"
inactive_class = f"{base_class} text-gray-600 hover:bg-gray-100 hover:text-gray-800" icon_active_class = "text-neutral-700" icon_inactive_class = "text-gray-400 group-hover:text-gray-500" link_content = rx.el.span( rx.icon( tag=icon_name, size=18, class_name=rx.cond( current_path_check, icon_active_class, icon_inactive_class, ) + " mr-3.5", ), text, class_name=rx.cond(current_path_check, active_class, inactive_class) + " group w-full", on_click=rx.cond(on_click, on_click, rx.noop()), ) if href: return rx.el.a( link_content, href=href, class_name="cursor-pointer", ) else: return rx.el.button( link_content, class_name="w-full text-left cursor-pointer", ) def sidebar() -> rx.Component: """A simple static sideba
active_class = f"{base_class} font-medium text-neutral-700 bg-neutral-100"
import reflex as rx from retail_dashboard.states.dashboard_state import DashboardState def nav_link( text: str, icon_name: str, href: str | None = None, on_click: rx.event.EventHandler | None = None, ) -> rx.Component: """A reusable navigation link component.""" current_path_check = rx.cond(href, DashboardState.router.page.path == href, False) base_class = "flex items-center px-3.5 py-2.5 text-sm rounded-lg" active_class = f"{base_class} font-medium text-neutral-700 bg-neutral-100"
icon_active_class = "text-neutral-700" icon_inactive_class = "text-gray-400 group-hover:text-gray-500" link_content = rx.el.span( rx.icon( tag=icon_name, size=18, class_name=rx.cond( current_path_check, icon_active_class, icon_inactive_class, ) + " mr-3.5", ), text, class_name=rx.cond(current_path_check, active_class, inactive_class) + " group w-full", on_click=rx.cond(on_click, on_click, rx.noop()), ) if href: return rx.el.a( link_content, href=href, class_name="cursor-pointer", ) else: return rx.el.button( link_content, class_name="w-full text-left cursor-pointer", ) def sidebar() -> rx.Component: """A simple static sidebar component.""" return rx.el.aside( rx.el.div( rx.el.div(
inactive_class = f"{base_class} text-gray-600 hover:bg-gray-100 hover:text-gray-800"
import reflex as rx from retail_dashboard.states.dashboard_state import DashboardState def nav_link( text: str, icon_name: str, href: str | None = None, on_click: rx.event.EventHandler | None = None, ) -> rx.Component: """A reusable navigation link component.""" current_path_check = rx.cond(href, DashboardState.router.page.path == href, False) base_class = "flex items-center px-3.5 py-2.5 text-sm rounded-lg" active_class = f"{base_class} font-medium text-neutral-700 bg-neutral-100" inactive_class = f"{base_class} text-gray-600 hover:bg-gray-100 hover:text-gray-800"
icon_inactive_class = "text-gray-400 group-hover:text-gray-500" link_content = rx.el.span( rx.icon( tag=icon_name, size=18, class_name=rx.cond( current_path_check, icon_active_class, icon_inactive_class, ) + " mr-3.5", ), text, class_name=rx.cond(current_path_check, active_class, inactive_class) + " group w-full", on_click=rx.cond(on_click, on_click, rx.noop()), ) if href: return rx.el.a( link_content, href=href, class_name="cursor-pointer", ) else: return rx.el.button( link_content, class_name="w-full text-left cursor-pointer", ) def sidebar() -> rx.Component: """A simple static sidebar component.""" return rx.el.aside( rx.el.div( rx.el.div( rx.icon(tag="store", size=20),
icon_active_class = "text-neutral-700"
import reflex as rx from retail_dashboard.states.dashboard_state import DashboardState def nav_link( text: str, icon_name: str, href: str | None = None, on_click: rx.event.EventHandler | None = None, ) -> rx.Component: """A reusable navigation link component.""" current_path_check = rx.cond(href, DashboardState.router.page.path == href, False) base_class = "flex items-center px-3.5 py-2.5 text-sm rounded-lg" active_class = f"{base_class} font-medium text-neutral-700 bg-neutral-100" inactive_class = f"{base_class} text-gray-600 hover:bg-gray-100 hover:text-gray-800" icon_active_class = "text-neutral-700"
link_content = rx.el.span( rx.icon( tag=icon_name, size=18, class_name=rx.cond( current_path_check, icon_active_class, icon_inactive_class, ) + " mr-3.5", ), text, class_name=rx.cond(current_path_check, active_class, inactive_class) + " group w-full", on_click=rx.cond(on_click, on_click, rx.noop()), ) if href: return rx.el.a( link_content, href=href, class_name="cursor-pointer", ) else: return rx.el.button( link_content, class_name="w-full text-left cursor-pointer", ) def sidebar() -> rx.Component: """A simple static sidebar component.""" return rx.el.aside( rx.el.div( rx.el.div( rx.icon(tag="store", size=20), class_name="text-white font-bold text-lg mr-3 p-2.5 bg-
icon_inactive_class = "text-gray-400 group-hover:text-gray-500"
from retail_dashboard.components.details_table import details_table from retail_dashboard.components.header import header as details_page_header def details_page_layout() -> rx.Component: """The main layout for the Details page.""" return rx.el.div( details_page_header(), details_table(), class_name="p-2 md:p-6", )
import reflex as rx
import io from collections import defaultdict from typing import Dict, List, Optional, Set import pandas as pd import reflex as rx from retail_dashboard.models.entry import DetailEntry from retail_dashboard.states.data import raw_data class DashboardState(rx.State): """State for the dashboard page.""" _data: List[DetailEntry] = raw_data column_names: List[str] = [ "Owner", "Status", "Country", "Stability", "Costs", "Last edited", ] search_owner: str = "" selected_statuses: Set[str] = set() selected_countries: Set[str] = set() min_cost: Optional[float] = None max_cost: Optional[float] = None temp_selected_statuses: Set[str] = set() temp_selected_countries: Set[str] = set() temp_min_cost_str: str = "" temp_max_cost_str: str = "" show_status_filter: bool = False show_country_filter: bool = False show_costs_filter: bool = False sort_column: Optional[str] = None sort
import datetime
import datetime import io
from typing import Dict, List, Optional, Set import pandas as pd import reflex as rx from retail_dashboard.models.entry import DetailEntry from retail_dashboard.states.data import raw_data class DashboardState(rx.State): """State for the dashboard page.""" _data: List[DetailEntry] = raw_data column_names: List[str] = [ "Owner", "Status", "Country", "Stability", "Costs", "Last edited", ] search_owner: str = "" selected_statuses: Set[str] = set() selected_countries: Set[str] = set() min_cost: Optional[float] = None max_cost: Optional[float] = None temp_selected_statuses: Set[str] = set() temp_selected_countries: Set[str] = set() temp_min_cost_str: str = "" temp_max_cost_str: str = "" show_status_filter: bool = False show_country_filter: bool = False show_costs_filter: bool = False sort_column: Optional[str] = None sort_ascending: bool = True selected_rows: Set
from collections import defaultdict
import datetime import io from collections import defaultdict
import pandas as pd import reflex as rx from retail_dashboard.models.entry import DetailEntry from retail_dashboard.states.data import raw_data class DashboardState(rx.State): """State for the dashboard page.""" _data: List[DetailEntry] = raw_data column_names: List[str] = [ "Owner", "Status", "Country", "Stability", "Costs", "Last edited", ] search_owner: str = "" selected_statuses: Set[str] = set() selected_countries: Set[str] = set() min_cost: Optional[float] = None max_cost: Optional[float] = None temp_selected_statuses: Set[str] = set() temp_selected_countries: Set[str] = set() temp_min_cost_str: str = "" temp_max_cost_str: str = "" show_status_filter: bool = False show_country_filter: bool = False show_costs_filter: bool = False sort_column: Optional[str] = None sort_ascending: bool = True selected_rows: Set[int] = set() current_page: int = 1 r
from typing import Dict, List, Optional, Set
import datetime import io from collections import defaultdict from typing import Dict, List, Optional, Set
import reflex as rx from retail_dashboard.models.entry import DetailEntry from retail_dashboard.states.data import raw_data class DashboardState(rx.State): """State for the dashboard page.""" _data: List[DetailEntry] = raw_data column_names: List[str] = [ "Owner", "Status", "Country", "Stability", "Costs", "Last edited", ] search_owner: str = "" selected_statuses: Set[str] = set() selected_countries: Set[str] = set() min_cost: Optional[float] = None max_cost: Optional[float] = None temp_selected_statuses: Set[str] = set() temp_selected_countries: Set[str] = set() temp_min_cost_str: str = "" temp_max_cost_str: str = "" show_status_filter: bool = False show_country_filter: bool = False show_costs_filter: bool = False sort_column: Optional[str] = None sort_ascending: bool = True selected_rows: Set[int] = set() current_page: int = 1 rows_per_page: int = 1
import pandas as pd
import datetime import io from collections import defaultdict from typing import Dict, List, Optional, Set import pandas as pd
from retail_dashboard.models.entry import DetailEntry from retail_dashboard.states.data import raw_data class DashboardState(rx.State): """State for the dashboard page.""" _data: List[DetailEntry] = raw_data column_names: List[str] = [ "Owner", "Status", "Country", "Stability", "Costs", "Last edited", ] search_owner: str = "" selected_statuses: Set[str] = set() selected_countries: Set[str] = set() min_cost: Optional[float] = None max_cost: Optional[float] = None temp_selected_statuses: Set[str] = set() temp_selected_countries: Set[str] = set() temp_min_cost_str: str = "" temp_max_cost_str: str = "" show_status_filter: bool = False show_country_filter: bool = False show_costs_filter: bool = False sort_column: Optional[str] = None sort_ascending: bool = True selected_rows: Set[int] = set() current_page: int = 1 rows_per_page: int = 10 def _parse_da
import reflex as rx
import datetime import io from collections import defaultdict from typing import Dict, List, Optional, Set import pandas as pd import reflex as rx
from retail_dashboard.states.data import raw_data class DashboardState(rx.State): """State for the dashboard page.""" _data: List[DetailEntry] = raw_data column_names: List[str] = [ "Owner", "Status", "Country", "Stability", "Costs", "Last edited", ] search_owner: str = "" selected_statuses: Set[str] = set() selected_countries: Set[str] = set() min_cost: Optional[float] = None max_cost: Optional[float] = None temp_selected_statuses: Set[str] = set() temp_selected_countries: Set[str] = set() temp_min_cost_str: str = "" temp_max_cost_str: str = "" show_status_filter: bool = False show_country_filter: bool = False show_costs_filter: bool = False sort_column: Optional[str] = None sort_ascending: bool = True selected_rows: Set[int] = set() current_page: int = 1 rows_per_page: int = 10 def _parse_datetime_for_costs( self, item: DetailEntry, inpu
from retail_dashboard.models.entry import DetailEntry
import datetime import io from collections import defaultdict from typing import Dict, List, Optional, Set import pandas as pd import reflex as rx from retail_dashboard.models.entry import DetailEntry
class DashboardState(rx.State): """State for the dashboard page.""" _data: List[DetailEntry] = raw_data column_names: List[str] = [ "Owner", "Status", "Country", "Stability", "Costs", "Last edited", ] search_owner: str = "" selected_statuses: Set[str] = set() selected_countries: Set[str] = set() min_cost: Optional[float] = None max_cost: Optional[float] = None temp_selected_statuses: Set[str] = set() temp_selected_countries: Set[str] = set() temp_min_cost_str: str = "" temp_max_cost_str: str = "" show_status_filter: bool = False show_country_filter: bool = False show_costs_filter: bool = False sort_column: Optional[str] = None sort_ascending: bool = True selected_rows: Set[int] = set() current_page: int = 1 rows_per_page: int = 10 def _parse_datetime_for_costs( self, item: DetailEntry, input_format: str ) -> Optional[tuple[datetime.dat
from retail_dashboard.states.data import raw_data
reflex as rx from retail_dashboard.models.entry import DetailEntry from retail_dashboard.states.data import raw_data class DashboardState(rx.State): """State for the dashboard page.""" _data: List[DetailEntry] = raw_data column_names: List[str] = [ "Owner", "Status", "Country", "Stability", "Costs", "Last edited", ] search_owner: str = "" selected_statuses: Set[str] = set() selected_countries: Set[str] = set() min_cost: Optional[float] = None max_cost: Optional[float] = None temp_selected_statuses: Set[str] = set() temp_selected_countries: Set[str] = set() temp_min_cost_str: str = "" temp_max_cost_str: str = "" show_status_filter: bool = False show_country_filter: bool = False show_costs_filter: bool = False sort_column: Optional[str] = None sort_ascending: bool = True selected_rows: Set[int] = set() current_page: int = 1 rows_per_page: int = 10
@rx.var def total_entries_count(self) -> int: """Total number of entries in the raw data.""" return len(self._data) @rx.var def live_entries_count(self) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = [] for
def _parse_datetime_for_costs( self, item: DetailEntry, input_format: str ) -> Optional[tuple[datetime.datetime, float]]: """Helper to parse datetime and return (datetime, costs) or None on error.""" try: dt_obj = datetime.datetime.strptime(item["last_edited"], input_format) return dt_obj, item["costs"] except ValueError: return None
names: List[str] = [ "Owner", "Status", "Country", "Stability", "Costs", "Last edited", ] search_owner: str = "" selected_statuses: Set[str] = set() selected_countries: Set[str] = set() min_cost: Optional[float] = None max_cost: Optional[float] = None temp_selected_statuses: Set[str] = set() temp_selected_countries: Set[str] = set() temp_min_cost_str: str = "" temp_max_cost_str: str = "" show_status_filter: bool = False show_country_filter: bool = False show_costs_filter: bool = False sort_column: Optional[str] = None sort_ascending: bool = True selected_rows: Set[int] = set() current_page: int = 1 rows_per_page: int = 10 def _parse_datetime_for_costs( self, item: DetailEntry, input_format: str ) -> Optional[tuple[datetime.datetime, float]]: """Helper to parse datetime and return (datetime, costs) or None on error.""" try:
return dt_obj, item["costs"] except ValueError: return None @rx.var def total_entries_count(self) -> int: """Total number of entries in the raw data.""" return len(self._data) @rx.var def live_entries_count(self) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" outpu
dt_obj = datetime.datetime.strptime(item["last_edited"], input_format)
d_statuses: Set[str] = set() selected_countries: Set[str] = set() min_cost: Optional[float] = None max_cost: Optional[float] = None temp_selected_statuses: Set[str] = set() temp_selected_countries: Set[str] = set() temp_min_cost_str: str = "" temp_max_cost_str: str = "" show_status_filter: bool = False show_country_filter: bool = False show_costs_filter: bool = False sort_column: Optional[str] = None sort_ascending: bool = True selected_rows: Set[int] = set() current_page: int = 1 rows_per_page: int = 10 def _parse_datetime_for_costs( self, item: DetailEntry, input_format: str ) -> Optional[tuple[datetime.datetime, float]]: """Helper to parse datetime and return (datetime, costs) or None on error.""" try: dt_obj = datetime.datetime.strptime(item["last_edited"], input_format) return dt_obj, item["costs"] except ValueError: return None @rx.var
@rx.var def live_entries_count(self) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = [] for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item:
def total_entries_count(self) -> int: """Total number of entries in the raw data.""" return len(self._data)
ne temp_selected_statuses: Set[str] = set() temp_selected_countries: Set[str] = set() temp_min_cost_str: str = "" temp_max_cost_str: str = "" show_status_filter: bool = False show_country_filter: bool = False show_costs_filter: bool = False sort_column: Optional[str] = None sort_ascending: bool = True selected_rows: Set[int] = set() current_page: int = 1 rows_per_page: int = 10 def _parse_datetime_for_costs( self, item: DetailEntry, input_format: str ) -> Optional[tuple[datetime.datetime, float]]: """Helper to parse datetime and return (datetime, costs) or None on error.""" try: dt_obj = datetime.datetime.strptime(item["last_edited"], input_format) return dt_obj, item["costs"] except ValueError: return None @rx.var def total_entries_count(self) -> int: """Total number of entries in the raw data.""" return len(self._data) @rx.var
@rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = [] for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item: valid_items.append(parsed_item) for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += co
def live_entries_count(self) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live"))
tatus_filter: bool = False show_country_filter: bool = False show_costs_filter: bool = False sort_column: Optional[str] = None sort_ascending: bool = True selected_rows: Set[int] = set() current_page: int = 1 rows_per_page: int = 10 def _parse_datetime_for_costs( self, item: DetailEntry, input_format: str ) -> Optional[tuple[datetime.datetime, float]]: """Helper to parse datetime and return (datetime, costs) or None on error.""" try: dt_obj = datetime.datetime.strptime(item["last_edited"], input_format) return dt_obj, item["costs"] except ValueError: return None @rx.var def total_entries_count(self) -> int: """Total number of entries in the raw data.""" return len(self._data) @rx.var def live_entries_count(self) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var
@rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = [] for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item: valid_items.append(parsed_item) for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += cost sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str
def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive"))
ted_rows: Set[int] = set() current_page: int = 1 rows_per_page: int = 10 def _parse_datetime_for_costs( self, item: DetailEntry, input_format: str ) -> Optional[tuple[datetime.datetime, float]]: """Helper to parse datetime and return (datetime, costs) or None on error.""" try: dt_obj = datetime.datetime.strptime(item["last_edited"], input_format) return dt_obj, item["costs"] except ValueError: return None @rx.var def total_entries_count(self) -> int: """Total number of entries in the raw data.""" return len(self._data) @rx.var def live_entries_count(self) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var
@rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = [] for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item: valid_items.append(parsed_item) for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += cost sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_
def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived"))
ional[tuple[datetime.datetime, float]]: """Helper to parse datetime and return (datetime, costs) or None on error.""" try: dt_obj = datetime.datetime.strptime(item["last_edited"], input_format) return dt_obj, item["costs"] except ValueError: return None @rx.var def total_entries_count(self) -> int: """Total number of entries in the raw data.""" return len(self._data) @rx.var def live_entries_count(self) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var
@rx.var def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort keys to move try-except out of the sorting process itself items_with_sort_keys = [ (self._get_sort_key_for_recent_activities(item), item) for item in self._data ] # Sort based on the precomputed keys items_with_sort_keys.sort(key=lambda x: x[0], reverse=True) # Extract the original items in sorted order sorted_data = [item for _, item in items_with_sort_keys] return sorted_data[:5] def _get_sort_key_for_recent_activities( self, item: DetailEntry ) -> datetime.datetime: """Helper to get sort key for recent activities, handling potential ValueError.""" try: return datetime.datetime.strptime(item["last_edited"], "%d/%m/%Y %H:%M") except ValueError: return datetime.datetime.min
def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = [] for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item: valid_items.append(parsed_item) for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += cost sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data
try: dt_obj = datetime.datetime.strptime(item["last_edited"], input_format) return dt_obj, item["costs"] except ValueError: return None @rx.var def total_entries_count(self) -> int: """Total number of entries in the raw data.""" return len(self._data) @rx.var def live_entries_count(self) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart."""
input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = [] for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item: valid_items.append(parsed_item) for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += cost sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data @rx.var def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edi
daily_costs = defaultdict(float)
e.strptime(item["last_edited"], input_format) return dt_obj, item["costs"] except ValueError: return None @rx.var def total_entries_count(self) -> int: """Total number of entries in the raw data.""" return len(self._data) @rx.var def live_entries_count(self) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float)
output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = [] for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item: valid_items.append(parsed_item) for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += cost sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data @rx.var def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort ke
input_format = "%d/%m/%Y %H:%M"
rmat) return dt_obj, item["costs"] except ValueError: return None @rx.var def total_entries_count(self) -> int: """Total number of entries in the raw data.""" return len(self._data) @rx.var def live_entries_count(self) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M"
display_format = "%b %d" valid_items = [] for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item: valid_items.append(parsed_item) for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += cost sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data @rx.var def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort keys to move try-except out of the so
output_format = "%Y-%m-%d"
ror: return None @rx.var def total_entries_count(self) -> int: """Total number of entries in the raw data.""" return len(self._data) @rx.var def live_entries_count(self) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d"
for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item: valid_items.append(parsed_item) for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += cost sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data @rx.var def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort keys to move try-except out of the sorting process itself items_with_sort_keys = [
valid_items = []
one @rx.var def total_entries_count(self) -> int: """Total number of entries in the raw data.""" return len(self._data) @rx.var def live_entries_count(self) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = []
for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += cost sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data @rx.var def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort keys to move try-except out of the sorting process itself items_with_sort_keys = [ (self._get_sort_key_for_recent_activities(item), item) for item in self._data ] # Sort based on the precomputed keys items_with_sort_keys.sor
for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item: valid_items.append(parsed_item)
es_count(self) -> int: """Total number of entries in the raw data.""" return len(self._data) @rx.var def live_entries_count(self) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = [] for item in self._data:
if parsed_item: valid_items.append(parsed_item) for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += cost sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data @rx.var def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort keys to move try-except out of the sorting process itself items_with_sort_keys = [ (self._get_sort_key_for_recent_activities(item), item) for item in self._data ]
parsed_item = self._parse_datetime_for_costs(item, input_format)
return len(self._data) @rx.var def live_entries_count(self) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = [] for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format)
for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += cost sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data @rx.var def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort keys to move try-except out of the sorting process itself items_with_sort_keys = [ (self._get_sort_key_for_recent_activities(item), item) for item in self._data ] # Sort based on the precomputed keys items_with_sort_keys.sor
if parsed_item: valid_items.append(parsed_item)
elf) -> int: """Count of 'Live' entries.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = [] for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item: valid_items.append(parsed_item)
sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data @rx.var def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort keys to move try-except out of the sorting process itself items_with_sort_keys = [ (self._get_sort_key_for_recent_activities(item), item) for item in self._data ] # Sort based on the precomputed keys items_with_sort_keys.sort(key=lambda x: x[0], reverse=True) # Extract the original items in sorted order sorted_data = [item for _, item in items
for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += cost
es.""" return sum((1 for item in self._data if item["status"] == "Live")) @rx.var def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = [] for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item: valid_items.append(parsed_item) for dt_obj, cost in valid_items:
daily_costs[date_str] += cost sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data @rx.var def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort keys to move try-except out of the sorting process itself items_with_sort_keys = [ (self._get_sort_key_for_recent_activities(item), item) for item in self._data ] # Sort based on the precomputed keys items_with_sort_keys.sort(key=lambda x: x[0], reverse=True) # Extract the original items in sorted order
date_str = dt_obj.strftime(output_format)
r def inactive_entries_count(self) -> int: """Count of 'Inactive' entries.""" return sum((1 for item in self._data if item["status"] == "Inactive")) @rx.var def archived_entries_count(self) -> int: """Count of 'Archived' entries.""" return sum((1 for item in self._data if item["status"] == "Archived")) @rx.var def costs_trend_data( self, ) -> List[Dict[str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = [] for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item: valid_items.append(parsed_item) for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += cost
chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data @rx.var def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort keys to move try-except out of the sorting process itself items_with_sort_keys = [ (self._get_sort_key_for_recent_activities(item), item) for item in self._data ] # Sort based on the precomputed keys items_with_sort_keys.sort(key=lambda x: x[0], reverse=True) # Extract the original items in sorted order sorted_data = [item for _, item in items_with_sort_keys] return sorted_data[:5]
sorted_dates = sorted(daily_costs.keys())
str, str | float]]: """Data for the costs trend line chart.""" daily_costs = defaultdict(float) input_format = "%d/%m/%Y %H:%M" output_format = "%Y-%m-%d" display_format = "%b %d" valid_items = [] for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item: valid_items.append(parsed_item) for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += cost sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data @rx.var
def _get_sort_key_for_recent_activities( self, item: DetailEntry ) -> datetime.datetime: """Helper to get sort key for recent activities, handling potential ValueError.""" try: return datetime.datetime.strptime(item["last_edited"], "%d/%m/%Y %H:%M") except ValueError: return datetime.datetime.min @rx.var def unique_statuses(self) -> List[str]: """Get unique statuses from the data.""" return sorted({item["status"] for item in self._data}) @rx.var def unique_countries(self) -> List[str]: """Get unique countries from the data.""" return sorted({item["country"] for item in self._data}) @rx.var def filtered_data(self) -> List[DetailEntry]: """Filter the data based on current filter selections.""" data = self._data if self.search_owner: data = [ item for item in data if self.search_owne
def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort keys to move try-except out of the sorting process itself items_with_sort_keys = [ (self._get_sort_key_for_recent_activities(item), item) for item in self._data ] # Sort based on the precomputed keys items_with_sort_keys.sort(key=lambda x: x[0], reverse=True) # Extract the original items in sorted order sorted_data = [item for _, item in items_with_sort_keys] return sorted_data[:5]
%d" valid_items = [] for item in self._data: parsed_item = self._parse_datetime_for_costs(item, input_format) if parsed_item: valid_items.append(parsed_item) for dt_obj, cost in valid_items: date_str = dt_obj.strftime(output_format) daily_costs[date_str] += cost sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data @rx.var def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort keys to move try-except out of the sorting process itself
# Sort based on the precomputed keys items_with_sort_keys.sort(key=lambda x: x[0], reverse=True) # Extract the original items in sorted order sorted_data = [item for _, item in items_with_sort_keys] return sorted_data[:5] def _get_sort_key_for_recent_activities( self, item: DetailEntry ) -> datetime.datetime: """Helper to get sort key for recent activities, handling potential ValueError.""" try: return datetime.datetime.strptime(item["last_edited"], "%d/%m/%Y %H:%M") except ValueError: return datetime.datetime.min @rx.var def unique_statuses(self) -> List[str]: """Get unique statuses from the data.""" return sorted({item["status"] for item in self._data}) @rx.var def unique_countries(self) -> List[str]: """Get unique countries from the data.""" return sorted({item["country"] for item in self._data}) @rx.var def filtered_d
items_with_sort_keys = [ (self._get_sort_key_for_recent_activities(item), item) for item in self._data ]
daily_costs[date_str] += cost sorted_dates = sorted(daily_costs.keys()) chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data @rx.var def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort keys to move try-except out of the sorting process itself items_with_sort_keys = [ (self._get_sort_key_for_recent_activities(item), item) for item in self._data ] # Sort based on the precomputed keys items_with_sort_keys.sort(key=lambda x: x[0], reverse=True) # Extract the original items in sorted order
return sorted_data[:5] def _get_sort_key_for_recent_activities( self, item: DetailEntry ) -> datetime.datetime: """Helper to get sort key for recent activities, handling potential ValueError.""" try: return datetime.datetime.strptime(item["last_edited"], "%d/%m/%Y %H:%M") except ValueError: return datetime.datetime.min @rx.var def unique_statuses(self) -> List[str]: """Get unique statuses from the data.""" return sorted({item["status"] for item in self._data}) @rx.var def unique_countries(self) -> List[str]: """Get unique countries from the data.""" return sorted({item["country"] for item in self._data}) @rx.var def filtered_data(self) -> List[DetailEntry]: """Filter the data based on current filter selections.""" data = self._data if self.search_owner: data = [ item for item in data
sorted_data = [item for _, item in items_with_sort_keys]
chart_data: List[Dict[str, str | float]] = [ { "date": datetime.datetime.strptime(date_str, output_format).strftime( display_format ), "total_costs": round(daily_costs[date_str], 2), } for date_str in sorted_dates ] return chart_data @rx.var def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort keys to move try-except out of the sorting process itself items_with_sort_keys = [ (self._get_sort_key_for_recent_activities(item), item) for item in self._data ] # Sort based on the precomputed keys items_with_sort_keys.sort(key=lambda x: x[0], reverse=True) # Extract the original items in sorted order sorted_data = [item for _, item in items_with_sort_keys] return sorted_data[:5]
@rx.var def unique_statuses(self) -> List[str]: """Get unique statuses from the data.""" return sorted({item["status"] for item in self._data}) @rx.var def unique_countries(self) -> List[str]: """Get unique countries from the data.""" return sorted({item["country"] for item in self._data}) @rx.var def filtered_data(self) -> List[DetailEntry]: """Filter the data based on current filter selections.""" data = self._data if self.search_owner: data = [ item for item in data if self.search_owner.lower() in item["owner"].lower() ] if self.selected_statuses: data = [item for item in data if item["status"] in self.selected_statuses] if self.selected_countries: data = [item for item in data if item["country"] in self.selected_countries] if self.min_cost is not None: data = [item for
def _get_sort_key_for_recent_activities( self, item: DetailEntry ) -> datetime.datetime: """Helper to get sort key for recent activities, handling potential ValueError.""" try: return datetime.datetime.strptime(item["last_edited"], "%d/%m/%Y %H:%M") except ValueError: return datetime.datetime.min
def recent_activities(self) -> List[DetailEntry]: """Get the 5 most recent activities based on last_edited date.""" # Precompute sort keys to move try-except out of the sorting process itself items_with_sort_keys = [ (self._get_sort_key_for_recent_activities(item), item) for item in self._data ] # Sort based on the precomputed keys items_with_sort_keys.sort(key=lambda x: x[0], reverse=True) # Extract the original items in sorted order sorted_data = [item for _, item in items_with_sort_keys] return sorted_data[:5] def _get_sort_key_for_recent_activities( self, item: DetailEntry ) -> datetime.datetime: """Helper to get sort key for recent activities, handling potential ValueError.""" try: return datetime.datetime.strptime(item["last_edited"], "%d/%m/%Y %H:%M") except ValueError: return datetime.datetime.min @rx.var
@rx.var def unique_countries(self) -> List[str]: """Get unique countries from the data.""" return sorted({item["country"] for item in self._data}) @rx.var def filtered_data(self) -> List[DetailEntry]: """Filter the data based on current filter selections.""" data = self._data if self.search_owner: data = [ item for item in data if self.search_owner.lower() in item["owner"].lower() ] if self.selected_statuses: data = [item for item in data if item["status"] in self.selected_statuses] if self.selected_countries: data = [item for item in data if item["country"] in self.selected_countries] if self.min_cost is not None: data = [item for item in data if item["costs"] >= self.min_cost] if self.max_cost is not None: data = [item for item in data if item["costs"] <= self.max_cost]
def unique_statuses(self) -> List[str]: """Get unique statuses from the data.""" return sorted({item["status"] for item in self._data})
-except out of the sorting process itself items_with_sort_keys = [ (self._get_sort_key_for_recent_activities(item), item) for item in self._data ] # Sort based on the precomputed keys items_with_sort_keys.sort(key=lambda x: x[0], reverse=True) # Extract the original items in sorted order sorted_data = [item for _, item in items_with_sort_keys] return sorted_data[:5] def _get_sort_key_for_recent_activities( self, item: DetailEntry ) -> datetime.datetime: """Helper to get sort key for recent activities, handling potential ValueError.""" try: return datetime.datetime.strptime(item["last_edited"], "%d/%m/%Y %H:%M") except ValueError: return datetime.datetime.min @rx.var def unique_statuses(self) -> List[str]: """Get unique statuses from the data.""" return sorted({item["status"] for item in self._data}) @rx.var
@rx.var def filtered_data(self) -> List[DetailEntry]: """Filter the data based on current filter selections.""" data = self._data if self.search_owner: data = [ item for item in data if self.search_owner.lower() in item["owner"].lower() ] if self.selected_statuses: data = [item for item in data if item["status"] in self.selected_statuses] if self.selected_countries: data = [item for item in data if item["country"] in self.selected_countries] if self.min_cost is not None: data = [item for item in data if item["costs"] >= self.min_cost] if self.max_cost is not None: data = [item for item in data if item["costs"] <= self.max_cost] return data def _get_sort_key_for_filtered_data( self, item: DetailEntry, internal_key: str, is_date_col: bool ) -> datetime.datetime | str | int | float
def unique_countries(self) -> List[str]: """Get unique countries from the data.""" return sorted({item["country"] for item in self._data})
data ] # Sort based on the precomputed keys items_with_sort_keys.sort(key=lambda x: x[0], reverse=True) # Extract the original items in sorted order sorted_data = [item for _, item in items_with_sort_keys] return sorted_data[:5] def _get_sort_key_for_recent_activities( self, item: DetailEntry ) -> datetime.datetime: """Helper to get sort key for recent activities, handling potential ValueError.""" try: return datetime.datetime.strptime(item["last_edited"], "%d/%m/%Y %H:%M") except ValueError: return datetime.datetime.min @rx.var def unique_statuses(self) -> List[str]: """Get unique statuses from the data.""" return sorted({item["status"] for item in self._data}) @rx.var def unique_countries(self) -> List[str]: """Get unique countries from the data.""" return sorted({item["country"] for item in self._data}) @rx.var
def _get_sort_key_for_filtered_data( self, item: DetailEntry, internal_key: str, is_date_col: bool ) -> datetime.datetime | str | int | float: """Helper to get sort key for filtered_and_sorted_data.""" try: if is_date_col: return datetime.datetime.strptime(item[internal_key], "%d/%m/%Y %H:%M") val = item[internal_key] if isinstance(val, (int, float)): return val return str(val).lower() except (KeyError, ValueError): # Return a value that will sort consistently for error cases if is_date_col: return datetime.datetime.min return "" @rx.var def filtered_and_sorted_data(self) -> List[DetailEntry]: """Sort the filtered data.""" data_to_sort = self.filtered_data if self.sort_column: sort_key_map = { "Owner": "owner", "Status": "status",
def filtered_data(self) -> List[DetailEntry]: """Filter the data based on current filter selections.""" data = self._data if self.search_owner: data = [ item for item in data if self.search_owner.lower() in item["owner"].lower() ] if self.selected_statuses: data = [item for item in data if item["status"] in self.selected_statuses] if self.selected_countries: data = [item for item in data if item["country"] in self.selected_countries] if self.min_cost is not None: data = [item for item in data if item["costs"] >= self.min_cost] if self.max_cost is not None: data = [item for item in data if item["costs"] <= self.max_cost] return data
se=True) # Extract the original items in sorted order sorted_data = [item for _, item in items_with_sort_keys] return sorted_data[:5] def _get_sort_key_for_recent_activities( self, item: DetailEntry ) -> datetime.datetime: """Helper to get sort key for recent activities, handling potential ValueError.""" try: return datetime.datetime.strptime(item["last_edited"], "%d/%m/%Y %H:%M") except ValueError: return datetime.datetime.min @rx.var def unique_statuses(self) -> List[str]: """Get unique statuses from the data.""" return sorted({item["status"] for item in self._data}) @rx.var def unique_countries(self) -> List[str]: """Get unique countries from the data.""" return sorted({item["country"] for item in self._data}) @rx.var def filtered_data(self) -> List[DetailEntry]: """Filter the data based on current filter selections."""
if self.search_owner: data = [ item for item in data if self.search_owner.lower() in item["owner"].lower() ] if self.selected_statuses: data = [item for item in data if item["status"] in self.selected_statuses] if self.selected_countries: data = [item for item in data if item["country"] in self.selected_countries] if self.min_cost is not None: data = [item for item in data if item["costs"] >= self.min_cost] if self.max_cost is not None: data = [item for item in data if item["costs"] <= self.max_cost] return data def _get_sort_key_for_filtered_data( self, item: DetailEntry, internal_key: str, is_date_col: bool ) -> datetime.datetime | str | int | float: """Helper to get sort key for filtered_and_sorted_data.""" try: if is_date_col: return datetime.datetime.strp
data = self._data