22
33import { useCallback , useEffect , useMemo , useRef , useState } from 'react'
44import { Command } from 'cmdk'
5- import { BookOpen , Layout , ScrollText } from 'lucide-react'
5+ import { Database , HelpCircle , Layout , Settings } from 'lucide-react'
66import { useParams , useRouter } from 'next/navigation'
77import { createPortal } from 'react-dom'
8+ import { Library } from '@/components/emcn'
89import { useBrandConfig } from '@/lib/branding/branding'
910import { cn } from '@/lib/core/utils/cn'
1011import { hasTriggerCapability } from '@/lib/workflows/triggers/trigger-utils'
@@ -15,6 +16,7 @@ import type {
1516 SearchDocItem ,
1617 SearchToolOperationItem ,
1718} from '@/stores/modals/search/types'
19+ import { useSettingsModalStore } from '@/stores/modals/settings/store'
1820
1921interface SearchModalProps {
2022 open : boolean
@@ -43,7 +45,8 @@ interface PageItem {
4345 id : string
4446 name : string
4547 icon : React . ComponentType < { className ?: string } >
46- href : string
48+ href ?: string
49+ onClick ?: ( ) => void
4750 shortcut ?: string
4851}
4952
@@ -61,6 +64,7 @@ export function SearchModal({
6164 const inputRef = useRef < HTMLInputElement > ( null )
6265 const [ search , setSearch ] = useState ( '' )
6366 const [ mounted , setMounted ] = useState ( false )
67+ const openSettingsModal = useSettingsModalStore ( ( state ) => state . openModal )
6468
6569 useEffect ( ( ) => {
6670 setMounted ( true )
@@ -70,12 +74,16 @@ export function SearchModal({
7074 ( state ) => state . data
7175 )
7276
77+ const openHelpModal = useCallback ( ( ) => {
78+ window . dispatchEvent ( new CustomEvent ( 'open-help-modal' ) )
79+ } , [ ] )
80+
7381 const pages = useMemo (
7482 ( ) : PageItem [ ] => [
7583 {
7684 id : 'logs' ,
7785 name : 'Logs' ,
78- icon : ScrollText ,
86+ icon : Library ,
7987 href : `/workspace/${ workspaceId } /logs` ,
8088 shortcut : '⌘⇧L' ,
8189 } ,
@@ -86,13 +94,26 @@ export function SearchModal({
8694 href : `/workspace/${ workspaceId } /templates` ,
8795 } ,
8896 {
89- id : 'docs' ,
90- name : 'Docs' ,
91- icon : BookOpen ,
92- href : brand . documentationUrl || 'https://docs.sim.ai/' ,
97+ id : 'knowledge-base' ,
98+ name : 'Knowledge Base' ,
99+ icon : Database ,
100+ href : `/workspace/${ workspaceId } /knowledge` ,
101+ } ,
102+ {
103+ id : 'help' ,
104+ name : 'Help' ,
105+ icon : HelpCircle ,
106+ onClick : openHelpModal ,
107+ } ,
108+ {
109+ id : 'settings' ,
110+ name : 'Settings' ,
111+ icon : Settings ,
112+ onClick : openSettingsModal ,
113+ shortcut : '⌘,' ,
93114 } ,
94115 ] ,
95- [ workspaceId , brand . documentationUrl ]
116+ [ workspaceId , openHelpModal , openSettingsModal ]
96117 )
97118
98119 useEffect ( ( ) => {
@@ -179,10 +200,14 @@ export function SearchModal({
179200
180201 const handlePageSelect = useCallback (
181202 ( page : PageItem ) => {
182- if ( page . href . startsWith ( 'http' ) ) {
183- window . open ( page . href , '_blank' , 'noopener,noreferrer' )
184- } else {
185- router . push ( page . href )
203+ if ( page . onClick ) {
204+ page . onClick ( )
205+ } else if ( page . href ) {
206+ if ( page . href . startsWith ( 'http' ) ) {
207+ window . open ( page . href , '_blank' , 'noopener,noreferrer' )
208+ } else {
209+ router . push ( page . href )
210+ }
186211 }
187212 onOpenChange ( false )
188213 } ,
@@ -269,7 +294,7 @@ export function SearchModal({
269294 { blocks . map ( ( block ) => (
270295 < CommandItem
271296 key = { block . id }
272- value = { block . name }
297+ value = { ` ${ block . name } block- ${ block . id } ` }
273298 keywords = { [ block . description ] }
274299 onSelect = { ( ) => handleBlockSelect ( block , 'block' ) }
275300 icon = { block . icon }
@@ -287,7 +312,7 @@ export function SearchModal({
287312 { tools . map ( ( tool ) => (
288313 < CommandItem
289314 key = { tool . id }
290- value = { tool . name }
315+ value = { ` ${ tool . name } tool- ${ tool . id } ` }
291316 keywords = { [ tool . description ] }
292317 onSelect = { ( ) => handleBlockSelect ( tool , 'tool' ) }
293318 icon = { tool . icon }
@@ -305,7 +330,7 @@ export function SearchModal({
305330 { triggers . map ( ( trigger ) => (
306331 < CommandItem
307332 key = { trigger . id }
308- value = { trigger . name }
333+ value = { ` ${ trigger . name } trigger- ${ trigger . id } ` }
309334 keywords = { [ trigger . description ] }
310335 onSelect = { ( ) => handleBlockSelect ( trigger , 'trigger' ) }
311336 icon = { trigger . icon }
@@ -323,7 +348,7 @@ export function SearchModal({
323348 { workflows . map ( ( workflow ) => (
324349 < Command . Item
325350 key = { workflow . id }
326- value = { workflow . name }
351+ value = { ` ${ workflow . name } workflow- ${ workflow . id } ` }
327352 onSelect = { ( ) => handleWorkflowSelect ( workflow ) }
328353 className = 'group flex h-[28px] w-full cursor-pointer items-center gap-[8px] rounded-[6px] px-[10px] text-left text-[15px] aria-selected:bg-[var(--border)] aria-selected:shadow-sm data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50'
329354 >
@@ -345,7 +370,7 @@ export function SearchModal({
345370 { toolOperations . map ( ( op ) => (
346371 < CommandItem
347372 key = { op . id }
348- value = { op . searchValue }
373+ value = { ` ${ op . searchValue } operation- ${ op . id } ` }
349374 keywords = { op . keywords }
350375 onSelect = { ( ) => handleToolOperationSelect ( op ) }
351376 icon = { op . icon }
@@ -363,7 +388,7 @@ export function SearchModal({
363388 { workspaces . map ( ( workspace ) => (
364389 < Command . Item
365390 key = { workspace . id }
366- value = { workspace . name }
391+ value = { ` ${ workspace . name } workspace- ${ workspace . id } ` }
367392 onSelect = { ( ) => handleWorkspaceSelect ( workspace ) }
368393 className = 'group flex h-[28px] w-full cursor-pointer items-center gap-[8px] rounded-[6px] px-[10px] text-left text-[15px] aria-selected:bg-[var(--border)] aria-selected:shadow-sm data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50'
369394 >
@@ -381,7 +406,7 @@ export function SearchModal({
381406 { docs . map ( ( doc ) => (
382407 < CommandItem
383408 key = { doc . id }
384- value = { `${ doc . name } docs documentation` }
409+ value = { `${ doc . name } docs documentation doc- ${ doc . id } ` }
385410 onSelect = { ( ) => handleDocSelect ( doc ) }
386411 icon = { doc . icon }
387412 bgColor = '#6B7280'
@@ -400,7 +425,7 @@ export function SearchModal({
400425 return (
401426 < Command . Item
402427 key = { page . id }
403- value = { page . name }
428+ value = { ` ${ page . name } page- ${ page . id } ` }
404429 onSelect = { ( ) => handlePageSelect ( page ) }
405430 className = 'group flex h-[28px] w-full cursor-pointer items-center gap-[8px] rounded-[6px] px-[10px] text-left text-[15px] aria-selected:bg-[var(--border)] aria-selected:shadow-sm data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50'
406431 >
0 commit comments