|
| 1 | +import reflex as rx |
| 2 | + |
| 3 | +from business_analytics_dashboard.states.dashboard_state import DashboardState |
| 4 | + |
| 5 | + |
| 6 | +def pagination_controls() -> rx.Component: |
| 7 | + """Component for table pagination controls.""" |
| 8 | + return rx.el.div( |
| 9 | + rx.el.span( |
| 10 | + f"Page {DashboardState.current_page} of {DashboardState.total_pages}", |
| 11 | + class_name="text-sm text-gray-700 mr-4", |
| 12 | + ), |
| 13 | + rx.el.button( |
| 14 | + "Previous", |
| 15 | + on_click=DashboardState.previous_page, |
| 16 | + disabled=DashboardState.current_page <= 1, |
| 17 | + class_name="px-4 py-2 text-sm font-medium text-gray-700 bg-white border border-gray-300 rounded-l-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed", |
| 18 | + ), |
| 19 | + rx.el.button( |
| 20 | + "Next", |
| 21 | + on_click=DashboardState.next_page, |
| 22 | + disabled=DashboardState.current_page >= DashboardState.total_pages, |
| 23 | + class_name="px-4 py-2 text-sm font-medium text-gray-700 bg-white border-t border-b border-r border-gray-300 rounded-r-md hover:bg-gray-50 disabled:opacity-50 disabled:cursor-not-allowed", |
| 24 | + ), |
| 25 | + class_name="flex justify-end items-center mt-4", |
| 26 | + ) |
| 27 | + |
| 28 | + |
| 29 | +def account_executive_metrics_table() -> rx.Component: |
| 30 | + """Table displaying account executive metrics (employee data).""" |
| 31 | + return rx.el.div( |
| 32 | + rx.el.h2( |
| 33 | + "Account Executive Metrics", |
| 34 | + class_name="text-2xl font-semibold text-gray-800 mb-4", |
| 35 | + ), |
| 36 | + rx.el.div( |
| 37 | + rx.el.div( |
| 38 | + rx.el.label( |
| 39 | + "Filter by Department:", |
| 40 | + html_for="department-select", |
| 41 | + class_name="text-sm font-medium text-gray-700 mr-2", |
| 42 | + ), |
| 43 | + rx.el.select( |
| 44 | + rx.el.option("All", value="All"), |
| 45 | + rx.foreach( |
| 46 | + DashboardState.departments_for_filter, |
| 47 | + lambda dept: rx.el.option(dept, value=dept), |
| 48 | + ), |
| 49 | + id="department-select", |
| 50 | + value=DashboardState.selected_department, |
| 51 | + on_change=DashboardState.set_selected_department, |
| 52 | + class_name="p-3 border rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white text-gray-900", |
| 53 | + ), |
| 54 | + class_name="flex items-center", |
| 55 | + ), |
| 56 | + rx.el.input( |
| 57 | + type="text", |
| 58 | + placeholder="Search in table...", |
| 59 | + default_value=DashboardState.search_query, |
| 60 | + on_change=DashboardState.set_search_query.debounce(300), |
| 61 | + class_name="w-full md:w-auto p-3 border rounded-lg shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white text-gray-900 placeholder-gray-400", |
| 62 | + ), |
| 63 | + class_name="flex flex-col md:flex-row justify-between items-center mb-6 space-y-4 md:space-y-0", |
| 64 | + ), |
| 65 | + rx.el.div( |
| 66 | + rx.cond( |
| 67 | + DashboardState.loading, |
| 68 | + rx.el.div( |
| 69 | + rx.el.p( |
| 70 | + "Loading employee data...", |
| 71 | + class_name="text-center text-gray-500 py-4", |
| 72 | + ), |
| 73 | + class_name="w-full", |
| 74 | + ), |
| 75 | + rx.el.div( |
| 76 | + rx.el.table( |
| 77 | + rx.el.thead( |
| 78 | + rx.el.tr( |
| 79 | + rx.el.th( |
| 80 | + "ID", |
| 81 | + class_name="p-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500 bg-gray-50 border-b", |
| 82 | + ), |
| 83 | + rx.el.th( |
| 84 | + "First Name", |
| 85 | + class_name="p-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500 bg-gray-50 border-b", |
| 86 | + ), |
| 87 | + rx.el.th( |
| 88 | + "Last Name", |
| 89 | + class_name="p-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500 bg-gray-50 border-b", |
| 90 | + ), |
| 91 | + rx.el.th( |
| 92 | + "Email", |
| 93 | + class_name="p-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500 bg-gray-50 border-b", |
| 94 | + ), |
| 95 | + rx.el.th( |
| 96 | + "Department", |
| 97 | + class_name="p-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500 bg-gray-50 border-b", |
| 98 | + ), |
| 99 | + rx.el.th( |
| 100 | + "Salary", |
| 101 | + class_name="p-3 text-left text-xs font-semibold uppercase tracking-wider text-gray-500 bg-gray-50 border-b", |
| 102 | + ), |
| 103 | + rx.el.th( |
| 104 | + "Projects Closed", |
| 105 | + class_name="p-3 text-center text-xs font-semibold uppercase tracking-wider text-gray-500 bg-gray-50 border-b", |
| 106 | + ), |
| 107 | + rx.el.th( |
| 108 | + "Pending Projects", |
| 109 | + class_name="p-3 text-center text-xs font-semibold uppercase tracking-wider text-gray-500 bg-gray-50 border-b", |
| 110 | + ), |
| 111 | + class_name="bg-gray-50", |
| 112 | + ) |
| 113 | + ), |
| 114 | + rx.el.tbody( |
| 115 | + rx.foreach( |
| 116 | + DashboardState.paginated_employees, |
| 117 | + lambda employee: rx.el.tr( |
| 118 | + rx.el.td( |
| 119 | + employee["employee_id"], |
| 120 | + class_name="p-3 border-b text-sm text-gray-700", |
| 121 | + ), |
| 122 | + rx.el.td( |
| 123 | + employee["first_name"], |
| 124 | + class_name="p-3 border-b text-sm text-gray-700", |
| 125 | + ), |
| 126 | + rx.el.td( |
| 127 | + employee["last_name"], |
| 128 | + class_name="p-3 border-b text-sm text-gray-700", |
| 129 | + ), |
| 130 | + rx.el.td( |
| 131 | + employee["email"], |
| 132 | + class_name="p-3 border-b text-sm text-gray-700", |
| 133 | + ), |
| 134 | + rx.el.td( |
| 135 | + employee["department"], |
| 136 | + class_name="p-3 border-b text-sm text-gray-700", |
| 137 | + ), |
| 138 | + rx.el.td( |
| 139 | + "$ " + employee["salary"].to_string(), |
| 140 | + class_name="p-3 border-b text-sm text-gray-700", |
| 141 | + ), |
| 142 | + rx.el.td( |
| 143 | + employee["projects_closed"], |
| 144 | + class_name="p-3 border-b text-sm text-gray-700 text-center", |
| 145 | + ), |
| 146 | + rx.el.td( |
| 147 | + employee["pending_projects"], |
| 148 | + class_name="p-3 border-b text-sm text-gray-700 text-center", |
| 149 | + ), |
| 150 | + class_name="hover:bg-gray-50 transition-colors", |
| 151 | + ), |
| 152 | + ) |
| 153 | + ), |
| 154 | + rx.cond( |
| 155 | + ~DashboardState.loading |
| 156 | + & (DashboardState.filtered_employees.length() == 0), |
| 157 | + rx.el.caption( |
| 158 | + rx.el.p( |
| 159 | + rx.cond( |
| 160 | + (DashboardState.search_query != "") |
| 161 | + | (DashboardState.selected_department != "All"), |
| 162 | + "No employees match your search or filter.", |
| 163 | + "No employee data available.", |
| 164 | + ), |
| 165 | + class_name="text-center text-gray-500 py-4", |
| 166 | + ), |
| 167 | + class_name="caption-bottom", |
| 168 | + ), |
| 169 | + rx.fragment(), |
| 170 | + ), |
| 171 | + class_name="w-full border-collapse bg-white rounded-t-lg shadow-md overflow-hidden", |
| 172 | + ), |
| 173 | + rx.cond( |
| 174 | + ~DashboardState.loading & (DashboardState.total_pages > 1), |
| 175 | + pagination_controls(), |
| 176 | + rx.fragment(), |
| 177 | + ), |
| 178 | + class_name="overflow-x-auto shadow rounded-lg border border-gray-200", |
| 179 | + ), |
| 180 | + ) |
| 181 | + ), |
| 182 | + class_name="bg-white p-6 rounded-lg shadow-md", |
| 183 | + ) |
0 commit comments