import React, { useState } from "react"; import { Button } from "@/shared/common/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger, } from "@/shared/common/ui/dropdown-menu"; import { ChevronDown } from "lucide-react"; import { PermittedDashboardItem, DashaboardParam, } from "@/record-management/services/api/advancedDashboardService"; import { useAdvancedDashboardHook } from "@/shared/hooks/useAdvancedDashboardHook"; import useSettings from "@/record-management/components/hooks/useSettings"; import { useLocalizedName } from "@/shared/common/localizedName"; import { getFormattedDashboardLabel } from "@/performance-management/utils/dashboardUtils"; import { PositionDto } from "@/record-management/dto/userRecords/usersDto"; const AdvancedDashboardPage = () => { const [selectedDashboard, setSelectedDashboard] = useState(null); const [selectedParameters, setSelectedParameters] = useState< Record >({}); const localizedName = useLocalizedName(); const { permittedDashboards, dashboardUrl, isLoadingPermitted, isLoadingUrl, } = useAdvancedDashboardHook(selectedDashboard?.id); const { allScopedDepartments, allScopedEmployees } = useSettings(); const positionOptions = Array.isArray(allScopedDepartments) ? allScopedDepartments.map((pos: PositionDto) => ({ label: localizedName(pos.name) || "N/A", value: pos.id, })) : []; const employeeOptions = Array.isArray(allScopedEmployees) ? allScopedEmployees.map((emp: any) => ({ label: localizedName(emp.name) || "N/A", value: emp.id, })) : []; const handleParameterSelect = (key: string, value: string) => { setSelectedParameters((prev) => ({ ...prev, [key]: value, })); }; return (
{/* Dashboard + Position + Employee in a row */}
{/* Dashboard Dropdown */} Available Dashboards {permittedDashboards?.items.map((dashboard) => ( { setSelectedDashboard(dashboard); setSelectedParameters({}); // reset parameters }}> {getFormattedDashboardLabel(dashboard.name, "am")} ))} {/* Position Dropdown */} {selectedDashboard?.params?.includes(DashaboardParam.POSITION) && ( )} {/* Employee Dropdown */} {selectedDashboard?.params?.includes(DashaboardParam.EMPLOYEE) && ( )}
{/* Dashboard iframe */} {isLoadingUrl ? (

Loading dashboard...

) : dashboardUrl ? (