Skip to content

Commit 67f359c

Browse files
Merge remote-tracking branch 'origin/main' into beta-releases
2 parents 50fa9ff + fc705a0 commit 67f359c

27 files changed

+932
-300
lines changed

THIRD-PARTY-NOTICES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
The following third-party software is used by and included in **Mongodb Compass**.
2-
This document was automatically generated on Tue Jun 25 2024.
2+
This document was automatically generated on Wed Jun 26 2024.
33

44
## List of dependencies
55

packages/compass-aggregations/src/modules/input-documents.spec.ts

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
1+
import { expect } from 'chai';
2+
import { defaultPreferencesInstance } from 'compass-preferences-model';
3+
import sinon from 'sinon';
4+
15
import reducer, {
26
toggleInputDocumentsCollapsed,
37
updateInputDocuments,
48
loadingInputDocuments,
9+
refreshInputDocuments,
510
ActionTypes,
611
} from './input-documents';
7-
import { expect } from 'chai';
12+
import type { RootState } from '.';
13+
import type { DataService } from './data-service';
814

915
describe('input documents module', function () {
16+
afterEach(function () {
17+
sinon.restore();
18+
});
19+
1020
describe('#toggleInputDocumentsCollapsed', function () {
1121
it('returns the ActionTypes.CollapseToggled action', function () {
1222
expect(toggleInputDocumentsCollapsed()).to.deep.equal({
@@ -33,6 +43,53 @@ describe('input documents module', function () {
3343
});
3444
});
3545

46+
describe('#refreshInputDocuments', function () {
47+
it('should apply maxTimeMS to the aggregation when it is set', async function () {
48+
const refreshInputDocumentsThunk = refreshInputDocuments();
49+
50+
const mockAggregate = sinon.stub().resolves([]);
51+
const mockState: Partial<RootState> = {
52+
dataService: {
53+
dataService: {
54+
aggregate: mockAggregate,
55+
} as unknown as DataService,
56+
},
57+
namespace: 'test.namespace',
58+
maxTimeMS: undefined,
59+
settings: {
60+
isExpanded: false,
61+
isCommentMode: false,
62+
isDirty: false,
63+
limit: 10,
64+
sampleSize: 10,
65+
},
66+
};
67+
68+
await refreshInputDocumentsThunk(
69+
sinon.stub(),
70+
() => mockState as RootState,
71+
{ preferences: defaultPreferencesInstance } as any
72+
);
73+
74+
expect(mockAggregate.calledOnce).to.be.true;
75+
expect(mockAggregate.firstCall.args[2]).to.deep.equal({
76+
maxTimeMS: 60_000,
77+
});
78+
79+
mockState.maxTimeMS = 1000;
80+
await refreshInputDocumentsThunk(
81+
sinon.stub(),
82+
() => mockState as RootState,
83+
{ preferences: defaultPreferencesInstance } as any
84+
);
85+
86+
expect(mockAggregate.calledTwice).to.be.true;
87+
expect(mockAggregate.secondCall.args[2]).to.deep.equal({
88+
maxTimeMS: 1000,
89+
});
90+
});
91+
});
92+
3693
describe('#reducer', function () {
3794
context(
3895
'when the action is not toggle input documents collapsed',

packages/compass-aggregations/src/modules/input-documents.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { capMaxTimeMSAtPreferenceLimit } from 'compass-preferences-model/provide
33
import type { PipelineBuilderThunkAction } from '.';
44
import type { AnyAction } from 'redux';
55
import { isAction } from '../utils/is-action';
6+
import { DEFAULT_MAX_TIME_MS } from '../constants';
67

78
export enum ActionTypes {
89
CollapseToggled = 'aggregations/input-documents/CollapseToggled',
@@ -111,9 +112,10 @@ export const refreshInputDocuments = (): PipelineBuilderThunkAction<
111112
}
112113

113114
const options = {
114-
maxTimeMS: capMaxTimeMSAtPreferenceLimit(preferences, maxTimeMS) as
115-
| number
116-
| undefined,
115+
maxTimeMS: capMaxTimeMSAtPreferenceLimit(
116+
preferences,
117+
maxTimeMS ?? DEFAULT_MAX_TIME_MS
118+
),
117119
};
118120

119121
const aggregateOptions = { ...options };

packages/compass-aggregations/src/stores/store.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,14 @@ export function activateAggregationsPlugin(
262262
maxTimeMSChanged(preferences.getPreferences().maxTimeMS || null)
263263
);
264264

265+
const onCloseOrReplace = () => {
266+
return !store.getState().isModified;
267+
};
268+
269+
addCleanup(workspaces.onTabReplace?.(onCloseOrReplace));
270+
271+
addCleanup(workspaces.onTabClose?.(onCloseOrReplace));
272+
265273
return {
266274
store,
267275
deactivate: cleanup,

packages/compass-connections/src/hooks/use-connection-repository.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function sortedAlphabetically(a: ConnectionInfo, b: ConnectionInfo): number {
4343
export type ConnectionRepository = {
4444
favoriteConnections: ConnectionInfo[];
4545
nonFavoriteConnections: ConnectionInfo[];
46+
autoConnectInfo?: ConnectionInfo;
4647
saveConnection: (info: PartialConnectionInfo) => Promise<ConnectionInfo>;
4748
deleteConnection: (info: ConnectionInfo) => Promise<void>;
4849
getConnectionInfoById: (
@@ -189,6 +190,7 @@ export function useConnectionRepository(): ConnectionRepository {
189190
getConnectionTitleById,
190191
favoriteConnections,
191192
nonFavoriteConnections,
193+
autoConnectInfo,
192194
saveConnection,
193195
deleteConnection,
194196
};

packages/compass-connections/src/hooks/use-connections-with-status.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ export function useConnectionsWithStatus(): ConnectionInfoWithStatus[] {
1717
// when this code is refactored to use the hadron plugin interface, storage
1818
// should be handled through the plugin activation lifecycle
1919
const connectionsManager = useConnectionsManagerContext();
20-
const { favoriteConnections, nonFavoriteConnections } =
20+
const { favoriteConnections, nonFavoriteConnections, autoConnectInfo } =
2121
useConnectionRepository();
2222
const allConnections = useMemo(() => {
23-
return [...favoriteConnections, ...nonFavoriteConnections];
24-
}, [favoriteConnections, nonFavoriteConnections]);
23+
return favoriteConnections.concat(
24+
nonFavoriteConnections,
25+
autoConnectInfo ? autoConnectInfo : []
26+
);
27+
}, [favoriteConnections, nonFavoriteConnections, autoConnectInfo]);
2528

2629
const [connectionsWithStatus, setConnectionsWithStatus] = useState<
2730
ConnectionInfoWithStatus[]
@@ -60,7 +63,7 @@ export function useConnectionsWithStatus(): ConnectionInfoWithStatus[] {
6063

6164
useEffect(() => {
6265
updateListRef.current();
63-
}, [favoriteConnections, nonFavoriteConnections]);
66+
}, [favoriteConnections, nonFavoriteConnections, autoConnectInfo]);
6467

6568
useEffect(() => {
6669
const updateOnStatusChange = () => {

packages/compass-e2e-tests/helpers/commands/close-workspace-tabs.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import type { CompassBrowser } from '../compass-browser';
22
import * as Selectors from '../selectors';
33

44
export async function closeWorkspaceTabs(
5-
browser: CompassBrowser
5+
browser: CompassBrowser,
6+
autoConfirmTabClose = true
67
): Promise<void> {
78
const countTabs = async () => {
89
return (await browser.$$(Selectors.workspaceTab(null))).length;
@@ -15,6 +16,14 @@ export async function closeWorkspaceTabs(
1516
await currentActiveTab.click();
1617
await browser.waitUntil(async () => {
1718
await currentActiveTab.$(Selectors.CloseWorkspaceTab).click();
19+
if (autoConfirmTabClose) {
20+
// Tabs in "dirty" state can't be closed without confirmation
21+
if (await browser.$(Selectors.ConfirmTabCloseModal).isExisting()) {
22+
await browser.clickVisible(
23+
browser.$(Selectors.ConfirmTabCloseModal).$('button=Close tab')
24+
);
25+
}
26+
}
1827
return (await currentActiveTab.isExisting()) === false;
1928
});
2029
}

packages/compass-e2e-tests/helpers/commands/collection-workspaces.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,21 @@ async function navigateToCollection(
55
browser: CompassBrowser,
66
// TODO(COMPASS-8002): take connectionName into account
77
dbName: string,
8-
collectionName: string
8+
collectionName: string,
9+
10+
// Close all the workspace tabs to get rid of all the state we
11+
// might have accumulated. This is the only way to get back to the zero
12+
// state of Schema, and Validation tabs without re-connecting.
13+
closeExistingTabs = true
914
): Promise<void> {
1015
const collectionSelector = Selectors.sidebarCollection(
1116
dbName,
1217
collectionName
1318
);
1419

15-
// Close all the workspace tabs to get rid of all the state we
16-
// might have accumulated. This is the only way to get back to the zero
17-
// state of Schema, and Validation tabs without re-connecting.
18-
await browser.closeWorkspaceTabs();
20+
if (closeExistingTabs) {
21+
await browser.closeWorkspaceTabs();
22+
}
1923

2024
// search for the collection and wait for the collection to be there and visible
2125
await browser.clickVisible(Selectors.SidebarFilterInput);
@@ -39,9 +43,15 @@ export async function navigateToCollectionTab(
3943
| 'Aggregations'
4044
| 'Schema'
4145
| 'Indexes'
42-
| 'Validation' = 'Documents'
46+
| 'Validation' = 'Documents',
47+
closeExistingTabs = true
4348
): Promise<void> {
44-
await navigateToCollection(browser, dbName, collectionName);
49+
await navigateToCollection(
50+
browser,
51+
dbName,
52+
collectionName,
53+
closeExistingTabs
54+
);
4555
await navigateWithinCurrentCollectionTabs(browser, tabName);
4656
}
4757

packages/compass-e2e-tests/helpers/commands/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export * from './save-favorite';
4343
export * from './save-connection-string-as-favorite';
4444
export * from './select-connection';
4545
export * from './select-connection-menu-item';
46-
export * from './select-favorites-menu-item';
46+
export * from './select-connections-menu-item';
4747
export * from './open-settings-modal';
4848
export * from './wait-for-connection-result';
4949
export * from './screenshot';
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { TEST_MULTIPLE_CONNECTIONS } from '../compass';
2+
import type { CompassBrowser } from '../compass-browser';
3+
import * as Selectors from '../selectors';
4+
5+
export async function selectConnectionsMenuItem(
6+
browser: CompassBrowser,
7+
itemSelector: string
8+
) {
9+
const Sidebar = TEST_MULTIPLE_CONNECTIONS
10+
? Selectors.Multiple
11+
: Selectors.Single;
12+
13+
if (!TEST_MULTIPLE_CONNECTIONS) {
14+
// In the single connection world the button only appears on hover
15+
16+
const selector = Selectors.Single.FavoriteConnectionsHeader;
17+
await browser.$(selector).waitForDisplayed();
18+
19+
// workaround for weirdness in the ItemActionControls menu opener icon
20+
await browser.clickVisible(Selectors.Single.ConnectionsTitle);
21+
22+
// Hover over an arbitrary other element to ensure that the second hover will
23+
// actually be a fresh one. This otherwise breaks if this function is called
24+
// twice in a row.
25+
await browser.hover(`*:not(${selector}, ${selector} *)`);
26+
await browser.hover(selector);
27+
}
28+
29+
await browser.clickVisible(Sidebar.ConnectionsMenuButton);
30+
await browser.$(Sidebar.ConnectionsMenu).waitForDisplayed();
31+
await browser.clickVisible(itemSelector);
32+
}

0 commit comments

Comments
 (0)