From 1f215d8ecb7fbd92ce417b62fbde0cb9ae6ab7ae Mon Sep 17 00:00:00 2001 From: kaitranntt Date: Sun, 7 Dec 2025 20:57:30 -0500 Subject: [PATCH] refactor(ui): replace settings page with deprecation notice - Remove complex settings editor (217 lines) - Add simple deprecation redirect to API Profiles page - Improve UX by consolidating settings functionality --- ui/src/pages/settings.tsx | 253 ++++++-------------------------------- 1 file changed, 37 insertions(+), 216 deletions(-) diff --git a/ui/src/pages/settings.tsx b/ui/src/pages/settings.tsx index dac482f4..68638cfc 100644 --- a/ui/src/pages/settings.tsx +++ b/ui/src/pages/settings.tsx @@ -1,225 +1,46 @@ -import { useState, useMemo } from 'react'; -import { useSearchParams } from 'react-router-dom'; -import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; -import { Button } from '@/components/ui/button'; +/** + * Settings Page - Deprecated + * Settings functionality has been moved to API Profiles page + */ + +import { Link } from 'react-router-dom'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; -import { Input } from '@/components/ui/input'; -import { Label } from '@/components/ui/label'; -import { MaskedInput } from '@/components/ui/masked-input'; -import { ConfirmDialog } from '@/components/confirm-dialog'; -import { Edit, Save, X } from 'lucide-react'; -import { toast } from 'sonner'; -import { api } from '@/lib/api-client'; - -interface Settings { - env?: Record; -} - -interface SettingsResponse { - profile: string; - settings: Settings; - mtime: number; - path: string; -} +import { Button } from '@/components/ui/button'; +import { Construction, ArrowRight } from 'lucide-react'; export function SettingsPage() { - const [searchParams, setSearchParams] = useSearchParams(); - const profile = searchParams.get('profile'); - const [editMode, setEditMode] = useState(false); - const [editedSettings, setEditedSettings] = useState(null); - const [conflictDialog, setConflictDialog] = useState(false); - const queryClient = useQueryClient(); - - // Fetch profiles for selector - const { data: profilesData } = useQuery({ - queryKey: ['profiles'], - queryFn: () => api.profiles.list(), - }); - - // Fetch settings for selected profile - const { data, isLoading, refetch } = useQuery({ - queryKey: ['settings', profile], - queryFn: () => fetch(`/api/settings/${profile}/raw`).then((r) => r.json()), - enabled: !!profile, - }); - - // Use edited settings when in edit mode, otherwise use data directly - const currentSettings = useMemo(() => { - return editMode && editedSettings ? editedSettings : data?.settings; - }, [editMode, editedSettings, data?.settings]); - - // Save mutation - const saveMutation = useMutation({ - mutationFn: async () => { - const res = await fetch(`/api/settings/${profile}`, { - method: 'PUT', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - settings: editedSettings, - expectedMtime: data?.mtime, - }), - }); - - if (res.status === 409) { - throw new Error('CONFLICT'); - } - - if (!res.ok) { - throw new Error('Failed to save'); - } - - return res.json(); - }, - onSuccess: () => { - queryClient.invalidateQueries({ queryKey: ['settings', profile] }); - setEditedSettings(null); - setEditMode(false); - toast.success('Settings saved'); - }, - onError: (error: Error) => { - if (error.message === 'CONFLICT') { - setConflictDialog(true); - } else { - toast.error(error.message); - } - }, - }); - - const handleSave = () => { - saveMutation.mutate(); - }; - - const handleConflictResolve = async (overwrite: boolean) => { - setConflictDialog(false); - if (overwrite) { - // Refetch to get new mtime, then save - await refetch(); - saveMutation.mutate(); - } else { - // Discard local changes - setEditedSettings(null); - setEditMode(false); - } - }; - - const updateEnvValue = (key: string, value: string) => { - setEditedSettings((prev) => ({ - ...prev, - env: { - ...prev?.env, - [key]: value, - }, - })); - }; - return (
-
-

Settings Editor

- -
+

Settings

- {!profile && ( - - -

Select a profile to view/edit settings.

-
-
- )} - - {profile && isLoading && ( - - -

Loading...

-
-
- )} - - {profile && data && currentSettings && ( - - - Environment Variables -
- {!editMode ? ( - - ) : ( - <> - - - - )} -
-
- - {Object.entries(currentSettings.env || {}).map(([key, value]) => ( -
- - {key.includes('TOKEN') || key.includes('KEY') ? ( - updateEnvValue(key, e.target.value)} - disabled={!editMode} - /> - ) : ( - updateEnvValue(key, e.target.value)} - disabled={!editMode} - className="font-mono" - /> - )} -
- ))} - -
-

Path: {data.path}

-

Last modified: {new Date(data.mtime).toLocaleString()}

-
-
-
- )} - - handleConflictResolve(true)} - onCancel={() => handleConflictResolve(false)} - /> + + + + + Page Relocated + + + +

+ The settings editor has been integrated into the API Profiles page for + a better user experience. +

+

To edit environment variables for a profile:

+
    +
  1. Go to API Profiles page
  2. +
  3. Click the actions menu (...) on any profile
  4. +
  5. Select "Edit Settings"
  6. +
+
+ +
+
+
); }