Skip to content

Commit 69f7964

Browse files
chore(my-queries): support for multiple connections for my-queries COMPASS-7904, COMPASS-7915 (#5841)
1 parent ce5a318 commit 69f7964

File tree

21 files changed

+1783
-620
lines changed

21 files changed

+1783
-620
lines changed

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-saved-aggregations-queries/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,11 @@
5353
"@mongodb-js/compass-connections": "^1.30.1",
5454
"@mongodb-js/compass-logging": "^1.2.18",
5555
"@mongodb-js/compass-workspaces": "^0.11.0",
56+
"@mongodb-js/connection-form": "^1.28.1",
57+
"@mongodb-js/connection-info": "^0.3.1",
5658
"@mongodb-js/my-queries-storage": "^0.8.1",
5759
"bson": "^6.7.0",
60+
"compass-preferences-model": "^2.20.0",
5861
"fuse.js": "^6.5.3",
5962
"hadron-app-registry": "^9.1.11",
6063
"mongodb-ns": "^2.4.2",
@@ -64,6 +67,7 @@
6467
"redux-thunk": "^2.4.2"
6568
},
6669
"devDependencies": {
70+
"@mongodb-js/connection-storage": "^0.12.1",
6771
"@mongodb-js/eslint-config-compass": "^1.1.1",
6872
"@mongodb-js/mocha-config-compass": "^1.3.9",
6973
"@mongodb-js/prettier-config-compass": "^1.0.2",

packages/compass-saved-aggregations-queries/src/components/aggregations-queries-list.tsx

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,27 @@ import {
99
} from '@mongodb-js/compass-components';
1010
import { fetchItems } from '../stores/aggregations-queries-items';
1111
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';
1316
import type { RootState } from '../stores';
1417
import { SavedItemCard, CARD_WIDTH, CARD_HEIGHT } from './saved-item-card';
1518
import type { Action } from './saved-item-card';
1619
import { NoSavedItems, NoSearchResults } from './empty-list-items';
17-
import OpenItemModal from './open-item-modal';
1820
import EditItemModal from './edit-item-modal';
1921
import { useGridFilters, useFilteredItems } from '../hooks/use-grid-filters';
2022
import { editItem } from '../stores/edit-item';
2123
import { confirmDeleteItem } from '../stores/delete-item';
2224
import { copyToClipboard } from '../stores/copy-to-clipboard';
2325
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';
2433

2534
const sortBy: { name: keyof Item; label: string }[] = [
2635
{
@@ -73,7 +82,11 @@ export type AggregationsQueriesListProps = {
7382
loading: boolean;
7483
items: Item[];
7584
onMount(): void;
76-
onOpenItem(id: string): void;
85+
onOpenItem(id: string, activeConnections: ConnectionInfo[]): void;
86+
onOpenItemForDiffTarget(
87+
id: string,
88+
activeConnections: ConnectionInfo[]
89+
): void;
7790
onEditItem(id: string): void;
7891
onDeleteItem(id: string): void;
7992
onCopyToClipboard(id: string): void;
@@ -84,6 +97,7 @@ export const AggregationsQueriesList = ({
8497
items,
8598
onMount,
8699
onOpenItem,
100+
onOpenItemForDiffTarget,
87101
onEditItem,
88102
onDeleteItem,
89103
onCopyToClipboard,
@@ -92,6 +106,22 @@ export const AggregationsQueriesList = ({
92106
void onMount();
93107
}, [onMount]);
94108

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+
95125
const {
96126
controls: filterControls,
97127
conditions: filters,
@@ -155,7 +185,10 @@ export const AggregationsQueriesList = ({
155185
(id: string, actionName: Action) => {
156186
switch (actionName) {
157187
case 'open':
158-
onOpenItem(id);
188+
handleOpenItem(id);
189+
return;
190+
case 'open-in':
191+
handleOpenItemForDiffTarget(id);
159192
return;
160193
case 'rename':
161194
onEditItem(id);
@@ -168,7 +201,13 @@ export const AggregationsQueriesList = ({
168201
return;
169202
}
170203
},
171-
[onOpenItem, onEditItem, onDeleteItem, onCopyToClipboard]
204+
[
205+
handleOpenItem,
206+
handleOpenItemForDiffTarget,
207+
onEditItem,
208+
onDeleteItem,
209+
onCopyToClipboard,
210+
]
172211
);
173212

174213
const renderItem: React.ComponentProps<typeof VirtualGrid>['renderItem'] =
@@ -228,7 +267,9 @@ export const AggregationsQueriesList = ({
228267
classNames={{ row: rowStyles }}
229268
resetActiveItemOnBlur={false}
230269
></VirtualGrid>
231-
<OpenItemModal></OpenItemModal>
270+
<SelectConnectionModal />
271+
<SelectConnectionAndNamespaceModal />
272+
<NoActiveConnectionsModal />
232273
<EditItemModal></EditItemModal>
233274
</ControlsContext.Provider>
234275
);
@@ -242,6 +283,7 @@ const mapState = ({ savedItems: { items, loading } }: RootState) => ({
242283
const mapDispatch = {
243284
onMount: fetchItems,
244285
onOpenItem: openSavedItem,
286+
onOpenItemForDiffTarget: openSelectConnectionAndNamespaceModal,
245287
onEditItem: editItem,
246288
onDeleteItem: confirmDeleteItem,
247289
onCopyToClipboard: copyToClipboard,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React from 'react';
2+
import {
3+
type MapDispatchToProps,
4+
type MapStateToProps,
5+
connect,
6+
} from 'react-redux';
7+
import { type RootState } from '../stores';
8+
import { closeModal } from '../stores/open-item';
9+
import { Banner, InfoModal } from '@mongodb-js/compass-components';
10+
11+
type NoActiveConnectionsModalProps = {
12+
isOpened: boolean;
13+
onClose(): void;
14+
};
15+
16+
const NoActiveConnectionsModal: React.FunctionComponent<
17+
NoActiveConnectionsModalProps
18+
> = ({ isOpened, onClose }) => {
19+
return (
20+
<InfoModal
21+
title="Connect to a cluster"
22+
open={isOpened}
23+
onClose={onClose}
24+
showCloseButton={false}
25+
data-testid="no-active-connection-modal"
26+
>
27+
<Banner variant="warning">
28+
It appears that you are not connected to a cluster. Establish a
29+
connection first.
30+
</Banner>
31+
</InfoModal>
32+
);
33+
};
34+
35+
const mapState: MapStateToProps<
36+
Pick<NoActiveConnectionsModalProps, 'isOpened'>,
37+
Record<string, never>,
38+
RootState
39+
> = ({ openItem: { openedModal } }) => {
40+
return {
41+
isOpened: openedModal === 'no-active-connections-modal',
42+
};
43+
};
44+
45+
const mapDispatch: MapDispatchToProps<
46+
Pick<NoActiveConnectionsModalProps, 'onClose'>,
47+
Record<string, never>
48+
> = {
49+
onClose: closeModal,
50+
};
51+
52+
export default connect(mapState, mapDispatch)(NoActiveConnectionsModal);

0 commit comments

Comments
 (0)