Skip to content

Commit

Permalink
feat: better violation names on statistics page
Browse files Browse the repository at this point in the history
  • Loading branch information
r4zendev committed Jan 2, 2025
1 parent 24dae62 commit b9977f8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@ export const MetricsResponseSchema = z.object({
high: z.number(),
critical: z.number(),
}),
violationCounts: z.record(z.string(), z.number()),
violationCounts: z.array(
z.object({
name: z.string(),
id: z.string(),
count: z.number(),
}),
),
});

export const fetchBusinessReportMetrics = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ export const PortfolioRiskStatistics: FunctionComponent<z.infer<typeof MetricsRe
</TableRow>
</TableHeader>
<TableBody ref={parent}>
{filteredRiskIndicators.map(({ name, count }, index) => (
{filteredRiskIndicators.map(({ name, count, id }, index) => (
<TableRow key={name} className={'border-b-0 hover:bg-[unset]'}>
<TableCell className={ctw('pb-0 ps-0', index !== 0 && 'pt-2')}>
<Link
to={`/${locale}/merchant-monitoring?findings[0]=${name}`}
to={`/${locale}/merchant-monitoring?findings[0]=${id}`}
className={`block h-full cursor-pointer rounded bg-blue-200 p-1 transition-all`}
style={{ width: `${widths[index]}%` }}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,10 @@ export const usePortfolioRiskStatisticsLogic = ({
},
[],
);
const totalRiskIndicators = Object.values(violationCounts).reduce((acc, curr) => acc + curr, 0);
const totalRiskIndicators = violationCounts.reduce((acc, { count }) => acc + count, 0);
const filteredRiskIndicators = useMemo(
() =>
Object.entries(violationCounts)
.map(([name, count]) => ({ name, count }))
violationCounts
.sort((a, b) => (riskIndicatorsSorting === 'asc' ? a.count - b.count : b.count - a.count))
.slice(0, 5),
[violationCounts, riskIndicatorsSorting],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,11 @@ export class BusinessReportMetricsDto {
riskLevelCounts!: RiskLevelCountsDto;

@ApiProperty({
description: 'Counts of violations by type',
description: 'Detected violations counts',
example: { PROHIBITED_CONTENT: 2, MISSING_INFORMATION: 1 },
type: 'object',
additionalProperties: { type: 'number' },
type: 'array',
})
@IsObject()
@Type(() => Object)
violationCounts!: Record<string, number>;
violationCounts!: Array<{ count: number; name: string; id: string }>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ const MetricsResponseSchema = z.object({
high: z.number(),
critical: z.number(),
}),
violationCounts: z.record(z.string(), z.number()),
violationCounts: z.array(
z.object({
name: z.string(),
id: z.string(),
count: z.number(),
}),
),
});

@Injectable()
Expand Down

0 comments on commit b9977f8

Please sign in to comment.