@allbluecn/admin-app 0.4.0 → 0.5.1
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 +3 -3
- package/src/components/admin/developer-log.tsx +2 -2
- package/src/components/knowledge/public/kp-crud-page.tsx +208 -0
- package/src/components/market/market-app-form.tsx +1 -1
- package/src/components/user/settings-profile.tsx +1 -1
- package/src/components/user/user-create-dialog.tsx +1 -1
- package/src/components/user/user-detail/user-detail-dialogs.tsx +3 -3
- package/src/paraglide/messages/_index.js +0 -2
- package/src/routes/_nav/knowledge-public/bookmarks/route.lazy.tsx +36 -111
- package/src/routes/_nav/knowledge-public/compliance/route.lazy.tsx +29 -105
- package/src/routes/_nav/knowledge-public/legal/route.lazy.tsx +30 -108
- package/src/routes/_nav/monitoring/errors/route.lazy.tsx +1 -1
- package/src/routes/_nav/monitoring/logs/route.lazy.tsx +1 -1
- package/src/routes/_nav/monitoring/metrics/route.lazy.tsx +1 -1
- package/src/routes/_nav/permissions/route.lazy.tsx +1 -1
- package/src/routes/_nav/sso/route.lazy.tsx +1 -1
- package/src/server/knowledge/public/kp-factory.ts +134 -0
- package/src/server/serverFns/knowledge/public/bookmarks/create.ts +23 -25
- package/src/server/serverFns/knowledge/public/bookmarks/delete.ts +2 -14
- package/src/server/serverFns/knowledge/public/bookmarks/detail.ts +2 -11
- package/src/server/serverFns/knowledge/public/bookmarks/list.ts +32 -38
- package/src/server/serverFns/knowledge/public/bookmarks/update.ts +23 -22
- package/src/server/serverFns/knowledge/public/compliance/create.ts +10 -15
- package/src/server/serverFns/knowledge/public/compliance/delete.ts +2 -14
- package/src/server/serverFns/knowledge/public/compliance/detail.ts +2 -11
- package/src/server/serverFns/knowledge/public/compliance/list.ts +24 -31
- package/src/server/serverFns/knowledge/public/compliance/update.ts +22 -22
- package/src/server/serverFns/knowledge/public/legal/create.ts +11 -15
- package/src/server/serverFns/knowledge/public/legal/delete.ts +2 -14
- package/src/server/serverFns/knowledge/public/legal/detail.ts +2 -11
- package/src/server/serverFns/knowledge/public/legal/list.ts +24 -32
- package/src/server/serverFns/knowledge/public/legal/update.ts +20 -22
- package/src/paraglide/messages/common_button_cancel.js +0 -29
- package/src/paraglide/messages/common_dependency_table_pagination_total.js +0 -29
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allbluecn/admin-app",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "AGPL-3.0-or-later",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@allbluecn/database": "0.
|
|
9
|
-
"@allbluecn/kernel": "0.
|
|
8
|
+
"@allbluecn/database": "0.11.0",
|
|
9
|
+
"@allbluecn/kernel": "0.12.0",
|
|
10
10
|
"@auth/core": "^0.41.2",
|
|
11
11
|
"@base-ui/react": "^1.8.0",
|
|
12
12
|
"@fontsource-variable/inter": "^5.3.0",
|
|
@@ -133,7 +133,7 @@ function DeveloperLogDialog({
|
|
|
133
133
|
</div>
|
|
134
134
|
</div>
|
|
135
135
|
<DialogFooter>
|
|
136
|
-
<Button variant="outline" onClick={() => onOpenChange(false)}>{m.
|
|
136
|
+
<Button variant="outline" onClick={() => onOpenChange(false)}>{m.common_common_cancel()}</Button>
|
|
137
137
|
<Button onClick={handleSave}>{m.common_button_save()}</Button>
|
|
138
138
|
</DialogFooter>
|
|
139
139
|
</DialogContent>
|
|
@@ -335,7 +335,7 @@ function DeveloperLogPage() {
|
|
|
335
335
|
trigger={<Button variant="ghost" size="icon" className="size-7 text-destructive"><Trash2 className="size-3.5" /></Button>}
|
|
336
336
|
title={m.common_button_delete()}
|
|
337
337
|
description={m.common_developerLogs_deleteConfirm()}
|
|
338
|
-
cancelLabel={m.
|
|
338
|
+
cancelLabel={m.common_common_cancel()}
|
|
339
339
|
confirmLabel={m.common_button_confirm()}
|
|
340
340
|
confirmClassName="bg-destructive hover:bg-destructive/90"
|
|
341
341
|
onConfirm={() => handleDelete(entry.id)}
|
|
@@ -0,0 +1,208 @@
|
|
|
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
|
+
// S34(审计 A11 建议):knowledge-public 三管理页(bookmarks/compliance/legal)
|
|
19
|
+
// 的同构 CRUD 骨架抽取——状态机(搜索同步/表单开合/删除确认)收进 useKpCrud,
|
|
20
|
+
// 页面 chrome(标题头/搜索栏/表格容器)收进 KpCrudShell。列定义与表单对话框
|
|
21
|
+
// 各域差异大,保留在各页(audit/billing 页结构各异不强抽,审计同口径)。
|
|
22
|
+
|
|
23
|
+
import { useEffect, useState, useTransition, type ReactNode } from 'react'
|
|
24
|
+
import { useNavigate, useRouter } from '@tanstack/react-router'
|
|
25
|
+
import { PlusIcon, SearchIcon } from 'lucide-react'
|
|
26
|
+
import { Button } from '@/components/ui/button'
|
|
27
|
+
import { Input } from '@/components/ui/input'
|
|
28
|
+
import { DataTable, type AdminColumnDef } from '@/components/data-table/data-table'
|
|
29
|
+
import { ConfirmDialog } from '@/components/confirm-dialog'
|
|
30
|
+
import { toast } from '@/components/ui/toast'
|
|
31
|
+
import { m } from '@/paraglide/messages.js'
|
|
32
|
+
|
|
33
|
+
export interface KpCrud<Row> {
|
|
34
|
+
searchInput: string
|
|
35
|
+
setSearchInput: (v: string) => void
|
|
36
|
+
applySearch: () => void
|
|
37
|
+
refresh: () => void
|
|
38
|
+
formOpen: boolean
|
|
39
|
+
setFormOpen: (o: boolean) => void
|
|
40
|
+
editing: Row | null
|
|
41
|
+
openCreate: () => void
|
|
42
|
+
openEdit: (row: Row) => void
|
|
43
|
+
deleting: Row | null
|
|
44
|
+
setDeleting: (row: Row | null) => void
|
|
45
|
+
deletePending: boolean
|
|
46
|
+
confirmDelete: () => void
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 三页同构 CRUD 状态机(S34):搜索同步 / 表单开合 / 删除确认 */
|
|
50
|
+
export function useKpCrud<Row extends { id: string; title?: string }>(args: {
|
|
51
|
+
routePath: string
|
|
52
|
+
search?: string
|
|
53
|
+
/** 删除请求(确认对话框提交时调用,错误 toast 在此统一处理) */
|
|
54
|
+
deleteFn: (row: Row) => Promise<unknown>
|
|
55
|
+
/** 删除成功专用文案(各域 i18n key) */
|
|
56
|
+
deleteSuccessToast: string
|
|
57
|
+
}): KpCrud<Row> {
|
|
58
|
+
const navigate = useNavigate()
|
|
59
|
+
const router = useRouter()
|
|
60
|
+
const [searchInput, setSearchInput] = useState(args.search ?? '')
|
|
61
|
+
const [formOpen, setFormOpen] = useState(false)
|
|
62
|
+
const [editing, setEditing] = useState<Row | null>(null)
|
|
63
|
+
const [deleting, setDeleting] = useState<Row | null>(null)
|
|
64
|
+
const [deletePending, startDelete] = useTransition()
|
|
65
|
+
|
|
66
|
+
// URL search 变化(后退/前进、外部导航)同步回输入框
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
setSearchInput(args.search ?? '')
|
|
69
|
+
}, [args.search])
|
|
70
|
+
|
|
71
|
+
function refresh() {
|
|
72
|
+
router.invalidate()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function applySearch() {
|
|
76
|
+
navigate({
|
|
77
|
+
to: args.routePath,
|
|
78
|
+
search: (s: Record<string, unknown>) => ({ ...s, search: searchInput.trim() || undefined }),
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function openCreate() {
|
|
83
|
+
setEditing(null)
|
|
84
|
+
setFormOpen(true)
|
|
85
|
+
}
|
|
86
|
+
function openEdit(row: Row) {
|
|
87
|
+
setEditing(row)
|
|
88
|
+
setFormOpen(true)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function confirmDelete() {
|
|
92
|
+
if (!deleting) return
|
|
93
|
+
startDelete(async () => {
|
|
94
|
+
try {
|
|
95
|
+
await args.deleteFn(deleting)
|
|
96
|
+
toast.success(args.deleteSuccessToast)
|
|
97
|
+
setDeleting(null)
|
|
98
|
+
refresh()
|
|
99
|
+
} catch (err) {
|
|
100
|
+
toast.error(err instanceof Error ? err.message : m.common_common_deleteFailed())
|
|
101
|
+
}
|
|
102
|
+
})
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
searchInput,
|
|
107
|
+
setSearchInput,
|
|
108
|
+
applySearch,
|
|
109
|
+
refresh,
|
|
110
|
+
formOpen,
|
|
111
|
+
setFormOpen,
|
|
112
|
+
editing,
|
|
113
|
+
openCreate,
|
|
114
|
+
openEdit,
|
|
115
|
+
deleting,
|
|
116
|
+
setDeleting,
|
|
117
|
+
deletePending,
|
|
118
|
+
confirmDelete,
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export interface KpCrudShellProps<Row> {
|
|
123
|
+
title: string
|
|
124
|
+
subtitle: string
|
|
125
|
+
createLabel: string
|
|
126
|
+
searchPlaceholder: string
|
|
127
|
+
/** 总数(副标题插值) */
|
|
128
|
+
total: number
|
|
129
|
+
items: Row[]
|
|
130
|
+
// S34:shell 仅转发列定义(类型在页面侧构造),AdminColumnDef 对泛型 Row 的
|
|
131
|
+
// RowData 联合约束无法被交叉约束证明,此处用 any 转发
|
|
132
|
+
columns: AdminColumnDef<any>[]
|
|
133
|
+
/** useKpCrud 状态(表格与删除确认对话框所需子集) */
|
|
134
|
+
crud: KpCrud<Row>
|
|
135
|
+
deleteConfirmTitle: string
|
|
136
|
+
deleteConfirmDescription: string
|
|
137
|
+
/** 标题头右侧扩展插槽(如 bookmarks 的 GitHub 全量同步按钮,位于创建按钮左侧) */
|
|
138
|
+
headerActions?: ReactNode
|
|
139
|
+
/** 额外对话框插槽(如 bookmarks 的同步确认,位于 shell 自身对话框之后) */
|
|
140
|
+
children?: ReactNode
|
|
141
|
+
/** 表单对话框(各域自行配置,open/editing 由 shell 注入) */
|
|
142
|
+
renderFormDialog: (ctx: { open: boolean; editing: Row | null; onOpenChange: (o: boolean) => void; onSuccess: () => void }) => ReactNode
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** 三页同构页面 chrome(S34):标题头 / 搜索栏 / 数据表 / 删除确认 */
|
|
146
|
+
export function KpCrudShell<Row extends Record<string, any> & { id: string; title?: string }>(props: KpCrudShellProps<Row>) {
|
|
147
|
+
const { crud } = props
|
|
148
|
+
return (
|
|
149
|
+
<div className="space-y-4 p-6">
|
|
150
|
+
<div className="flex items-center justify-between">
|
|
151
|
+
<div>
|
|
152
|
+
<h2 className="text-xl font-bold">{props.title}</h2>
|
|
153
|
+
<p className="text-sm text-muted-foreground">
|
|
154
|
+
{props.subtitle}
|
|
155
|
+
</p>
|
|
156
|
+
</div>
|
|
157
|
+
<div className="flex items-center gap-2">
|
|
158
|
+
{props.headerActions}
|
|
159
|
+
<Button onClick={crud.openCreate}>
|
|
160
|
+
<PlusIcon className="mr-1 size-4" />
|
|
161
|
+
{props.createLabel}
|
|
162
|
+
</Button>
|
|
163
|
+
</div>
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
<div className="flex items-center gap-2">
|
|
167
|
+
<div className="relative max-w-sm flex-1">
|
|
168
|
+
<SearchIcon className="absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
|
|
169
|
+
<Input
|
|
170
|
+
value={crud.searchInput}
|
|
171
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => crud.setSearchInput(e.target.value)}
|
|
172
|
+
onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
173
|
+
if (e.key === 'Enter') crud.applySearch()
|
|
174
|
+
}}
|
|
175
|
+
placeholder={props.searchPlaceholder}
|
|
176
|
+
className="pl-8"
|
|
177
|
+
/>
|
|
178
|
+
</div>
|
|
179
|
+
<Button variant="outline" onClick={crud.applySearch}>
|
|
180
|
+
{m.common_common_search()}
|
|
181
|
+
</Button>
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
<DataTable columns={props.columns} data={props.items} />
|
|
185
|
+
|
|
186
|
+
{props.renderFormDialog({
|
|
187
|
+
open: crud.formOpen,
|
|
188
|
+
editing: crud.editing,
|
|
189
|
+
onOpenChange: crud.setFormOpen,
|
|
190
|
+
onSuccess: crud.refresh,
|
|
191
|
+
})}
|
|
192
|
+
|
|
193
|
+
<ConfirmDialog
|
|
194
|
+
open={!!crud.deleting}
|
|
195
|
+
onOpenChange={(o: boolean) => !o && crud.setDeleting(null)}
|
|
196
|
+
title={props.deleteConfirmTitle}
|
|
197
|
+
description={props.deleteConfirmDescription}
|
|
198
|
+
cancelLabel={m.common_common_cancel()}
|
|
199
|
+
confirmLabel={crud.deletePending ? m.common_common_deleting() : m.common_common_delete()}
|
|
200
|
+
confirmClassName="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
|
201
|
+
confirmDisabled={crud.deletePending}
|
|
202
|
+
cancelDisabled={crud.deletePending}
|
|
203
|
+
onConfirm={crud.confirmDelete}
|
|
204
|
+
/>
|
|
205
|
+
{props.children}
|
|
206
|
+
</div>
|
|
207
|
+
)
|
|
208
|
+
}
|
|
@@ -111,7 +111,7 @@ export function MarketAppForm({ open, onOpenChange, editData, onSuccess }: Marke
|
|
|
111
111
|
// 非 JSON 响应(网关 502 HTML 错误页等)时 res.json() 会抛 SyntaxError,须兜底通用文案
|
|
112
112
|
// 服务端 err.error 可能携带内部细节(栈/表名),不当作用户文案(A1x-1 批);
|
|
113
113
|
// 通用文案兜底 + console.warn 留证
|
|
114
|
-
|
|
114
|
+
const message = m.common_market_form_operationFailed()
|
|
115
115
|
try {
|
|
116
116
|
const err = (await res.json()) as { error?: string }
|
|
117
117
|
if (err?.error) console.warn('[market-app-form] submit failed:', err.error)
|
|
@@ -416,7 +416,7 @@ export default function SettingsProfile({
|
|
|
416
416
|
type="button"
|
|
417
417
|
variant="outline"
|
|
418
418
|
>
|
|
419
|
-
{showEmailChangeForm ? m.
|
|
419
|
+
{showEmailChangeForm ? m.common_common_cancel() : m['admin-users_profile_changeEmail']()}
|
|
420
420
|
</Button>
|
|
421
421
|
)}
|
|
422
422
|
</div>
|
|
@@ -151,7 +151,7 @@ export function UserCreateDialog({ open, onOpenChange }: UserCreateDialogProps)
|
|
|
151
151
|
</div>
|
|
152
152
|
<DialogFooter>
|
|
153
153
|
<Button type="button" variant="outline" onClick={() => onOpenChange(false)}>
|
|
154
|
-
{m.
|
|
154
|
+
{m.common_common_cancel()}
|
|
155
155
|
</Button>
|
|
156
156
|
<Button type="submit" disabled={isPending}>
|
|
157
157
|
{isPending ? m['admin-users_create_submitting']() : m.common_button_create()}
|
|
@@ -83,7 +83,7 @@ function UserSingleSelectDialog({
|
|
|
83
83
|
</Select>
|
|
84
84
|
</div>
|
|
85
85
|
<DialogFooter>
|
|
86
|
-
<Button variant="outline" onClick={onCancel}>{m.
|
|
86
|
+
<Button variant="outline" onClick={onCancel}>{m.common_common_cancel()}</Button>
|
|
87
87
|
<Button disabled={isPending} onClick={onSubmit}>{m.common_button_confirm()}</Button>
|
|
88
88
|
</DialogFooter>
|
|
89
89
|
</DialogContent>
|
|
@@ -154,7 +154,7 @@ export function UserPasswordDialog({
|
|
|
154
154
|
<Input type="password" value={value} onChange={(e: React.ChangeEvent<HTMLInputElement>) => onValueChange(e.target.value)} />
|
|
155
155
|
</div>
|
|
156
156
|
<DialogFooter>
|
|
157
|
-
<Button type="button" variant="outline" onClick={onCancel}>{m.
|
|
157
|
+
<Button type="button" variant="outline" onClick={onCancel}>{m.common_common_cancel()}</Button>
|
|
158
158
|
<Button type="submit" disabled={isPending || !value.trim()}>{m['admin-users_dialog_password_confirm']()}</Button>
|
|
159
159
|
</DialogFooter>
|
|
160
160
|
</form>
|
|
@@ -190,7 +190,7 @@ export function UserDeactivateDialog({
|
|
|
190
190
|
</AlertDialogHeader>
|
|
191
191
|
<Input placeholder={m['admin-users_dialog_deactivate_placeholder']()} value={confirmName} onChange={(e: React.ChangeEvent<HTMLInputElement>) => onConfirmNameChange(e.target.value)} />
|
|
192
192
|
<AlertDialogFooter>
|
|
193
|
-
<AlertDialogCancel>{m.
|
|
193
|
+
<AlertDialogCancel>{m.common_common_cancel()}</AlertDialogCancel>
|
|
194
194
|
<AlertDialogAction
|
|
195
195
|
disabled={confirmName !== username || isPending}
|
|
196
196
|
onClick={onSubmit}
|
|
@@ -502,7 +502,6 @@ export * from './common_bookmarkform_url1.js'
|
|
|
502
502
|
export * from './common_bookmarkform_urlhint2.js'
|
|
503
503
|
export * from './common_bookmarkform_urlrequired2.js'
|
|
504
504
|
export * from './common_button_back.js'
|
|
505
|
-
export * from './common_button_cancel.js'
|
|
506
505
|
export * from './common_button_close.js'
|
|
507
506
|
export * from './common_button_confirm.js'
|
|
508
507
|
export * from './common_button_create.js'
|
|
@@ -685,7 +684,6 @@ export * from './common_dependency_table_columns_status.js'
|
|
|
685
684
|
export * from './common_dependency_table_empty.js'
|
|
686
685
|
export * from './common_dependency_table_pagination_next.js'
|
|
687
686
|
export * from './common_dependency_table_pagination_prev.js'
|
|
688
|
-
export * from './common_dependency_table_pagination_total.js'
|
|
689
687
|
export * from './common_dependency_table_searchplaceholder1.js'
|
|
690
688
|
export * from './common_dependency_table_stats_outdated.js'
|
|
691
689
|
export * from './common_dependency_table_stats_watched.js'
|
|
@@ -15,14 +15,12 @@
|
|
|
15
15
|
// You should have received a copy of the GNU Affero General Public License
|
|
16
16
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
17
|
|
|
18
|
-
import { createLazyFileRoute
|
|
18
|
+
import { createLazyFileRoute } from '@tanstack/react-router'
|
|
19
19
|
import { m } from '@/paraglide/messages.js'
|
|
20
|
-
import {
|
|
20
|
+
import { useState, useTransition } from 'react'
|
|
21
21
|
import {
|
|
22
|
-
PlusIcon,
|
|
23
22
|
PencilIcon,
|
|
24
23
|
Trash2Icon,
|
|
25
|
-
SearchIcon,
|
|
26
24
|
StarIcon,
|
|
27
25
|
RefreshCwIcon,
|
|
28
26
|
ExternalLinkIcon,
|
|
@@ -33,9 +31,8 @@ import {
|
|
|
33
31
|
BookOpen,
|
|
34
32
|
type LucideIcon,
|
|
35
33
|
} from 'lucide-react'
|
|
36
|
-
import {
|
|
34
|
+
import { type AdminColumnDef } from '@/components/data-table/data-table'
|
|
37
35
|
import { Button } from '@/components/ui/button'
|
|
38
|
-
import { Input } from '@/components/ui/input'
|
|
39
36
|
import { Badge } from '@/components/ui/badge'
|
|
40
37
|
import { ConfirmDialog } from '@/components/confirm-dialog'
|
|
41
38
|
import { toast } from '@/components/ui/toast'
|
|
@@ -46,6 +43,7 @@ import {
|
|
|
46
43
|
type BookmarkRow,
|
|
47
44
|
} from '@/components/knowledge/public/bookmark-form-dialog'
|
|
48
45
|
import { adminDeleteBookmarkFn } from '@/server/serverFns/knowledge/public/bookmarks/delete'
|
|
46
|
+
import { KpCrudShell, useKpCrud } from '@/components/knowledge/public/kp-crud-page'
|
|
49
47
|
import { adminSyncAllGithubFn } from '@/server/serverFns/knowledge/public/bookmarks/sync-all-github'
|
|
50
48
|
|
|
51
49
|
const categoryIconMap: Record<string, LucideIcon> = {
|
|
@@ -83,55 +81,17 @@ function BookmarksPage() {
|
|
|
83
81
|
const { items: rawItems, total } = Route.useLoaderData()
|
|
84
82
|
const items = rawItems as BookmarkRow[]
|
|
85
83
|
const { search } = Route.useSearch()
|
|
86
|
-
const navigate = useNavigate()
|
|
87
|
-
const router = useRouter()
|
|
88
84
|
const locale = Route.useRouteContext().locale
|
|
89
|
-
const [searchInput, setSearchInput] = useState(search ?? '')
|
|
90
|
-
const [formOpen, setFormOpen] = useState(false)
|
|
91
|
-
const [editing, setEditing] = useState<BookmarkRow | null>(null)
|
|
92
|
-
const [deleting, setDeleting] = useState<BookmarkRow | null>(null)
|
|
93
|
-
const [deletePending, startDelete] = useTransition()
|
|
94
85
|
const [syncing, startSync] = useTransition()
|
|
95
86
|
const [syncConfirmOpen, setSyncConfirmOpen] = useState(false)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function applySearch() {
|
|
107
|
-
navigate({
|
|
108
|
-
to: '/knowledge-public/bookmarks',
|
|
109
|
-
search: (s) => ({ ...s, search: searchInput.trim() || undefined }),
|
|
110
|
-
})
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function openCreate() {
|
|
114
|
-
setEditing(null)
|
|
115
|
-
setFormOpen(true)
|
|
116
|
-
}
|
|
117
|
-
function openEdit(row: BookmarkRow) {
|
|
118
|
-
setEditing(row)
|
|
119
|
-
setFormOpen(true)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function confirmDelete() {
|
|
123
|
-
if (!deleting) return
|
|
124
|
-
startDelete(async () => {
|
|
125
|
-
try {
|
|
126
|
-
await adminDeleteBookmarkFn({ data: { id: deleting.id } })
|
|
127
|
-
toast.success(m.common_knowledgePublic_bookmarks_deleted())
|
|
128
|
-
setDeleting(null)
|
|
129
|
-
refresh()
|
|
130
|
-
} catch (err) {
|
|
131
|
-
toast.error(err instanceof Error ? err.message : m.common_common_deleteFailed())
|
|
132
|
-
}
|
|
133
|
-
})
|
|
134
|
-
}
|
|
87
|
+
// S34:状态机与页面 chrome 收敛到共享骨架,页面只保留列定义与域内对话框
|
|
88
|
+
const crud = useKpCrud<BookmarkRow>({
|
|
89
|
+
routePath: '/knowledge-public/bookmarks',
|
|
90
|
+
search,
|
|
91
|
+
deleteFn: (row) => adminDeleteBookmarkFn({ data: { id: row.id } }),
|
|
92
|
+
deleteSuccessToast: m.common_knowledgePublic_bookmarks_deleted(),
|
|
93
|
+
})
|
|
94
|
+
const { openEdit, setDeleting } = crud
|
|
135
95
|
|
|
136
96
|
// 全量强制同步是批量外呼昂贵操作,收进 ConfirmDialog 二次确认(与删除操作同级防护)
|
|
137
97
|
function syncAllGithub() {
|
|
@@ -142,7 +102,7 @@ function BookmarksPage() {
|
|
|
142
102
|
m.common_knowledgePublic_bookmarks_syncComplete({ total: res.total, success: res.success, failed: res.failed }),
|
|
143
103
|
)
|
|
144
104
|
setSyncConfirmOpen(false)
|
|
145
|
-
refresh()
|
|
105
|
+
crud.refresh()
|
|
146
106
|
} catch (err) {
|
|
147
107
|
toast.error(err instanceof Error ? err.message : m.common_knowledgePublic_bookmarks_syncFailed())
|
|
148
108
|
}
|
|
@@ -281,51 +241,29 @@ function BookmarksPage() {
|
|
|
281
241
|
]
|
|
282
242
|
|
|
283
243
|
return (
|
|
284
|
-
<
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
<div className="flex items-center gap-2">
|
|
303
|
-
<div className="relative max-w-sm flex-1">
|
|
304
|
-
<SearchIcon className="absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-muted-foreground" />
|
|
305
|
-
<Input
|
|
306
|
-
value={searchInput}
|
|
307
|
-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setSearchInput(e.target.value)}
|
|
308
|
-
onKeyDown={(e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
309
|
-
if (e.key === 'Enter') applySearch()
|
|
310
|
-
}}
|
|
311
|
-
placeholder={m.common_knowledgePublic_bookmarks_placeholder()}
|
|
312
|
-
className="pl-8"
|
|
313
|
-
/>
|
|
314
|
-
</div>
|
|
315
|
-
<Button variant="outline" onClick={applySearch}>
|
|
316
|
-
{m.common_common_search()}
|
|
244
|
+
<KpCrudShell
|
|
245
|
+
title={m.common_knowledgePublic_bookmarks_title()}
|
|
246
|
+
subtitle={m.common_knowledgePublic_bookmarks_subtitle({ total })}
|
|
247
|
+
createLabel={m.common_common_create()}
|
|
248
|
+
searchPlaceholder={m.common_knowledgePublic_bookmarks_placeholder()}
|
|
249
|
+
total={total}
|
|
250
|
+
items={items}
|
|
251
|
+
columns={columns}
|
|
252
|
+
crud={crud}
|
|
253
|
+
deleteConfirmTitle={m.common_knowledgePublic_bookmarks_deleteConfirmTitle()}
|
|
254
|
+
deleteConfirmDescription={m.common_knowledgePublic_bookmarks_deleteConfirmDesc({
|
|
255
|
+
title: crud.deleting?.title ?? '',
|
|
256
|
+
})}
|
|
257
|
+
headerActions={
|
|
258
|
+
<Button variant="outline" onClick={() => setSyncConfirmOpen(true)} disabled={syncing}>
|
|
259
|
+
<RefreshCwIcon className={`mr-1 size-4 ${syncing ? 'animate-spin' : ''}`} />
|
|
260
|
+
{syncing ? m.common_knowledgePublic_bookmarks_syncing() : m.common_knowledgePublic_bookmarks_syncGithub()}
|
|
317
261
|
</Button>
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
open={formOpen}
|
|
324
|
-
onOpenChange={setFormOpen}
|
|
325
|
-
item={editing}
|
|
326
|
-
onSuccess={refresh}
|
|
327
|
-
/>
|
|
328
|
-
|
|
262
|
+
}
|
|
263
|
+
renderFormDialog={({ open, editing, onOpenChange, onSuccess }) => (
|
|
264
|
+
<BookmarkFormDialog open={open} onOpenChange={onOpenChange} item={editing} onSuccess={onSuccess} />
|
|
265
|
+
)}
|
|
266
|
+
>
|
|
329
267
|
<ConfirmDialog
|
|
330
268
|
open={syncConfirmOpen}
|
|
331
269
|
onOpenChange={setSyncConfirmOpen}
|
|
@@ -337,19 +275,6 @@ function BookmarksPage() {
|
|
|
337
275
|
cancelDisabled={syncing}
|
|
338
276
|
onConfirm={syncAllGithub}
|
|
339
277
|
/>
|
|
340
|
-
|
|
341
|
-
<ConfirmDialog
|
|
342
|
-
open={!!deleting}
|
|
343
|
-
onOpenChange={(o: boolean) => !o && setDeleting(null)}
|
|
344
|
-
title={m.common_knowledgePublic_bookmarks_deleteConfirmTitle()}
|
|
345
|
-
description={m.common_knowledgePublic_bookmarks_deleteConfirmDesc({ title: deleting?.title ?? '' })}
|
|
346
|
-
cancelLabel={m.common_common_cancel()}
|
|
347
|
-
confirmLabel={deletePending ? m.common_common_deleting() : m.common_common_delete()}
|
|
348
|
-
confirmClassName="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
|
349
|
-
confirmDisabled={deletePending}
|
|
350
|
-
cancelDisabled={deletePending}
|
|
351
|
-
onConfirm={confirmDelete}
|
|
352
|
-
/>
|
|
353
|
-
</div>
|
|
278
|
+
</KpCrudShell>
|
|
354
279
|
)
|
|
355
280
|
}
|