import { Button } from '@affine/admin/components/ui/button'; import { ScrollArea } from '@affine/admin/components/ui/scroll-area'; import { Separator } from '@affine/admin/components/ui/separator'; import { get } from 'lodash-es'; import { CheckIcon } from 'lucide-react'; import { useCallback, useState } from 'react'; import { Header } from '../header'; import { useNav } from '../nav/context'; import { ALL_CONFIG, ALL_CONFIGURABLE_MODULES, type ConfigDescriptor, } from './config'; import { ConfigInput } from './config-input'; import { ConfirmChanges } from './confirm-changes'; import { RuntimeSettingRow } from './runtime-setting-row'; import { useAppConfig } from './use-app-config'; export function SettingsPage() { const { appConfig, update, save, updates } = useAppConfig(); const [open, setOpen] = useState(false); const onOpen = useCallback(() => setOpen(true), [setOpen]); const disableSave = Object.keys(updates).length === 0; const saveChanges = useCallback(() => { if (disableSave) { return; } save( Object.entries(updates).map(([key, { to }]) => { const splitAt = key.indexOf('.'); const [module, field] = [key.slice(0, splitAt), key.slice(splitAt + 1)]; return { module, key: field, value: to, }; }) ); setOpen(false); }, [save, disableSave, updates]); return (
} />
); } export const AdminPanel = ({ appConfig, onUpdate, }: { appConfig: Record; onUpdate: (module: string, field: string, value: any) => void; }) => { const { currentModule } = useNav(); return (
{ALL_CONFIGURABLE_MODULES.filter( module => module === currentModule ).map(module => { const fields = Object.keys(ALL_CONFIG[module]); return (
{module}
{fields.map((field, index) => { // @ts-expect-error allow const { desc, type } = ALL_CONFIG[module][ field ] as ConfigDescriptor; return (
{index !== 0 && }
); })}
); })}
); }; export { SettingsPage as Component };