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;
|
className?: string;
|
||||||
title: string;
|
title: string;
|
||||||
data: GetUserWithDocumentMonthlyGrowth;
|
data: GetUserWithDocumentMonthlyGrowth;
|
||||||
cummulative?: boolean;
|
|
||||||
completed?: boolean;
|
completed?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -17,28 +16,23 @@ export const UserWithDocumentChart = ({
|
|||||||
className,
|
className,
|
||||||
data,
|
data,
|
||||||
title,
|
title,
|
||||||
cummulative = false,
|
|
||||||
completed = false,
|
completed = false,
|
||||||
}: UserWithDocumentChartProps) => {
|
}: UserWithDocumentChartProps) => {
|
||||||
const formattedData = (data: GetUserWithDocumentMonthlyGrowth, completed: boolean) => {
|
const formattedData = (data: GetUserWithDocumentMonthlyGrowth, completed: boolean) => {
|
||||||
return [...data]
|
return [...data].reverse().map(({ month, count, signed_count }) => {
|
||||||
.reverse()
|
const formattedMonth = DateTime.fromFormat(month, 'yyyy-MM').toFormat('LLL');
|
||||||
.map(({ month, count, cume_count, signed_count, cume_signed_count }) => {
|
if (completed) {
|
||||||
const formattedMonth = DateTime.fromFormat(month, 'yyyy-MM').toFormat('LLL');
|
return {
|
||||||
if (completed) {
|
month: formattedMonth,
|
||||||
return {
|
count: Number(signed_count),
|
||||||
month: formattedMonth,
|
};
|
||||||
count: Number(signed_count),
|
} else {
|
||||||
cummulative: Number(cume_signed_count),
|
return {
|
||||||
};
|
month: formattedMonth,
|
||||||
} else {
|
count: Number(count),
|
||||||
return {
|
};
|
||||||
month: formattedMonth,
|
}
|
||||||
count: Number(count),
|
});
|
||||||
cummulative: Number(cume_count),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -62,7 +56,7 @@ export const UserWithDocumentChart = ({
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Bar
|
<Bar
|
||||||
dataKey={cummulative ? 'cummulative' : 'count'}
|
dataKey="count"
|
||||||
fill="hsl(var(--primary))"
|
fill="hsl(var(--primary))"
|
||||||
radius={[4, 4, 0, 0]}
|
radius={[4, 4, 0, 0]}
|
||||||
maxBarSize={60}
|
maxBarSize={60}
|
||||||
|
|||||||
@ -53,17 +53,13 @@ export const getUserWithAtLeastOneDocumentSignedPerMonth = async () => {
|
|||||||
export type GetUserWithDocumentMonthlyGrowth = Array<{
|
export type GetUserWithDocumentMonthlyGrowth = Array<{
|
||||||
month: string;
|
month: string;
|
||||||
count: number;
|
count: number;
|
||||||
cume_count: number;
|
|
||||||
signed_count: number;
|
signed_count: number;
|
||||||
cume_signed_count: number;
|
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
type GetUserWithDocumentMonthlyGrowthQueryResult = Array<{
|
type GetUserWithDocumentMonthlyGrowthQueryResult = Array<{
|
||||||
month: Date;
|
month: Date;
|
||||||
count: bigint;
|
count: bigint;
|
||||||
cume_count: bigint;
|
|
||||||
signed_count: bigint;
|
signed_count: bigint;
|
||||||
cume_signed_count: bigint;
|
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
export const getUserWithSignedDocumentMonthlyGrowth = async () => {
|
export const getUserWithSignedDocumentMonthlyGrowth = async () => {
|
||||||
@ -71,9 +67,7 @@ export const getUserWithSignedDocumentMonthlyGrowth = async () => {
|
|||||||
SELECT
|
SELECT
|
||||||
DATE_TRUNC('month', "Document"."createdAt") AS "month",
|
DATE_TRUNC('month', "Document"."createdAt") AS "month",
|
||||||
COUNT(DISTINCT "Document"."userId") as "count",
|
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"
|
||||||
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"
|
|
||||||
FROM "Document"
|
FROM "Document"
|
||||||
GROUP BY "month"
|
GROUP BY "month"
|
||||||
ORDER BY "month" DESC
|
ORDER BY "month" DESC
|
||||||
@ -83,8 +77,6 @@ export const getUserWithSignedDocumentMonthlyGrowth = async () => {
|
|||||||
return result.map((row) => ({
|
return result.map((row) => ({
|
||||||
month: DateTime.fromJSDate(row.month).toFormat('yyyy-MM'),
|
month: DateTime.fromJSDate(row.month).toFormat('yyyy-MM'),
|
||||||
count: Number(row.count),
|
count: Number(row.count),
|
||||||
cume_count: Number(row.cume_count),
|
|
||||||
signed_count: Number(row.signed_count),
|
signed_count: Number(row.signed_count),
|
||||||
cume_signed_count: Number(row.cume_signed_count),
|
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user