@schemavaults/auth-ui 0.14.4 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/UsersCard/UsersCard.d.ts +1 -1
- package/dist/components/UsersCard/UsersCard.js +2 -47
- package/dist/components/UsersCard/UsersCard.js.map +1 -1
- package/dist/components/UsersChartsRow/UsersBreakdownCard.d.ts +15 -0
- package/dist/components/UsersChartsRow/UsersBreakdownCard.js +74 -0
- package/dist/components/UsersChartsRow/UsersBreakdownCard.js.map +1 -0
- package/dist/components/UsersChartsRow/UsersChartsRow.d.ts +21 -0
- package/dist/components/UsersChartsRow/UsersChartsRow.js +15 -0
- package/dist/components/UsersChartsRow/UsersChartsRow.js.map +1 -0
- package/dist/components/UsersChartsRow/UsersGrowthCard.d.ts +17 -0
- package/dist/components/UsersChartsRow/UsersGrowthCard.js +60 -0
- package/dist/components/UsersChartsRow/UsersGrowthCard.js.map +1 -0
- package/dist/components/UsersChartsRow/index.d.ts +8 -0
- package/dist/components/UsersChartsRow/index.js +5 -0
- package/dist/components/UsersChartsRow/index.js.map +1 -0
- package/dist/components/UsersChartsRow/user-chart-data.d.ts +89 -0
- package/dist/components/UsersChartsRow/user-chart-data.js +194 -0
- package/dist/components/UsersChartsRow/user-chart-data.js.map +1 -0
- package/dist/components/UsersStatsRow/UsersStatsRow.d.ts +1 -1
- package/dist/components/UsersStatsRow/UsersStatsRow.js +2 -46
- package/dist/components/UsersStatsRow/UsersStatsRow.js.map +1 -1
- package/dist/components/UsersTable/index.d.ts +2 -0
- package/dist/components/UsersTable/index.js +1 -0
- package/dist/components/UsersTable/index.js.map +1 -1
- package/dist/components/UsersTable/useAllUsersList.d.ts +18 -0
- package/dist/components/UsersTable/useAllUsersList.js +58 -0
- package/dist/components/UsersTable/useAllUsersList.js.map +1 -0
- package/dist/components/index.d.ts +4 -2
- package/dist/components/index.js +2 -1
- package/dist/components/index.js.map +1 -1
- package/dist/lib/useMeasuredWidth.d.ts +18 -0
- package/dist/lib/useMeasuredWidth.js +38 -0
- package/dist/lib/useMeasuredWidth.js.map +1 -0
- package/package.json +7 -7
|
@@ -2,58 +2,13 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, cn, } from "@schemavaults/ui";
|
|
4
4
|
import UsersTable from "../UsersTable";
|
|
5
|
-
import {
|
|
6
|
-
import useSWR from "swr";
|
|
5
|
+
import { useAllUsersList } from "../UsersTable/useAllUsersList";
|
|
7
6
|
export function UsersCard(props) {
|
|
8
7
|
const cardTitle = props.cardTitle ?? "Users";
|
|
9
8
|
const cardDescription = props.cardDescription ?? "View and manage registered users.";
|
|
10
9
|
const cardClassName = cn("w-full", props.cardClassName);
|
|
11
10
|
const getUserHref = props.getUserHref;
|
|
12
|
-
const
|
|
13
|
-
const users = useSWR(listAllUsersEndpoint, async () => {
|
|
14
|
-
try {
|
|
15
|
-
const response = await fetch(listAllUsersEndpoint, {
|
|
16
|
-
method: "GET",
|
|
17
|
-
credentials: "include",
|
|
18
|
-
});
|
|
19
|
-
if (!response.ok || response.status !== 200) {
|
|
20
|
-
throw new Error(`Failed to list users (response status: ${response.status})!`);
|
|
21
|
-
}
|
|
22
|
-
const body = await response.json();
|
|
23
|
-
if (typeof body !== "object" ||
|
|
24
|
-
!body ||
|
|
25
|
-
!("success" in body) ||
|
|
26
|
-
!body.success) {
|
|
27
|
-
throw new Error("Received failure response when attempting to list users");
|
|
28
|
-
}
|
|
29
|
-
if (!("data" in body) ||
|
|
30
|
-
typeof body.data !== "object" ||
|
|
31
|
-
!body.data ||
|
|
32
|
-
!("users" in body.data) ||
|
|
33
|
-
!Array.isArray(body.data.users)) {
|
|
34
|
-
throw new Error("Failed to extract 'users' array from response!");
|
|
35
|
-
}
|
|
36
|
-
const usersWithSub = body.data.users.map((user) => ({
|
|
37
|
-
...user,
|
|
38
|
-
sub: user.uid,
|
|
39
|
-
}));
|
|
40
|
-
const parsed_users = await userDataSchema
|
|
41
|
-
.array()
|
|
42
|
-
.safeParseAsync(usersWithSub);
|
|
43
|
-
if (!parsed_users.success) {
|
|
44
|
-
console.error(`Failed to parse 'users' from response object: `, parsed_users.error);
|
|
45
|
-
throw new Error("Failed to parse 'users' from response object!");
|
|
46
|
-
}
|
|
47
|
-
const users = parsed_users.data;
|
|
48
|
-
return users;
|
|
49
|
-
}
|
|
50
|
-
catch (e) {
|
|
51
|
-
console.error(`Failed to list users: `, e);
|
|
52
|
-
throw new Error(`Failed to list users!`);
|
|
53
|
-
}
|
|
54
|
-
}, {
|
|
55
|
-
fallbackData: props.preloaded,
|
|
56
|
-
});
|
|
11
|
+
const users = useAllUsersList({ initialData: props.preloaded });
|
|
57
12
|
return (_jsxs(Card, { className: cardClassName, children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: cardTitle }), _jsx(CardDescription, { children: cardDescription })] }), _jsx(CardContent, { children: _jsx(UsersTable, { users: users, getUserHref: getUserHref }) }), _jsx(CardFooter, { children: _jsx("div", { className: "flex flex-row items-start justify-start gap-2" }) })] }));
|
|
58
13
|
}
|
|
59
14
|
//# sourceMappingURL=UsersCard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UsersCard.js","sourceRoot":"","sources":["../../../src/components/UsersCard/UsersCard.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EACL,IAAI,EACJ,WAAW,EACX,eAAe,EACf,UAAU,EACV,UAAU,EACV,SAAS,EACT,EAAE,GACH,MAAM,kBAAkB,CAAC;AAC1B,OAAO,UAAU,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"UsersCard.js","sourceRoot":"","sources":["../../../src/components/UsersCard/UsersCard.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EACL,IAAI,EACJ,WAAW,EACX,eAAe,EACf,UAAU,EACV,UAAU,EACV,SAAS,EACT,EAAE,GACH,MAAM,kBAAkB,CAAC;AAC1B,OAAO,UAAU,MAAM,yBAAyB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAW1E,MAAM,UAAU,SAAS,CAAC,KAAqB;IAC7C,MAAM,SAAS,GAAG,KAAK,CAAC,SAAS,IAAI,OAAO,CAAC;IAC7C,MAAM,eAAe,GACnB,KAAK,CAAC,eAAe,IAAI,mCAAmC,CAAC;IAE/D,MAAM,aAAa,GAAW,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAC,CAAC;IAChE,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;IAEtC,MAAM,KAAK,GAAG,eAAe,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAEhE,OAAO,CACL,MAAC,IAAI,IAAC,SAAS,EAAE,aAAa,aAC5B,MAAC,UAAU,eACT,KAAC,SAAS,cAAE,SAAS,GAAa,EAClC,KAAC,eAAe,cAAE,eAAe,GAAmB,IACzC,EACb,KAAC,WAAW,cACV,KAAC,UAAU,IAAC,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,GAAI,GAC1C,EACd,KAAC,UAAU,cACT,cAAK,SAAS,EAAC,+CAA+C,GAAO,GAC1D,IACR,CACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ReactElement } from "react";
|
|
2
|
+
import type { UserData } from "@schemavaults/auth-common";
|
|
3
|
+
export interface UsersBreakdownCardProps {
|
|
4
|
+
/** SSR-preloaded users, used as SWR `fallbackData`. */
|
|
5
|
+
preloaded?: readonly UserData[];
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @description Breaks every registered account down into standard, admin and
|
|
10
|
+
* disabled accounts as a donut chart. Each account is counted exactly once:
|
|
11
|
+
* a disabled administrator counts as disabled, so the slices add up to the
|
|
12
|
+
* total.
|
|
13
|
+
*/
|
|
14
|
+
export declare function UsersBreakdownCard(props: UsersBreakdownCardProps): ReactElement;
|
|
15
|
+
export default UsersBreakdownCard;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle, PieChart, cn, } from "@schemavaults/ui";
|
|
5
|
+
import { ShieldCheck, UserRound, UserX } from "lucide-react";
|
|
6
|
+
import { useAllUsersList } from "../UsersTable/useAllUsersList";
|
|
7
|
+
import { summarizeUserBreakdown, } from "./user-chart-data";
|
|
8
|
+
/**
|
|
9
|
+
* Blue / amber / red read as three distinct hues in both themes, and none of
|
|
10
|
+
* them is `primary`, which is near-black in light mode and near-white in
|
|
11
|
+
* dark mode and so cannot carry a chart segment.
|
|
12
|
+
*/
|
|
13
|
+
const CATEGORIES = [
|
|
14
|
+
{
|
|
15
|
+
id: "normal",
|
|
16
|
+
label: "Standard",
|
|
17
|
+
color: "default",
|
|
18
|
+
swatchClassName: "bg-schemavaults-brand-blue",
|
|
19
|
+
Icon: UserRound,
|
|
20
|
+
title: "Active accounts without administrator privileges.",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
id: "admin",
|
|
24
|
+
label: "Admins",
|
|
25
|
+
color: "warning",
|
|
26
|
+
swatchClassName: "bg-warning",
|
|
27
|
+
Icon: ShieldCheck,
|
|
28
|
+
title: "Active accounts with administrator privileges. Disabled administrators are counted under Disabled, so this can be lower than the Admins stat card.",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "disabled",
|
|
32
|
+
label: "Disabled",
|
|
33
|
+
color: "destructive",
|
|
34
|
+
swatchClassName: "bg-destructive",
|
|
35
|
+
Icon: UserX,
|
|
36
|
+
title: "Accounts blocked from signing in, administrator or not.",
|
|
37
|
+
},
|
|
38
|
+
];
|
|
39
|
+
function formatPercentage(count, total) {
|
|
40
|
+
if (total <= 0) {
|
|
41
|
+
return "0%";
|
|
42
|
+
}
|
|
43
|
+
const percent = (count / total) * 100;
|
|
44
|
+
// Keep a decimal for slivers so a real-but-tiny slice never reads as "0%".
|
|
45
|
+
if (percent > 0 && percent < 1) {
|
|
46
|
+
return `${percent.toFixed(1)}%`;
|
|
47
|
+
}
|
|
48
|
+
return `${Math.round(percent)}%`;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* @description Breaks every registered account down into standard, admin and
|
|
52
|
+
* disabled accounts as a donut chart. Each account is counted exactly once:
|
|
53
|
+
* a disabled administrator counts as disabled, so the slices add up to the
|
|
54
|
+
* total.
|
|
55
|
+
*/
|
|
56
|
+
export function UsersBreakdownCard(props) {
|
|
57
|
+
const users = useAllUsersList({ initialData: props.preloaded });
|
|
58
|
+
const breakdown = useMemo(() => summarizeUserBreakdown(users.data ?? []), [users.data]);
|
|
59
|
+
const loading = !users.data;
|
|
60
|
+
const segments = useMemo(() => CATEGORIES.map((category) => ({
|
|
61
|
+
id: category.id,
|
|
62
|
+
value: breakdown[category.id],
|
|
63
|
+
label: `${category.label}: ${breakdown[category.id]} of ${breakdown.total}`,
|
|
64
|
+
color: category.color,
|
|
65
|
+
})), [breakdown]);
|
|
66
|
+
return (_jsxs(Card, { className: cn("w-full", props.className), "data-testid": "users-breakdown-card", children: [_jsxs(CardHeader, { children: [_jsx(CardTitle, { children: "User breakdown" }), _jsx(CardDescription, { children: "Every account counted once \u2014 a disabled administrator counts as disabled." })] }), _jsxs(CardContent, { className: "flex flex-col items-center gap-6 sm:flex-row sm:items-center sm:justify-start", children: [_jsx(PieChart, { segments: segments, label: loading
|
|
67
|
+
? "Loading the breakdown of users by role and status"
|
|
68
|
+
: `Users by role and status: ${CATEGORIES.map((category) => `${breakdown[category.id]} ${category.label.toLowerCase()}`).join(", ")}`, size: "md", innerRadius: 0.62, segmentGap: 2, className: cn("shrink-0", loading && "animate-pulse opacity-60"), "data-testid": "users-breakdown-pie-chart", children: _jsxs("div", { className: "flex flex-col items-center leading-none", children: [_jsx("span", { className: "text-2xl font-semibold tabular-nums", children: breakdown.total }), _jsx("span", { className: "text-muted-foreground text-xs", children: breakdown.total === 1 ? "user" : "users" })] }) }), _jsx("ul", { className: "flex w-full min-w-0 flex-col gap-3", children: CATEGORIES.map((category) => {
|
|
69
|
+
const count = breakdown[category.id];
|
|
70
|
+
return (_jsxs("li", { className: "flex flex-row items-center gap-2.5", title: category.title, "data-testid": `users-breakdown-legend-${category.id}`, children: [_jsx("span", { "aria-hidden": "true", className: cn("size-2.5 shrink-0 rounded-full", category.swatchClassName) }), _jsx(category.Icon, { "aria-hidden": "true", className: "text-muted-foreground size-4 shrink-0" }), _jsx("span", { className: "truncate text-sm font-medium", children: category.label }), _jsxs("span", { className: "ml-auto flex shrink-0 flex-row items-baseline gap-2", children: [_jsx("span", { className: "text-sm font-semibold tabular-nums", children: count }), _jsx("span", { className: "text-muted-foreground w-10 text-right text-xs tabular-nums", children: formatPercentage(count, breakdown.total) })] })] }, category.id));
|
|
71
|
+
}) })] })] }));
|
|
72
|
+
}
|
|
73
|
+
export default UsersBreakdownCard;
|
|
74
|
+
//# sourceMappingURL=UsersBreakdownCard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsersBreakdownCard.js","sourceRoot":"","sources":["../../../src/components/UsersChartsRow/UsersBreakdownCard.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,OAAO,EAAqB,MAAM,OAAO,CAAC;AACnD,OAAO,EACL,IAAI,EACJ,WAAW,EACX,eAAe,EACf,UAAU,EACV,SAAS,EACT,QAAQ,EACR,EAAE,GAGH,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MA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OAAO,IAAI,0BAA0B,CAAC,iBACpD,2BAA2B,YAEvC,eAAK,SAAS,EAAC,yCAAyC,aACtD,eAAM,SAAS,EAAC,qCAAqC,YAClD,SAAS,CAAC,KAAK,GACX,EACP,eAAM,SAAS,EAAC,+BAA+B,YAC5C,SAAS,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,GACpC,IACH,GACG,EAEX,aAAI,SAAS,EAAC,oCAAoC,YAC/C,UAAU,CAAC,GAAG,CAAC,CAAC,QAA4B,EAAgB,EAAE;4BAC7D,MAAM,KAAK,GAAW,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;4BAC7C,OAAO,CACL,cAEE,SAAS,EAAC,oCAAoC,EAC9C,KAAK,EAAE,QAAQ,CAAC,KAAK,iBACR,0BAA0B,QAAQ,CAAC,EAAE,EAAE,aAEpD,8BACc,MAAM,EAClB,SAAS,EAAE,EAAE,CACX,gCAAgC,EAChC,QAAQ,CAAC,eAAe,CACzB,GACD,EACF,KAAC,QAAQ,CAAC,IAAI,mBACA,MAAM,EAClB,SAAS,EAAC,uCAAuC,GACjD,EACF,eAAM,SAAS,EAAC,8BAA8B,YAC3C,QAAQ,CAAC,KAAK,GACV,EACP,gBAAM,SAAS,EAAC,qDAAqD,aACnE,eAAM,SAAS,EAAC,oCAAoC,YACjD,KAAK,GACD,EACP,eAAM,SAAS,EAAC,4DAA4D,YACzE,gBAAgB,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,CAAC,GACpC,IACF,KA1BF,QAAQ,CAAC,EAAE,CA2Bb,CACN,CAAC;wBACJ,CAAC,CAAC,GACC,IACO,IACT,CACR,CAAC;AACJ,CAAC;AAED,eAAe,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
import type { UserData } from "@schemavaults/auth-common";
|
|
3
|
+
import type { UserGrowthRangeId } from "./user-chart-data";
|
|
4
|
+
export interface UsersChartsRowProps {
|
|
5
|
+
/**
|
|
6
|
+
* SSR-preloaded users, used as SWR `fallbackData` so both charts render on
|
|
7
|
+
* first paint. Both cards read the same SWR key as the users table, so the
|
|
8
|
+
* page still makes a single request for the list.
|
|
9
|
+
*/
|
|
10
|
+
preloaded?: readonly UserData[];
|
|
11
|
+
/** Range the sign-ups chart opens on. Defaults to the trailing 30 days. */
|
|
12
|
+
defaultGrowthRange?: UserGrowthRangeId;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* @description The charts shown above the users table on `/admin/users`:
|
|
17
|
+
* sign-ups over time (spikes and cumulative growth) alongside the standard /
|
|
18
|
+
* admin / disabled split of every account.
|
|
19
|
+
*/
|
|
20
|
+
export declare function UsersChartsRow(props: UsersChartsRowProps): ReactElement;
|
|
21
|
+
export default UsersChartsRow;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cn } from "@schemavaults/ui";
|
|
4
|
+
import UsersGrowthCard from "./UsersGrowthCard";
|
|
5
|
+
import UsersBreakdownCard from "./UsersBreakdownCard";
|
|
6
|
+
/**
|
|
7
|
+
* @description The charts shown above the users table on `/admin/users`:
|
|
8
|
+
* sign-ups over time (spikes and cumulative growth) alongside the standard /
|
|
9
|
+
* admin / disabled split of every account.
|
|
10
|
+
*/
|
|
11
|
+
export function UsersChartsRow(props) {
|
|
12
|
+
return (_jsxs("div", { className: cn("grid w-full grid-cols-1 gap-4 lg:grid-cols-3", props.className), children: [_jsx(UsersGrowthCard, { preloaded: props.preloaded, defaultRange: props.defaultGrowthRange, className: "lg:col-span-2" }), _jsx(UsersBreakdownCard, { preloaded: props.preloaded })] }));
|
|
13
|
+
}
|
|
14
|
+
export default UsersChartsRow;
|
|
15
|
+
//# sourceMappingURL=UsersChartsRow.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsersChartsRow.js","sourceRoot":"","sources":["../../../src/components/UsersChartsRow/UsersChartsRow.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAGb,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAEtC,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,kBAAkB,MAAM,sBAAsB,CAAC;AAetD;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,KAA0B;IACvD,OAAO,CACL,eACE,SAAS,EAAE,EAAE,CACX,8CAA8C,EAC9C,KAAK,CAAC,SAAS,CAChB,aAED,KAAC,eAAe,IACd,SAAS,EAAE,KAAK,CAAC,SAAS,EAC1B,YAAY,EAAE,KAAK,CAAC,kBAAkB,EACtC,SAAS,EAAC,eAAe,GACzB,EACF,KAAC,kBAAkB,IAAC,SAAS,EAAE,KAAK,CAAC,SAAS,GAAI,IAC9C,CACP,CAAC;AACJ,CAAC;AAED,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type ReactElement } from "react";
|
|
2
|
+
import type { UserData } from "@schemavaults/auth-common";
|
|
3
|
+
import { type UserGrowthRangeId } from "./user-chart-data";
|
|
4
|
+
export interface UsersGrowthCardProps {
|
|
5
|
+
/** SSR-preloaded users, used as SWR `fallbackData`. */
|
|
6
|
+
preloaded?: readonly UserData[];
|
|
7
|
+
/** Range selected on first render. Defaults to the trailing 30 days. */
|
|
8
|
+
defaultRange?: UserGrowthRangeId;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @description Charts account creation over a selectable trailing window: a
|
|
13
|
+
* bar sparkline of sign-ups per bucket, where a tall bar is an influx spike,
|
|
14
|
+
* above a cumulative area sparkline of the total account count.
|
|
15
|
+
*/
|
|
16
|
+
export declare function UsersGrowthCard(props: UsersGrowthCardProps): ReactElement;
|
|
17
|
+
export default UsersGrowthCard;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle, Separator, Sparkline, StatCardTrend, ToggleGroup, ToggleGroupItem, cn, } from "@schemavaults/ui";
|
|
5
|
+
import { useAllUsersList } from "../UsersTable/useAllUsersList";
|
|
6
|
+
import useMeasuredWidth from "../../lib/useMeasuredWidth";
|
|
7
|
+
import { USER_GROWTH_RANGE_IDS, USER_GROWTH_RANGE_LABELS, buildUserGrowthSeries, describeUserGrowthTrend, formatUtcDay, isUserGrowthRangeId, } from "./user-chart-data";
|
|
8
|
+
/** Widths used for the server render, until the resize observer reports. */
|
|
9
|
+
const SIGNUPS_FALLBACK_WIDTH = 560;
|
|
10
|
+
const TOTAL_FALLBACK_WIDTH = 240;
|
|
11
|
+
const RANGE_TO_SPOKEN_LABEL = {
|
|
12
|
+
"7d": "7 days",
|
|
13
|
+
"30d": "30 days",
|
|
14
|
+
"90d": "90 days",
|
|
15
|
+
all: "all time",
|
|
16
|
+
};
|
|
17
|
+
function describeBucketWidth(bucket_days) {
|
|
18
|
+
return bucket_days === 1 ? "day" : `${bucket_days}-day period`;
|
|
19
|
+
}
|
|
20
|
+
function describePeak(peak, bucket_days) {
|
|
21
|
+
const signups = `${peak.signups} sign-up${peak.signups === 1 ? "" : "s"}`;
|
|
22
|
+
if (bucket_days === 1) {
|
|
23
|
+
return `Busiest ${describeBucketWidth(bucket_days)}: ${signups} on ${formatUtcDay(peak.start)}.`;
|
|
24
|
+
}
|
|
25
|
+
// `end` is exclusive, so step back inside the bucket to name its last day.
|
|
26
|
+
return `Busiest ${describeBucketWidth(bucket_days)}: ${signups} between ${formatUtcDay(peak.start)} and ${formatUtcDay(peak.end - 1)}.`;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @description Charts account creation over a selectable trailing window: a
|
|
30
|
+
* bar sparkline of sign-ups per bucket, where a tall bar is an influx spike,
|
|
31
|
+
* above a cumulative area sparkline of the total account count.
|
|
32
|
+
*/
|
|
33
|
+
export function UsersGrowthCard(props) {
|
|
34
|
+
const users = useAllUsersList({ initialData: props.preloaded });
|
|
35
|
+
const [range, setRange] = useState(props.defaultRange ?? "30d");
|
|
36
|
+
const series = useMemo(() => buildUserGrowthSeries(users.data ?? [], range), [users.data, range]);
|
|
37
|
+
const trend = useMemo(() => describeUserGrowthTrend(series), [series]);
|
|
38
|
+
const signups_per_bucket = useMemo(() => series.buckets.map((bucket) => bucket.signups), [series.buckets]);
|
|
39
|
+
const cumulative_per_bucket = useMemo(() => series.buckets.map((bucket) => bucket.cumulative), [series.buckets]);
|
|
40
|
+
const signups_chart = useMeasuredWidth(SIGNUPS_FALLBACK_WIDTH);
|
|
41
|
+
const total_chart = useMeasuredWidth(TOTAL_FALLBACK_WIDTH);
|
|
42
|
+
const loading = !users.data;
|
|
43
|
+
const first_bucket = series.buckets[0];
|
|
44
|
+
const last_bucket = series.buckets[series.buckets.length - 1];
|
|
45
|
+
const bucket_label = describeBucketWidth(series.bucket_days);
|
|
46
|
+
const spoken_range = RANGE_TO_SPOKEN_LABEL[range];
|
|
47
|
+
return (_jsxs(Card, { className: cn("w-full", props.className), "data-testid": "users-growth-card", children: [_jsxs(CardHeader, { className: "flex flex-row flex-wrap items-start justify-between gap-x-4 gap-y-2 space-y-0", children: [_jsxs("div", { className: "flex min-w-0 flex-col gap-1.5", children: [_jsx(CardTitle, { children: "New users" }), _jsxs(CardDescription, { children: ["Sign-ups per ", bucket_label, " (UTC) \u2014 a tall bar is an influx spike."] })] }), _jsx(ToggleGroup, { type: "single", value: range, onValueChange: (next) => {
|
|
48
|
+
// Radix-style toggle groups emit "" when the active item is
|
|
49
|
+
// clicked again; keep the current selection in that case.
|
|
50
|
+
if (isUserGrowthRangeId(next)) {
|
|
51
|
+
setRange(next);
|
|
52
|
+
}
|
|
53
|
+
}, variant: "outline", size: "sm", className: "flex shrink-0 flex-row flex-wrap gap-1", "aria-label": "Sign-up chart range", children: USER_GROWTH_RANGE_IDS.map((range_id) => (_jsx(ToggleGroupItem, { value: range_id, "data-testid": `users-growth-range-${range_id}`, children: USER_GROWTH_RANGE_LABELS[range_id] }, range_id))) })] }), _jsxs(CardContent, { className: "flex flex-col gap-4", children: [_jsxs("div", { className: "flex flex-row flex-wrap items-baseline gap-x-3 gap-y-1", children: [_jsx("span", { className: cn("text-3xl font-semibold tabular-nums leading-none", loading && "animate-pulse opacity-60"), "data-testid": "users-growth-signups-value", children: series.signups }), _jsxs("span", { className: "text-muted-foreground text-sm", children: ["new ", series.signups === 1 ? "account" : "accounts", " (", spoken_range, ")"] }), trend && trend.comparable ? (_jsxs(StatCardTrend, { direction: trend.direction, children: [trend.percent > 0 ? "+" : "", trend.percent, "% vs previous ", spoken_range] })) : null] }), _jsxs("div", { className: "flex flex-col gap-1.5", children: [_jsx("div", { ref: signups_chart.ref, className: "w-full", children: _jsx(Sparkline, { data: signups_per_bucket, variant: "bar", color: "default", min: 0, width: signups_chart.width, height: 72, label: `Sign-ups per ${bucket_label} over ${spoken_range}: ${series.signups} in total`, className: cn("w-full", loading && "animate-pulse opacity-60"), "data-testid": "users-growth-signups-sparkline" }) }), first_bucket && last_bucket ? (_jsxs("div", { className: "text-muted-foreground flex flex-row justify-between text-xs tabular-nums", children: [_jsx("span", { children: formatUtcDay(first_bucket.start) }), _jsx("span", { children: formatUtcDay(last_bucket.end - 1) })] })) : null] }), _jsxs("p", { className: "text-muted-foreground text-xs", children: [series.peak
|
|
54
|
+
? describePeak(series.peak, series.bucket_days)
|
|
55
|
+
: `No accounts were created in the last ${spoken_range}.`, trend && !trend.comparable
|
|
56
|
+
? ` No sign-ups in the previous ${spoken_range}.`
|
|
57
|
+
: ""] }), _jsx(Separator, {}), _jsxs("div", { className: "flex flex-row flex-wrap items-center gap-x-3 gap-y-1", children: [_jsx("span", { className: "text-muted-foreground shrink-0 text-xs font-medium uppercase tracking-wide", children: "Total users" }), _jsx("div", { ref: total_chart.ref, className: "min-w-24 flex-1", children: _jsx(Sparkline, { data: cumulative_per_bucket, variant: "area", color: "default", width: total_chart.width, height: 32, label: `Total registered accounts over ${spoken_range}, ending at ${series.total}`, className: cn("w-full", loading && "animate-pulse opacity-60"), "data-testid": "users-growth-total-sparkline" }) }), _jsx("span", { className: "shrink-0 text-sm font-semibold tabular-nums", "data-testid": "users-growth-total-value", children: series.total })] })] })] }));
|
|
58
|
+
}
|
|
59
|
+
export default UsersGrowthCard;
|
|
60
|
+
//# sourceMappingURL=UsersGrowthCard.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UsersGrowthCard.js","sourceRoot":"","sources":["../../../src/components/UsersChartsRow/UsersGrowthCard.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAqB,MAAM,OAAO,CAAC;AAC7D,OAAO,EACL,IAAI,EACJ,WAAW,EACX,eAAe,EACf,UAAU,EACV,SAAS,EACT,SAAS,EACT,SAAS,EACT,aAAa,EACb,WAAW,EACX,eAAe,EACf,EAAE,GACH,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAC1E,OAAO,gBAAgB,MAAM,wBAAwB,CAAC;AACtD,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,uBAAuB,EACvB,YAAY,EACZ,mBAAmB,GAKpB,MAAM,mBAAmB,CAAC;AAU3B,4EAA4E;AAC5E,MAAM,sBAAsB,GAAW,GAAG,CAAC;AAC3C,MAAM,oBAAoB,GAAW,GAAG,CAAC;AAEzC,MAAM,qBAAqB,GAAsC;IAC/D,IAAI,EAAE,QAAQ;IACd,KAAK,EAAE,SAAS;IAChB,KAAK,EAAE,SAAS;IAChB,GAAG,EAAE,UAAU;CAChB,CAAC;AAEF,SAAS,mBAAmB,CAAC,WA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,8BAA8B,GAC1C,GACE,EACN,eACE,SAAS,EAAC,6CAA6C,iBAC3C,0BAA0B,YAErC,MAAM,CAAC,KAAK,GACR,IACH,IACM,IACT,CACR,CAAC;AACJ,CAAC;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { UsersChartsRow, UsersChartsRow as default } from "./UsersChartsRow";
|
|
2
|
+
export type { UsersChartsRowProps } from "./UsersChartsRow";
|
|
3
|
+
export { UsersGrowthCard } from "./UsersGrowthCard";
|
|
4
|
+
export type { UsersGrowthCardProps } from "./UsersGrowthCard";
|
|
5
|
+
export { UsersBreakdownCard } from "./UsersBreakdownCard";
|
|
6
|
+
export type { UsersBreakdownCardProps } from "./UsersBreakdownCard";
|
|
7
|
+
export { USER_CATEGORY_IDS, USER_GROWTH_RANGE_IDS, USER_GROWTH_RANGE_LABELS, buildUserGrowthSeries, describeUserGrowthTrend, formatUtcDay, formatUtcDayShort, isUserGrowthRangeId, startOfUtcDay, summarizeUserBreakdown, } from "./user-chart-data";
|
|
8
|
+
export type { BuildUserGrowthSeriesOptions, UserBreakdown, UserCategoryId, UserGrowthBucket, UserGrowthRangeId, UserGrowthSeries, UserGrowthTrend, } from "./user-chart-data";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { UsersChartsRow, UsersChartsRow as default } from "./UsersChartsRow";
|
|
2
|
+
export { UsersGrowthCard } from "./UsersGrowthCard";
|
|
3
|
+
export { UsersBreakdownCard } from "./UsersBreakdownCard";
|
|
4
|
+
export { USER_CATEGORY_IDS, USER_GROWTH_RANGE_IDS, USER_GROWTH_RANGE_LABELS, buildUserGrowthSeries, describeUserGrowthTrend, formatUtcDay, formatUtcDayShort, isUserGrowthRangeId, startOfUtcDay, summarizeUserBreakdown, } from "./user-chart-data";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/UsersChartsRow/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,cAAc,IAAI,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,uBAAuB,EACvB,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,aAAa,EACb,sBAAsB,GACvB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { UserData } from "@schemavaults/auth-common";
|
|
2
|
+
/**
|
|
3
|
+
* Buckets are aligned to UTC midnight rather than the viewer's midnight so
|
|
4
|
+
* that the series rendered on the server (from the SSR-preloaded users)
|
|
5
|
+
* matches the series the browser computes while hydrating. UTC days are also
|
|
6
|
+
* always exactly `DAY_MS` long, which local days are not across a DST
|
|
7
|
+
* transition.
|
|
8
|
+
*/
|
|
9
|
+
export declare function startOfUtcDay(timestamp_ms: number): number;
|
|
10
|
+
/** Formats a UTC timestamp as `YYYY/MM/DD`, matching `printDateTime`. */
|
|
11
|
+
export declare function formatUtcDay(timestamp_ms: number): string;
|
|
12
|
+
/** Formats a UTC timestamp as `MM/DD`, for compact chart axis labels. */
|
|
13
|
+
export declare function formatUtcDayShort(timestamp_ms: number): string;
|
|
14
|
+
export declare const USER_CATEGORY_IDS: readonly ["normal", "admin", "disabled"];
|
|
15
|
+
export type UserCategoryId = (typeof USER_CATEGORY_IDS)[number];
|
|
16
|
+
export interface UserBreakdown {
|
|
17
|
+
/** Every registered account. */
|
|
18
|
+
total: number;
|
|
19
|
+
/** Enabled accounts without the admin flag. */
|
|
20
|
+
normal: number;
|
|
21
|
+
/** Enabled accounts with the admin flag. */
|
|
22
|
+
admin: number;
|
|
23
|
+
/** Accounts blocked from signing in, admin or not. */
|
|
24
|
+
disabled: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* @description Assigns every user to exactly one category so the three
|
|
28
|
+
* counts always sum to `total` and can be drawn as a pie chart. Being
|
|
29
|
+
* disabled wins over being an admin: a disabled administrator is counted
|
|
30
|
+
* once, under `disabled`, because the account cannot sign in either way.
|
|
31
|
+
*
|
|
32
|
+
* Note that this deliberately differs from the "Admins" / "Disabled" stat
|
|
33
|
+
* cards, which count the `admin` and `disabled` flags independently.
|
|
34
|
+
*/
|
|
35
|
+
export declare function summarizeUserBreakdown(users: readonly UserData[]): UserBreakdown;
|
|
36
|
+
export declare const USER_GROWTH_RANGE_IDS: readonly ["7d", "30d", "90d", "all"];
|
|
37
|
+
export type UserGrowthRangeId = (typeof USER_GROWTH_RANGE_IDS)[number];
|
|
38
|
+
export declare function isUserGrowthRangeId(value: unknown): value is UserGrowthRangeId;
|
|
39
|
+
export declare const USER_GROWTH_RANGE_LABELS: Record<UserGrowthRangeId, string>;
|
|
40
|
+
export interface UserGrowthBucket {
|
|
41
|
+
/** Inclusive start of the bucket, ms since the epoch. */
|
|
42
|
+
start: number;
|
|
43
|
+
/** Exclusive end of the bucket, ms since the epoch. */
|
|
44
|
+
end: number;
|
|
45
|
+
/** Accounts created within the bucket. */
|
|
46
|
+
signups: number;
|
|
47
|
+
/** Every account that existed by `end`, including those created earlier. */
|
|
48
|
+
cumulative: number;
|
|
49
|
+
}
|
|
50
|
+
export interface UserGrowthSeries {
|
|
51
|
+
buckets: readonly UserGrowthBucket[];
|
|
52
|
+
/** Width of each bucket in whole days. */
|
|
53
|
+
bucket_days: number;
|
|
54
|
+
/** Accounts created anywhere in the window. */
|
|
55
|
+
signups: number;
|
|
56
|
+
/**
|
|
57
|
+
* Accounts created in the equally long window immediately before this one,
|
|
58
|
+
* or `null` when there is no such window to compare against (the "all"
|
|
59
|
+
* range, which already starts at the very first sign-up).
|
|
60
|
+
*/
|
|
61
|
+
previous_signups: number | null;
|
|
62
|
+
/** The busiest bucket — the most recent one when several tie. */
|
|
63
|
+
peak: UserGrowthBucket | null;
|
|
64
|
+
/** Every registered account, i.e. the cumulative total today. */
|
|
65
|
+
total: number;
|
|
66
|
+
}
|
|
67
|
+
export interface BuildUserGrowthSeriesOptions {
|
|
68
|
+
/** Overrides "now"; defaults to `Date.now()`. */
|
|
69
|
+
now?: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @description Buckets sign-ups into a daily (or, for wide ranges, multi-day)
|
|
73
|
+
* series so the sparklines can show both sign-up spikes and cumulative
|
|
74
|
+
* growth. `users` may be in any order.
|
|
75
|
+
*/
|
|
76
|
+
export declare function buildUserGrowthSeries(users: readonly UserData[], range: UserGrowthRangeId, { now }?: BuildUserGrowthSeriesOptions): UserGrowthSeries;
|
|
77
|
+
export interface UserGrowthTrend {
|
|
78
|
+
direction: "up" | "down" | "neutral";
|
|
79
|
+
/** Whole-percent change against the previous window. */
|
|
80
|
+
percent: number;
|
|
81
|
+
/** `false` when the previous window had no sign-ups to compare against. */
|
|
82
|
+
comparable: boolean;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @description Compares the window's sign-ups against the equally long
|
|
86
|
+
* window before it. A previous window with no sign-ups has no meaningful
|
|
87
|
+
* percentage, so the change is reported as not comparable.
|
|
88
|
+
*/
|
|
89
|
+
export declare function describeUserGrowthTrend(series: UserGrowthSeries): UserGrowthTrend | null;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
2
|
+
/**
|
|
3
|
+
* Buckets are aligned to UTC midnight rather than the viewer's midnight so
|
|
4
|
+
* that the series rendered on the server (from the SSR-preloaded users)
|
|
5
|
+
* matches the series the browser computes while hydrating. UTC days are also
|
|
6
|
+
* always exactly `DAY_MS` long, which local days are not across a DST
|
|
7
|
+
* transition.
|
|
8
|
+
*/
|
|
9
|
+
export function startOfUtcDay(timestamp_ms) {
|
|
10
|
+
return Math.floor(timestamp_ms / DAY_MS) * DAY_MS;
|
|
11
|
+
}
|
|
12
|
+
/** Formats a UTC timestamp as `YYYY/MM/DD`, matching `printDateTime`. */
|
|
13
|
+
export function formatUtcDay(timestamp_ms) {
|
|
14
|
+
const date = new Date(timestamp_ms);
|
|
15
|
+
const month = `0${date.getUTCMonth() + 1}`.slice(-2);
|
|
16
|
+
const day_of_month = `0${date.getUTCDate()}`.slice(-2);
|
|
17
|
+
return `${date.getUTCFullYear()}/${month}/${day_of_month}`;
|
|
18
|
+
}
|
|
19
|
+
/** Formats a UTC timestamp as `MM/DD`, for compact chart axis labels. */
|
|
20
|
+
export function formatUtcDayShort(timestamp_ms) {
|
|
21
|
+
const date = new Date(timestamp_ms);
|
|
22
|
+
const month = `0${date.getUTCMonth() + 1}`.slice(-2);
|
|
23
|
+
const day_of_month = `0${date.getUTCDate()}`.slice(-2);
|
|
24
|
+
return `${month}/${day_of_month}`;
|
|
25
|
+
}
|
|
26
|
+
export const USER_CATEGORY_IDS = ["normal", "admin", "disabled"];
|
|
27
|
+
/**
|
|
28
|
+
* @description Assigns every user to exactly one category so the three
|
|
29
|
+
* counts always sum to `total` and can be drawn as a pie chart. Being
|
|
30
|
+
* disabled wins over being an admin: a disabled administrator is counted
|
|
31
|
+
* once, under `disabled`, because the account cannot sign in either way.
|
|
32
|
+
*
|
|
33
|
+
* Note that this deliberately differs from the "Admins" / "Disabled" stat
|
|
34
|
+
* cards, which count the `admin` and `disabled` flags independently.
|
|
35
|
+
*/
|
|
36
|
+
export function summarizeUserBreakdown(users) {
|
|
37
|
+
let normal = 0;
|
|
38
|
+
let admin = 0;
|
|
39
|
+
let disabled = 0;
|
|
40
|
+
for (const user of users) {
|
|
41
|
+
if (user.disabled) {
|
|
42
|
+
disabled += 1;
|
|
43
|
+
}
|
|
44
|
+
else if (user.admin) {
|
|
45
|
+
admin += 1;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
normal += 1;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return { total: users.length, normal, admin, disabled };
|
|
52
|
+
}
|
|
53
|
+
export const USER_GROWTH_RANGE_IDS = ["7d", "30d", "90d", "all"];
|
|
54
|
+
export function isUserGrowthRangeId(value) {
|
|
55
|
+
return (typeof value === "string" &&
|
|
56
|
+
USER_GROWTH_RANGE_IDS.includes(value));
|
|
57
|
+
}
|
|
58
|
+
/** Trailing-window length in days, or `null` for "since the first sign-up". */
|
|
59
|
+
const RANGE_TO_DAYS = {
|
|
60
|
+
"7d": 7,
|
|
61
|
+
"30d": 30,
|
|
62
|
+
"90d": 90,
|
|
63
|
+
all: null,
|
|
64
|
+
};
|
|
65
|
+
export const USER_GROWTH_RANGE_LABELS = {
|
|
66
|
+
"7d": "7d",
|
|
67
|
+
"30d": "30d",
|
|
68
|
+
"90d": "90d",
|
|
69
|
+
all: "All",
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Upper bound on the number of buckets drawn for the "all" range; the bucket
|
|
73
|
+
* width grows in whole days until the series fits.
|
|
74
|
+
*/
|
|
75
|
+
const MAX_ALL_RANGE_BUCKETS = 60;
|
|
76
|
+
/**
|
|
77
|
+
* @description Buckets sign-ups into a daily (or, for wide ranges, multi-day)
|
|
78
|
+
* series so the sparklines can show both sign-up spikes and cumulative
|
|
79
|
+
* growth. `users` may be in any order.
|
|
80
|
+
*/
|
|
81
|
+
export function buildUserGrowthSeries(users, range, { now = Date.now() } = {}) {
|
|
82
|
+
const total = users.length;
|
|
83
|
+
const today_start = startOfUtcDay(now);
|
|
84
|
+
// The newest bucket runs to the end of today, so today's sign-ups show up
|
|
85
|
+
// right away instead of at the next UTC midnight.
|
|
86
|
+
const window_end = today_start + DAY_MS;
|
|
87
|
+
const created_at_ms = users
|
|
88
|
+
.map((user) => user.created_at)
|
|
89
|
+
.sort((a, b) => a - b);
|
|
90
|
+
const range_days = RANGE_TO_DAYS[range];
|
|
91
|
+
let bucket_days;
|
|
92
|
+
let bucket_count;
|
|
93
|
+
let window_start;
|
|
94
|
+
if (range_days === null) {
|
|
95
|
+
const first_signup = created_at_ms[0];
|
|
96
|
+
if (first_signup === undefined) {
|
|
97
|
+
return {
|
|
98
|
+
buckets: [],
|
|
99
|
+
bucket_days: 1,
|
|
100
|
+
signups: 0,
|
|
101
|
+
previous_signups: null,
|
|
102
|
+
peak: null,
|
|
103
|
+
total,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
const span_days = Math.max(1, Math.round((window_end - startOfUtcDay(first_signup)) / DAY_MS));
|
|
107
|
+
bucket_days = Math.max(1, Math.ceil(span_days / MAX_ALL_RANGE_BUCKETS));
|
|
108
|
+
bucket_count = Math.ceil(span_days / bucket_days);
|
|
109
|
+
// Anchored on the newest bucket so the last one always ends today; the
|
|
110
|
+
// oldest bucket may reach a little further back than the first sign-up.
|
|
111
|
+
window_start = window_end - bucket_count * bucket_days * DAY_MS;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
bucket_days = 1;
|
|
115
|
+
bucket_count = range_days;
|
|
116
|
+
window_start = window_end - bucket_count * DAY_MS;
|
|
117
|
+
}
|
|
118
|
+
const bucket_ms = bucket_days * DAY_MS;
|
|
119
|
+
const signups_per_bucket = new Array(bucket_count).fill(0);
|
|
120
|
+
// Accounts that already existed when the window opened; the cumulative
|
|
121
|
+
// series has to start from those rather than from zero.
|
|
122
|
+
let cumulative = 0;
|
|
123
|
+
let signups_in_window = 0;
|
|
124
|
+
let previous_signups = 0;
|
|
125
|
+
const previous_window_start = window_start - bucket_count * bucket_ms;
|
|
126
|
+
for (const created_at of created_at_ms) {
|
|
127
|
+
if (created_at < window_start) {
|
|
128
|
+
cumulative += 1;
|
|
129
|
+
if (created_at >= previous_window_start) {
|
|
130
|
+
previous_signups += 1;
|
|
131
|
+
}
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
if (created_at >= window_end) {
|
|
135
|
+
// Clock skew between the database and this process; count it in the
|
|
136
|
+
// newest bucket rather than dropping it from the chart.
|
|
137
|
+
const last_index = bucket_count - 1;
|
|
138
|
+
signups_per_bucket[last_index] = (signups_per_bucket[last_index] ?? 0) + 1;
|
|
139
|
+
signups_in_window += 1;
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const index = Math.min(bucket_count - 1, Math.floor((created_at - window_start) / bucket_ms));
|
|
143
|
+
signups_per_bucket[index] = (signups_per_bucket[index] ?? 0) + 1;
|
|
144
|
+
signups_in_window += 1;
|
|
145
|
+
}
|
|
146
|
+
const buckets = [];
|
|
147
|
+
let peak = null;
|
|
148
|
+
for (let index = 0; index < bucket_count; index += 1) {
|
|
149
|
+
const signups = signups_per_bucket[index] ?? 0;
|
|
150
|
+
cumulative += signups;
|
|
151
|
+
const bucket = {
|
|
152
|
+
start: window_start + index * bucket_ms,
|
|
153
|
+
end: window_start + (index + 1) * bucket_ms,
|
|
154
|
+
signups,
|
|
155
|
+
cumulative,
|
|
156
|
+
};
|
|
157
|
+
buckets.push(bucket);
|
|
158
|
+
// `>=` keeps the most recent bucket when several share the highest count,
|
|
159
|
+
// which is the one an administrator is looking for.
|
|
160
|
+
if (signups > 0 && (peak === null || signups >= peak.signups)) {
|
|
161
|
+
peak = bucket;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
buckets,
|
|
166
|
+
bucket_days,
|
|
167
|
+
signups: signups_in_window,
|
|
168
|
+
previous_signups: range_days === null ? null : previous_signups,
|
|
169
|
+
peak,
|
|
170
|
+
total,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* @description Compares the window's sign-ups against the equally long
|
|
175
|
+
* window before it. A previous window with no sign-ups has no meaningful
|
|
176
|
+
* percentage, so the change is reported as not comparable.
|
|
177
|
+
*/
|
|
178
|
+
export function describeUserGrowthTrend(series) {
|
|
179
|
+
const previous = series.previous_signups;
|
|
180
|
+
if (previous === null) {
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
183
|
+
const current = series.signups;
|
|
184
|
+
const direction = current > previous ? "up" : current < previous ? "down" : "neutral";
|
|
185
|
+
if (previous === 0) {
|
|
186
|
+
return { direction, percent: 0, comparable: false };
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
direction,
|
|
190
|
+
percent: Math.round(((current - previous) / previous) * 100),
|
|
191
|
+
comparable: true,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=user-chart-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"user-chart-data.js","sourceRoot":"","sources":["../../../src/components/UsersChartsRow/user-chart-data.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,GAAW,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,YAAoB;IAChD,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,GAAG,MAAM,CAAC,GAAG,MAAM,CAAC;AACpD,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,YAAY,CAAC,YAAoB;IAC/C,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC;IACpC,MAAM,KAAK,GAAW,IAAI,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7D,MAAM,YAAY,GAAW,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/D,OAAO,GAAG,IAAI,CAAC,cAAc,EAAE,IAAI,KAAK,IAAI,YAAY,EAAE,CAAC;AAC7D,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,iBAAiB,CAAC,YAAoB;IACpD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC;IACpC,MAAM,KAAK,GAAW,IAAI,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,EAAE,CAA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gBAAgB,EAAE,UAAU,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,gBAAgB;QAC/D,IAAI;QACJ,KAAK;KACN,CAAC;AACJ,CAAC;AAUD;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CACrC,MAAwB;IAExB,MAAM,QAAQ,GAAkB,MAAM,CAAC,gBAAgB,CAAC;IACxD,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,MAAM,OAAO,GAAW,MAAM,CAAC,OAAO,CAAC;IACvC,MAAM,SAAS,GACb,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;IACtE,IAAI,QAAQ,KAAK,CAAC,EAAE,CAAC;QACnB,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC;IACtD,CAAC;IACD,OAAO;QACL,SAAS;QACT,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,GAAG,QAAQ,CAAC,GAAG,QAAQ,CAAC,GAAG,GAAG,CAAC;QAC5D,UAAU,EAAE,IAAI;KACjB,CAAC;AACJ,CAAC"}
|
|
@@ -2,54 +2,10 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { useMemo } from "react";
|
|
4
4
|
import { StatCard, StatCardHeader, StatCardLabel, StatCardValue, StatCardDescription, StatCardIcon, cn, } from "@schemavaults/ui";
|
|
5
|
-
import { userDataSchema } from "@schemavaults/auth-common";
|
|
6
5
|
import { ShieldCheck, UserRound, UserX } from "lucide-react";
|
|
7
|
-
import
|
|
8
|
-
const LIST_ALL_USERS_ENDPOINT = "/api/admin/users/list";
|
|
6
|
+
import { useAllUsersList } from "../UsersTable/useAllUsersList";
|
|
9
7
|
export function UsersStatsRow(props) {
|
|
10
|
-
const users =
|
|
11
|
-
try {
|
|
12
|
-
const response = await fetch(LIST_ALL_USERS_ENDPOINT, {
|
|
13
|
-
method: "GET",
|
|
14
|
-
credentials: "include",
|
|
15
|
-
});
|
|
16
|
-
if (!response.ok || response.status !== 200) {
|
|
17
|
-
throw new Error(`Failed to list users (response status: ${response.status})!`);
|
|
18
|
-
}
|
|
19
|
-
const body = await response.json();
|
|
20
|
-
if (typeof body !== "object" ||
|
|
21
|
-
!body ||
|
|
22
|
-
!("success" in body) ||
|
|
23
|
-
!body.success) {
|
|
24
|
-
throw new Error("Received failure response when attempting to list users");
|
|
25
|
-
}
|
|
26
|
-
if (!("data" in body) ||
|
|
27
|
-
typeof body.data !== "object" ||
|
|
28
|
-
!body.data ||
|
|
29
|
-
!("users" in body.data) ||
|
|
30
|
-
!Array.isArray(body.data.users)) {
|
|
31
|
-
throw new Error("Failed to extract 'users' array from response!");
|
|
32
|
-
}
|
|
33
|
-
const usersWithSub = body.data.users.map((user) => ({
|
|
34
|
-
...user,
|
|
35
|
-
sub: user.uid,
|
|
36
|
-
}));
|
|
37
|
-
const parsed_users = await userDataSchema
|
|
38
|
-
.array()
|
|
39
|
-
.safeParseAsync(usersWithSub);
|
|
40
|
-
if (!parsed_users.success) {
|
|
41
|
-
console.error(`Failed to parse 'users' from response object: `, parsed_users.error);
|
|
42
|
-
throw new Error("Failed to parse 'users' from response object!");
|
|
43
|
-
}
|
|
44
|
-
return parsed_users.data;
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
console.error(`Failed to list users: `, e);
|
|
48
|
-
throw new Error(`Failed to list users!`);
|
|
49
|
-
}
|
|
50
|
-
}, {
|
|
51
|
-
fallbackData: props.preloaded,
|
|
52
|
-
});
|
|
8
|
+
const users = useAllUsersList({ initialData: props.preloaded });
|
|
53
9
|
const stats = useMemo(() => {
|
|
54
10
|
const data = users.data ?? [];
|
|
55
11
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UsersStatsRow.js","sourceRoot":"","sources":["../../../src/components/UsersStatsRow/UsersStatsRow.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,OAAO,EAAqB,MAAM,OAAO,CAAC;AACnD,OAAO,EACL,QAAQ,EACR,cAAc,EACd,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,EAAE,GACH,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"UsersStatsRow.js","sourceRoot":"","sources":["../../../src/components/UsersStatsRow/UsersStatsRow.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,OAAO,EAAqB,MAAM,OAAO,CAAC;AACnD,OAAO,EACL,QAAQ,EACR,cAAc,EACd,aAAa,EACb,aAAa,EACb,mBAAmB,EACnB,YAAY,EACZ,EAAE,GACH,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,yCAAyC,CAAC;AAO1E,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,MAAM,KAAK,GAAG,eAAe,CAAC,EAAE,WAAW,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC;IAEhE,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,EAAE;QACzB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QAC9B,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,MAAM;YAClB,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM;YAC1C,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,M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AAI,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/UsersTable/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,UAAU,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,EACL,eAAe,EACf,uBAAuB,GACxB,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type SWRResponse } from "swr";
|
|
2
|
+
import { type UserData } from "@schemavaults/auth-common";
|
|
3
|
+
export declare const LIST_ALL_USERS_ENDPOINT = "/api/admin/users/list";
|
|
4
|
+
export interface UseAllUsersListOptions {
|
|
5
|
+
/**
|
|
6
|
+
* SSR-preloaded users, used as SWR `fallbackData` so tables, counts and
|
|
7
|
+
* charts render on first paint.
|
|
8
|
+
*/
|
|
9
|
+
initialData?: readonly UserData[] | undefined;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* @description Lists every registered user from the admin-only list
|
|
13
|
+
* endpoint. Every consumer shares the same SWR key, so the users table, the
|
|
14
|
+
* stat cards and the charts on `/admin/users` are served by a single
|
|
15
|
+
* request.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useAllUsersList({ initialData }?: UseAllUsersListOptions): SWRResponse<readonly UserData[], Error>;
|
|
18
|
+
export default useAllUsersList;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import useSWR from "swr";
|
|
3
|
+
import { userDataSchema } from "@schemavaults/auth-common";
|
|
4
|
+
export const LIST_ALL_USERS_ENDPOINT = "/api/admin/users/list";
|
|
5
|
+
async function listAllUsers() {
|
|
6
|
+
try {
|
|
7
|
+
const response = await fetch(LIST_ALL_USERS_ENDPOINT, {
|
|
8
|
+
method: "GET",
|
|
9
|
+
credentials: "include",
|
|
10
|
+
});
|
|
11
|
+
if (!response.ok || response.status !== 200) {
|
|
12
|
+
throw new Error(`Failed to list users (response status: ${response.status})!`);
|
|
13
|
+
}
|
|
14
|
+
const body = await response.json();
|
|
15
|
+
if (typeof body !== "object" ||
|
|
16
|
+
!body ||
|
|
17
|
+
!("success" in body) ||
|
|
18
|
+
!body.success) {
|
|
19
|
+
throw new Error("Received failure response when attempting to list users");
|
|
20
|
+
}
|
|
21
|
+
if (!("data" in body) ||
|
|
22
|
+
typeof body.data !== "object" ||
|
|
23
|
+
!body.data ||
|
|
24
|
+
!("users" in body.data) ||
|
|
25
|
+
!Array.isArray(body.data.users)) {
|
|
26
|
+
throw new Error("Failed to extract 'users' array from response!");
|
|
27
|
+
}
|
|
28
|
+
const usersWithSub = body.data.users.map((user) => ({
|
|
29
|
+
...user,
|
|
30
|
+
sub: user.uid,
|
|
31
|
+
}));
|
|
32
|
+
const parsed_users = await userDataSchema
|
|
33
|
+
.array()
|
|
34
|
+
.safeParseAsync(usersWithSub);
|
|
35
|
+
if (!parsed_users.success) {
|
|
36
|
+
console.error(`Failed to parse 'users' from response object: `, parsed_users.error);
|
|
37
|
+
throw new Error("Failed to parse 'users' from response object!");
|
|
38
|
+
}
|
|
39
|
+
return parsed_users.data;
|
|
40
|
+
}
|
|
41
|
+
catch (e) {
|
|
42
|
+
console.error(`Failed to list users: `, e);
|
|
43
|
+
throw new Error(`Failed to list users!`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @description Lists every registered user from the admin-only list
|
|
48
|
+
* endpoint. Every consumer shares the same SWR key, so the users table, the
|
|
49
|
+
* stat cards and the charts on `/admin/users` are served by a single
|
|
50
|
+
* request.
|
|
51
|
+
*/
|
|
52
|
+
export function useAllUsersList({ initialData } = {}) {
|
|
53
|
+
return useSWR(LIST_ALL_USERS_ENDPOINT, listAllUsers, {
|
|
54
|
+
fallbackData: initialData ? [...initialData] : undefined,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
export default useAllUsersList;
|
|
58
|
+
//# sourceMappingURL=useAllUsersList.js.map
|
|
@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I,CAAC,KAAK,CAAC,GAAG,CACtC,CAAC,IAA6B,EAAE,EAAE,CAAC,CAAC;YAClC,GAAG,IAAI;YACP,GAAG,EAAE,IAAI,CAAC,GAAG;SACd,CAAC,CACH,CAAC;QAEF,MAAM,YAAY,GAAG,MAAM,cAAc;aACtC,KAAK,EAAE;aACP,cAAc,CAAC,YAAY,CAAC,CAAC;QAEhC,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,CAAC;YAC1B,OAAO,CAAC,KAAK,CACX,gDAAgD,EAChD,YAAY,CAAC,KAAK,CACnB,CAAC;YACF,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAC;QACnE,CAAC;QAED,OAAO,YAAY,CAAC,IAAI,CAAC;IAC3B,CAAC;IAAC,OAAO,CAAU,EAAE,CAAC;QACpB,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,CAAC,CAAC,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAC7B,EAAE,WAAW,KAA6B,EAAE;IAE5C,OAAO,MAAM,CACX,uBAAuB,EACvB,YAAY,EACZ;QACE,YAAY,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,SAAS;KACzD,CACF,CAAC;AACJ,CAAC;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -22,12 +22,14 @@ export { InviteCodesCard } from "./InviteCodesCard";
|
|
|
22
22
|
export type { InviteCodesCardProps } from "./InviteCodesCard";
|
|
23
23
|
export { InviteCodesTable, useAllInviteCodes, clearUseAllInviteCodesCache, } from "./InviteCodesTable";
|
|
24
24
|
export type { InviteCodesDatatableProps, UseAllInviteCodesOptions, } from "./InviteCodesTable";
|
|
25
|
-
export { UsersTable } from "./UsersTable";
|
|
26
|
-
export type { UsersDatatableProps } from "./UsersTable";
|
|
25
|
+
export { UsersTable, useAllUsersList, LIST_ALL_USERS_ENDPOINT, } from "./UsersTable";
|
|
26
|
+
export type { UsersDatatableProps, UseAllUsersListOptions, } from "./UsersTable";
|
|
27
27
|
export { UsersCard } from "./UsersCard";
|
|
28
28
|
export type { UsersCardProps } from "./UsersCard";
|
|
29
29
|
export { UsersStatsRow } from "./UsersStatsRow";
|
|
30
30
|
export type { UsersStatsRowProps } from "./UsersStatsRow";
|
|
31
|
+
export { UsersChartsRow, UsersGrowthCard, UsersBreakdownCard, USER_CATEGORY_IDS, USER_GROWTH_RANGE_IDS, USER_GROWTH_RANGE_LABELS, buildUserGrowthSeries, describeUserGrowthTrend, formatUtcDay, formatUtcDayShort, isUserGrowthRangeId, startOfUtcDay, summarizeUserBreakdown, } from "./UsersChartsRow";
|
|
32
|
+
export type { UsersChartsRowProps, UsersGrowthCardProps, UsersBreakdownCardProps, BuildUserGrowthSeriesOptions, UserBreakdown, UserCategoryId, UserGrowthBucket, UserGrowthRangeId, UserGrowthSeries, UserGrowthTrend, } from "./UsersChartsRow";
|
|
31
33
|
export { OrganizationsTable, useAllOrganizationsList, clearUseAllOrganizationsListCache, } from "./OrganizationsTable";
|
|
32
34
|
export type { OrganizationsDatatableProps, UseAllOrganizationsListOptions, } from "./OrganizationsTable";
|
|
33
35
|
export { OrganizationsCard } from "./OrganizationsCard";
|
package/dist/components/index.js
CHANGED
|
@@ -10,9 +10,10 @@ export * from "./ApiServersCard";
|
|
|
10
10
|
export { useApiServersList } from "./ApiServersTable";
|
|
11
11
|
export { InviteCodesCard } from "./InviteCodesCard";
|
|
12
12
|
export { InviteCodesTable, useAllInviteCodes, clearUseAllInviteCodesCache, } from "./InviteCodesTable";
|
|
13
|
-
export { UsersTable } from "./UsersTable";
|
|
13
|
+
export { UsersTable, useAllUsersList, LIST_ALL_USERS_ENDPOINT, } from "./UsersTable";
|
|
14
14
|
export { UsersCard } from "./UsersCard";
|
|
15
15
|
export { UsersStatsRow } from "./UsersStatsRow";
|
|
16
|
+
export { UsersChartsRow, UsersGrowthCard, UsersBreakdownCard, USER_CATEGORY_IDS, USER_GROWTH_RANGE_IDS, USER_GROWTH_RANGE_LABELS, buildUserGrowthSeries, describeUserGrowthTrend, formatUtcDay, formatUtcDayShort, isUserGrowthRangeId, startOfUtcDay, summarizeUserBreakdown, } from "./UsersChartsRow";
|
|
16
17
|
export { OrganizationsTable, useAllOrganizationsList, clearUseAllOrganizationsListCache, } from "./OrganizationsTable";
|
|
17
18
|
export { OrganizationsCard } from "./OrganizationsCard";
|
|
18
19
|
export { OrganizationsStatsRow } from "./OrganizationsStatsRow";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAG9B,OAAO,EACL,0BAA0B,EAC1B,qBAAqB,EACrB,6BAA6B,GAC9B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,+BAA+B,EAC/B,4BAA4B,GAC7B,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EACL,kBAAkB,EAClB,4BAA4B,EAC5B,0BAA0B,GAC3B,MAAM,sBAAsB,CAAC;AAM9B,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,sBAAsB,EACtB,iBAAiB,EACjB,6BAA6B,GAC9B,MAAM,mBAAmB,CAAC;AAM3B,cAAc,iBAAiB,CAAC;AAGhC,cAAc,YAAY,CAAC;AAI3B,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,cAAc,kBAAkB,CAAC;AAOjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,2BAA2B,GAC5B,MAAM,oBAAoB,CAAC;AAM5B,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mapp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MAAM,gCAAgC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
export interface UseMeasuredWidthResult<T extends HTMLElement> {
|
|
3
|
+
/** Attach to the element whose width the chart should match. */
|
|
4
|
+
ref: RefObject<T | null>;
|
|
5
|
+
/** The measured width in whole pixels, or `fallback_width` before measuring. */
|
|
6
|
+
width: number;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* @description Tracks an element's rendered width. The chart primitives in
|
|
10
|
+
* `@schemavaults/ui` size their SVG canvas in pixels, so a chart that should
|
|
11
|
+
* span its card has to be told how wide the card currently is.
|
|
12
|
+
*
|
|
13
|
+
* The fallback width is used for the server render and the first client
|
|
14
|
+
* render — the observer only reports after mount — so the two agree and
|
|
15
|
+
* hydration stays clean.
|
|
16
|
+
*/
|
|
17
|
+
export declare function useMeasuredWidth<T extends HTMLElement>(fallback_width: number): UseMeasuredWidthResult<T>;
|
|
18
|
+
export default useMeasuredWidth;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useEffect, useRef, useState } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* @description Tracks an element's rendered width. The chart primitives in
|
|
5
|
+
* `@schemavaults/ui` size their SVG canvas in pixels, so a chart that should
|
|
6
|
+
* span its card has to be told how wide the card currently is.
|
|
7
|
+
*
|
|
8
|
+
* The fallback width is used for the server render and the first client
|
|
9
|
+
* render — the observer only reports after mount — so the two agree and
|
|
10
|
+
* hydration stays clean.
|
|
11
|
+
*/
|
|
12
|
+
export function useMeasuredWidth(fallback_width) {
|
|
13
|
+
const ref = useRef(null);
|
|
14
|
+
const [width, setWidth] = useState(fallback_width);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
const element = ref.current;
|
|
17
|
+
if (!element || typeof ResizeObserver === "undefined") {
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
const observer = new ResizeObserver((entries) => {
|
|
21
|
+
const entry = entries[0];
|
|
22
|
+
if (!entry) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
const measured = Math.round(entry.contentRect.width);
|
|
26
|
+
if (measured > 0) {
|
|
27
|
+
setWidth(measured);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
observer.observe(element);
|
|
31
|
+
return () => {
|
|
32
|
+
observer.disconnect();
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
35
|
+
return { ref, width };
|
|
36
|
+
}
|
|
37
|
+
export default useMeasuredWidth;
|
|
38
|
+
//# sourceMappingURL=useMeasuredWidth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMeasuredWidth.js","sourceRoot":"","sources":["../../src/lib/useMeasuredWidth.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;AASpE;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,cAAsB;IAEtB,MAAM,GAAG,GAAG,MAAM,CAAW,IAAI,CAAC,CAAC;IACnC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,QAAQ,CAAS,cAAc,CAAC,CAAC;IAE3D,SAAS,CAAC,GAA6B,EAAE;QACvC,MAAM,OAAO,GAAa,GAAG,CAAC,OAAO,CAAC;QACtC,IAAI,CAAC,OAAO,IAAI,OAAO,cAAc,KAAK,WAAW,EAAE,CAAC;YACtD,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,QAAQ,GAAG,IAAI,cAAc,CAAC,CAAC,OAA8B,EAAE,EAAE;YACrE,MAAM,KAAK,GAAoC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC1D,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,OAAO;YACT,CAAC;YACD,MAAM,QAAQ,GAAW,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAC7D,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;gBACjB,QAAQ,CAAC,QAAQ,CAAC,CAAC;YACrB,CAAC;QACH,CAAC,CAAC,CAAC;QACH,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAE1B,OAAO,GAAS,EAAE;YAChB,QAAQ,CAAC,UAAU,EAAE,CAAC;QACxB,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC;AACxB,CAAC;AAED,eAAe,gBAAgB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schemavaults/auth-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"description": "React.js UI components for authentication/authorization shared between different SchemaVaults apps",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"react": "^19.2.8",
|
|
17
17
|
"react-dom": "^19.2.8",
|
|
18
18
|
"next": "^16.2.11",
|
|
19
|
-
"@schemavaults/ui": "^0.
|
|
20
|
-
"@schemavaults/auth-react-provider": "0.16.
|
|
21
|
-
"@schemavaults/app-definitions": "0.13.
|
|
22
|
-
"@schemavaults/auth-common": "0.26.
|
|
19
|
+
"@schemavaults/ui": "^0.101.0",
|
|
20
|
+
"@schemavaults/auth-react-provider": "0.16.32",
|
|
21
|
+
"@schemavaults/app-definitions": "0.13.2",
|
|
22
|
+
"@schemavaults/auth-common": "0.26.6",
|
|
23
23
|
"lucide-react": "0.575.0",
|
|
24
24
|
"swr": "2.3.4",
|
|
25
25
|
"postcss": "8.5.3",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"tsc-alias": "1.9.0",
|
|
31
31
|
"@types/react": "19.2.14",
|
|
32
32
|
"@types/react-dom": "19.2.3",
|
|
33
|
-
"bun-types": "1.
|
|
33
|
+
"bun-types": "1.4.2",
|
|
34
34
|
"eslint": "9.39.1",
|
|
35
35
|
"@eslint/js": "9.39.1",
|
|
36
36
|
"globals": "16.5.0",
|
|
@@ -68,5 +68,5 @@
|
|
|
68
68
|
"access": "public"
|
|
69
69
|
},
|
|
70
70
|
"type": "module",
|
|
71
|
-
"packageManager": "bun@1.
|
|
71
|
+
"packageManager": "bun@1.4.2"
|
|
72
72
|
}
|