3
3
import { BookIcon , CircuitBoard , GlobeIcon } from "lucide-react" ;
4
4
import { useRouter } from "next/router" ;
5
5
import React from "react" ;
6
+ import {
7
+ extractServices ,
8
+ type Services ,
9
+ } from "@/components/dashboard/settings/users/add-permissions" ;
6
10
import {
7
11
MariadbIcon ,
8
12
MongodbIcon ,
@@ -20,13 +24,34 @@ import {
20
24
CommandSeparator ,
21
25
} from "@/components/ui/command" ;
22
26
import { authClient } from "@/lib/auth-client" ;
23
- // import {
24
- // extractServices,
25
- // type Services,
26
- // } from "@/pages/dashboard/project/[projectId]";
27
27
import { api } from "@/utils/api" ;
28
28
import { StatusTooltip } from "../shared/status-tooltip" ;
29
29
30
+ // Extended Services type to include environmentId and environmentName for search navigation
31
+ type SearchServices = Services & {
32
+ environmentId : string ;
33
+ environmentName : string ;
34
+ } ;
35
+
36
+ const extractAllServicesFromProject = ( project : any ) : SearchServices [ ] => {
37
+ const allServices : SearchServices [ ] = [ ] ;
38
+
39
+ // Iterate through all environments in the project
40
+ project . environments ?. forEach ( ( environment : any ) => {
41
+ const environmentServices = extractServices ( environment ) ;
42
+ const servicesWithEnvironmentId : SearchServices [ ] = environmentServices . map (
43
+ ( service ) => ( {
44
+ ...service ,
45
+ environmentId : environment . environmentId ,
46
+ environmentName : environment . name ,
47
+ } ) ,
48
+ ) ;
49
+ allServices . push ( ...servicesWithEnvironmentId ) ;
50
+ } ) ;
51
+
52
+ return allServices ;
53
+ } ;
54
+
30
55
export const SearchCommand = ( ) => {
31
56
const router = useRouter ( ) ;
32
57
const [ open , setOpen ] = React . useState ( false ) ;
@@ -51,7 +76,7 @@ export const SearchCommand = () => {
51
76
52
77
return (
53
78
< div >
54
- { /* <CommandDialog open={open} onOpenChange={setOpen}>
79
+ < CommandDialog open = { open } onOpenChange = { setOpen } >
55
80
< CommandInput
56
81
placeholder = { "Search projects or settings" }
57
82
value = { search }
@@ -63,25 +88,37 @@ export const SearchCommand = () => {
63
88
</ CommandEmpty >
64
89
< CommandGroup heading = { "Projects" } >
65
90
< CommandList >
66
- {data?.map((project) => (
67
- <CommandItem
68
- key={project.projectId}
69
- onSelect={() => {
70
- router.push(`/dashboard/project/${project.projectId}`);
71
- setOpen(false);
72
- }}
73
- >
74
- <BookIcon className="size-4 text-muted-foreground mr-2" />
75
- {project.name}
76
- </CommandItem>
77
- ))}
91
+ { data ?. map ( ( project ) => {
92
+ console . log ( "project" , project ) ;
93
+ const productionEnvironment = project . environments . find (
94
+ ( environment ) => environment . name === "production" ,
95
+ ) ;
96
+
97
+ if ( ! productionEnvironment ) return null ;
98
+
99
+ return (
100
+ < CommandItem
101
+ key = { project . projectId }
102
+ onSelect = { ( ) => {
103
+ router . push (
104
+ `/dashboard/project/${ project . projectId } /environment/${ productionEnvironment ! . environmentId } ` ,
105
+ ) ;
106
+ setOpen ( false ) ;
107
+ } }
108
+ >
109
+ < BookIcon className = "size-4 text-muted-foreground mr-2" />
110
+ { project . name } / { productionEnvironment ! . name }
111
+ </ CommandItem >
112
+ ) ;
113
+ } ) }
78
114
</ CommandList >
79
115
</ CommandGroup >
80
116
< CommandSeparator />
81
117
< CommandGroup heading = { "Services" } >
82
118
< CommandList >
83
119
{ data ?. map ( ( project ) => {
84
- const applications: Services[] = extractServices(project);
120
+ const applications : SearchServices [ ] =
121
+ extractAllServicesFromProject ( project ) ;
85
122
return applications . map ( ( application ) => (
86
123
< CommandItem
87
124
key = { application . id }
@@ -114,7 +151,8 @@ export const SearchCommand = () => {
114
151
< CircuitBoard className = "h-6 w-6 mr-2" />
115
152
) }
116
153
< span className = "flex-grow" >
117
- {project.name} / {application.name}{" "}
154
+ { project . name } / { application . environmentName } /{ " " }
155
+ { application . name } { " " }
118
156
< div style = { { display : "none" } } > { application . id } </ div >
119
157
</ span >
120
158
< div >
@@ -181,7 +219,7 @@ export const SearchCommand = () => {
181
219
</ CommandItem >
182
220
</ CommandGroup >
183
221
</ CommandList >
184
- </CommandDialog> */ }
222
+ </ CommandDialog >
185
223
</ div >
186
224
) ;
187
225
} ;
0 commit comments