feat(settings): 增加连接移除确认并收拢数据源设置
build / build (push) Successful in 1m6s

This commit is contained in:
姚章浩
2026-10-27 09:40:13 +08:00
parent 8930ef29cd
commit 5b6e154459
3 changed files with 112 additions and 16 deletions
+21
View File
@@ -1,3 +1,24 @@
.source-management-details {
margin-top: 18px;
border-top: 1px solid var(--border-base);
}
.source-management-details > details {
padding: 12px 0;
}
.source-management-details summary {
cursor: pointer;
color: var(--ink-mute);
font-size: 12px;
}
.source-management-details summary:focus-visible {
outline: 2px solid #2978bd;
outline-offset: 3px;
}
.source-management-details .source-policy-panel {
margin-top: 16px;
margin-bottom: 0;
border-bottom: 0;
}
.source-account {
margin: 0 0 14px;
font-size: 12px;
+88 -10
View File
@@ -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,
+3 -6
View File
@@ -3,7 +3,7 @@ import { useCallback, useEffect, useState } from 'react'
import { BackupScheduleSection } from './BackupScheduleSection'
import { QAModelSettings } from './QAModelSettings'
import { MembersSection } from './MembersSection'
import { DingtalkAccountStatus, SourceRefreshPolicy, SourceSettingsAudit, SourceSettingsCard } from './SourceManagement'
import { DingtalkAccountStatus, SourceManagementDetails, SourceSettingsCard } from './SourceManagement'
import { RoutingBindingsSection } from './RoutingBindingsSection'
import { ProductionBindingsSection } from './ProductionBindingsSection'
import { SourceWizard } from './SourceWizard'
@@ -44,8 +44,7 @@ interface Props {
initialSection?: SectionKey
}
type SectionKey =
'sources' | 'services' | 'bindings' | 'production-bindings' | 'storage' | 'refresh' | 'members' | 'source-audit'
type SectionKey = 'sources' | 'services' | 'bindings' | 'production-bindings' | 'storage' | 'refresh' | 'members'
const sections: { key: SectionKey; label: string; adminOnly?: boolean }[] = [
{ key: 'sources', label: '数据源配置' },
@@ -55,7 +54,6 @@ const sections: { key: SectionKey; label: string; adminOnly?: boolean }[] = [
{ key: 'storage', label: '存储与备份' },
{ key: 'refresh', label: '刷新策略' },
{ key: 'members', label: '成员与角色', adminOnly: true },
{ key: 'source-audit', label: '数据源设置审计' },
] as { key: SectionKey; label: string; adminOnly?: boolean }[]
const sourceTypeLabels: Record<string, string> = {
@@ -256,6 +254,7 @@ export function SystemSettingsView({
<div className="empty-state">还没有已接入的来源:用上面的「+ 添加数据源」加入。</div>
)}
</div>
<SourceManagementDetails connections={listedConnections} onSourcesChanged={onSourcesChanged} />
</section>
) : null}
{section === 'services' ? (
@@ -397,10 +396,8 @@ export function SystemSettingsView({
{section === 'production-bindings' ? <ProductionBindingsSection /> : null}
{section === 'storage' ? <BackupScheduleSection /> : null}
{section === 'members' && identity?.role === 'admin' ? <MembersSection /> : null}
{section === 'source-audit' ? <SourceSettingsAudit connections={listedConnections} /> : null}
{section === 'refresh' ? (
<section className="settings-panel wide" id="settings-refresh">
<SourceRefreshPolicy connections={listedConnections} onSourcesChanged={onSourcesChanged} />
<div className="settings-section-heading">
<div>
<h2>刷新策略</h2>