This commit is contained in:
@@ -2,7 +2,8 @@ import './SourceManagement.css'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { DingtalkSessionControl } from './DingtalkSessionControl'
|
||||
import { fetchAvailableDingtalkSources } from './dingtalkSources'
|
||||
import { fetchSourceConnectionList, fetchSourceSettingsRevisions } from './sourceConnections'
|
||||
import { archiveSourceConnection, fetchSourceConnectionList, fetchSourceSettingsRevisions } from './sourceConnections'
|
||||
import { useOptionalAuth } from './auth'
|
||||
import type { SourceConnectionListItem, SourceSettingsRevision } from './sourceConnections'
|
||||
import { configuredInterval, saveSourceRefresh } from './sourceRefreshPolicy'
|
||||
|
||||
@@ -70,6 +71,8 @@ export function SourceSettingsCard({
|
||||
}) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [confirm, setConfirm] = useState(false)
|
||||
const [confirmRemove, setConfirmRemove] = useState(false)
|
||||
const isAdmin = useOptionalAuth()?.identity?.role === 'admin'
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [message, setMessage] = useState('')
|
||||
const [error, setError] = useState('')
|
||||
@@ -88,6 +91,20 @@ export function SourceSettingsCard({
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
const remove = async () => {
|
||||
if (!isAdmin || busy) return
|
||||
setBusy(true)
|
||||
setError('')
|
||||
try {
|
||||
await archiveSourceConnection(connection.id)
|
||||
setConfirmRemove(false)
|
||||
onSourcesChanged()
|
||||
} catch (cause) {
|
||||
setError(errorText(cause))
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}
|
||||
const manual = connection.source_type === 'manual'
|
||||
return (
|
||||
<article className="settings-source-row">
|
||||
@@ -106,7 +123,7 @@ export function SourceSettingsCard({
|
||||
: '仅手动刷新'}
|
||||
</span>
|
||||
</div>
|
||||
{!manual ? (
|
||||
{!manual || isAdmin ? (
|
||||
<button
|
||||
className="secondary source-more"
|
||||
aria-expanded={open}
|
||||
@@ -118,14 +135,28 @@ export function SourceSettingsCard({
|
||||
) : null}
|
||||
{open ? (
|
||||
<div className="source-schedule-form" id={`source-options-${connection.id}`}>
|
||||
<button
|
||||
className={connection.enabled ? 'danger' : 'secondary'}
|
||||
disabled={busy}
|
||||
onClick={() => (connection.enabled ? setConfirm(true) : void toggle())}
|
||||
>
|
||||
{busy ? '处理中…' : connection.enabled ? '暂停自动刷新' : '恢复自动刷新'}
|
||||
</button>
|
||||
<small>仅控制自动扫描,不下架或删除已有知识。</small>
|
||||
{!manual ? (
|
||||
<button
|
||||
className={connection.enabled ? 'danger' : 'secondary'}
|
||||
disabled={busy}
|
||||
onClick={() => (connection.enabled ? setConfirm(true) : void toggle())}
|
||||
>
|
||||
{busy ? '处理中…' : connection.enabled ? '暂停自动刷新' : '恢复自动刷新'}
|
||||
</button>
|
||||
) : null}
|
||||
{isAdmin ? (
|
||||
<button
|
||||
className="danger"
|
||||
disabled={busy}
|
||||
onClick={() => {
|
||||
setError('')
|
||||
setConfirmRemove(true)
|
||||
}}
|
||||
>
|
||||
移除连接
|
||||
</button>
|
||||
) : null}
|
||||
<small>仅管理平台连接,不删除源端文件或已入库知识。</small>
|
||||
</div>
|
||||
) : null}
|
||||
{message ? (
|
||||
@@ -138,6 +169,30 @@ export function SourceSettingsCard({
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
{confirmRemove ? (
|
||||
<div className="modal-backdrop" role="dialog" aria-modal="true" aria-label="移除连接">
|
||||
<div className="modal-card">
|
||||
<h3>移除「{connection.name}」的连接?</h3>
|
||||
<p>移除后将不再展示该来源,也不再安排新的自动扫描。</p>
|
||||
<p>
|
||||
<strong>源端文件和已入库知识不会删除,历史记录保留。</strong>
|
||||
</p>
|
||||
{error ? (
|
||||
<p role="alert" className="error-message">
|
||||
{error}
|
||||
</p>
|
||||
) : null}
|
||||
<div className="modal-actions">
|
||||
<button className="secondary" disabled={busy} onClick={() => setConfirmRemove(false)}>
|
||||
取消
|
||||
</button>
|
||||
<button className="danger" disabled={busy} onClick={() => void remove()}>
|
||||
{busy ? '移除中…' : '确认移除'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
{confirm ? (
|
||||
<div className="modal-backdrop" role="dialog" aria-modal="true" aria-label="暂停自动刷新">
|
||||
<div className="modal-card">
|
||||
@@ -158,6 +213,29 @@ export function SourceSettingsCard({
|
||||
)
|
||||
}
|
||||
|
||||
export function SourceManagementDetails({
|
||||
connections,
|
||||
onSourcesChanged,
|
||||
}: {
|
||||
connections: SourceConnectionListItem[]
|
||||
onSourcesChanged: () => void
|
||||
}) {
|
||||
const [policyOpen, setPolicyOpen] = useState(false)
|
||||
const [auditOpen, setAuditOpen] = useState(false)
|
||||
return (
|
||||
<div className="source-management-details">
|
||||
<details onToggle={(event) => setPolicyOpen(event.currentTarget.open)}>
|
||||
<summary>刷新设置</summary>
|
||||
{policyOpen ? <SourceRefreshPolicy connections={connections} onSourcesChanged={onSourcesChanged} /> : null}
|
||||
</details>
|
||||
<details onToggle={(event) => setAuditOpen(event.currentTarget.open)}>
|
||||
<summary>数据源设置审计</summary>
|
||||
{auditOpen ? <SourceSettingsAudit connections={connections} /> : null}
|
||||
</details>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function SourceRefreshPolicy({
|
||||
connections,
|
||||
onSourcesChanged,
|
||||
|
||||
Reference in New Issue
Block a user