@allbluecn/admin-app 0.1.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.
Files changed (276) hide show
  1. package/package.json +86 -0
  2. package/src/client.tsx +31 -0
  3. package/src/components/admin/admin-user-menu.tsx +90 -0
  4. package/src/components/admin/developer-log.tsx +356 -0
  5. package/src/components/ai-provider/model-list-editor.tsx +147 -0
  6. package/src/components/ai-provider/provider-form.tsx +434 -0
  7. package/src/components/ai-provider/provider-icon.tsx +43 -0
  8. package/src/components/ai-provider/provider-logo.tsx +87 -0
  9. package/src/components/ai-provider/provider-table.tsx +258 -0
  10. package/src/components/auth/admin-login-form.tsx +214 -0
  11. package/src/components/auth/auth-brand-panel.tsx +60 -0
  12. package/src/components/auth/auth-header.tsx +38 -0
  13. package/src/components/auth/auth-layout.tsx +66 -0
  14. package/src/components/auth/auth-providers.tsx +34 -0
  15. package/src/components/auth/icon-input.tsx +46 -0
  16. package/src/components/auth/oauth-section.tsx +51 -0
  17. package/src/components/auth/password-input.tsx +67 -0
  18. package/src/components/common/page-header.tsx +42 -0
  19. package/src/components/common/placeholder-page.tsx +42 -0
  20. package/src/components/component/component-form-dialog.tsx +348 -0
  21. package/src/components/component/component-import-dialog.tsx +235 -0
  22. package/src/components/component/component-table.tsx +153 -0
  23. package/src/components/data-table/data-table-pagination.tsx +114 -0
  24. package/src/components/data-table/data-table.tsx +218 -0
  25. package/src/components/data-table/table-detail-layout.tsx +99 -0
  26. package/src/components/dependency/changelog-dialog.tsx +108 -0
  27. package/src/components/dependency/columns.tsx +232 -0
  28. package/src/components/dependency/dependency-table.tsx +368 -0
  29. package/src/components/dependency/edit-dialog.tsx +200 -0
  30. package/src/components/knowledge-public/bookmark-form-dialog.tsx +215 -0
  31. package/src/components/knowledge-public/compliance-form-dialog.tsx +308 -0
  32. package/src/components/knowledge-public/legal-form-dialog.tsx +315 -0
  33. package/src/components/layout/sidebar-02/app-sidebar.tsx +160 -0
  34. package/src/components/layout/sidebar-02/index.tsx +33 -0
  35. package/src/components/layout/sidebar-02/logo.tsx +40 -0
  36. package/src/components/layout/sidebar-02/nav-main.tsx +153 -0
  37. package/src/components/layout/sidebar-02/nav-notifications.tsx +78 -0
  38. package/src/components/layout/sidebar-02/team-switcher.tsx +106 -0
  39. package/src/components/magicui/animated-theme-toggler.tsx +272 -0
  40. package/src/components/magicui/rainbow-button.tsx +78 -0
  41. package/src/components/market/columns.tsx +151 -0
  42. package/src/components/market/market-app-form.tsx +237 -0
  43. package/src/components/market/market-app-list.tsx +156 -0
  44. package/src/components/monitoring/error-list.tsx +143 -0
  45. package/src/components/monitoring/health-cards.tsx +152 -0
  46. package/src/components/monitoring/metrics-stats.tsx +184 -0
  47. package/src/components/monitoring/request-log-table.tsx +179 -0
  48. package/src/components/providers/theme-toggle.tsx +59 -0
  49. package/src/components/settings/avatar/avatar-config.ts +46 -0
  50. package/src/components/ui/alert-dialog.tsx +216 -0
  51. package/src/components/ui/alert.tsx +76 -0
  52. package/src/components/ui/avatar.tsx +129 -0
  53. package/src/components/ui/badge.tsx +66 -0
  54. package/src/components/ui/button.tsx +84 -0
  55. package/src/components/ui/card.tsx +120 -0
  56. package/src/components/ui/checkbox.tsx +50 -0
  57. package/src/components/ui/collapsible.tsx +50 -0
  58. package/src/components/ui/dialog.tsx +185 -0
  59. package/src/components/ui/dropdown-menu.tsx +286 -0
  60. package/src/components/ui/field.tsx +255 -0
  61. package/src/components/ui/input-group.tsx +171 -0
  62. package/src/components/ui/input.tsx +36 -0
  63. package/src/components/ui/label.tsx +41 -0
  64. package/src/components/ui/pagination.tsx +146 -0
  65. package/src/components/ui/select.tsx +209 -0
  66. package/src/components/ui/separator.tsx +45 -0
  67. package/src/components/ui/sheet.tsx +164 -0
  68. package/src/components/ui/sidebar.tsx +719 -0
  69. package/src/components/ui/skeleton.tsx +30 -0
  70. package/src/components/ui/sonner.tsx +37 -0
  71. package/src/components/ui/switch.tsx +48 -0
  72. package/src/components/ui/table.tsx +133 -0
  73. package/src/components/ui/textarea.tsx +35 -0
  74. package/src/components/ui/tooltip.tsx +74 -0
  75. package/src/components/user/columns.tsx +153 -0
  76. package/src/components/user/settings-activity-log.tsx +358 -0
  77. package/src/components/user/settings-profile/constants.ts +42 -0
  78. package/src/components/user/settings-profile/types.ts +47 -0
  79. package/src/components/user/settings-profile.tsx +664 -0
  80. package/src/components/user/user-create-dialog.tsx +137 -0
  81. package/src/components/user/user-filters.tsx +117 -0
  82. package/src/hooks/use-mobile.ts +36 -0
  83. package/src/instrument.client.ts +34 -0
  84. package/src/lib/anyhub/capabilities.ts +59 -0
  85. package/src/lib/anyhub/types.ts +43 -0
  86. package/src/lib/auth-client.ts +83 -0
  87. package/src/lib/auth-utils.ts +24 -0
  88. package/src/lib/auth.config.ts +264 -0
  89. package/src/lib/avatar.ts +41 -0
  90. package/src/lib/i18n/client.ts +32 -0
  91. package/src/lib/i18n/config.ts +40 -0
  92. package/src/lib/i18n/detect.ts +43 -0
  93. package/src/lib/i18n/locales/en/admin-ai.json +128 -0
  94. package/src/lib/i18n/locales/en/admin-billing.json +56 -0
  95. package/src/lib/i18n/locales/en/admin-users.json +88 -0
  96. package/src/lib/i18n/locales/en/common.json +877 -0
  97. package/src/lib/i18n/locales/en/enterprise.json +208 -0
  98. package/src/lib/i18n/locales/zh/admin-ai.json +128 -0
  99. package/src/lib/i18n/locales/zh/admin-billing.json +56 -0
  100. package/src/lib/i18n/locales/zh/admin-users.json +88 -0
  101. package/src/lib/i18n/locales/zh/common.json +877 -0
  102. package/src/lib/i18n/locales/zh/enterprise.json +208 -0
  103. package/src/lib/i18n/server.ts +18 -0
  104. package/src/lib/i18n/types.ts +5 -0
  105. package/src/lib/monitoring-benchmarks.ts +85 -0
  106. package/src/lib/monitoring-descriptions.ts +78 -0
  107. package/src/lib/prisma.ts +18 -0
  108. package/src/lib/router-context.ts +38 -0
  109. package/src/lib/session.ts +38 -0
  110. package/src/lib/utils.ts +23 -0
  111. package/src/providers/index.tsx +45 -0
  112. package/src/routeTree.gen.ts +1199 -0
  113. package/src/router.tsx +51 -0
  114. package/src/routes/__root.tsx +170 -0
  115. package/src/routes/_nav/ai-providers/$id/edit/route.lazy.tsx +74 -0
  116. package/src/routes/_nav/ai-providers/$id/edit/route.tsx +35 -0
  117. package/src/routes/_nav/ai-providers/index/route.lazy.tsx +33 -0
  118. package/src/routes/_nav/ai-providers/new/route.lazy.tsx +31 -0
  119. package/src/routes/_nav/ai-providers/new/route.tsx +20 -0
  120. package/src/routes/_nav/ai-providers/route.lazy.tsx +26 -0
  121. package/src/routes/_nav/ai-providers/route.tsx +31 -0
  122. package/src/routes/_nav/apps/route.lazy.tsx +30 -0
  123. package/src/routes/_nav/apps/route.tsx +20 -0
  124. package/src/routes/_nav/audit/route.lazy.tsx +100 -0
  125. package/src/routes/_nav/audit/route.tsx +25 -0
  126. package/src/routes/_nav/billing/invoices/route.lazy.tsx +86 -0
  127. package/src/routes/_nav/billing/invoices/route.tsx +25 -0
  128. package/src/routes/_nav/billing/route.lazy.tsx +48 -0
  129. package/src/routes/_nav/billing/route.tsx +27 -0
  130. package/src/routes/_nav/billing/subscriptions/$subscriptionId/route.lazy.tsx +160 -0
  131. package/src/routes/_nav/billing/subscriptions/$subscriptionId/route.tsx +25 -0
  132. package/src/routes/_nav/billing/subscriptions/route.lazy.tsx +113 -0
  133. package/src/routes/_nav/billing/subscriptions/route.tsx +28 -0
  134. package/src/routes/_nav/compliance/route.lazy.tsx +184 -0
  135. package/src/routes/_nav/compliance/route.tsx +25 -0
  136. package/src/routes/_nav/components/route.lazy.tsx +184 -0
  137. package/src/routes/_nav/components/route.tsx +40 -0
  138. package/src/routes/_nav/dashboard/route.lazy.tsx +33 -0
  139. package/src/routes/_nav/dashboard/route.tsx +20 -0
  140. package/src/routes/_nav/dependencies/route.lazy.tsx +66 -0
  141. package/src/routes/_nav/dependencies/route.tsx +32 -0
  142. package/src/routes/_nav/developer-logs/route.lazy.tsx +6 -0
  143. package/src/routes/_nav/developer-logs/route.tsx +14 -0
  144. package/src/routes/_nav/docs/route.lazy.tsx +30 -0
  145. package/src/routes/_nav/docs/route.tsx +20 -0
  146. package/src/routes/_nav/knowledge-public/bookmarks/route.lazy.tsx +355 -0
  147. package/src/routes/_nav/knowledge-public/bookmarks/route.tsx +40 -0
  148. package/src/routes/_nav/knowledge-public/compliance/route.lazy.tsx +245 -0
  149. package/src/routes/_nav/knowledge-public/compliance/route.tsx +40 -0
  150. package/src/routes/_nav/knowledge-public/legal/route.lazy.tsx +242 -0
  151. package/src/routes/_nav/knowledge-public/legal/route.tsx +40 -0
  152. package/src/routes/_nav/licenses/$licenseId/route.lazy.tsx +235 -0
  153. package/src/routes/_nav/licenses/$licenseId/route.tsx +25 -0
  154. package/src/routes/_nav/licenses/new/route.lazy.tsx +237 -0
  155. package/src/routes/_nav/licenses/route.lazy.tsx +143 -0
  156. package/src/routes/_nav/licenses/route.tsx +25 -0
  157. package/src/routes/_nav/market/route.lazy.tsx +31 -0
  158. package/src/routes/_nav/market/route.tsx +20 -0
  159. package/src/routes/_nav/monitoring/ai-usage/route.lazy.tsx +305 -0
  160. package/src/routes/_nav/monitoring/ai-usage/route.tsx +3 -0
  161. package/src/routes/_nav/monitoring/errors/route.lazy.tsx +111 -0
  162. package/src/routes/_nav/monitoring/health/route.lazy.tsx +260 -0
  163. package/src/routes/_nav/monitoring/logs/route.lazy.tsx +165 -0
  164. package/src/routes/_nav/monitoring/metrics/route.lazy.tsx +240 -0
  165. package/src/routes/_nav/monitoring/overview/route.lazy.tsx +138 -0
  166. package/src/routes/_nav/monitoring/route.lazy.tsx +68 -0
  167. package/src/routes/_nav/monitoring/route.tsx +20 -0
  168. package/src/routes/_nav/monitoring/sentry/route.lazy.tsx +399 -0
  169. package/src/routes/_nav/monitoring/sentry/route.tsx +20 -0
  170. package/src/routes/_nav/permissions/route.lazy.tsx +504 -0
  171. package/src/routes/_nav/permissions/route.tsx +26 -0
  172. package/src/routes/_nav/route.lazy.tsx +31 -0
  173. package/src/routes/_nav/route.tsx +34 -0
  174. package/src/routes/_nav/settings/route.lazy.tsx +30 -0
  175. package/src/routes/_nav/settings/route.tsx +20 -0
  176. package/src/routes/_nav/sso/route.lazy.tsx +145 -0
  177. package/src/routes/_nav/sso/route.tsx +25 -0
  178. package/src/routes/_nav/users/$userId/route.lazy.tsx +432 -0
  179. package/src/routes/_nav/users/$userId/route.tsx +27 -0
  180. package/src/routes/_nav/users/-components/users-table.tsx +38 -0
  181. package/src/routes/_nav/users/route.lazy.tsx +74 -0
  182. package/src/routes/_nav/users/route.tsx +43 -0
  183. package/src/routes/api/compliance-download/$jobId.ts +35 -0
  184. package/src/routes/api/observability/errors.ts +41 -0
  185. package/src/routes/api/observability/health.ts +30 -0
  186. package/src/routes/api.auth.$.ts +31 -0
  187. package/src/routes/api.sentry-test.ts +33 -0
  188. package/src/routes/index/route.lazy.tsx +22 -0
  189. package/src/routes/index/route.tsx +24 -0
  190. package/src/routes/login/route.lazy.tsx +46 -0
  191. package/src/routes/login/route.tsx +28 -0
  192. package/src/routes/sentry-tunnel.ts +61 -0
  193. package/src/routes/setup/route.lazy.tsx +94 -0
  194. package/src/routes/setup/route.tsx +28 -0
  195. package/src/server/__tests__/admin-ai-alerts.test.ts +113 -0
  196. package/src/server/__tests__/licenses-issue.test.ts +98 -0
  197. package/src/server/admin-ai-alerts.ts +177 -0
  198. package/src/server/admin-ai-usage.ts +134 -0
  199. package/src/server/auth-helpers.ts +51 -0
  200. package/src/server/entitlements.ts +24 -0
  201. package/src/server/knowledge-public/canonical-id.ts +55 -0
  202. package/src/server/knowledge-public/github-sync.ts +86 -0
  203. package/src/server/license-issue.ts +78 -0
  204. package/src/server/middlewares/request.ts +26 -0
  205. package/src/server/observability/debug-middleware.ts +39 -0
  206. package/src/server/observability/error-reporter.ts +99 -0
  207. package/src/server/observability/health-check.ts +140 -0
  208. package/src/server/observability/index.ts +33 -0
  209. package/src/server/observability/logger.ts +49 -0
  210. package/src/server/observability/metrics.ts +105 -0
  211. package/src/server/observability/request-middleware.ts +125 -0
  212. package/src/server/observability/timing.ts +42 -0
  213. package/src/server/pro-services.ts +32 -0
  214. package/src/server/serverFns/admin-billing.ts +94 -0
  215. package/src/server/serverFns/ai-provider/create.ts +92 -0
  216. package/src/server/serverFns/ai-provider/delete.ts +42 -0
  217. package/src/server/serverFns/ai-provider/get.ts +35 -0
  218. package/src/server/serverFns/ai-provider/list.ts +92 -0
  219. package/src/server/serverFns/ai-provider/update.ts +73 -0
  220. package/src/server/serverFns/anyhub/market.ts +64 -0
  221. package/src/server/serverFns/audit.ts +57 -0
  222. package/src/server/serverFns/auth/session.ts +26 -0
  223. package/src/server/serverFns/auth/setup.ts +73 -0
  224. package/src/server/serverFns/compliance.ts +85 -0
  225. package/src/server/serverFns/components/import.ts +197 -0
  226. package/src/server/serverFns/components/list.ts +51 -0
  227. package/src/server/serverFns/components/mutations.ts +84 -0
  228. package/src/server/serverFns/dependency/helpers.ts +245 -0
  229. package/src/server/serverFns/dependency/list.ts +127 -0
  230. package/src/server/serverFns/dependency/sync.ts +123 -0
  231. package/src/server/serverFns/dependency/update.ts +51 -0
  232. package/src/server/serverFns/developer-log-auto-generate.ts +176 -0
  233. package/src/server/serverFns/developer-logs.ts +132 -0
  234. package/src/server/serverFns/knowledge-public/bookmarks/create.ts +53 -0
  235. package/src/server/serverFns/knowledge-public/bookmarks/delete.ts +31 -0
  236. package/src/server/serverFns/knowledge-public/bookmarks/detail.ts +32 -0
  237. package/src/server/serverFns/knowledge-public/bookmarks/list.ts +66 -0
  238. package/src/server/serverFns/knowledge-public/bookmarks/sync-all-github.ts +56 -0
  239. package/src/server/serverFns/knowledge-public/bookmarks/update.ts +50 -0
  240. package/src/server/serverFns/knowledge-public/compliance/create.ts +58 -0
  241. package/src/server/serverFns/knowledge-public/compliance/delete.ts +31 -0
  242. package/src/server/serverFns/knowledge-public/compliance/detail.ts +32 -0
  243. package/src/server/serverFns/knowledge-public/compliance/list.ts +59 -0
  244. package/src/server/serverFns/knowledge-public/compliance/update.ts +53 -0
  245. package/src/server/serverFns/knowledge-public/legal/create.ts +62 -0
  246. package/src/server/serverFns/knowledge-public/legal/delete.ts +31 -0
  247. package/src/server/serverFns/knowledge-public/legal/detail.ts +32 -0
  248. package/src/server/serverFns/knowledge-public/legal/list.ts +60 -0
  249. package/src/server/serverFns/knowledge-public/legal/update.ts +55 -0
  250. package/src/server/serverFns/licenses.ts +92 -0
  251. package/src/server/serverFns/locale.ts +10 -0
  252. package/src/server/serverFns/monitoring/check-ai-alerts.ts +13 -0
  253. package/src/server/serverFns/monitoring/get-ai-usage-overview.ts +25 -0
  254. package/src/server/serverFns/monitoring/get-errors.ts +43 -0
  255. package/src/server/serverFns/monitoring/get-health-settings.ts +35 -0
  256. package/src/server/serverFns/monitoring/get-health.ts +55 -0
  257. package/src/server/serverFns/monitoring/get-metrics.ts +46 -0
  258. package/src/server/serverFns/monitoring/get-request-logs.ts +66 -0
  259. package/src/server/serverFns/monitoring/report-error.ts +55 -0
  260. package/src/server/serverFns/monitoring/reset.ts +70 -0
  261. package/src/server/serverFns/permissions.ts +214 -0
  262. package/src/server/serverFns/sentry/config.ts +88 -0
  263. package/src/server/serverFns/sso-config.ts +83 -0
  264. package/src/server/serverFns/user/create.ts +40 -0
  265. package/src/server/serverFns/user/delete.ts +29 -0
  266. package/src/server/serverFns/user/detail.ts +45 -0
  267. package/src/server/serverFns/user/list.ts +56 -0
  268. package/src/server/serverFns/user/reset-password.ts +28 -0
  269. package/src/server/serverFns/user/update-role.ts +26 -0
  270. package/src/server/serverFns/user/update-status.ts +26 -0
  271. package/src/server.ts +27 -0
  272. package/src/start.ts +85 -0
  273. package/src/styles/_keyframe-animations.scss +91 -0
  274. package/src/styles/_variables.scss +296 -0
  275. package/src/styles/globals.css +200 -0
  276. package/src/types/start-authjs.d.ts +27 -0
@@ -0,0 +1,355 @@
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 { createLazyFileRoute, useNavigate, useRouter } from '@tanstack/react-router'
19
+ import { useState, useTransition } from 'react'
20
+ import { useTranslation } from 'react-i18next'
21
+ import {
22
+ PlusIcon,
23
+ PencilIcon,
24
+ Trash2Icon,
25
+ SearchIcon,
26
+ StarIcon,
27
+ RefreshCwIcon,
28
+ ExternalLinkIcon,
29
+ Folder,
30
+ Globe,
31
+ Code,
32
+ Book,
33
+ BookOpen,
34
+ type LucideIcon,
35
+ } from 'lucide-react'
36
+
37
+ const categoryIconMap: Record<string, LucideIcon> = {
38
+ Folder, Globe, Code, Book, BookOpen,
39
+ }
40
+ import { DataTable, type AdminColumnDef } from '@/components/data-table/data-table'
41
+ import { Button } from '@/components/ui/button'
42
+ import { Input } from '@/components/ui/input'
43
+ import { Badge } from '@/components/ui/badge'
44
+ import {
45
+ AlertDialog,
46
+ AlertDialogAction,
47
+ AlertDialogCancel,
48
+ AlertDialogContent,
49
+ AlertDialogDescription,
50
+ AlertDialogFooter,
51
+ AlertDialogHeader,
52
+ AlertDialogTitle,
53
+ } from '@/components/ui/alert-dialog'
54
+ import { toast } from '@/components/ui/sonner'
55
+ import {
56
+ BookmarkFormDialog,
57
+ type BookmarkRow,
58
+ } from '@/components/knowledge-public/bookmark-form-dialog'
59
+ import { adminDeleteBookmarkFn } from '@/server/serverFns/knowledge-public/bookmarks/delete'
60
+ import { adminSyncAllGithubFn } from '@/server/serverFns/knowledge-public/bookmarks/sync-all-github'
61
+
62
+ export const Route = createLazyFileRoute('/_nav/knowledge-public/bookmarks')({
63
+ pendingComponent: () => (
64
+ <div className="flex h-64 items-center justify-center">
65
+ <div className="size-8 animate-spin rounded-full border-2 border-primary border-t-transparent" />
66
+ </div>
67
+ ),
68
+ component: BookmarksPage,
69
+ })
70
+
71
+ function FaviconCell({ faviconUrl, categoryIcon }: { faviconUrl: string | null; categoryIcon?: string }) {
72
+ const [showFallback, setShowFallback] = useState(false)
73
+ const Icon = categoryIconMap[categoryIcon ?? 'Folder'] ?? Folder
74
+ if (faviconUrl && !showFallback) {
75
+ return (
76
+ <img
77
+ src={faviconUrl}
78
+ alt=""
79
+ className="size-4 shrink-0 rounded-sm"
80
+ onError={() => setShowFallback(true)}
81
+ />
82
+ )
83
+ }
84
+ return (
85
+ <span className="flex size-4 shrink-0 items-center justify-center rounded-sm text-muted-foreground">
86
+ <Icon className="size-3.5" />
87
+ </span>
88
+ )
89
+ }
90
+
91
+ function BookmarksPage() {
92
+ const { t } = useTranslation('common')
93
+ const { items: rawItems, total } = Route.useLoaderData()
94
+ const items = rawItems as unknown as BookmarkRow[]
95
+ const { search } = Route.useSearch()
96
+ const navigate = useNavigate()
97
+ const router = useRouter()
98
+ const [searchInput, setSearchInput] = useState(search ?? '')
99
+ const [formOpen, setFormOpen] = useState(false)
100
+ const [editing, setEditing] = useState<BookmarkRow | null>(null)
101
+ const [deleting, setDeleting] = useState<BookmarkRow | null>(null)
102
+ const [deletePending, startDelete] = useTransition()
103
+ const [syncing, startSync] = useTransition()
104
+
105
+ function refresh() {
106
+ router.invalidate()
107
+ }
108
+
109
+ function applySearch() {
110
+ navigate({
111
+ to: '/knowledge-public/bookmarks',
112
+ search: (s) => ({ ...s, search: searchInput.trim() || undefined }),
113
+ })
114
+ }
115
+
116
+ function openCreate() {
117
+ setEditing(null)
118
+ setFormOpen(true)
119
+ }
120
+ function openEdit(row: BookmarkRow) {
121
+ setEditing(row)
122
+ setFormOpen(true)
123
+ }
124
+
125
+ function confirmDelete() {
126
+ if (!deleting) return
127
+ startDelete(async () => {
128
+ try {
129
+ await adminDeleteBookmarkFn({ data: { id: deleting.id } })
130
+ toast.success(t('knowledgePublic.bookmarks.deleted'))
131
+ setDeleting(null)
132
+ refresh()
133
+ } catch (err) {
134
+ toast.error(err instanceof Error ? err.message : t('common.deleteFailed'))
135
+ }
136
+ })
137
+ }
138
+
139
+ function syncAllGithub() {
140
+ startSync(async () => {
141
+ try {
142
+ const res = await adminSyncAllGithubFn({ data: { force: true } })
143
+ toast.success(
144
+ t('knowledgePublic.bookmarks.syncComplete', { total: res.total, success: res.success, failed: res.failed }),
145
+ )
146
+ refresh()
147
+ } catch (err) {
148
+ toast.error(err instanceof Error ? err.message : t('knowledgePublic.bookmarks.syncFailed'))
149
+ }
150
+ })
151
+ }
152
+
153
+ const columns: AdminColumnDef<BookmarkRow>[] = [
154
+ {
155
+ accessorKey: 'title',
156
+ header: t('knowledgePublic.bookmarks.columns.website'),
157
+ cell: ({ row }) => {
158
+ const b = row.original
159
+ return (
160
+ <div className="flex min-w-[180px] items-center gap-2">
161
+ <FaviconCell faviconUrl={b.faviconUrl} categoryIcon={b.categoryIcon} />
162
+ <div className="flex flex-col">
163
+ <span className="font-medium">{b.title}</span>
164
+ {b.isGithub && (
165
+ <Badge variant="secondary" className="w-fit font-normal">
166
+ GitHub
167
+ </Badge>
168
+ )}
169
+ </div>
170
+ </div>
171
+ )
172
+ },
173
+ },
174
+ {
175
+ accessorKey: 'url',
176
+ header: t('knowledgePublic.bookmarks.columns.url'),
177
+ cell: ({ row }) => {
178
+ const url = row.original.url
179
+ return (
180
+ <a
181
+ href={url}
182
+ target="_blank"
183
+ rel="noopener noreferrer"
184
+ className="inline-flex max-w-[280px] items-center gap-1 text-sm text-muted-foreground hover:text-foreground hover:underline"
185
+ >
186
+ <span className="truncate">{url}</span>
187
+ <ExternalLinkIcon className="size-3 shrink-0" />
188
+ </a>
189
+ )
190
+ },
191
+ },
192
+ {
193
+ accessorKey: 'categoryId',
194
+ header: t('knowledgePublic.bookmarks.columns.category'),
195
+ cell: ({ row }) =>
196
+ row.original.categoryId ? (
197
+ <Badge variant="outline" className="font-mono text-xs">
198
+ {row.original.categoryId}
199
+ </Badge>
200
+ ) : (
201
+ <span className="text-muted-foreground">-</span>
202
+ ),
203
+ },
204
+ {
205
+ id: 'github',
206
+ header: 'GitHub',
207
+ cell: ({ row }) => {
208
+ const b = row.original
209
+ if (!b.isGithub) return <span className="text-muted-foreground">-</span>
210
+ return (
211
+ <div className="flex flex-col gap-0.5">
212
+ <span className="inline-flex items-center gap-1 text-sm">
213
+ <StarIcon className="size-3.5 text-amber-500" />
214
+ {b.githubStars != null ? b.githubStars.toLocaleString('en-US') : '-'}
215
+ </span>
216
+ {b.githubLatestVersion && (
217
+ <Badge variant="secondary" className="w-fit font-mono text-xs font-normal">
218
+ {b.githubLatestVersion}
219
+ </Badge>
220
+ )}
221
+ </div>
222
+ )
223
+ },
224
+ },
225
+ {
226
+ accessorKey: 'tags',
227
+ header: t('knowledgePublic.bookmarks.columns.tags'),
228
+ cell: ({ row }) => (
229
+ <div className="flex max-w-xs flex-wrap gap-1">
230
+ {row.original.tags.length === 0 ? (
231
+ <span className="text-muted-foreground">-</span>
232
+ ) : (
233
+ row.original.tags.map((tag) => (
234
+ <Badge key={tag} variant="secondary" className="font-normal">
235
+ {tag}
236
+ </Badge>
237
+ ))
238
+ )}
239
+ </div>
240
+ ),
241
+ },
242
+ {
243
+ accessorKey: 'createdAt',
244
+ header: t('knowledgePublic.bookmarks.columns.createdAt'),
245
+ cell: ({ row }) => (
246
+ <span className="text-muted-foreground">
247
+ {new Date(row.original.createdAt).toLocaleDateString('zh-CN')}
248
+ </span>
249
+ ),
250
+ },
251
+ {
252
+ id: 'actions',
253
+ header: '',
254
+ cell: ({ row }) => (
255
+ <div className="flex items-center gap-1">
256
+ <Button
257
+ variant="ghost"
258
+ size="sm"
259
+ onClick={(e) => {
260
+ e.stopPropagation()
261
+ openEdit(row.original)
262
+ }}
263
+ >
264
+ <PencilIcon className="mr-1 size-3.5" />
265
+ {t('common.edit')}
266
+ </Button>
267
+ <Button
268
+ variant="ghost"
269
+ size="sm"
270
+ className="text-destructive hover:text-destructive"
271
+ onClick={(e) => {
272
+ e.stopPropagation()
273
+ setDeleting(row.original)
274
+ }}
275
+ >
276
+ <Trash2Icon className="mr-1 size-3.5" />
277
+ {t('common.delete')}
278
+ </Button>
279
+ </div>
280
+ ),
281
+ },
282
+ ]
283
+
284
+ return (
285
+ <div className="space-y-4 p-6">
286
+ <div className="flex items-center justify-between">
287
+ <div>
288
+ <h2 className="text-xl font-bold">{t('knowledgePublic.bookmarks.title')}</h2>
289
+ <p className="text-sm text-muted-foreground">{t('knowledgePublic.bookmarks.subtitle', { total })}</p>
290
+ </div>
291
+ <div className="flex items-center gap-2">
292
+ <Button variant="outline" onClick={syncAllGithub} disabled={syncing}>
293
+ <RefreshCwIcon className={`mr-1 size-4 ${syncing ? 'animate-spin' : ''}`} />
294
+ {syncing ? t('knowledgePublic.bookmarks.syncing') : t('knowledgePublic.bookmarks.syncGithub')}
295
+ </Button>
296
+ <Button onClick={openCreate}>
297
+ <PlusIcon className="mr-1 size-4" />
298
+ {t('common.create')}
299
+ </Button>
300
+ </div>
301
+ </div>
302
+
303
+ <div className="flex items-center gap-2">
304
+ <div className="relative max-w-sm flex-1">
305
+ <SearchIcon className="absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
306
+ <Input
307
+ value={searchInput}
308
+ onChange={(e) => setSearchInput(e.target.value)}
309
+ onKeyDown={(e) => {
310
+ if (e.key === 'Enter') applySearch()
311
+ }}
312
+ placeholder={t('knowledgePublic.bookmarks.placeholder')}
313
+ className="pl-8"
314
+ />
315
+ </div>
316
+ <Button variant="outline" onClick={applySearch}>
317
+ {t('common.search')}
318
+ </Button>
319
+ </div>
320
+
321
+ <DataTable columns={columns} data={items} />
322
+
323
+ <BookmarkFormDialog
324
+ open={formOpen}
325
+ onOpenChange={setFormOpen}
326
+ item={editing}
327
+ onSuccess={refresh}
328
+ />
329
+
330
+ <AlertDialog open={!!deleting} onOpenChange={(o) => !o && setDeleting(null)}>
331
+ <AlertDialogContent>
332
+ <AlertDialogHeader>
333
+ <AlertDialogTitle>{t('knowledgePublic.bookmarks.deleteConfirmTitle')}</AlertDialogTitle>
334
+ <AlertDialogDescription>
335
+ {t('knowledgePublic.bookmarks.deleteConfirmDesc', { title: deleting?.title })}
336
+ </AlertDialogDescription>
337
+ </AlertDialogHeader>
338
+ <AlertDialogFooter>
339
+ <AlertDialogCancel disabled={deletePending}>{t('common.cancel')}</AlertDialogCancel>
340
+ <AlertDialogAction
341
+ onClick={(e) => {
342
+ e.preventDefault()
343
+ confirmDelete()
344
+ }}
345
+ disabled={deletePending}
346
+ className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
347
+ >
348
+ {deletePending ? t('common.deleting') : t('common.delete')}
349
+ </AlertDialogAction>
350
+ </AlertDialogFooter>
351
+ </AlertDialogContent>
352
+ </AlertDialog>
353
+ </div>
354
+ )
355
+ }
@@ -0,0 +1,40 @@
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 { createFileRoute } from '@tanstack/react-router'
19
+ import { z } from 'zod'
20
+ import { adminListBookmarksFn } from '@/server/serverFns/knowledge-public/bookmarks/list'
21
+
22
+ const bookmarkSearchSchema = z.object({
23
+ search: z.string().optional(),
24
+ categoryId: z.string().optional(),
25
+ isGithub: z.boolean().optional(),
26
+ })
27
+
28
+ export const Route = createFileRoute('/_nav/knowledge-public/bookmarks')({
29
+ validateSearch: bookmarkSearchSchema,
30
+ loaderDeps: ({ search }) => search,
31
+ loader: async ({ deps }) => {
32
+ return adminListBookmarksFn({
33
+ data: {
34
+ search: deps.search,
35
+ categoryId: deps.categoryId,
36
+ isGithub: deps.isGithub,
37
+ },
38
+ })
39
+ },
40
+ })
@@ -0,0 +1,245 @@
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 { createLazyFileRoute, useNavigate, useRouter } from '@tanstack/react-router'
19
+ import { useState, useTransition } from 'react'
20
+ import { useTranslation } from 'react-i18next'
21
+ import { PlusIcon, PencilIcon, Trash2Icon, SearchIcon } from 'lucide-react'
22
+ import { DataTable, type AdminColumnDef } from '@/components/data-table/data-table'
23
+ import { Button } from '@/components/ui/button'
24
+ import { Input } from '@/components/ui/input'
25
+ import { Badge } from '@/components/ui/badge'
26
+ import {
27
+ AlertDialog,
28
+ AlertDialogAction,
29
+ AlertDialogCancel,
30
+ AlertDialogContent,
31
+ AlertDialogDescription,
32
+ AlertDialogFooter,
33
+ AlertDialogHeader,
34
+ AlertDialogTitle,
35
+ } from '@/components/ui/alert-dialog'
36
+ import { toast } from '@/components/ui/sonner'
37
+ import {
38
+ ComplianceFormDialog,
39
+ type ComplianceRow,
40
+ } from '@/components/knowledge-public/compliance-form-dialog'
41
+ import { adminDeleteComplianceFn } from '@/server/serverFns/knowledge-public/compliance/delete'
42
+
43
+ export const Route = createLazyFileRoute('/_nav/knowledge-public/compliance')({
44
+ pendingComponent: () => (
45
+ <div className="flex h-64 items-center justify-center">
46
+ <div className="size-8 animate-spin rounded-full border-2 border-primary border-t-transparent" />
47
+ </div>
48
+ ),
49
+ component: CompliancePage,
50
+ })
51
+
52
+ function CompliancePage() {
53
+ const { t } = useTranslation('common')
54
+ const { items: rawItems, total } = Route.useLoaderData()
55
+ const items = rawItems as unknown as ComplianceRow[]
56
+ const { search } = Route.useSearch()
57
+ const navigate = useNavigate()
58
+ const router = useRouter()
59
+ const [searchInput, setSearchInput] = useState(search ?? '')
60
+ const [formOpen, setFormOpen] = useState(false)
61
+ const [editing, setEditing] = useState<ComplianceRow | null>(null)
62
+ const [deleting, setDeleting] = useState<ComplianceRow | null>(null)
63
+ const [deletePending, startDelete] = useTransition()
64
+
65
+ function refresh() {
66
+ router.invalidate()
67
+ }
68
+
69
+ function applySearch() {
70
+ navigate({
71
+ to: '/knowledge-public/compliance',
72
+ search: (s) => ({ ...s, search: searchInput.trim() || undefined }),
73
+ })
74
+ }
75
+
76
+ function openCreate() {
77
+ setEditing(null)
78
+ setFormOpen(true)
79
+ }
80
+ function openEdit(row: ComplianceRow) {
81
+ setEditing(row)
82
+ setFormOpen(true)
83
+ }
84
+
85
+ function confirmDelete() {
86
+ if (!deleting) return
87
+ startDelete(async () => {
88
+ try {
89
+ await adminDeleteComplianceFn({ data: { id: deleting.id } })
90
+ toast.success(t('knowledgePublic.compliance.deleted'))
91
+ setDeleting(null)
92
+ refresh()
93
+ } catch (err) {
94
+ toast.error(err instanceof Error ? err.message : t('common.deleteFailed'))
95
+ }
96
+ })
97
+ }
98
+
99
+ const columns: AdminColumnDef<ComplianceRow>[] = [
100
+ {
101
+ accessorKey: 'title',
102
+ header: t('knowledgePublic.compliance.columns.title'),
103
+ cell: ({ row }) => <span className="font-medium">{row.original.title}</span>,
104
+ },
105
+ {
106
+ accessorKey: 'industry',
107
+ header: t('knowledgePublic.compliance.columns.industry'),
108
+ cell: ({ row }) => (
109
+ <Badge variant="outline">{row.original.industry}</Badge>
110
+ ),
111
+ },
112
+ {
113
+ accessorKey: 'regulatoryBody',
114
+ header: t('knowledgePublic.compliance.columns.regulatoryBody'),
115
+ cell: ({ row }) => (
116
+ <span className="text-muted-foreground">
117
+ {row.original.regulatoryBody ?? '-'}
118
+ </span>
119
+ ),
120
+ },
121
+ {
122
+ accessorKey: 'tags',
123
+ header: t('knowledgePublic.compliance.columns.tags'),
124
+ cell: ({ row }) => (
125
+ <div className="flex max-w-xs flex-wrap gap-1">
126
+ {row.original.tags.length === 0 ? (
127
+ <span className="text-muted-foreground">-</span>
128
+ ) : (
129
+ row.original.tags.map((tag) => (
130
+ <Badge key={tag} variant="secondary" className="font-normal">
131
+ {tag}
132
+ </Badge>
133
+ ))
134
+ )}
135
+ </div>
136
+ ),
137
+ },
138
+ {
139
+ accessorKey: 'createdAt',
140
+ header: t('knowledgePublic.compliance.columns.createdAt'),
141
+ cell: ({ row }) => (
142
+ <span className="text-muted-foreground">
143
+ {new Date(row.original.createdAt).toLocaleDateString('zh-CN')}
144
+ </span>
145
+ ),
146
+ },
147
+ {
148
+ id: 'actions',
149
+ header: '',
150
+ cell: ({ row }) => (
151
+ <div className="flex items-center gap-1">
152
+ <Button
153
+ variant="ghost"
154
+ size="sm"
155
+ onClick={(e) => {
156
+ e.stopPropagation()
157
+ openEdit(row.original)
158
+ }}
159
+ >
160
+ <PencilIcon className="mr-1 size-3.5" />
161
+ {t('common.edit')}
162
+ </Button>
163
+ <Button
164
+ variant="ghost"
165
+ size="sm"
166
+ className="text-destructive hover:text-destructive"
167
+ onClick={(e) => {
168
+ e.stopPropagation()
169
+ setDeleting(row.original)
170
+ }}
171
+ >
172
+ <Trash2Icon className="mr-1 size-3.5" />
173
+ {t('common.delete')}
174
+ </Button>
175
+ </div>
176
+ ),
177
+ },
178
+ ]
179
+
180
+ return (
181
+ <div className="space-y-4 p-6">
182
+ <div className="flex items-center justify-between">
183
+ <div>
184
+ <h2 className="text-xl font-bold">{t('knowledgePublic.compliance.title')}</h2>
185
+ <p className="text-sm text-muted-foreground">{t('knowledgePublic.compliance.subtitle', { total })}</p>
186
+ </div>
187
+ <Button onClick={openCreate}>
188
+ <PlusIcon className="mr-1 size-4" />
189
+ {t('common.create')}
190
+ </Button>
191
+ </div>
192
+
193
+ <div className="flex items-center gap-2">
194
+ <div className="relative max-w-sm flex-1">
195
+ <SearchIcon className="absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
196
+ <Input
197
+ value={searchInput}
198
+ onChange={(e) => setSearchInput(e.target.value)}
199
+ onKeyDown={(e) => {
200
+ if (e.key === 'Enter') applySearch()
201
+ }}
202
+ placeholder={t('knowledgePublic.compliance.placeholder')}
203
+ className="pl-8"
204
+ />
205
+ </div>
206
+ <Button variant="outline" onClick={applySearch}>
207
+ {t('common.search')}
208
+ </Button>
209
+ </div>
210
+
211
+ <DataTable columns={columns} data={items} />
212
+
213
+ <ComplianceFormDialog
214
+ open={formOpen}
215
+ onOpenChange={setFormOpen}
216
+ item={editing}
217
+ onSuccess={refresh}
218
+ />
219
+
220
+ <AlertDialog open={!!deleting} onOpenChange={(o) => !o && setDeleting(null)}>
221
+ <AlertDialogContent>
222
+ <AlertDialogHeader>
223
+ <AlertDialogTitle>{t('knowledgePublic.compliance.deleteConfirmTitle')}</AlertDialogTitle>
224
+ <AlertDialogDescription>
225
+ {t('knowledgePublic.compliance.deleteConfirmDesc', { title: deleting?.title })}
226
+ </AlertDialogDescription>
227
+ </AlertDialogHeader>
228
+ <AlertDialogFooter>
229
+ <AlertDialogCancel disabled={deletePending}>{t('common.cancel')}</AlertDialogCancel>
230
+ <AlertDialogAction
231
+ onClick={(e) => {
232
+ e.preventDefault()
233
+ confirmDelete()
234
+ }}
235
+ disabled={deletePending}
236
+ className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
237
+ >
238
+ {deletePending ? t('common.deleting') : t('common.delete')}
239
+ </AlertDialogAction>
240
+ </AlertDialogFooter>
241
+ </AlertDialogContent>
242
+ </AlertDialog>
243
+ </div>
244
+ )
245
+ }
@@ -0,0 +1,40 @@
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 { createFileRoute } from '@tanstack/react-router'
19
+ import { z } from 'zod'
20
+ import { adminListComplianceFn } from '@/server/serverFns/knowledge-public/compliance/list'
21
+
22
+ const complianceSearchSchema = z.object({
23
+ search: z.string().optional(),
24
+ industry: z.string().optional(),
25
+ region: z.string().optional(),
26
+ })
27
+
28
+ export const Route = createFileRoute('/_nav/knowledge-public/compliance')({
29
+ validateSearch: complianceSearchSchema,
30
+ loaderDeps: ({ search }) => search,
31
+ loader: async ({ deps }) => {
32
+ return adminListComplianceFn({
33
+ data: {
34
+ search: deps.search,
35
+ industry: deps.industry,
36
+ region: deps.region,
37
+ },
38
+ })
39
+ },
40
+ })