yangdx
commited on
Commit
·
422ad46
1
Parent(s):
9f2e859
Improve graph label search functionality and UI behavior
Browse files- Display a drop down list box when user input is empty
- Ensure graph is available before searching
lightrag_webui/src/components/graph/GraphSearch.tsx
CHANGED
|
@@ -85,7 +85,18 @@ export const GraphSearchInput = ({
|
|
| 85 |
const loadOptions = useCallback(
|
| 86 |
async (query?: string): Promise<OptionItem[]> => {
|
| 87 |
if (onFocus) onFocus(null)
|
| 88 |
-
if (!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
const result: OptionItem[] = searchEngine.search(query).map((r: { id: string }) => ({
|
| 90 |
id: r.id,
|
| 91 |
type: 'nodes'
|
|
@@ -103,7 +114,7 @@ export const GraphSearchInput = ({
|
|
| 103 |
}
|
| 104 |
]
|
| 105 |
},
|
| 106 |
-
[searchEngine, onFocus, t]
|
| 107 |
)
|
| 108 |
|
| 109 |
return (
|
|
|
|
| 85 |
const loadOptions = useCallback(
|
| 86 |
async (query?: string): Promise<OptionItem[]> => {
|
| 87 |
if (onFocus) onFocus(null)
|
| 88 |
+
if (!graph || !searchEngine) return []
|
| 89 |
+
|
| 90 |
+
// If no query, return first searchResultLimit nodes
|
| 91 |
+
if (!query) {
|
| 92 |
+
const nodeIds = graph.nodes().slice(0, searchResultLimit)
|
| 93 |
+
return nodeIds.map(id => ({
|
| 94 |
+
id,
|
| 95 |
+
type: 'nodes'
|
| 96 |
+
}))
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
// If has query, search nodes
|
| 100 |
const result: OptionItem[] = searchEngine.search(query).map((r: { id: string }) => ({
|
| 101 |
id: r.id,
|
| 102 |
type: 'nodes'
|
|
|
|
| 114 |
}
|
| 115 |
]
|
| 116 |
},
|
| 117 |
+
[graph, searchEngine, onFocus, t]
|
| 118 |
)
|
| 119 |
|
| 120 |
return (
|
lightrag_webui/src/components/ui/AsyncSearch.tsx
CHANGED
|
@@ -193,7 +193,7 @@ export function AsyncSearch<T>({
|
|
| 193 |
</div>
|
| 194 |
)}
|
| 195 |
</div>
|
| 196 |
-
<CommandList hidden={!open
|
| 197 |
{error && <div className="text-destructive p-4 text-center">{error}</div>}
|
| 198 |
{loading && options.length === 0 && (loadingSkeleton || <DefaultLoadingSkeleton />)}
|
| 199 |
{!loading &&
|
|
|
|
| 193 |
</div>
|
| 194 |
)}
|
| 195 |
</div>
|
| 196 |
+
<CommandList hidden={!open}>
|
| 197 |
{error && <div className="text-destructive p-4 text-center">{error}</div>}
|
| 198 |
{loading && options.length === 0 && (loadingSkeleton || <DefaultLoadingSkeleton />)}
|
| 199 |
{!loading &&
|