feat(default): reorganize system settings pricing UI

Refine the default system settings structure and model pricing editor so pricing configuration is easier to scan and edit.
This commit is contained in:
CaIon
2026-05-06 16:29:45 +08:00
parent 9acf5fecae
commit 0f9f094a48
62 changed files with 3655 additions and 2343 deletions
@@ -0,0 +1,95 @@
import { useMemo } from 'react'
import { useParams } from '@tanstack/react-router'
import { useTranslation } from 'react-i18next'
import { useStatus } from '@/hooks/use-status'
import { getOptionValue, useSystemOptions } from '../hooks/use-system-options'
import type { OperationsSettings } from '../types'
import {
OPERATIONS_DEFAULT_SECTION,
getOperationsSectionContent,
} from './section-registry.tsx'
const defaultOperationsSettings: OperationsSettings = {
RetryTimes: 0,
DefaultCollapseSidebar: false,
DemoSiteEnabled: false,
SelfUseModeEnabled: false,
ChannelDisableThreshold: '',
QuotaRemindThreshold: '',
AutomaticDisableChannelEnabled: false,
AutomaticEnableChannelEnabled: false,
AutomaticDisableKeywords: '',
AutomaticDisableStatusCodes: '401',
AutomaticRetryStatusCodes:
'100-199,300-399,401-407,409-499,500-503,505-523,525-599',
'monitor_setting.auto_test_channel_enabled': false,
'monitor_setting.auto_test_channel_minutes': 10,
SMTPServer: '',
SMTPPort: '',
SMTPAccount: '',
SMTPFrom: '',
SMTPToken: '',
SMTPSSLEnabled: false,
SMTPForceAuthLogin: false,
WorkerUrl: '',
WorkerValidKey: '',
WorkerAllowHttpImageRequestEnabled: false,
LogConsumeEnabled: false,
'performance_setting.disk_cache_enabled': false,
'performance_setting.disk_cache_threshold_mb': 10,
'performance_setting.disk_cache_max_size_mb': 1024,
'performance_setting.disk_cache_path': '',
'performance_setting.monitor_enabled': false,
'performance_setting.monitor_cpu_threshold': 90,
'performance_setting.monitor_memory_threshold': 90,
'performance_setting.monitor_disk_threshold': 95,
'perf_metrics_setting.enabled': true,
'perf_metrics_setting.flush_interval': 5,
'perf_metrics_setting.bucket_time': 'hour',
'perf_metrics_setting.retention_days': 0,
}
export function OperationsSettings() {
const { t } = useTranslation()
const { data, isLoading } = useSystemOptions()
const { status } = useStatus()
const params = useParams({
from: '/_authenticated/system-settings/operations/$section',
})
const settings = useMemo(
() => getOptionValue(data?.data, defaultOperationsSettings),
[data?.data]
)
if (isLoading) {
return (
<div className='text-muted-foreground flex h-full w-full flex-1 items-center justify-center'>
{t('Loading maintenance settings...')}
</div>
)
}
const activeSection = (params?.section ?? OPERATIONS_DEFAULT_SECTION) as
| 'behavior'
| 'monitoring'
| 'email'
| 'worker'
| 'logs'
| 'performance'
| 'update-checker'
const sectionContent = getOperationsSectionContent(
activeSection,
settings,
status?.version as string | undefined,
status?.start_time as number | null | undefined
)
return (
<div className='flex h-full w-full flex-1 flex-col'>
<div className='faded-bottom h-full w-full overflow-y-auto scroll-smooth pe-4 pb-12'>
<div className='space-y-4'>{sectionContent}</div>
</div>
</div>
)
}
@@ -0,0 +1,163 @@
import type { OperationsSettings } from '../types'
import { createSectionRegistry } from '../utils/section-registry'
import { SystemBehaviorSection } from '../general/system-behavior-section'
import { EmailSettingsSection } from '../integrations/email-settings-section'
import { MonitoringSettingsSection } from '../integrations/monitoring-settings-section'
import { WorkerSettingsSection } from '../integrations/worker-settings-section'
import { LogSettingsSection } from '../maintenance/log-settings-section'
import { PerformanceSection } from '../maintenance/performance-section'
import { UpdateCheckerSection } from '../maintenance/update-checker-section'
const OPERATIONS_SECTIONS = [
{
id: 'behavior',
titleKey: 'System Behavior',
descriptionKey: 'Configure system-wide behavior and defaults',
build: (settings: OperationsSettings) => (
<SystemBehaviorSection
defaultValues={{
RetryTimes: settings.RetryTimes,
DefaultCollapseSidebar: settings.DefaultCollapseSidebar,
DemoSiteEnabled: settings.DemoSiteEnabled,
SelfUseModeEnabled: settings.SelfUseModeEnabled,
}}
/>
),
},
{
id: 'monitoring',
titleKey: 'Monitoring & Alerts',
descriptionKey: 'Configure channel monitoring and automation',
build: (settings: OperationsSettings) => (
<MonitoringSettingsSection
defaultValues={{
ChannelDisableThreshold: settings.ChannelDisableThreshold,
QuotaRemindThreshold: settings.QuotaRemindThreshold,
AutomaticDisableChannelEnabled:
settings.AutomaticDisableChannelEnabled,
AutomaticEnableChannelEnabled: settings.AutomaticEnableChannelEnabled,
AutomaticDisableKeywords: settings.AutomaticDisableKeywords,
AutomaticDisableStatusCodes: settings.AutomaticDisableStatusCodes,
AutomaticRetryStatusCodes: settings.AutomaticRetryStatusCodes,
'monitor_setting.auto_test_channel_enabled':
settings['monitor_setting.auto_test_channel_enabled'],
'monitor_setting.auto_test_channel_minutes':
settings['monitor_setting.auto_test_channel_minutes'],
}}
/>
),
},
{
id: 'email',
titleKey: 'SMTP Email',
descriptionKey: 'Configure SMTP email settings',
build: (settings: OperationsSettings) => (
<EmailSettingsSection
defaultValues={{
SMTPServer: settings.SMTPServer,
SMTPPort: settings.SMTPPort,
SMTPAccount: settings.SMTPAccount,
SMTPFrom: settings.SMTPFrom,
SMTPToken: settings.SMTPToken,
SMTPSSLEnabled: settings.SMTPSSLEnabled,
SMTPForceAuthLogin: settings.SMTPForceAuthLogin,
}}
/>
),
},
{
id: 'worker',
titleKey: 'Worker Proxy',
descriptionKey: 'Configure worker service settings',
build: (settings: OperationsSettings) => (
<WorkerSettingsSection
defaultValues={{
WorkerUrl: settings.WorkerUrl,
WorkerValidKey: settings.WorkerValidKey,
WorkerAllowHttpImageRequestEnabled:
settings.WorkerAllowHttpImageRequestEnabled,
}}
/>
),
},
{
id: 'logs',
titleKey: 'Log Maintenance',
descriptionKey: 'Configure log consumption settings',
build: (settings: OperationsSettings) => (
<LogSettingsSection
defaultEnabled={Boolean(settings.LogConsumeEnabled)}
/>
),
},
{
id: 'performance',
titleKey: 'Performance',
descriptionKey: 'Disk cache, system monitoring and performance stats',
build: (settings: OperationsSettings) => (
<PerformanceSection
defaultValues={{
'performance_setting.disk_cache_enabled':
settings['performance_setting.disk_cache_enabled'] ?? false,
'performance_setting.disk_cache_threshold_mb':
settings['performance_setting.disk_cache_threshold_mb'] ?? 10,
'performance_setting.disk_cache_max_size_mb':
settings['performance_setting.disk_cache_max_size_mb'] ?? 1024,
'performance_setting.disk_cache_path':
settings['performance_setting.disk_cache_path'] ?? '',
'performance_setting.monitor_enabled':
settings['performance_setting.monitor_enabled'] ?? false,
'performance_setting.monitor_cpu_threshold':
settings['performance_setting.monitor_cpu_threshold'] ?? 90,
'performance_setting.monitor_memory_threshold':
settings['performance_setting.monitor_memory_threshold'] ?? 90,
'performance_setting.monitor_disk_threshold':
settings['performance_setting.monitor_disk_threshold'] ?? 95,
'perf_metrics_setting.enabled':
settings['perf_metrics_setting.enabled'] ?? true,
'perf_metrics_setting.flush_interval':
settings['perf_metrics_setting.flush_interval'] ?? 5,
'perf_metrics_setting.bucket_time':
settings['perf_metrics_setting.bucket_time'] ?? 'hour',
'perf_metrics_setting.retention_days':
settings['perf_metrics_setting.retention_days'] ?? 0,
}}
/>
),
},
{
id: 'update-checker',
titleKey: 'System maintenance',
descriptionKey: 'Check for system updates',
build: (
_settings: OperationsSettings,
currentVersion?: string | null,
startTime?: number | null
) => (
<UpdateCheckerSection
currentVersion={currentVersion}
startTime={startTime}
/>
),
},
] as const
export type OperationsSectionId = (typeof OPERATIONS_SECTIONS)[number]['id']
const operationsRegistry = createSectionRegistry<
OperationsSectionId,
OperationsSettings,
[string | null | undefined, number | null | undefined]
>({
sections: OPERATIONS_SECTIONS,
defaultSection: 'behavior',
basePath: '/system-settings/operations',
urlStyle: 'path',
})
export const OPERATIONS_SECTION_IDS = operationsRegistry.sectionIds
export const OPERATIONS_DEFAULT_SECTION = operationsRegistry.defaultSection
export const getOperationsSectionNavItems =
operationsRegistry.getSectionNavItems
export const getOperationsSectionContent =
operationsRegistry.getSectionContent