@allbluecn/admin-app 0.3.1 → 0.3.3
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/package.json +19 -17
- package/src/components/admin/admin-user-menu.tsx +4 -4
- package/src/components/admin/developer-log.tsx +16 -32
- package/src/components/ai-memory/memory-facts-panel.tsx +30 -70
- package/src/components/ai-prompts/preview-panel.tsx +1 -1
- package/src/components/ai-prompts/prompt-editor.tsx +8 -9
- package/src/components/ai-prompts/prompt-table.tsx +6 -6
- package/src/components/ai-prompts/section-editor.tsx +3 -3
- package/src/components/ai-prompts/variable-panel.tsx +2 -2
- package/src/components/ai-prompts/version-history.tsx +21 -41
- package/src/components/ai-provider/model-list-editor.tsx +2 -3
- package/src/components/ai-provider/provider-form.tsx +7 -7
- package/src/components/ai-provider/provider-table.tsx +17 -40
- package/src/components/auth/admin-login-form.tsx +7 -7
- package/src/components/auth/icon-input.tsx +2 -2
- package/src/components/auth/password-input.tsx +2 -2
- package/src/components/component/component-form-dialog.tsx +10 -18
- package/src/components/component/component-import-dialog.tsx +6 -6
- package/src/components/component/component-preview.tsx +311 -0
- package/src/components/component/component-table.tsx +3 -3
- package/src/components/dependency/changelog-dialog.tsx +2 -2
- package/src/components/dependency/columns.tsx +3 -3
- package/src/components/dependency/dependency-table.tsx +7 -7
- package/src/components/dependency/edit-dialog.tsx +8 -8
- package/src/components/invitations/invitations-page.tsx +26 -49
- package/src/components/knowledge-public/bookmark-form-dialog.tsx +6 -6
- package/src/components/knowledge-public/compliance-form-dialog.tsx +6 -6
- package/src/components/knowledge-public/legal-form-dialog.tsx +7 -7
- package/src/components/layout/sidebar-02/app-sidebar.tsx +1 -2
- package/src/components/layout/sidebar-02/index.tsx +1 -1
- package/src/components/layout/sidebar-02/nav-main.tsx +2 -3
- package/src/components/layout/sidebar-02/nav-notifications.tsx +3 -3
- package/src/components/market/columns.tsx +4 -4
- package/src/components/market/market-app-form.tsx +6 -7
- package/src/components/market/market-app-list.tsx +14 -29
- package/src/components/monitoring/error-list.tsx +2 -2
- package/src/components/monitoring/metrics-stats.tsx +1 -1
- package/src/components/monitoring/request-log-table.tsx +2 -2
- package/src/components/oauth-providers/provider-page.tsx +20 -38
- package/src/components/permissions/assign-dialog.tsx +135 -0
- package/src/components/permissions/create-role-dialog.tsx +135 -0
- package/src/components/permissions/types.ts +49 -0
- package/src/components/user/columns.tsx +6 -6
- package/src/components/user/settings-activity-log.tsx +7 -7
- package/src/components/user/settings-profile/avatar-uploader.tsx +118 -0
- package/src/components/user/settings-profile/social-links.tsx +63 -0
- package/src/components/user/settings-profile.tsx +26 -125
- package/src/components/user/user-create-dialog.tsx +6 -6
- package/src/components/user/user-detail/error-boundary.tsx +19 -0
- package/src/components/user/user-detail/user-detail-dialogs.tsx +203 -0
- package/src/components/user/user-filters.tsx +4 -4
- package/src/lib/auth/page-gate.ts +28 -0
- package/src/lib/auth.config.ts +25 -9
- package/src/lib/i18n/detect.ts +1 -1
- package/src/lib/loader-serial.ts +14 -0
- package/src/paraglide/README.md +1 -1
- package/src/providers/index.tsx +1 -1
- package/src/routeTree.gen.ts +67 -78
- package/src/routes/__root.tsx +4 -4
- package/src/routes/_nav/audit/route.lazy.tsx +1 -2
- package/src/routes/_nav/compliance/route.lazy.tsx +5 -3
- package/src/routes/_nav/components/route.lazy.tsx +14 -34
- package/src/routes/_nav/knowledge-public/bookmarks/route.lazy.tsx +18 -38
- package/src/routes/_nav/knowledge-public/compliance/route.lazy.tsx +18 -38
- package/src/routes/_nav/knowledge-public/legal/route.lazy.tsx +6 -6
- package/src/routes/_nav/licenses/$licenseId/route.lazy.tsx +3 -3
- package/src/routes/_nav/licenses/new/route.lazy.tsx +5 -5
- package/src/routes/_nav/licenses/route.lazy.tsx +1 -1
- package/src/routes/_nav/monitoring/ai-usage/route.lazy.tsx +2 -2
- package/src/routes/_nav/monitoring/errors/route.lazy.tsx +10 -10
- package/src/routes/_nav/monitoring/errors/route.tsx +7 -0
- package/src/routes/_nav/monitoring/health/route.lazy.tsx +13 -15
- package/src/routes/_nav/monitoring/health/route.tsx +14 -0
- package/src/routes/_nav/monitoring/logs/route.lazy.tsx +24 -9
- package/src/routes/_nav/monitoring/logs/route.tsx +13 -0
- package/src/routes/_nav/monitoring/metrics/route.lazy.tsx +12 -14
- package/src/routes/_nav/monitoring/metrics/route.tsx +7 -0
- package/src/routes/_nav/monitoring/overview/route.lazy.tsx +14 -13
- package/src/routes/_nav/monitoring/overview/route.tsx +17 -0
- package/src/routes/_nav/monitoring/route.lazy.tsx +6 -6
- package/src/routes/_nav/monitoring/sentry/route.lazy.tsx +2 -2
- package/src/routes/_nav/permissions/route.lazy.tsx +21 -311
- package/src/routes/_nav/permissions/route.tsx +1 -1
- package/src/routes/_nav/route.tsx +5 -13
- package/src/routes/_nav/sso/route.lazy.tsx +2 -3
- package/src/routes/_nav/users/$userId/route.lazy.tsx +91 -156
- package/src/routes/_nav/users/-components/users-table.tsx +1 -1
- package/src/routes/_nav/users/route.lazy.tsx +1 -1
- package/src/routes/login/route.lazy.tsx +1 -1
- package/src/routes/setup/route.lazy.tsx +2 -2
- package/src/server/__tests__/admin-billing.test.ts +191 -16
- package/src/server/__tests__/compliance.test.ts +44 -7
- package/src/server/__tests__/permissions.test.ts +10 -5
- package/src/server/__tests__/prompt-defaults.test.ts +3 -3
- package/src/server/admin-ai-alerts.ts +2 -1
- package/src/server/admin-ai-usage.ts +2 -1
- package/src/server/ai-memory/store.ts +6 -2
- package/src/server/{serverFns/ai-prompts → ai-prompts}/prompt-defaults.ts +5 -3
- package/src/server/{serverFns/dependency → dependency}/helpers.ts +4 -3
- package/src/server/knowledge-public/github-sync.ts +2 -1
- package/src/server/license-issue.ts +2 -1
- package/src/server/middlewares/auth-rate-limit.ts +117 -0
- package/src/server/observability/health-check.ts +4 -1
- package/src/server/observability/metrics.ts +17 -15
- package/src/server/observability/request-middleware.ts +2 -1
- package/src/server/observability/timing.ts +14 -16
- package/src/server/serverFns/admin-billing.ts +107 -12
- package/src/server/serverFns/ai-memory/list-users.ts +2 -1
- package/src/server/serverFns/ai-prompts/activate.ts +2 -1
- package/src/server/serverFns/ai-prompts/get.ts +3 -2
- package/src/server/serverFns/ai-prompts/list.ts +3 -2
- package/src/server/serverFns/ai-prompts/rollback.ts +3 -1
- package/src/server/serverFns/ai-prompts/save.ts +5 -3
- package/src/server/serverFns/ai-provider/create.ts +4 -1
- package/src/server/serverFns/ai-provider/delete.ts +4 -1
- package/src/server/serverFns/ai-provider/get.ts +4 -1
- package/src/server/serverFns/ai-provider/list.ts +28 -1
- package/src/server/serverFns/ai-provider/seed-from-seed.ts +2 -1
- package/src/server/serverFns/ai-provider/update.ts +4 -1
- package/src/server/serverFns/anyhub/market.ts +8 -1
- package/src/server/serverFns/audit.ts +14 -1
- package/src/server/serverFns/auth/setup.ts +3 -1
- package/src/server/serverFns/compliance.ts +32 -3
- package/src/server/serverFns/components/import.ts +69 -14
- package/src/server/serverFns/components/list.ts +4 -1
- package/src/server/serverFns/components/mutations.ts +9 -1
- package/src/server/serverFns/dependency/list.ts +28 -5
- package/src/server/serverFns/dependency/sync.ts +7 -2
- package/src/server/serverFns/dependency/update.ts +4 -1
- package/src/server/serverFns/developer-log-auto-generate.ts +63 -32
- package/src/server/serverFns/developer-logs.ts +5 -1
- package/src/server/serverFns/invitations.ts +7 -1
- package/src/server/serverFns/knowledge-public/bookmarks/create.ts +2 -1
- package/src/server/serverFns/knowledge-public/bookmarks/delete.ts +2 -1
- package/src/server/serverFns/knowledge-public/bookmarks/detail.ts +2 -1
- package/src/server/serverFns/knowledge-public/bookmarks/list.ts +2 -1
- package/src/server/serverFns/knowledge-public/bookmarks/sync-all-github.ts +2 -1
- package/src/server/serverFns/knowledge-public/bookmarks/update.ts +2 -1
- package/src/server/serverFns/knowledge-public/compliance/create.ts +2 -1
- package/src/server/serverFns/knowledge-public/compliance/delete.ts +2 -1
- package/src/server/serverFns/knowledge-public/compliance/detail.ts +2 -1
- package/src/server/serverFns/knowledge-public/compliance/list.ts +2 -1
- package/src/server/serverFns/knowledge-public/compliance/update.ts +2 -1
- package/src/server/serverFns/knowledge-public/legal/create.ts +2 -1
- package/src/server/serverFns/knowledge-public/legal/delete.ts +2 -1
- package/src/server/serverFns/knowledge-public/legal/detail.ts +2 -1
- package/src/server/serverFns/knowledge-public/legal/list.ts +2 -1
- package/src/server/serverFns/knowledge-public/legal/update.ts +2 -1
- package/src/server/serverFns/licenses.ts +8 -2
- package/src/server/serverFns/monitoring/get-errors.ts +2 -1
- package/src/server/serverFns/monitoring/get-health.ts +2 -1
- package/src/server/serverFns/monitoring/get-metrics.ts +2 -1
- package/src/server/serverFns/monitoring/get-request-logs.ts +2 -1
- package/src/server/serverFns/monitoring/report-error.ts +2 -1
- package/src/server/serverFns/monitoring/reset.ts +2 -1
- package/src/server/serverFns/oauth-providers.ts +4 -1
- package/src/server/serverFns/permissions.ts +18 -11
- package/src/server/serverFns/sentry/config.ts +11 -8
- package/src/server/serverFns/sso-config.ts +17 -2
- package/src/server/serverFns/user/create.ts +6 -1
- package/src/server/serverFns/user/delete.ts +6 -1
- package/src/server/serverFns/user/detail.ts +5 -2
- package/src/server/serverFns/user/list.ts +19 -4
- package/src/server/serverFns/user/reset-password.ts +10 -2
- package/src/server/serverFns/user/update-role.ts +10 -2
- package/src/server/serverFns/user/update-status.ts +10 -2
- package/src/styles/globals.css +4 -0
- package/src/components/data-table/data-table-pagination.tsx +0 -112
- package/src/components/data-table/data-table.tsx +0 -218
- package/src/components/data-table/table-detail-layout.tsx +0 -98
- package/src/components/ui/alert-dialog.tsx +0 -187
- package/src/components/ui/alert.tsx +0 -75
- package/src/components/ui/avatar.tsx +0 -106
- package/src/components/ui/badge.tsx +0 -51
- package/src/components/ui/button.tsx +0 -57
- package/src/components/ui/card.tsx +0 -102
- package/src/components/ui/checkbox.tsx +0 -28
- package/src/components/ui/collapsible.tsx +0 -19
- package/src/components/ui/dialog.tsx +0 -155
- package/src/components/ui/dropdown-menu.tsx +0 -267
- package/src/components/ui/field.tsx +0 -236
- package/src/components/ui/input-group.tsx +0 -158
- package/src/components/ui/input.tsx +0 -19
- package/src/components/ui/label.tsx +0 -17
- package/src/components/ui/pagination.tsx +0 -130
- package/src/components/ui/select.tsx +0 -234
- package/src/components/ui/separator.tsx +0 -22
- package/src/components/ui/sheet.tsx +0 -135
- package/src/components/ui/sidebar.tsx +0 -721
- package/src/components/ui/skeleton.tsx +0 -13
- package/src/components/ui/switch.tsx +0 -29
- package/src/components/ui/table.tsx +0 -115
- package/src/components/ui/textarea.tsx +0 -17
- package/src/components/ui/toast.tsx +0 -282
- package/src/components/ui/tooltip.tsx +0 -63
- package/src/hooks/use-mobile.ts +0 -19
- package/src/lib/avatar.ts +0 -41
- /package/src/routes/{api.auth.$.ts → api/auth/$.ts} +0 -0
- /package/src/routes/{api.sentry-test.ts → api/sentry-test.ts} +0 -0
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
|
|
18
18
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
19
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
20
|
+
import { getPrisma } from '@allbluecn/database/get-prisma'
|
|
21
|
+
import { requireAdmin } from '@/server/auth-helpers'
|
|
21
22
|
|
|
22
23
|
const listInput = z.object({
|
|
23
24
|
page: z.number().default(1),
|
|
@@ -30,11 +31,13 @@ const listInput = z.object({
|
|
|
30
31
|
export const listUsersFn = createServerFn({ method: 'GET' })
|
|
31
32
|
.validator(listInput)
|
|
32
33
|
.handler(async ({ data }) => {
|
|
34
|
+
const prisma = await getPrisma()
|
|
35
|
+
await requireAdmin()
|
|
33
36
|
const { page, pageSize, search, role, status } = data
|
|
34
37
|
const where: any = {}
|
|
35
38
|
if (search) {
|
|
36
39
|
where.OR = [
|
|
37
|
-
{
|
|
40
|
+
{ username: { contains: search, mode: 'insensitive' } },
|
|
38
41
|
{ email: { contains: search, mode: 'insensitive' } },
|
|
39
42
|
]
|
|
40
43
|
}
|
|
@@ -46,8 +49,20 @@ export const listUsersFn = createServerFn({ method: 'GET' })
|
|
|
46
49
|
skip: (page - 1) * pageSize,
|
|
47
50
|
take: pageSize,
|
|
48
51
|
orderBy: { createdAt: 'desc' },
|
|
49
|
-
|
|
50
|
-
|
|
52
|
+
// SEC-01 联动:select 显式列出 UI 所需列,绝不返回 password / aiApiKey 等凭据字段
|
|
53
|
+
select: {
|
|
54
|
+
id: true,
|
|
55
|
+
email: true,
|
|
56
|
+
username: true,
|
|
57
|
+
role: true,
|
|
58
|
+
status: true,
|
|
59
|
+
avatarConfig: true,
|
|
60
|
+
bgShape: true,
|
|
61
|
+
bgColor: true,
|
|
62
|
+
createdAt: true,
|
|
63
|
+
updatedAt: true,
|
|
64
|
+
lastLoginAt: true,
|
|
65
|
+
_count: { select: { designs: true, anyhubMarketApps: true, reviews: true } },
|
|
51
66
|
},
|
|
52
67
|
}),
|
|
53
68
|
prisma.user.count({ where }),
|
|
@@ -17,12 +17,20 @@
|
|
|
17
17
|
|
|
18
18
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
19
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
20
|
+
import { getPrisma } from '@allbluecn/database/get-prisma'
|
|
21
21
|
import bcrypt from 'bcryptjs'
|
|
22
|
+
import { requireAdmin } from '@/server/auth-helpers'
|
|
22
23
|
|
|
23
24
|
export const resetUserPasswordFn = createServerFn({ method: 'POST' })
|
|
24
25
|
.validator(z.object({ userId: z.string(), newPassword: z.string().min(8) }))
|
|
25
26
|
.handler(async ({ data }) => {
|
|
27
|
+
const prisma = await getPrisma()
|
|
28
|
+
await requireAdmin()
|
|
26
29
|
const hashedPassword = await bcrypt.hash(data.newPassword, 12)
|
|
27
|
-
return prisma.user.update({
|
|
30
|
+
return prisma.user.update({
|
|
31
|
+
where: { id: data.userId },
|
|
32
|
+
data: { password: hashedPassword },
|
|
33
|
+
// 不回显 password 哈希
|
|
34
|
+
select: { id: true, email: true, username: true, role: true, status: true },
|
|
35
|
+
})
|
|
28
36
|
})
|
|
@@ -17,10 +17,18 @@
|
|
|
17
17
|
|
|
18
18
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
19
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
20
|
+
import { getPrisma } from '@allbluecn/database/get-prisma'
|
|
21
|
+
import { requireAdmin } from '@/server/auth-helpers'
|
|
21
22
|
|
|
22
23
|
export const updateUserRoleFn = createServerFn({ method: 'POST' })
|
|
23
24
|
.validator(z.object({ userId: z.string(), role: z.enum(['USER', 'ADMIN', 'SUPER_ADMIN']) }))
|
|
24
25
|
.handler(async ({ data }) => {
|
|
25
|
-
|
|
26
|
+
const prisma = await getPrisma()
|
|
27
|
+
await requireAdmin()
|
|
28
|
+
return prisma.user.update({
|
|
29
|
+
where: { id: data.userId },
|
|
30
|
+
data: { role: data.role },
|
|
31
|
+
// 不回显 password 哈希
|
|
32
|
+
select: { id: true, email: true, username: true, role: true, status: true },
|
|
33
|
+
})
|
|
26
34
|
})
|
|
@@ -17,10 +17,18 @@
|
|
|
17
17
|
|
|
18
18
|
import { createServerFn } from '@tanstack/react-start'
|
|
19
19
|
import { z } from 'zod'
|
|
20
|
-
import {
|
|
20
|
+
import { getPrisma } from '@allbluecn/database/get-prisma'
|
|
21
|
+
import { requireAdmin } from '@/server/auth-helpers'
|
|
21
22
|
|
|
22
23
|
export const updateUserStatusFn = createServerFn({ method: 'POST' })
|
|
23
24
|
.validator(z.object({ userId: z.string(), status: z.enum(['ACTIVE', 'INACTIVE', 'BANNED']) }))
|
|
24
25
|
.handler(async ({ data }) => {
|
|
25
|
-
|
|
26
|
+
const prisma = await getPrisma()
|
|
27
|
+
await requireAdmin()
|
|
28
|
+
return prisma.user.update({
|
|
29
|
+
where: { id: data.userId },
|
|
30
|
+
data: { status: data.status },
|
|
31
|
+
// 不回显 password 哈希
|
|
32
|
+
select: { id: true, email: true, username: true, role: true, status: true },
|
|
33
|
+
})
|
|
26
34
|
})
|
package/src/styles/globals.css
CHANGED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
-
// AllBlue - 理想之海
|
|
3
|
-
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
-
//
|
|
5
|
-
// This program is free software: you can redistribute it and/or modify
|
|
6
|
-
// it under the terms of the GNU Affero General Public License as published by
|
|
7
|
-
// the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
// (at your option) any later version.
|
|
9
|
-
//
|
|
10
|
-
// This program is distributed in the hope that it will be useful,
|
|
11
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
// GNU Affero General Public License for more details.
|
|
14
|
-
//
|
|
15
|
-
// You should have received a copy of the GNU Affero General Public License
|
|
16
|
-
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
-
|
|
18
|
-
import {
|
|
19
|
-
Pagination,
|
|
20
|
-
PaginationContent,
|
|
21
|
-
PaginationEllipsis,
|
|
22
|
-
PaginationItem,
|
|
23
|
-
PaginationLink,
|
|
24
|
-
PaginationNext,
|
|
25
|
-
PaginationPrevious,
|
|
26
|
-
} from "@/components/ui/pagination";
|
|
27
|
-
import { m } from '@/paraglide/messages.js'
|
|
28
|
-
interface DataTablePaginationProps {
|
|
29
|
-
page: number;
|
|
30
|
-
totalPages: number;
|
|
31
|
-
total: number;
|
|
32
|
-
onPageChange: (page: number) => void;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function getPageNumbers(current: number, total: number): (number | "ellipsis")[] {
|
|
36
|
-
if (total <= 5) {
|
|
37
|
-
return Array.from({ length: total }, (_, i) => i + 1);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const pages: (number | "ellipsis")[] = [1];
|
|
41
|
-
|
|
42
|
-
if (current > 3) {
|
|
43
|
-
pages.push("ellipsis");
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const start = Math.max(2, current - 1);
|
|
47
|
-
const end = Math.min(total - 1, current + 1);
|
|
48
|
-
|
|
49
|
-
for (let i = start; i <= end; i++) {
|
|
50
|
-
pages.push(i);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (current < total - 2) {
|
|
54
|
-
pages.push("ellipsis");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
pages.push(total);
|
|
58
|
-
|
|
59
|
-
return pages;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export function DataTablePagination({
|
|
63
|
-
page,
|
|
64
|
-
totalPages,
|
|
65
|
-
total,
|
|
66
|
-
onPageChange,
|
|
67
|
-
}: DataTablePaginationProps) {
|
|
68
|
-
const pages = getPageNumbers(page, totalPages);
|
|
69
|
-
|
|
70
|
-
return (
|
|
71
|
-
<div className="flex items-center justify-between gap-4 px-2 py-4">
|
|
72
|
-
<div className="text-sm text-muted-foreground whitespace-nowrap shrink-0">
|
|
73
|
-
{m.common_pagination_total({ total, page, totalPages })}
|
|
74
|
-
</div>
|
|
75
|
-
<Pagination className="justify-end">
|
|
76
|
-
<PaginationContent>
|
|
77
|
-
<PaginationItem>
|
|
78
|
-
<PaginationPrevious
|
|
79
|
-
text={m.common_pagination_prev()}
|
|
80
|
-
onClick={() => page > 1 && onPageChange(page - 1)}
|
|
81
|
-
className={page <= 1 ? "pointer-events-none opacity-50" : "cursor-pointer"}
|
|
82
|
-
/>
|
|
83
|
-
</PaginationItem>
|
|
84
|
-
{pages.map((p, i) =>
|
|
85
|
-
p === "ellipsis" ? (
|
|
86
|
-
<PaginationItem key={`ellipsis-${i}`}>
|
|
87
|
-
<PaginationEllipsis />
|
|
88
|
-
</PaginationItem>
|
|
89
|
-
) : (
|
|
90
|
-
<PaginationItem key={p}>
|
|
91
|
-
<PaginationLink
|
|
92
|
-
isActive={p === page}
|
|
93
|
-
onClick={() => onPageChange(p)}
|
|
94
|
-
className="cursor-pointer"
|
|
95
|
-
>
|
|
96
|
-
{p}
|
|
97
|
-
</PaginationLink>
|
|
98
|
-
</PaginationItem>
|
|
99
|
-
)
|
|
100
|
-
)}
|
|
101
|
-
<PaginationItem>
|
|
102
|
-
<PaginationNext
|
|
103
|
-
text={m.common_pagination_next()}
|
|
104
|
-
onClick={() => page < totalPages && onPageChange(page + 1)}
|
|
105
|
-
className={page >= totalPages ? "pointer-events-none opacity-50" : "cursor-pointer"}
|
|
106
|
-
/>
|
|
107
|
-
</PaginationItem>
|
|
108
|
-
</PaginationContent>
|
|
109
|
-
</Pagination>
|
|
110
|
-
</div>
|
|
111
|
-
);
|
|
112
|
-
}
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
-
// AllBlue - 理想之海
|
|
3
|
-
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
-
//
|
|
5
|
-
// This program is free software: you can redistribute it and/or modify
|
|
6
|
-
// it under the terms of the GNU Affero General Public License as published by
|
|
7
|
-
// the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
// (at your option) any later version.
|
|
9
|
-
//
|
|
10
|
-
// This program is distributed in the hope that it will be useful,
|
|
11
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
// GNU Affero General Public License for more details.
|
|
14
|
-
//
|
|
15
|
-
// You should have received a copy of the GNU Affero General Public License
|
|
16
|
-
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
-
|
|
18
|
-
import type { CSSProperties } from 'react'
|
|
19
|
-
import { useRef } from 'react'
|
|
20
|
-
import {
|
|
21
|
-
type ColumnDef,
|
|
22
|
-
type RowData,
|
|
23
|
-
columnVisibilityFeature,
|
|
24
|
-
flexRender,
|
|
25
|
-
tableFeatures,
|
|
26
|
-
useTable,
|
|
27
|
-
} from '@tanstack/react-table'
|
|
28
|
-
import { useVirtualizer } from '@tanstack/react-virtual'
|
|
29
|
-
import {
|
|
30
|
-
Table,
|
|
31
|
-
TableBody,
|
|
32
|
-
TableCell,
|
|
33
|
-
TableHead,
|
|
34
|
-
TableHeader,
|
|
35
|
-
TableRow,
|
|
36
|
-
} from '@/components/ui/table'
|
|
37
|
-
import { VIRTUALIZE_THRESHOLD } from '@allbluecn/kernel'
|
|
38
|
-
|
|
39
|
-
export const dataTableFeatures = tableFeatures({
|
|
40
|
-
columnVisibilityFeature,
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
export type AdminColumnDef<
|
|
44
|
-
TData extends RowData,
|
|
45
|
-
TValue = unknown,
|
|
46
|
-
> = ColumnDef<typeof dataTableFeatures, TData, TValue> & {
|
|
47
|
-
meta?: { style?: CSSProperties }
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface DataTableProps<TData extends RowData> {
|
|
51
|
-
columns: AdminColumnDef<TData>[];
|
|
52
|
-
data: TData[];
|
|
53
|
-
onRowClick?: (row: TData) => void;
|
|
54
|
-
actions?: React.ReactNode;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const ROW_HEIGHT = 48
|
|
58
|
-
|
|
59
|
-
function ColGroup({ columns }: { columns: AdminColumnDef<any>[] }) {
|
|
60
|
-
return (
|
|
61
|
-
<colgroup>
|
|
62
|
-
{columns.map((col, i) => {
|
|
63
|
-
const style = (col.meta as { style?: CSSProperties } | undefined)?.style
|
|
64
|
-
const width = style?.width
|
|
65
|
-
return width != null ? <col key={i} style={{ width }} /> : null
|
|
66
|
-
})}
|
|
67
|
-
</colgroup>
|
|
68
|
-
)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function DataTable<TData extends RowData>({
|
|
72
|
-
columns,
|
|
73
|
-
data,
|
|
74
|
-
onRowClick,
|
|
75
|
-
actions,
|
|
76
|
-
}: DataTableProps<TData>) {
|
|
77
|
-
const table = useTable({
|
|
78
|
-
features: dataTableFeatures,
|
|
79
|
-
data,
|
|
80
|
-
columns,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const { rows } = table.getRowModel();
|
|
84
|
-
const parentRef = useRef<HTMLDivElement>(null);
|
|
85
|
-
|
|
86
|
-
const shouldVirtualize = rows.length > VIRTUALIZE_THRESHOLD;
|
|
87
|
-
|
|
88
|
-
const rowVirtualizer = useVirtualizer({
|
|
89
|
-
count: shouldVirtualize ? rows.length : 0,
|
|
90
|
-
getScrollElement: () => parentRef.current,
|
|
91
|
-
estimateSize: () => ROW_HEIGHT,
|
|
92
|
-
overscan: 10,
|
|
93
|
-
enabled: shouldVirtualize,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const virtualRows = shouldVirtualize ? rowVirtualizer.getVirtualItems() : [];
|
|
97
|
-
const totalHeight = shouldVirtualize ? rowVirtualizer.getTotalSize() : 0;
|
|
98
|
-
const paddingTop = virtualRows.length > 0 ? virtualRows[0].start : 0;
|
|
99
|
-
const paddingBottom =
|
|
100
|
-
virtualRows.length > 0
|
|
101
|
-
? totalHeight - virtualRows[virtualRows.length - 1].end
|
|
102
|
-
: 0;
|
|
103
|
-
|
|
104
|
-
const headerGroups = table.getHeaderGroups();
|
|
105
|
-
|
|
106
|
-
const renderRows = () => {
|
|
107
|
-
if (!shouldVirtualize) {
|
|
108
|
-
return rows.map((row) => (
|
|
109
|
-
<TableRow
|
|
110
|
-
key={row.id}
|
|
111
|
-
className={onRowClick ? 'cursor-pointer' : undefined}
|
|
112
|
-
onClick={() => onRowClick?.(row.original)}
|
|
113
|
-
>
|
|
114
|
-
{row.getVisibleCells().map((cell) => {
|
|
115
|
-
const style = (cell.column.columnDef.meta as
|
|
116
|
-
| { style?: CSSProperties }
|
|
117
|
-
| undefined)?.style
|
|
118
|
-
const alignClass =
|
|
119
|
-
style?.textAlign === 'right' ? 'text-right' : undefined
|
|
120
|
-
return (
|
|
121
|
-
<TableCell
|
|
122
|
-
key={cell.id}
|
|
123
|
-
className={alignClass}
|
|
124
|
-
style={{ width: style?.width }}
|
|
125
|
-
>
|
|
126
|
-
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
127
|
-
</TableCell>
|
|
128
|
-
)
|
|
129
|
-
})}
|
|
130
|
-
</TableRow>
|
|
131
|
-
))
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return (
|
|
135
|
-
<>
|
|
136
|
-
{paddingTop > 0 && <tr style={{ height: paddingTop }} />}
|
|
137
|
-
{virtualRows.map((virtualRow) => {
|
|
138
|
-
const row = rows[virtualRow.index]
|
|
139
|
-
return (
|
|
140
|
-
<TableRow
|
|
141
|
-
key={row.id}
|
|
142
|
-
style={{
|
|
143
|
-
position: 'absolute',
|
|
144
|
-
transform: `translateY(${virtualRow.start}px)`,
|
|
145
|
-
height: ROW_HEIGHT,
|
|
146
|
-
}}
|
|
147
|
-
className={onRowClick ? 'cursor-pointer' : undefined}
|
|
148
|
-
onClick={() => onRowClick?.(row.original)}
|
|
149
|
-
>
|
|
150
|
-
{row.getVisibleCells().map((cell) => {
|
|
151
|
-
const style = (cell.column.columnDef.meta as
|
|
152
|
-
| { style?: CSSProperties }
|
|
153
|
-
| undefined)?.style
|
|
154
|
-
const alignClass =
|
|
155
|
-
style?.textAlign === 'right' ? 'text-right' : undefined
|
|
156
|
-
return (
|
|
157
|
-
<TableCell
|
|
158
|
-
key={cell.id}
|
|
159
|
-
className={alignClass}
|
|
160
|
-
style={{ width: style?.width }}
|
|
161
|
-
>
|
|
162
|
-
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
163
|
-
</TableCell>
|
|
164
|
-
)
|
|
165
|
-
})}
|
|
166
|
-
</TableRow>
|
|
167
|
-
)
|
|
168
|
-
})}
|
|
169
|
-
{paddingBottom > 0 && <tr style={{ height: paddingBottom }} />}
|
|
170
|
-
</>
|
|
171
|
-
);
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
return (
|
|
175
|
-
<div className="rounded-md border flex flex-col min-h-0 flex-1 overflow-x-hidden">
|
|
176
|
-
<div className="shrink-0">
|
|
177
|
-
<Table className="table-fixed">
|
|
178
|
-
<ColGroup columns={columns} />
|
|
179
|
-
<TableHeader>
|
|
180
|
-
{headerGroups.map((headerGroup) => (
|
|
181
|
-
<TableRow key={headerGroup.id}>
|
|
182
|
-
{headerGroup.headers.map((header) => {
|
|
183
|
-
const style = (
|
|
184
|
-
header.column.columnDef.meta as
|
|
185
|
-
| { style?: CSSProperties }
|
|
186
|
-
| undefined
|
|
187
|
-
)?.style
|
|
188
|
-
const alignClass =
|
|
189
|
-
style?.textAlign === 'right' ? 'text-right' : undefined
|
|
190
|
-
return (
|
|
191
|
-
<TableHead
|
|
192
|
-
key={header.id}
|
|
193
|
-
className={alignClass}
|
|
194
|
-
style={{ width: style?.width }}
|
|
195
|
-
>
|
|
196
|
-
{header.isPlaceholder
|
|
197
|
-
? null
|
|
198
|
-
: flexRender(header.column.columnDef.header, header.getContext())}
|
|
199
|
-
</TableHead>
|
|
200
|
-
)
|
|
201
|
-
})}
|
|
202
|
-
</TableRow>
|
|
203
|
-
))}
|
|
204
|
-
</TableHeader>
|
|
205
|
-
</Table>
|
|
206
|
-
</div>
|
|
207
|
-
<div ref={parentRef} className="overflow-y-auto flex-1 min-h-0">
|
|
208
|
-
<div style={{ position: "relative", height: shouldVirtualize ? totalHeight : undefined }}>
|
|
209
|
-
<Table className="table-fixed">
|
|
210
|
-
<ColGroup columns={columns} />
|
|
211
|
-
<TableBody>{renderRows()}</TableBody>
|
|
212
|
-
</Table>
|
|
213
|
-
</div>
|
|
214
|
-
</div>
|
|
215
|
-
{actions && <div className="shrink-0 border-t">{actions}</div>}
|
|
216
|
-
</div>
|
|
217
|
-
);
|
|
218
|
-
}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
2
|
-
// AllBlue - 理想之海
|
|
3
|
-
// Copyright (C) 2026 AllBlue Contributors
|
|
4
|
-
//
|
|
5
|
-
// This program is free software: you can redistribute it and/or modify
|
|
6
|
-
// it under the terms of the GNU Affero General Public License as published by
|
|
7
|
-
// the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
// (at your option) any later version.
|
|
9
|
-
//
|
|
10
|
-
// This program is distributed in the hope that it will be useful,
|
|
11
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
// GNU Affero General Public License for more details.
|
|
14
|
-
//
|
|
15
|
-
// You should have received a copy of the GNU Affero General Public License
|
|
16
|
-
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
-
|
|
18
|
-
import { useNavigate } from "@tanstack/react-router";
|
|
19
|
-
import { m } from '@/paraglide/messages.js'
|
|
20
|
-
import { Button } from "@/components/ui/button";
|
|
21
|
-
import { Skeleton } from "@/components/ui/skeleton";
|
|
22
|
-
import { ArrowLeftIcon } from "lucide-react";
|
|
23
|
-
|
|
24
|
-
interface TableDetailLayoutProps {
|
|
25
|
-
backHref: string;
|
|
26
|
-
backLabel?: string;
|
|
27
|
-
title: string;
|
|
28
|
-
subtitle?: string;
|
|
29
|
-
avatar?: React.ReactNode;
|
|
30
|
-
badges?: React.ReactNode;
|
|
31
|
-
actions?: React.ReactNode;
|
|
32
|
-
loading?: boolean;
|
|
33
|
-
children: React.ReactNode;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function TableDetailLayout({
|
|
37
|
-
backHref,
|
|
38
|
-
backLabel,
|
|
39
|
-
title,
|
|
40
|
-
subtitle,
|
|
41
|
-
avatar,
|
|
42
|
-
badges,
|
|
43
|
-
actions,
|
|
44
|
-
loading,
|
|
45
|
-
children,
|
|
46
|
-
}: TableDetailLayoutProps) {
|
|
47
|
-
const navigate = useNavigate();
|
|
48
|
-
const resolvedBackLabel = backLabel ?? m.common_common_backToList()
|
|
49
|
-
|
|
50
|
-
if (loading) {
|
|
51
|
-
return (
|
|
52
|
-
<div className="p-6 space-y-6">
|
|
53
|
-
<Skeleton className="h-8 w-24" />
|
|
54
|
-
<div className="flex items-center gap-4">
|
|
55
|
-
<Skeleton className="h-12 w-12 rounded-full" />
|
|
56
|
-
<div className="space-y-2">
|
|
57
|
-
<Skeleton className="h-6 w-40" />
|
|
58
|
-
<Skeleton className="h-4 w-60" />
|
|
59
|
-
</div>
|
|
60
|
-
</div>
|
|
61
|
-
<Skeleton className="h-64 w-full" />
|
|
62
|
-
</div>
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<div>
|
|
68
|
-
<div className="sticky top-0 z-10 bg-background border-b px-6 py-2.5">
|
|
69
|
-
<Button
|
|
70
|
-
variant="ghost"
|
|
71
|
-
size="sm"
|
|
72
|
-
onClick={() => navigate({ to: backHref })}
|
|
73
|
-
className="gap-1.5 text-muted-foreground hover:text-foreground"
|
|
74
|
-
>
|
|
75
|
-
<ArrowLeftIcon className="h-4 w-4" />
|
|
76
|
-
{resolvedBackLabel}
|
|
77
|
-
</Button>
|
|
78
|
-
</div>
|
|
79
|
-
<div className="p-6 pt-4 space-y-6">
|
|
80
|
-
<div className="flex items-start justify-between">
|
|
81
|
-
<div className="flex items-center gap-4">
|
|
82
|
-
{avatar}
|
|
83
|
-
<div>
|
|
84
|
-
<div className="flex items-center gap-2">
|
|
85
|
-
<h1 className="text-2xl font-bold">{title}</h1>
|
|
86
|
-
{badges}
|
|
87
|
-
</div>
|
|
88
|
-
{subtitle && <p className="text-muted-foreground mt-1">{subtitle}</p>}
|
|
89
|
-
</div>
|
|
90
|
-
</div>
|
|
91
|
-
{actions && <div className="flex gap-2">{actions}</div>}
|
|
92
|
-
</div>
|
|
93
|
-
|
|
94
|
-
{children}
|
|
95
|
-
</div>
|
|
96
|
-
</div>
|
|
97
|
-
);
|
|
98
|
-
}
|