feat: add telemetry event count
This commit is contained in:
parent
ac7b44e862
commit
8a3c93fff7
@ -11,6 +11,7 @@ import { Empty } from 'antd';
|
|||||||
export interface CommonListItem {
|
export interface CommonListItem {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
number?: number;
|
||||||
content?: React.ReactNode;
|
content?: React.ReactNode;
|
||||||
tags?: string[];
|
tags?: string[];
|
||||||
href: string;
|
href: string;
|
||||||
@ -84,12 +85,12 @@ export const CommonList: React.FC<CommonListProps> = React.memo((props) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<div className="flex w-full flex-col gap-1">
|
<div className="flex w-full items-center justify-between gap-1">
|
||||||
<div className="flex items-center">
|
|
||||||
<div className="flex items-center gap-2">
|
|
||||||
<div className="font-semibold">{item.title}</div>
|
<div className="font-semibold">{item.title}</div>
|
||||||
</div>
|
|
||||||
</div>
|
{item.number && item.number > 0 && (
|
||||||
|
<span className="opacity-60">{item.number}</span>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{item.content && (
|
{item.content && (
|
||||||
|
@ -27,6 +27,9 @@ function TelemetryComponent() {
|
|||||||
const { data = [] } = trpc.telemetry.all.useQuery({
|
const { data = [] } = trpc.telemetry.all.useQuery({
|
||||||
workspaceId,
|
workspaceId,
|
||||||
});
|
});
|
||||||
|
const { data: allEventCount = {} } = trpc.telemetry.allEventCount.useQuery({
|
||||||
|
workspaceId,
|
||||||
|
});
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const pathname = useRouterState({
|
const pathname = useRouterState({
|
||||||
select: (state) => state.location.pathname,
|
select: (state) => state.location.pathname,
|
||||||
@ -35,6 +38,7 @@ function TelemetryComponent() {
|
|||||||
const items = data.map((item) => ({
|
const items = data.map((item) => ({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
title: item.name,
|
title: item.name,
|
||||||
|
number: allEventCount[item.id] ?? 0,
|
||||||
href: `/telemetry/${item.id}`,
|
href: `/telemetry/${item.id}`,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -78,6 +78,33 @@ export const telemetryRouter = router({
|
|||||||
|
|
||||||
return res;
|
return res;
|
||||||
}),
|
}),
|
||||||
|
allEventCount: workspaceProcedure
|
||||||
|
.meta(
|
||||||
|
buildTelemetryOpenapi({
|
||||||
|
method: 'GET',
|
||||||
|
path: '/allEventCount',
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.output(z.record(z.string(), z.number()))
|
||||||
|
.query(async ({ input }) => {
|
||||||
|
const { workspaceId } = input;
|
||||||
|
|
||||||
|
const res = await prisma.telemetryEvent.groupBy({
|
||||||
|
by: ['telemetryId'],
|
||||||
|
where: {
|
||||||
|
workspaceId,
|
||||||
|
},
|
||||||
|
_count: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
return res.reduce<Record<string, number>>((prev, item) => {
|
||||||
|
if (item.telemetryId) {
|
||||||
|
prev[item.telemetryId] = item._count;
|
||||||
|
}
|
||||||
|
|
||||||
|
return prev;
|
||||||
|
}, {});
|
||||||
|
}),
|
||||||
eventCount: workspaceProcedure
|
eventCount: workspaceProcedure
|
||||||
.meta(
|
.meta(
|
||||||
buildTelemetryOpenapi({
|
buildTelemetryOpenapi({
|
||||||
|
Loading…
Reference in New Issue
Block a user