release: bump version to 0.52.0

This commit is contained in:
linkong committed 2026-05-12 17:15:02 +08:00
1 parent b15d097b9c
commit b87cb310fd
70 files changed
+5589 -2187

No files matched your search

+185 -9
View File
@@ -1,4 +1,5 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import type { Key } from 'react'
import {
Button,
Card,
@@ -11,6 +12,7 @@ import {
Modal,
Progress,
Row,
Select,
Space,
Table,
Tag,
@@ -50,6 +52,7 @@ interface BuiltInDataSource {
last_run: string | null
last_run_at?: string | null
last_status?: string | null
product?: string
is_running: boolean
task_id: number | null
progress: number | null
@@ -61,6 +64,8 @@ interface BuiltInDataSource {
phase_unit?: string | null
records_processed: number | null
total_records: number | null
collected_records?: number
has_collected_data?: boolean
is_free?: boolean
requires_credentials?: boolean
credential_provider?: string | null
@@ -108,6 +113,7 @@ interface UnifiedDataSource {
auth_type?: string
last_run_at?: string | null
last_status?: string | null
product?: string
is_running?: boolean
progress?: number | null
phase?: string | null
@@ -126,6 +132,8 @@ interface UnifiedDataSource {
requires_credentials?: boolean
credential_provider?: string | null
credential_status?: string
collected_records?: number
has_collected_data?: boolean
}
interface ViewDataSource extends UnifiedDataSource {
@@ -166,6 +174,32 @@ type DatasourceTaskStatus = {
status?: string | null
}
type ActiveFilter = 'enabled' | 'disabled' | 'all'
type StatusFilter = 'all' | 'success' | 'failed' | 'running' | 'not_run'
type CollectedFilter = 'all' | 'collected' | 'uncollected'
const PRODUCT_LABELS: Record<string, string> = {
vessels: '船只',
cables: '海底光缆',
satellites: '卫星',
bgp: 'BGP',
compute: '算力',
ai: 'AI',
media: '媒体',
other: '其他',
}
const PRODUCT_TAG_COLORS: Record<string, string> = {
vessels: 'cyan',
cables: 'geekblue',
satellites: 'purple',
bgp: 'volcano',
compute: 'blue',
ai: 'magenta',
media: 'green',
other: 'default',
}
function normalizeBuiltin(source: BuiltInDataSource): UnifiedDataSource {
return {
key: `builtin:${source.id}`,
@@ -175,6 +209,7 @@ function normalizeBuiltin(source: BuiltInDataSource): UnifiedDataSource {
source: source.source,
module: source.module,
priority: source.priority,
product: source.product,
frequency: source.frequency,
endpoint: source.endpoint,
is_active: source.is_active,
@@ -194,6 +229,8 @@ function normalizeBuiltin(source: BuiltInDataSource): UnifiedDataSource {
requires_credentials: source.requires_credentials,
credential_provider: source.credential_provider,
credential_status: source.credential_status,
collected_records: source.collected_records,
has_collected_data: source.has_collected_data,
headers: {},
config: {},
}
@@ -208,6 +245,13 @@ function DataSources() {
const [loading, setLoading] = useState(false)
const [triggerAllLoading, setTriggerAllLoading] = useState(false)
const [forceTriggerAll, setForceTriggerAll] = useState(false)
const [selectedRowKeys, setSelectedRowKeys] = useState<Key[]>([])
const [productFilter, setProductFilter] = useState<string>('all')
const [moduleFilter, setModuleFilter] = useState<string>('all')
const [activeFilter, setActiveFilter] = useState<ActiveFilter>('enabled')
const [statusFilter, setStatusFilter] = useState<StatusFilter>('all')
const [collectedFilter, setCollectedFilter] = useState<CollectedFilter>('all')
const [searchQuery, setSearchQuery] = useState('')
const [viewDrawerVisible, setViewDrawerVisible] = useState(false)
const [runningTasksVisible, setRunningTasksVisible] = useState(false)
const [viewingSource, setViewingSource] = useState<ViewDataSource | null>(null)
@@ -216,8 +260,15 @@ function DataSources() {
const tableRegionRef = useRef<HTMLDivElement | null>(null)
const allSources = useMemo(() => builtInSources.map(normalizeBuiltin), [builtInSources])
const selectedSourceIds = useMemo(
() => selectedRowKeys
.map((key) => allSources.find((source) => source.key === key)?.id)
.filter((id): id is number => typeof id === 'number'),
[allSources, selectedRowKeys],
)
const activeBuiltInCount = builtInSources.filter((source) => source.is_active).length
const collectedBuiltInCount = builtInSources.filter((source) => source.has_collected_data).length
const runningBuiltInSources = builtInSources.filter((source) => source.is_running)
const runningBuiltInCount = runningBuiltInSources.length
const aggregateProgress = runningBuiltInCount > 0
@@ -231,8 +282,16 @@ function DataSources() {
const fetchData = useCallback(async () => {
setLoading(true)
try {
const params = {
product: productFilter === 'all' ? undefined : productFilter,
module: moduleFilter === 'all' ? undefined : moduleFilter,
is_active: activeFilter === 'all' ? undefined : activeFilter === 'enabled',
run_status: statusFilter === 'all' ? undefined : statusFilter,
collected: collectedFilter === 'all' ? undefined : collectedFilter === 'collected',
q: searchQuery.trim() || undefined,
}
const [builtinRes, customRes] = await Promise.all([
axios.get('/api/v1/datasources'),
axios.get('/api/v1/datasources', { params }),
axios.get('/api/v1/datasources/configs'),
])
setBuiltInSources(builtinRes.data.data || [])
@@ -243,12 +302,17 @@ function DataSources() {
} finally {
setLoading(false)
}
}, [messageApi])
}, [activeFilter, collectedFilter, messageApi, moduleFilter, productFilter, searchQuery, statusFilter])
useEffect(() => {
void fetchData()
}, [fetchData])
useEffect(() => {
const visibleKeys = new Set(allSources.map((source) => source.key))
setSelectedRowKeys((keys) => keys.filter((key) => visibleKeys.has(String(key))))
}, [allSources])
useEffect(() => {
const updateHeight = () => {
setTableHeight(Math.max(260, (tableRegionRef.current?.offsetHeight || 0) - 56))
@@ -332,8 +396,15 @@ function DataSources() {
const handleTriggerAll = async () => {
try {
setTriggerAllLoading(true)
const res = await axios.post('/api/v1/datasources/trigger-all', null, {
params: { force: forceTriggerAll },
const res = await axios.post('/api/v1/datasources/trigger-batch', {
source_ids: selectedSourceIds,
force: forceTriggerAll,
product: selectedSourceIds.length ? undefined : productFilter === 'all' ? undefined : productFilter,
module: selectedSourceIds.length ? undefined : moduleFilter === 'all' ? undefined : moduleFilter,
is_active: selectedSourceIds.length ? undefined : activeFilter === 'all' ? undefined : activeFilter === 'enabled',
run_status: selectedSourceIds.length ? undefined : statusFilter === 'all' ? undefined : statusFilter,
collected: selectedSourceIds.length ? undefined : collectedFilter === 'all' ? undefined : collectedFilter === 'collected',
q: selectedSourceIds.length ? undefined : searchQuery.trim() || undefined,
})
const triggered = res.data.triggered || []
const skipped = res.data.skipped || []
@@ -343,10 +414,11 @@ function DataSources() {
skipped.length ? `跳过 ${skipped.length} 个` : null,
failed.length ? `失败 ${failed.length} 个` : null,
].filter(Boolean).join(','))
setSelectedRowKeys([])
void fetchData()
} catch (error: unknown) {
const err = error as { response?: { data?: { detail?: string } } }
messageApi.error(err.response?.data?.detail || '全触发失败')
messageApi.error(err.response?.data?.detail || '批量触发失败')
} finally {
setTriggerAllLoading(false)
}
@@ -431,6 +503,15 @@ function DataSources() {
width: 100,
render: () => <Tag color="blue">内置</Tag>,
},
{
title: '产品域',
key: 'product',
width: 110,
render: (_: unknown, record: UnifiedDataSource) => {
const product = record.product || 'other'
return <Tag color={PRODUCT_TAG_COLORS[product] || 'default'}>{PRODUCT_LABELS[product] || product}</Tag>
},
},
{
title: '层级/类型',
key: 'module',
@@ -451,6 +532,16 @@ function DataSources() {
width: 180,
render: (value: string | null | undefined) => formatDateTimeZhCN(value) || '-',
},
{
title: '已采集',
key: 'collected',
width: 110,
render: (_: unknown, record: UnifiedDataSource) => (
<Tag color={record.has_collected_data ? 'success' : 'default'}>
{record.has_collected_data ? `${record.collected_records || 0} 条` : '未采集'}
</Tag>
),
},
{
title: '状态',
key: 'status',
@@ -513,7 +604,7 @@ function DataSources() {
</div>
<div className="data-source-bulk-toolbar__stats">
<div className="data-source-bulk-toolbar__stat-pill">
<span className="data-source-bulk-toolbar__stat-label">全部</span>
<span className="data-source-bulk-toolbar__stat-label">当前筛选</span>
<strong>{allSources.length}</strong>
</div>
<div className="data-source-bulk-toolbar__stat-pill">
@@ -521,9 +612,19 @@ function DataSources() {
<strong>{builtInSources.length}</strong>
</div>
<div className="data-source-bulk-toolbar__stat-pill">
<span className="data-source-bulk-toolbar__stat-label">已启用内置</span>
<span className="data-source-bulk-toolbar__stat-label">已启用</span>
<strong>{activeBuiltInCount}</strong>
</div>
<div className="data-source-bulk-toolbar__stat-pill">
<span className="data-source-bulk-toolbar__stat-label">已有数据</span>
<strong>{collectedBuiltInCount}</strong>
</div>
{selectedSourceIds.length > 0 ? (
<div className="data-source-bulk-toolbar__stat-pill data-source-bulk-toolbar__stat-pill--success">
<span className="data-source-bulk-toolbar__stat-label">已选择</span>
<strong>{selectedSourceIds.length}</strong>
</div>
) : null}
{runningBuiltInCount > 0 ? (
<Tooltip title="查看采集中任务">
<button
@@ -548,18 +649,93 @@ function DataSources() {
强制全部采集
</Checkbox>
<Button type="primary" size="middle" icon={<SyncOutlined />} loading={triggerAllLoading} onClick={handleTriggerAll}>
一键采集
{selectedSourceIds.length ? '采集选中项' : '采集当前筛选'}
</Button>
</Space>
</div>
<div className="data-source-filter-toolbar">
<Select
className="data-source-filter-toolbar__control"
value={productFilter}
onChange={setProductFilter}
options={[
{ value: 'all', label: '全部产品域' },
{ value: 'vessels', label: '船只' },
{ value: 'cables', label: '海底光缆' },
{ value: 'satellites', label: '卫星' },
{ value: 'bgp', label: 'BGP' },
{ value: 'compute', label: '算力' },
{ value: 'ai', label: 'AI' },
{ value: 'media', label: '媒体' },
{ value: 'other', label: '其他' },
]}
/>
<Select
className="data-source-filter-toolbar__control"
value={moduleFilter}
onChange={setModuleFilter}
options={[
{ value: 'all', label: '全部层级' },
{ value: 'L1', label: 'L1' },
{ value: 'L2', label: 'L2' },
{ value: 'L3', label: 'L3' },
{ value: 'L4', label: 'L4' },
]}
/>
<Select
className="data-source-filter-toolbar__control"
value={activeFilter}
onChange={setActiveFilter}
options={[
{ value: 'enabled', label: '已启用' },
{ value: 'disabled', label: '已禁用' },
{ value: 'all', label: '全部启用状态' },
]}
/>
<Select
className="data-source-filter-toolbar__control"
value={statusFilter}
onChange={setStatusFilter}
options={[
{ value: 'all', label: '全部执行状态' },
{ value: 'success', label: '最近成功' },
{ value: 'failed', label: '最近失败' },
{ value: 'running', label: '采集中' },
{ value: 'not_run', label: '未执行' },
]}
/>
<Select
className="data-source-filter-toolbar__control"
value={collectedFilter}
onChange={setCollectedFilter}
options={[
{ value: 'all', label: '全部数据状态' },
{ value: 'collected', label: '已采集' },
{ value: 'uncollected', label: '未采集' },
]}
/>
<Input.Search
className="data-source-filter-toolbar__search"
allowClear
placeholder="搜索名称、标识或采集器"
value={searchQuery}
onChange={(event) => setSearchQuery(event.target.value)}
/>
</div>
<div ref={tableRegionRef} className="table-scroll-region data-source-table-region">
<Table
columns={columns}
dataSource={allSources}
rowKey="key"
rowSelection={{
selectedRowKeys,
onChange: setSelectedRowKeys,
preserveSelectedRowKeys: false,
columnWidth: 40,
}}
loading={loading}
pagination={false}
scroll={{ x: 1100, y: tableHeight }}
scroll={{ x: 1350, y: tableHeight }}
tableLayout="fixed"
size="small"
/>