refine admin leaderboard experience

This commit is contained in:
Administrator committed 2026-06-04 23:41:19 +08:00
1 parent fe0ede178e
commit 88c83b4dd7
13 files changed
+754 -405

No files matched your search

-10
View File
@@ -176,10 +176,6 @@ export async function getUserLeaderboard(
since: string;
until: string;
days?: number;
exclude_user_ids?: string[];
include_scheduled?: boolean;
include_admins?: boolean;
include_failed?: boolean;
},
limit = 20,
): Promise<AdminLeaderboardResponse> {
@@ -188,13 +184,7 @@ export async function getUserLeaderboard(
since: range.since,
until: range.until,
limit: String(limit),
include_scheduled: String(range.include_scheduled ?? true),
include_admins: String(range.include_admins ?? true),
include_failed: String(range.include_failed ?? true),
});
for (const userId of range.exclude_user_ids ?? []) {
params.append("exclude_user_ids", userId);
}
return parse(
await apiFetch(`${base()}/leaderboard?${params}`),
"Failed to load leaderboard",
-8
View File
@@ -20,10 +20,6 @@ export function useUserLeaderboard(
since: string;
until: string;
days?: number;
exclude_user_ids?: string[];
include_scheduled?: boolean;
include_admins?: boolean;
include_failed?: boolean;
},
limit = 20,
) {
@@ -33,10 +29,6 @@ export function useUserLeaderboard(
"leaderboard",
range.since,
range.until,
range.exclude_user_ids ?? [],
range.include_scheduled ?? true,
range.include_admins ?? true,
range.include_failed ?? true,
limit,
],
queryFn: () => getUserLeaderboard(range, limit),
@@ -35,6 +35,7 @@ import {
ShieldCheck,
Sparkles,
Target,
Trophy,
Users,
} from "lucide-react";
@@ -245,6 +246,20 @@ export const sidebarMenuItems: MenuItem[] = [
path: "/page/strategy/settings/llm-metrics",
adminOnly: true,
},
{
id: "mgmt-user-leaderboard",
label: "用户排行榜",
icon: Trophy,
path: "/page/strategy/admin/user-leaderboard",
adminOnly: true,
},
{
id: "mgmt-user-leaderboard-settings",
label: "排行榜设置",
icon: Settings,
path: "/page/strategy/admin/user-leaderboard/settings",
adminOnly: true,
},
{
id: "mgmt-users",
label: "用户管理",
@@ -61,6 +61,22 @@ export interface CitationDisplayUpdate {
cleanup_words?: string[];
}
export interface LeaderboardSettings {
exclude_user_ids: string[];
include_scheduled: boolean;
include_admins: boolean;
include_failed: boolean;
cleanup_system_questions: boolean;
}
export interface LeaderboardSettingsUpdate {
exclude_user_ids?: string[];
include_scheduled?: boolean;
include_admins?: boolean;
include_failed?: boolean;
cleanup_system_questions?: boolean;
}
export async function loadPrivateSquareStatus(): Promise<PrivateSquareStatus> {
const response = await apiFetch(
`${getBackendBaseURL()}/api/system-settings/private-square`,
@@ -127,6 +143,36 @@ export async function loadCitationDisplaySettings(): Promise<CitationDisplaySett
return (await response.json()) as CitationDisplaySettings;
}
export async function loadLeaderboardSettings(): Promise<LeaderboardSettings> {
const response = await apiFetch(
`${getBackendBaseURL()}/api/system-settings/leaderboard`,
);
if (!response.ok) {
throw new Error(`Failed to load leaderboard settings: ${response.status}`);
}
return (await response.json()) as LeaderboardSettings;
}
export async function updateLeaderboardSettings(
body: LeaderboardSettingsUpdate,
): Promise<LeaderboardSettings> {
const response = await apiFetch(
`${getBackendBaseURL()}/api/system-settings/leaderboard`,
{
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
},
);
if (!response.ok) {
const detail = await response
.json()
.catch(() => ({ detail: "Failed to update leaderboard settings" }));
throw new Error(detail.detail ?? "Failed to update leaderboard settings");
}
return (await response.json()) as LeaderboardSettings;
}
export async function updateCitationDisplaySettings(
body: CitationDisplayUpdate,
): Promise<CitationDisplaySettings> {
@@ -3,14 +3,17 @@ import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import {
loadAppearanceSettings,
loadCitationDisplaySettings,
loadLeaderboardSettings,
loadPrivateSquareStatus,
loadPromptPrefixSettings,
updateAppearanceSettings,
updateCitationDisplaySettings,
updateLeaderboardSettings,
updatePrivateSquareSettings,
updatePromptPrefixSettings,
type AppearanceUpdate,
type CitationDisplayUpdate,
type LeaderboardSettingsUpdate,
type PrivateSquareUpdate,
type PromptPrefixUpdate,
} from "./api";
@@ -19,6 +22,7 @@ const PROMPT_PREFIX_KEY = ["systemSettings", "promptPrefix"] as const;
const PRIVATE_SQUARE_KEY = ["systemSettings", "privateSquare"] as const;
const APPEARANCE_KEY = ["systemSettings", "appearance"] as const;
const CITATION_DISPLAY_KEY = ["systemSettings", "citationDisplay"] as const;
const LEADERBOARD_KEY = ["systemSettings", "leaderboard"] as const;
export function usePromptPrefixSettings() {
return useQuery({
@@ -102,3 +106,25 @@ export function useUpdateCitationDisplaySettings() {
},
});
}
export function useLeaderboardSettings() {
return useQuery({
queryKey: LEADERBOARD_KEY,
queryFn: () => loadLeaderboardSettings(),
staleTime: 60_000,
refetchOnWindowFocus: false,
retry: false,
});
}
export function useUpdateLeaderboardSettings() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (body: LeaderboardSettingsUpdate) =>
updateLeaderboardSettings(body),
onSuccess: (data) => {
queryClient.setQueryData(LEADERBOARD_KEY, data);
queryClient.invalidateQueries({ queryKey: ["admin-activity", "leaderboard"] });
},
});
}