-
Notifications
You must be signed in to change notification settings - Fork 327
Refactor evidence overview and policy components #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
...ale]/(app)/(dashboard)/[orgId]/evidence/(overview)/components/evidence-assignee-chart.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| "use client"; | ||
|
|
||
| import * as React from "react"; | ||
|
|
||
| import { | ||
| Card, | ||
| CardContent, | ||
| CardHeader, | ||
| CardFooter, | ||
| CardTitle, | ||
| } from "@bubba/ui/card"; | ||
| import { ChartContainer, ChartTooltip, ChartTooltipContent, type ChartConfig } from "@bubba/ui/chart"; | ||
| import { useI18n } from "@/locales/client"; | ||
| import { Bar, BarChart, XAxis, YAxis, Legend, ResponsiveContainer } from "recharts" | ||
|
|
||
| interface AssigneeData { | ||
| id: string; | ||
| name: string; | ||
| total: number; | ||
| published: number; | ||
| draft: number; | ||
| archived: number; | ||
| needs_review: number; | ||
| } | ||
|
|
||
| interface EvidenceAssigneeChartProps { | ||
| data?: AssigneeData[] | null; | ||
| } | ||
|
|
||
| const CHART_COLORS = { | ||
| published: "hsl(var(--chart-positive))", // green | ||
| draft: "hsl(var(--chart-neutral))", // yellow | ||
| archived: "hsl(var(--chart-warning))", // gray | ||
| needs_review: "hsl(var(--chart-destructive))", // red | ||
| }; | ||
|
|
||
| export function EvidenceAssigneeChart({ data }: EvidenceAssigneeChartProps) { | ||
| const t = useI18n(); | ||
|
|
||
| if (!data || data.length === 0) { | ||
| return ( | ||
| <Card className="flex flex-col"> | ||
| <CardHeader> | ||
| <CardTitle> | ||
| {t("evidence.dashboard.by_assignee") || | ||
| "Evidence by Assignee"} | ||
| </CardTitle> | ||
| </CardHeader> | ||
| <CardContent className="flex-1 flex items-center justify-center"> | ||
| <p className="text-center text-sm text-muted-foreground"> | ||
| No evidence assigned to users | ||
| </p> | ||
| </CardContent> | ||
| <CardFooter> | ||
| <div className="flex flex-wrap gap-4 py-2" /> | ||
| </CardFooter> | ||
| </Card> | ||
| ); | ||
| } | ||
|
|
||
| // Sort assignees by total policies (descending) | ||
| const sortedData = React.useMemo(() => { | ||
| return [...data].sort((a, b) => b.total - a.total).slice(0, 4).reverse(); | ||
| }, [data]); | ||
|
|
||
| const chartData = sortedData.map((item) => ({ | ||
| name: item.name, | ||
| published: item.published, | ||
| draft: item.draft, | ||
| archived: item.archived, | ||
| needs_review: item.needs_review, | ||
| })); | ||
|
|
||
| const chartConfig = { | ||
| published: { | ||
| label: t("evidence.status.published"), | ||
| color: CHART_COLORS.published, | ||
| }, | ||
| draft: { | ||
| label: t("evidence.status.draft"), | ||
| color: CHART_COLORS.draft, | ||
| }, | ||
| archived: { | ||
| label: t("evidence.status.isNotRelevant"), | ||
| color: CHART_COLORS.archived, | ||
| }, | ||
| needs_review: { | ||
| label: t("evidence.status.needs_review"), | ||
| color: CHART_COLORS.needs_review, | ||
| }, | ||
| } satisfies ChartConfig; | ||
|
|
||
| return ( | ||
| <Card className="flex flex-col"> | ||
| <CardHeader> | ||
| <CardTitle> | ||
| {t("evidence.dashboard.by_assignee") || | ||
| "Evidence by Assignee"} | ||
| </CardTitle> | ||
| </CardHeader> | ||
| <CardContent className="flex-1"> | ||
| <ChartContainer config={chartConfig}> | ||
| <ResponsiveContainer width="100%" height={250}> | ||
| <BarChart | ||
| accessibilityLayer | ||
| data={chartData} | ||
| layout="vertical" | ||
| barSize={30} | ||
| barGap={8} | ||
| margin={{ | ||
| top: 0, | ||
| right: 0, | ||
| bottom: 0, | ||
| left: 0 | ||
| }} | ||
| > | ||
| <XAxis type="number" hide /> | ||
| <YAxis | ||
| dataKey="name" | ||
| type="category" | ||
| tickLine={false} | ||
| tickMargin={10} | ||
| axisLine={false} | ||
| tickFormatter={(value) => value.split(' ')[0]} | ||
| /> | ||
| <ChartTooltip | ||
| cursor={false} | ||
| content={<ChartTooltipContent />} | ||
| /> | ||
| <Bar dataKey="published" stackId="a" fill={CHART_COLORS.published} /> | ||
| <Bar dataKey="draft" stackId="a" fill={CHART_COLORS.draft} /> | ||
| <Bar dataKey="archived" stackId="a" fill={CHART_COLORS.archived} /> | ||
| <Bar dataKey="needs_review" stackId="a" fill={CHART_COLORS.needs_review} /> | ||
| </BarChart> | ||
| </ResponsiveContainer> | ||
| </ChartContainer> | ||
| </CardContent> | ||
| <CardFooter> | ||
| <div className="flex flex-wrap gap-4 py-2"> | ||
| {Object.entries(chartConfig).map(([key, config]) => ( | ||
| <div key={key} className="flex items-center gap-2"> | ||
| <div | ||
| className="h-3 w-3" | ||
| style={{ backgroundColor: config.color }} | ||
| /> | ||
| <span className="text-xs">{config.label}</span> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| </CardFooter> | ||
| </Card> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate property naming for "archived" vs "isNotRelevant".
The chart references
archivedbut the database property isisNotRelevant. Ensure these concepts align correctly, or rename the property to maintain consistency across files.🛠️ Refactor suggestion
Mismatch in naming "needs_review" vs "needsReview".
Your chart data references
needs_review, but the backend logic incrementsneedsReview. This discrepancy can cause zero-increment issues. Rename the properties to match one another for correct tallying.📝 Committable suggestion