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:24:06 +08:00
parent 9acf5fecae
commit 0f9f094a48
62 changed files with 3655 additions and 2343 deletions
@@ -1,5 +1,3 @@
import type { MaintenanceSettings } from '../types'
export type HeaderNavPricingConfig = {
enabled: boolean
requireAuth: boolean
@@ -62,25 +60,6 @@ export const SIDEBAR_MODULES_DEFAULT: SidebarModulesAdminConfig = {
},
}
export const DEFAULT_MAINTENANCE_SETTINGS: MaintenanceSettings = {
Notice: '',
LogConsumeEnabled: false,
HeaderNavModules: JSON.stringify(HEADER_NAV_DEFAULT),
SidebarModulesAdmin: JSON.stringify(SIDEBAR_MODULES_DEFAULT),
'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,
}
const toBoolean = (value: unknown, fallback: boolean): boolean => {
if (typeof value === 'boolean') return value
if (typeof value === 'number') return value === 1
@@ -1,54 +0,0 @@
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 { DEFAULT_MAINTENANCE_SETTINGS } from './config'
import {
MAINTENANCE_DEFAULT_SECTION,
getMaintenanceSectionContent,
} from './section-registry.tsx'
export function MaintenanceSettings() {
const { t } = useTranslation()
const { data, isLoading } = useSystemOptions()
const { status } = useStatus()
const params = useParams({
from: '/_authenticated/system-settings/maintenance/$section',
})
const settings = useMemo(
() => getOptionValue(data?.data, DEFAULT_MAINTENANCE_SETTINGS),
[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 ?? MAINTENANCE_DEFAULT_SECTION) as
| 'update-checker'
| 'notice'
| 'logs'
| 'header-navigation'
| 'sidebar-modules'
| 'performance'
const sectionContent = getMaintenanceSectionContent(
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>
)
}
@@ -1,137 +0,0 @@
import type { MaintenanceSettings } from '../types'
import { createSectionRegistry } from '../utils/section-registry'
import {
parseHeaderNavModules,
parseSidebarModulesAdmin,
serializeHeaderNavModules,
serializeSidebarModulesAdmin,
} from './config'
import { HeaderNavigationSection } from './header-navigation-section'
import { LogSettingsSection } from './log-settings-section'
import { NoticeSection } from './notice-section'
import { PerformanceSection } from './performance-section'
import { SidebarModulesSection } from './sidebar-modules-section'
import { UpdateCheckerSection } from './update-checker-section'
const MAINTENANCE_SECTIONS = [
{
id: 'update-checker',
titleKey: 'System maintenance',
descriptionKey: 'Check for system updates',
build: (
_settings: MaintenanceSettings,
currentVersion?: string | null,
startTime?: number | null
) => (
<UpdateCheckerSection
currentVersion={currentVersion}
startTime={startTime}
/>
),
},
{
id: 'notice',
titleKey: 'System Notice',
descriptionKey: 'Configure system maintenance notice',
build: (settings: MaintenanceSettings) => (
<NoticeSection defaultValue={settings.Notice ?? ''} />
),
},
{
id: 'logs',
titleKey: 'Log Maintenance',
descriptionKey: 'Configure log consumption settings',
build: (settings: MaintenanceSettings) => (
<LogSettingsSection
defaultEnabled={Boolean(settings.LogConsumeEnabled)}
/>
),
},
{
id: 'header-navigation',
titleKey: 'Header navigation',
descriptionKey: 'Configure header navigation modules',
build: (settings: MaintenanceSettings) => {
const headerNavConfig = parseHeaderNavModules(settings.HeaderNavModules)
const headerNavSerialized = serializeHeaderNavModules(headerNavConfig)
return (
<HeaderNavigationSection
config={headerNavConfig}
initialSerialized={headerNavSerialized}
/>
)
},
},
{
id: 'sidebar-modules',
titleKey: 'Sidebar modules',
descriptionKey: 'Configure sidebar modules for admin',
build: (settings: MaintenanceSettings) => {
const sidebarConfig = parseSidebarModulesAdmin(
settings.SidebarModulesAdmin
)
const sidebarSerialized = serializeSidebarModulesAdmin(sidebarConfig)
return (
<SidebarModulesSection
config={sidebarConfig}
initialSerialized={sidebarSerialized}
/>
)
},
},
{
id: 'performance',
titleKey: 'Performance',
descriptionKey: 'Disk cache, system monitoring and performance stats',
build: (settings: MaintenanceSettings) => (
<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,
}}
/>
),
},
] as const
export type MaintenanceSectionId = (typeof MAINTENANCE_SECTIONS)[number]['id']
const maintenanceRegistry = createSectionRegistry<
MaintenanceSectionId,
MaintenanceSettings,
[string | null | undefined, number | null | undefined]
>({
sections: MAINTENANCE_SECTIONS,
defaultSection: 'update-checker',
basePath: '/system-settings/maintenance',
urlStyle: 'path',
})
export const MAINTENANCE_SECTION_IDS = maintenanceRegistry.sectionIds
export const MAINTENANCE_DEFAULT_SECTION = maintenanceRegistry.defaultSection
export const getMaintenanceSectionNavItems =
maintenanceRegistry.getSectionNavItems
export const getMaintenanceSectionContent =
maintenanceRegistry.getSectionContent