yangdx
commited on
Commit
·
90cf704
1
Parent(s):
9c0cc20
Remove API Key setting from webui
Browse files
lightrag_webui/src/components/graph/Settings.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import { useState, useCallback
|
2 |
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/Popover'
|
3 |
import Checkbox from '@/components/ui/Checkbox'
|
4 |
import Button from '@/components/ui/Button'
|
@@ -7,7 +7,6 @@ import Input from '@/components/ui/Input'
|
|
7 |
|
8 |
import { controlButtonVariant } from '@/lib/constants'
|
9 |
import { useSettingsStore } from '@/stores/settings'
|
10 |
-
import { useBackendState } from '@/stores/state'
|
11 |
|
12 |
import { SettingsIcon } from 'lucide-react'
|
13 |
import { useTranslation } from 'react-i18next';
|
@@ -113,7 +112,6 @@ const LabeledNumberInput = ({
|
|
113 |
*/
|
114 |
export default function Settings() {
|
115 |
const [opened, setOpened] = useState<boolean>(false)
|
116 |
-
const [tempApiKey, setTempApiKey] = useState<string>('')
|
117 |
|
118 |
const showPropertyPanel = useSettingsStore.use.showPropertyPanel()
|
119 |
const showNodeSearchBar = useSettingsStore.use.showNodeSearchBar()
|
@@ -127,12 +125,7 @@ export default function Settings() {
|
|
127 |
const graphLayoutMaxIterations = useSettingsStore.use.graphLayoutMaxIterations()
|
128 |
|
129 |
const enableHealthCheck = useSettingsStore.use.enableHealthCheck()
|
130 |
-
|
131 |
-
|
132 |
-
useEffect(() => {
|
133 |
-
setTempApiKey(apiKey || '')
|
134 |
-
}, [apiKey, opened])
|
135 |
-
|
136 |
const setEnableNodeDrag = useCallback(
|
137 |
() => useSettingsStore.setState((pre) => ({ enableNodeDrag: !pre.enableNodeDrag })),
|
138 |
[]
|
@@ -180,11 +173,22 @@ export default function Settings() {
|
|
180 |
const setGraphQueryMaxDepth = useCallback((depth: number) => {
|
181 |
if (depth < 1) return
|
182 |
useSettingsStore.setState({ graphQueryMaxDepth: depth })
|
|
|
|
|
|
|
|
|
|
|
183 |
}, [])
|
184 |
|
185 |
const setGraphMinDegree = useCallback((degree: number) => {
|
186 |
if (degree < 0) return
|
187 |
useSettingsStore.setState({ graphMinDegree: degree })
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
}, [])
|
189 |
|
190 |
const setGraphLayoutMaxIterations = useCallback((iterations: number) => {
|
@@ -192,26 +196,21 @@ export default function Settings() {
|
|
192 |
useSettingsStore.setState({ graphLayoutMaxIterations: iterations })
|
193 |
}, [])
|
194 |
|
195 |
-
const setApiKey = useCallback(async () => {
|
196 |
-
useSettingsStore.setState({ apiKey: tempApiKey || null })
|
197 |
-
await useBackendState.getState().check()
|
198 |
-
setOpened(false)
|
199 |
-
}, [tempApiKey])
|
200 |
-
|
201 |
-
const handleTempApiKeyChange = useCallback(
|
202 |
-
(e: React.ChangeEvent<HTMLInputElement>) => {
|
203 |
-
setTempApiKey(e.target.value)
|
204 |
-
},
|
205 |
-
[setTempApiKey]
|
206 |
-
)
|
207 |
-
|
208 |
const { t } = useTranslation();
|
|
|
|
|
|
|
209 |
|
210 |
return (
|
211 |
<>
|
212 |
-
<Popover open={opened}
|
213 |
<PopoverTrigger asChild>
|
214 |
-
<Button
|
|
|
|
|
|
|
|
|
|
|
215 |
<SettingsIcon />
|
216 |
</Button>
|
217 |
</PopoverTrigger>
|
@@ -293,30 +292,15 @@ export default function Settings() {
|
|
293 |
onEditFinished={setGraphLayoutMaxIterations}
|
294 |
/>
|
295 |
<Separator />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
|
297 |
-
<div className="flex flex-col gap-2">
|
298 |
-
<label className="text-sm font-medium">{t('graphPanel.sideBar.settings.apiKey')}</label>
|
299 |
-
<form className="flex h-6 gap-2" onSubmit={(e) => e.preventDefault()}>
|
300 |
-
<div className="w-0 flex-1">
|
301 |
-
<Input
|
302 |
-
type="password"
|
303 |
-
value={tempApiKey}
|
304 |
-
onChange={handleTempApiKeyChange}
|
305 |
-
placeholder={t('graphPanel.sideBar.settings.enterYourAPIkey')}
|
306 |
-
className="max-h-full w-full min-w-0"
|
307 |
-
autoComplete="off"
|
308 |
-
/>
|
309 |
-
</div>
|
310 |
-
<Button
|
311 |
-
onClick={setApiKey}
|
312 |
-
variant="outline"
|
313 |
-
size="sm"
|
314 |
-
className="max-h-full shrink-0"
|
315 |
-
>
|
316 |
-
{t('graphPanel.sideBar.settings.save')}
|
317 |
-
</Button>
|
318 |
-
</form>
|
319 |
-
</div>
|
320 |
</div>
|
321 |
</PopoverContent>
|
322 |
</Popover>
|
|
|
1 |
+
import { useState, useCallback} from 'react'
|
2 |
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/Popover'
|
3 |
import Checkbox from '@/components/ui/Checkbox'
|
4 |
import Button from '@/components/ui/Button'
|
|
|
7 |
|
8 |
import { controlButtonVariant } from '@/lib/constants'
|
9 |
import { useSettingsStore } from '@/stores/settings'
|
|
|
10 |
|
11 |
import { SettingsIcon } from 'lucide-react'
|
12 |
import { useTranslation } from 'react-i18next';
|
|
|
112 |
*/
|
113 |
export default function Settings() {
|
114 |
const [opened, setOpened] = useState<boolean>(false)
|
|
|
115 |
|
116 |
const showPropertyPanel = useSettingsStore.use.showPropertyPanel()
|
117 |
const showNodeSearchBar = useSettingsStore.use.showNodeSearchBar()
|
|
|
125 |
const graphLayoutMaxIterations = useSettingsStore.use.graphLayoutMaxIterations()
|
126 |
|
127 |
const enableHealthCheck = useSettingsStore.use.enableHealthCheck()
|
128 |
+
|
|
|
|
|
|
|
|
|
|
|
129 |
const setEnableNodeDrag = useCallback(
|
130 |
() => useSettingsStore.setState((pre) => ({ enableNodeDrag: !pre.enableNodeDrag })),
|
131 |
[]
|
|
|
173 |
const setGraphQueryMaxDepth = useCallback((depth: number) => {
|
174 |
if (depth < 1) return
|
175 |
useSettingsStore.setState({ graphQueryMaxDepth: depth })
|
176 |
+
const currentLabel = useSettingsStore.getState().queryLabel
|
177 |
+
useSettingsStore.getState().setQueryLabel('')
|
178 |
+
setTimeout(() => {
|
179 |
+
useSettingsStore.getState().setQueryLabel(currentLabel)
|
180 |
+
}, 300)
|
181 |
}, [])
|
182 |
|
183 |
const setGraphMinDegree = useCallback((degree: number) => {
|
184 |
if (degree < 0) return
|
185 |
useSettingsStore.setState({ graphMinDegree: degree })
|
186 |
+
const currentLabel = useSettingsStore.getState().queryLabel
|
187 |
+
useSettingsStore.getState().setQueryLabel('')
|
188 |
+
setTimeout(() => {
|
189 |
+
useSettingsStore.getState().setQueryLabel(currentLabel)
|
190 |
+
}, 300)
|
191 |
+
|
192 |
}, [])
|
193 |
|
194 |
const setGraphLayoutMaxIterations = useCallback((iterations: number) => {
|
|
|
196 |
useSettingsStore.setState({ graphLayoutMaxIterations: iterations })
|
197 |
}, [])
|
198 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
199 |
const { t } = useTranslation();
|
200 |
+
|
201 |
+
const saveSettings = () => setOpened(false);
|
202 |
+
const toggleSettings = () => setOpened(!opened);
|
203 |
|
204 |
return (
|
205 |
<>
|
206 |
+
<Popover open={opened}>
|
207 |
<PopoverTrigger asChild>
|
208 |
+
<Button
|
209 |
+
variant={controlButtonVariant}
|
210 |
+
tooltip={t('graphPanel.sideBar.settings.settings')}
|
211 |
+
size="icon"
|
212 |
+
onClick={toggleSettings}
|
213 |
+
>
|
214 |
<SettingsIcon />
|
215 |
</Button>
|
216 |
</PopoverTrigger>
|
|
|
292 |
onEditFinished={setGraphLayoutMaxIterations}
|
293 |
/>
|
294 |
<Separator />
|
295 |
+
<Button
|
296 |
+
onClick={saveSettings}
|
297 |
+
variant="outline"
|
298 |
+
size="sm"
|
299 |
+
className="ml-auto px-4"
|
300 |
+
>
|
301 |
+
{t('graphPanel.sideBar.settings.save')}
|
302 |
+
</Button>
|
303 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
304 |
</div>
|
305 |
</PopoverContent>
|
306 |
</Popover>
|