From bcc03820011b416994e52dc6a419dd4b63b7ea21 Mon Sep 17 00:00:00 2001 From: Adrian Bonpin Date: Mon, 27 Apr 2026 07:21:30 +0800 Subject: [PATCH] feat(settings-editor): add UX improvements - Add 'Create custom' button alongside 'Load defaults' when empty - Add setting type selector (text/number/boolean) when adding new settings - Add reorder controls for categories (up/down arrows) - Add reorder controls for settings within each category --- components/wizard/settings-editor.tsx | 153 +++++++++++++++++++++----- 1 file changed, 128 insertions(+), 25 deletions(-) diff --git a/components/wizard/settings-editor.tsx b/components/wizard/settings-editor.tsx index aa6e0ed..daba7df 100644 --- a/components/wizard/settings-editor.tsx +++ b/components/wizard/settings-editor.tsx @@ -58,6 +58,7 @@ export function SettingsEditor({ ) const [newCategoryName, setNewCategoryName] = useState("") const [newSettingNames, setNewSettingNames] = useState>({}) + const [newSettingTypes, setNewSettingTypes] = useState>({}) const toggleCategory = (category: string) => { setCollapsedCategories((prev) => { @@ -92,20 +93,63 @@ export function SettingsEditor({ const addSetting = (category: string) => { const name = (newSettingNames[category] || "").trim() if (!name) return - + const type = newSettingTypes[category] || "text" + const defaultValue = type === "boolean" ? false : type === "number" ? 0 : "" onChange( value.map((c) => { if (c.category !== category) return c if (c.settings.some((s) => s.title === name)) return c return { ...c, - settings: [...c.settings, { title: name, value: "" }], + settings: [...c.settings, { title: name, value: defaultValue }], } }) ) setNewSettingNames((prev) => ({ ...prev, [category]: "" })) } + const moveCategoryUp = (category: string) => { + const idx = value.findIndex((c) => c.category === category) + if (idx <= 0) return + const next = [...value] + ;[next[idx - 1], next[idx]] = [next[idx], next[idx - 1]] + onChange(next) + } + + const moveCategoryDown = (category: string) => { + const idx = value.findIndex((c) => c.category === category) + if (idx >= value.length - 1) return + const next = [...value] + ;[next[idx], next[idx + 1]] = [next[idx + 1], next[idx]] + onChange(next) + } + + const moveSettingUp = (category: string, settingTitle: string) => { + onChange( + value.map((c) => { + if (c.category !== category) return c + const idx = c.settings.findIndex((s) => s.title === settingTitle) + if (idx <= 0) return c + const next = [...c.settings] + ;[next[idx - 1], next[idx]] = [next[idx], next[idx - 1]] + return { ...c, settings: next } + }) + ) + } + + const moveSettingDown = (category: string, settingTitle: string) => { + onChange( + value.map((c) => { + if (c.category !== category) return c + const idx = c.settings.findIndex((s) => s.title === settingTitle) + if (idx >= c.settings.length - 1) return c + const next = [...c.settings] + ;[next[idx], next[idx + 1]] = [next[idx + 1], next[idx]] + return { ...c, settings: next } + }) + ) + } + const removeSetting = (category: string, settingTitle: string) => { onChange( value.map((c) => { @@ -148,17 +192,28 @@ export function SettingsEditor({ {isEmpty && (

No settings configured

- +
+ + +
)} - {value.map((cat) => { + {value.map((cat, index) => { const isCollapsed = collapsedCategories.has(cat.category) return ( - +
+ + + +
@@ -257,20 +330,50 @@ export function SettingsEditor({ /> )} - +
+ + + +
))}
+