feat: add event-targets columns

This commit is contained in:
马登山
2026-04-01 11:38:06 +08:00
parent 691545ed5c
commit 5b4f4d5317
4 changed files with 65 additions and 33 deletions
+62 -33
View File
@@ -21,6 +21,11 @@ interface RowData {
account_id: string
service: string
status: string
source?: string
}
function isConfigSource(source: string | undefined) {
return source === "config"
}
export default function EventsTargetPage() {
@@ -55,10 +60,43 @@ export default function EventsTargetPage() {
if (!searchTerm) return data
const term = searchTerm.toLowerCase()
return data.filter(
(row) => row.account_id?.toLowerCase().includes(term) || row.service?.toLowerCase().includes(term),
(row) =>
row.account_id?.toLowerCase().includes(term) ||
row.service?.toLowerCase().includes(term) ||
row.source?.toLowerCase().includes(term),
)
}, [data, searchTerm])
const deleteItem = useCallback(
async (row: RowData) => {
try {
await deleteEventTarget(`notify_${row.service}`, row.account_id)
message.success(t("Delete Success"))
loadData()
} catch (error) {
console.error(error)
const msg = (error as Error)?.message || t("Delete Failed")
message.error(msg)
}
},
[deleteEventTarget, loadData, message, t],
)
const confirmDelete = useCallback(
(row: RowData) => {
if (!isConfigSource(row.source)) return
dialog.error({
title: t("Warning"),
content: t("Are you sure you want to delete this destination?"),
positiveText: t("Confirm"),
negativeText: t("Cancel"),
onPositiveClick: () => deleteItem(row),
})
},
[deleteItem, dialog, t],
)
const columns: ColumnDef<RowData>[] = useMemo(
() => [
{
@@ -80,24 +118,37 @@ export default function EventsTargetPage() {
</Badge>
),
},
{
accessorKey: "source",
header: () => t("Source"),
cell: ({ row }) => {
const source = row.original.source
if (!source) return <span>-</span>
return <Badge variant={isConfigSource(source) ? "secondary" : "outline"}>{source}</Badge>
},
},
{
id: "actions",
header: () => t("Actions"),
enableSorting: false,
enableHiding: false,
meta: { width: 90 },
cell: ({ row }) => (
<div className="flex items-center gap-2">
<Button variant="outline" size="sm" onClick={() => confirmDelete(row.original)}>
<RiDeleteBin5Line className="size-4" aria-hidden />
<span>{t("Delete")}</span>
</Button>
</div>
),
cell: ({ row }) =>
isConfigSource(row.original.source) ? (
<div className="flex items-center gap-2">
<Button variant="outline" size="sm" onClick={() => confirmDelete(row.original)}>
<RiDeleteBin5Line className="size-4" aria-hidden />
<span>{t("Delete")}</span>
</Button>
</div>
) : (
<span className="text-muted-foreground">-</span>
),
},
],
// eslint-disable-next-line react-hooks/exhaustive-deps -- confirmDelete used in cell, stable ref
[t],
[confirmDelete, t],
)
const { table } = useDataTable<RowData>({
@@ -106,28 +157,6 @@ export default function EventsTargetPage() {
getRowId: (row) => `${row.service}-${row.account_id}`,
})
const confirmDelete = (row: RowData) => {
dialog.error({
title: t("Warning"),
content: t("Are you sure you want to delete this destination?"),
positiveText: t("Confirm"),
negativeText: t("Cancel"),
onPositiveClick: () => deleteItem(row),
})
}
const deleteItem = async (row: RowData) => {
try {
await deleteEventTarget(`notify_${row.service}`, row.account_id)
message.success(t("Delete Success"))
loadData()
} catch (error) {
console.error(error)
const msg = (error as Error)?.message || t("Delete Failed")
message.error(msg)
}
}
return (
<Page>
<PageHeader
+1
View File
@@ -12,6 +12,7 @@ export function useEventTarget() {
account_id: string
service: string
status: string
source?: string
}>
}>
}, [api])
+1
View File
@@ -710,6 +710,7 @@
"Start KMS": "Start KMS",
"Start Upload": "Start Upload",
"Status": "Status",
"Source": "Source",
"Status refreshed successfully": "Status refreshed successfully",
"Stop KMS": "Stop KMS",
"Storage Class": "Storage Class",
+1
View File
@@ -728,6 +728,7 @@
"Start KMS": "启动 KMS",
"Start Upload": "开始上传",
"Status": "状态",
"Source": "来源",
"Status refreshed successfully": "状态刷新成功",
"Stop KMS": "停止 KMS",
"Storage Class": "存储类型",