import { useEffect } from "react"; import { observer } from "mobx-react-lite"; import Link from "next/link"; import { useRouter } from "next/router"; import { TIssuesByPriorityWidgetFilters, TIssuesByPriorityWidgetResponse } from "@plane/types"; // hooks // components import { DurationFilterDropdown, IssuesByPriorityEmptyState, WidgetLoader, WidgetProps, } from "@/components/dashboard/widgets"; // helpers // types // constants import { IssuesByPriorityGraph } from "@/components/graphs"; import { EDurationFilters } from "@/constants/dashboard"; import { getCustomDates } from "@/helpers/dashboard.helper"; import { useDashboard } from "@/hooks/store"; const WIDGET_KEY = "issues_by_priority"; export const IssuesByPriorityWidget: React.FC = observer((props) => { const { dashboardId, workspaceSlug } = props; // router const router = useRouter(); // store hooks const { fetchWidgetStats, getWidgetDetails, getWidgetStats, updateDashboardWidgetFilters } = useDashboard(); // derived values const widgetDetails = getWidgetDetails(workspaceSlug, dashboardId, WIDGET_KEY); const widgetStats = getWidgetStats(workspaceSlug, dashboardId, WIDGET_KEY); const selectedDuration = widgetDetails?.widget_filters.duration ?? EDurationFilters.NONE; const selectedCustomDates = widgetDetails?.widget_filters.custom_dates ?? []; const handleUpdateFilters = async (filters: Partial) => { if (!widgetDetails) return; await updateDashboardWidgetFilters(workspaceSlug, dashboardId, widgetDetails.id, { widgetKey: WIDGET_KEY, filters, }); const filterDates = getCustomDates( filters.duration ?? selectedDuration, filters.custom_dates ?? selectedCustomDates ); fetchWidgetStats(workspaceSlug, dashboardId, { widget_key: WIDGET_KEY, ...(filterDates.trim() !== "" ? { target_date: filterDates } : {}), }); }; useEffect(() => { const filterDates = getCustomDates(selectedDuration, selectedCustomDates); fetchWidgetStats(workspaceSlug, dashboardId, { widget_key: WIDGET_KEY, ...(filterDates.trim() !== "" ? { target_date: filterDates } : {}), }); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); if (!widgetDetails || !widgetStats) return ; const totalCount = widgetStats.reduce((acc, item) => acc + item?.count, 0); const chartData = widgetStats.map((item) => ({ priority: item?.priority, priority_count: item?.count, })); return (
Assigned by priority handleUpdateFilters({ duration: val, ...(val === "custom" ? { custom_dates: customDates } : {}), }) } />
{totalCount > 0 ? (
{ router.push( `/${workspaceSlug}/workspace-views/assigned?priority=${`${datum.data.priority}`.toLowerCase()}` ); }} />
) : (
)}
); });