From f9f588aa160ae2ade22a3cf3e41c67200140ceff Mon Sep 17 00:00:00 2001 From: yangdx Date: Wed, 2 Apr 2025 23:40:16 +0800 Subject: [PATCH] Feat: add reset button to the right of input box --- .../src/components/graph/Settings.tsx | 58 ++++++++++++++----- 1 file changed, 42 insertions(+), 16 deletions(-) diff --git a/lightrag_webui/src/components/graph/Settings.tsx b/lightrag_webui/src/components/graph/Settings.tsx index f8b0e6cd..8c1ea652 100644 --- a/lightrag_webui/src/components/graph/Settings.tsx +++ b/lightrag_webui/src/components/graph/Settings.tsx @@ -8,7 +8,7 @@ import Input from '@/components/ui/Input' import { controlButtonVariant } from '@/lib/constants' import { useSettingsStore } from '@/stores/settings' -import { SettingsIcon } from 'lucide-react' +import { SettingsIcon, Undo2 } from 'lucide-react' import { useTranslation } from 'react-i18next'; /** @@ -44,13 +44,15 @@ const LabeledNumberInput = ({ onEditFinished, label, min, - max + max, + defaultValue }: { value: number onEditFinished: (value: number) => void label: string min: number max?: number + defaultValue?: number }) => { const [currentValue, setCurrentValue] = useState(value) @@ -81,6 +83,13 @@ const LabeledNumberInput = ({ } }, [value, currentValue, onEditFinished]) + const handleReset = useCallback(() => { + if (defaultValue !== undefined && value !== defaultValue) { + setCurrentValue(defaultValue) + onEditFinished(defaultValue) + } + }, [defaultValue, value, onEditFinished]) + return (
- { - if (e.key === 'Enter') { - onBlur() - } - }} - /> +
+ { + if (e.key === 'Enter') { + onBlur() + } + }} + /> + {defaultValue !== undefined && ( + + )} +
) } @@ -273,6 +296,7 @@ export default function Settings() { label={t('graphPanel.sideBar.settings.maxQueryDepth')} min={1} value={graphQueryMaxDepth} + defaultValue={3} onEditFinished={setGraphQueryMaxDepth} />