diff --git a/apps/web/src/pages/[organization]/[project]/[dashboard].tsx b/apps/web/src/pages/[organization]/[project]/[dashboard].tsx index 7afb398c..639caa05 100644 --- a/apps/web/src/pages/[organization]/[project]/[dashboard].tsx +++ b/apps/web/src/pages/[organization]/[project]/[dashboard].tsx @@ -4,12 +4,16 @@ import { api } from "@/utils/api"; import Link from "next/link"; import { PageTitle } from "@/components/PageTitle"; import { useOrganizationParams } from "@/hooks/useOrganizationParams"; -import { Suspense, useMemo } from "react"; +import { Suspense, useMemo, useState } from "react"; import { createServerSideProps } from "@/server/getServerSideProps"; import { Chart } from "@/components/report/chart"; import { timeRanges } from "@/utils/constants"; +import { type IChartRange } from "@/types"; +import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group"; +import { cn } from "@/utils/cn"; +import { getRangeLabel } from "@/utils/getRangeLabel"; -export const getServerSideProps = createServerSideProps() +export const getServerSideProps = createServerSideProps(); export default function Dashboard() { const params = useOrganizationParams(); @@ -18,20 +22,39 @@ export default function Dashboard() { projectSlug: params.project, dashboardSlug: params.dashboard, }); - + const dashboard = query.data?.dashboard ?? null; const reports = useMemo(() => { return query.data?.reports ?? []; - }, [query]) + }, [query]); + + const [range, setRange] = useState(null); return ( {dashboard?.name} + + + {timeRanges.map((item) => { + return ( + { + setRange((p) => (p === item.range ? null : item.range)); + }} + > + {item.title} + + ); + })} + +
{reports.map((report) => { - const range = timeRanges.find((item) => item.range === report.range) + const chartRange = getRangeLabel(report.range); return (
{report.name}
- {range &&
{range.title}
} + {chartRange && ( +
+ {chartRange} + {range && {getRangeLabel(range)}} +
+ )} -
- +
+
- ) + ); })}
diff --git a/apps/web/src/utils/getRangeLabel.ts b/apps/web/src/utils/getRangeLabel.ts new file mode 100644 index 00000000..8ec9fc55 --- /dev/null +++ b/apps/web/src/utils/getRangeLabel.ts @@ -0,0 +1,8 @@ +import { type IChartRange } from "@/types"; +import { timeRanges } from "./constants"; + +export function getRangeLabel(range: IChartRange) { + return timeRanges.find( + (item) => item.range === range, + )?.title ?? null +} \ No newline at end of file