mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 08:13:56 +10:00
fix: remove cummulative
This commit is contained in:
@ -9,7 +9,6 @@ export type UserWithDocumentChartProps = {
|
||||
className?: string;
|
||||
title: string;
|
||||
data: GetUserWithDocumentMonthlyGrowth;
|
||||
cummulative?: boolean;
|
||||
completed?: boolean;
|
||||
};
|
||||
|
||||
@ -17,25 +16,20 @@ export const UserWithDocumentChart = ({
|
||||
className,
|
||||
data,
|
||||
title,
|
||||
cummulative = false,
|
||||
completed = false,
|
||||
}: UserWithDocumentChartProps) => {
|
||||
const formattedData = (data: GetUserWithDocumentMonthlyGrowth, completed: boolean) => {
|
||||
return [...data]
|
||||
.reverse()
|
||||
.map(({ month, count, cume_count, signed_count, cume_signed_count }) => {
|
||||
return [...data].reverse().map(({ month, count, signed_count }) => {
|
||||
const formattedMonth = DateTime.fromFormat(month, 'yyyy-MM').toFormat('LLL');
|
||||
if (completed) {
|
||||
return {
|
||||
month: formattedMonth,
|
||||
count: Number(signed_count),
|
||||
cummulative: Number(cume_signed_count),
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
month: formattedMonth,
|
||||
count: Number(count),
|
||||
cummulative: Number(cume_count),
|
||||
};
|
||||
}
|
||||
});
|
||||
@ -62,7 +56,7 @@ export const UserWithDocumentChart = ({
|
||||
/>
|
||||
|
||||
<Bar
|
||||
dataKey={cummulative ? 'cummulative' : 'count'}
|
||||
dataKey="count"
|
||||
fill="hsl(var(--primary))"
|
||||
radius={[4, 4, 0, 0]}
|
||||
maxBarSize={60}
|
||||
|
||||
@ -53,17 +53,13 @@ export const getUserWithAtLeastOneDocumentSignedPerMonth = async () => {
|
||||
export type GetUserWithDocumentMonthlyGrowth = Array<{
|
||||
month: string;
|
||||
count: number;
|
||||
cume_count: number;
|
||||
signed_count: number;
|
||||
cume_signed_count: number;
|
||||
}>;
|
||||
|
||||
type GetUserWithDocumentMonthlyGrowthQueryResult = Array<{
|
||||
month: Date;
|
||||
count: bigint;
|
||||
cume_count: bigint;
|
||||
signed_count: bigint;
|
||||
cume_signed_count: bigint;
|
||||
}>;
|
||||
|
||||
export const getUserWithSignedDocumentMonthlyGrowth = async () => {
|
||||
@ -71,9 +67,7 @@ export const getUserWithSignedDocumentMonthlyGrowth = async () => {
|
||||
SELECT
|
||||
DATE_TRUNC('month', "Document"."createdAt") AS "month",
|
||||
COUNT(DISTINCT "Document"."userId") as "count",
|
||||
SUM(COUNT(DISTINCT "Document"."userId")) OVER (ORDER BY DATE_TRUNC('month', "Document"."createdAt")) as "cume_count",
|
||||
COUNT(DISTINCT CASE WHEN "Document"."status" = 'COMPLETED' THEN "Document"."userId" END) as "signed_count",
|
||||
SUM(COUNT(DISTINCT CASE WHEN "Document"."status" = 'COMPLETED' THEN "Document"."userId" END)) OVER (ORDER BY DATE_TRUNC('month', "Document"."createdAt")) as "cume_signed_count"
|
||||
COUNT(DISTINCT CASE WHEN "Document"."status" = 'COMPLETED' THEN "Document"."userId" END) as "signed_count"
|
||||
FROM "Document"
|
||||
GROUP BY "month"
|
||||
ORDER BY "month" DESC
|
||||
@ -83,8 +77,6 @@ export const getUserWithSignedDocumentMonthlyGrowth = async () => {
|
||||
return result.map((row) => ({
|
||||
month: DateTime.fromJSDate(row.month).toFormat('yyyy-MM'),
|
||||
count: Number(row.count),
|
||||
cume_count: Number(row.cume_count),
|
||||
signed_count: Number(row.signed_count),
|
||||
cume_signed_count: Number(row.cume_signed_count),
|
||||
}));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user