import { useState } from "react"; import { useRouter } from "next/router"; import useSWR from "swr"; // react-hook-form import { useForm } from "react-hook-form"; // services import analyticsService from "services/analytics.service"; // components import { AnalyticsGraph, AnalyticsSidebar, AnalyticsTable, CreateUpdateAnalyticsModal, } from "components/analytics"; // ui import { Loader, PrimaryButton } from "components/ui"; // types import { convertResponseToBarGraphData } from "constants/analytics"; // types import { IAnalyticsParams } from "types"; // fetch-keys import { ANALYTICS } from "constants/fetch-keys"; const defaultValues: IAnalyticsParams = { x_axis: "priority", y_axis: "issue_count", segment: null, project: null, }; type Props = { isProjectLevel?: boolean; fullScreen?: boolean; }; export const CustomAnalytics: React.FC = ({ isProjectLevel = false, fullScreen = true }) => { const [saveAnalyticsModal, setSaveAnalyticsModal] = useState(false); const router = useRouter(); const { workspaceSlug, projectId, cycleId, moduleId } = router.query; const { control, watch, setValue } = useForm({ defaultValues }); const params: IAnalyticsParams = { x_axis: watch("x_axis"), y_axis: watch("y_axis"), segment: watch("segment"), project: isProjectLevel ? projectId?.toString() : watch("project"), cycle: isProjectLevel && cycleId ? cycleId.toString() : null, module: isProjectLevel && moduleId ? moduleId.toString() : null, }; const { data: analytics, error: analyticsError, mutate: mutateAnalytics, } = useSWR( workspaceSlug ? ANALYTICS(workspaceSlug.toString(), params) : null, workspaceSlug ? () => analyticsService.getAnalytics(workspaceSlug.toString(), params) : null ); const yAxisKey = params.y_axis === "issue_count" ? "count" : "effort"; const barGraphData = convertResponseToBarGraphData( analytics?.distribution, watch("segment") ? true : false, watch("y_axis") ); return ( <> setSaveAnalyticsModal(false)} params={params} />
{!analyticsError ? ( analytics ? ( analytics.total > 0 ? ( <> ) : (

No matching issues found. Try changing the parameters.

) ) : ( ) ) : (

There was some error in fetching the data.

Refresh
)}
); };