@@ -9,18 +9,27 @@ import {
9
9
} from '@mongodb-js/compass-components' ;
10
10
import { fetchItems } from '../stores/aggregations-queries-items' ;
11
11
import type { Item } from '../stores/aggregations-queries-items' ;
12
- import { openSavedItem } from '../stores/open-item' ;
12
+ import {
13
+ openSavedItem ,
14
+ openSelectConnectionAndNamespaceModal ,
15
+ } from '../stores/open-item' ;
13
16
import type { RootState } from '../stores' ;
14
17
import { SavedItemCard , CARD_WIDTH , CARD_HEIGHT } from './saved-item-card' ;
15
18
import type { Action } from './saved-item-card' ;
16
19
import { NoSavedItems , NoSearchResults } from './empty-list-items' ;
17
- import OpenItemModal from './open-item-modal' ;
18
20
import EditItemModal from './edit-item-modal' ;
19
21
import { useGridFilters , useFilteredItems } from '../hooks/use-grid-filters' ;
20
22
import { editItem } from '../stores/edit-item' ;
21
23
import { confirmDeleteItem } from '../stores/delete-item' ;
22
24
import { copyToClipboard } from '../stores/copy-to-clipboard' ;
23
25
import { useTrackOnChange } from '@mongodb-js/compass-logging/provider' ;
26
+ import {
27
+ type ConnectionInfo ,
28
+ useActiveConnections ,
29
+ } from '@mongodb-js/compass-connections/provider' ;
30
+ import SelectConnectionModal from './select-connection-modal' ;
31
+ import SelectConnectionAndNamespaceModal from './select-connection-and-namespace-modal' ;
32
+ import NoActiveConnectionsModal from './no-active-connections-modal' ;
24
33
25
34
const sortBy : { name : keyof Item ; label : string } [ ] = [
26
35
{
@@ -73,7 +82,11 @@ export type AggregationsQueriesListProps = {
73
82
loading : boolean ;
74
83
items : Item [ ] ;
75
84
onMount ( ) : void ;
76
- onOpenItem ( id : string ) : void ;
85
+ onOpenItem ( id : string , activeConnections : ConnectionInfo [ ] ) : void ;
86
+ onOpenItemForDiffTarget (
87
+ id : string ,
88
+ activeConnections : ConnectionInfo [ ]
89
+ ) : void ;
77
90
onEditItem ( id : string ) : void ;
78
91
onDeleteItem ( id : string ) : void ;
79
92
onCopyToClipboard ( id : string ) : void ;
@@ -84,6 +97,7 @@ export const AggregationsQueriesList = ({
84
97
items,
85
98
onMount,
86
99
onOpenItem,
100
+ onOpenItemForDiffTarget,
87
101
onEditItem,
88
102
onDeleteItem,
89
103
onCopyToClipboard,
@@ -92,6 +106,22 @@ export const AggregationsQueriesList = ({
92
106
void onMount ( ) ;
93
107
} , [ onMount ] ) ;
94
108
109
+ const activeConnections = useActiveConnections ( ) ;
110
+
111
+ const handleOpenItem = useCallback (
112
+ ( id : string ) => {
113
+ onOpenItem ( id , activeConnections ) ;
114
+ } ,
115
+ [ activeConnections , onOpenItem ]
116
+ ) ;
117
+
118
+ const handleOpenItemForDiffTarget = useCallback (
119
+ ( id : string ) => {
120
+ onOpenItemForDiffTarget ( id , activeConnections ) ;
121
+ } ,
122
+ [ activeConnections , onOpenItemForDiffTarget ]
123
+ ) ;
124
+
95
125
const {
96
126
controls : filterControls ,
97
127
conditions : filters ,
@@ -155,7 +185,10 @@ export const AggregationsQueriesList = ({
155
185
( id : string , actionName : Action ) => {
156
186
switch ( actionName ) {
157
187
case 'open' :
158
- onOpenItem ( id ) ;
188
+ handleOpenItem ( id ) ;
189
+ return ;
190
+ case 'open-in' :
191
+ handleOpenItemForDiffTarget ( id ) ;
159
192
return ;
160
193
case 'rename' :
161
194
onEditItem ( id ) ;
@@ -168,7 +201,13 @@ export const AggregationsQueriesList = ({
168
201
return ;
169
202
}
170
203
} ,
171
- [ onOpenItem , onEditItem , onDeleteItem , onCopyToClipboard ]
204
+ [
205
+ handleOpenItem ,
206
+ handleOpenItemForDiffTarget ,
207
+ onEditItem ,
208
+ onDeleteItem ,
209
+ onCopyToClipboard ,
210
+ ]
172
211
) ;
173
212
174
213
const renderItem : React . ComponentProps < typeof VirtualGrid > [ 'renderItem' ] =
@@ -228,7 +267,9 @@ export const AggregationsQueriesList = ({
228
267
classNames = { { row : rowStyles } }
229
268
resetActiveItemOnBlur = { false }
230
269
> </ VirtualGrid >
231
- < OpenItemModal > </ OpenItemModal >
270
+ < SelectConnectionModal />
271
+ < SelectConnectionAndNamespaceModal />
272
+ < NoActiveConnectionsModal />
232
273
< EditItemModal > </ EditItemModal >
233
274
</ ControlsContext . Provider >
234
275
) ;
@@ -242,6 +283,7 @@ const mapState = ({ savedItems: { items, loading } }: RootState) => ({
242
283
const mapDispatch = {
243
284
onMount : fetchItems ,
244
285
onOpenItem : openSavedItem ,
286
+ onOpenItemForDiffTarget : openSelectConnectionAndNamespaceModal ,
245
287
onEditItem : editItem ,
246
288
onDeleteItem : confirmDeleteItem ,
247
289
onCopyToClipboard : copyToClipboard ,
0 commit comments