Skip to content

Commit 9393cb0

Browse files
authored
chore(connections): remove connectionInfoAccess interface from everywhere in the app COMPASS-8306 (#6249)
* chore(connections): remove connectionInfoAccess interface from everywhere in the app * chore: fix various check failures * chore(serverstats): esm export for refactored component * chore(serverstats): fix component import
1 parent 1c2d2b2 commit 9393cb0

File tree

98 files changed

+796
-1105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+796
-1105
lines changed

configs/testing-library-compass/src/index.tsx

+21-6
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ import {
4747
import { TelemetryProvider } from '@mongodb-js/compass-telemetry/provider';
4848
import { CompassComponentsProvider } from '@mongodb-js/compass-components';
4949
import {
50+
TestEnvCurrentConnectionContext,
5051
ConnectionInfoProvider,
51-
TEST_CONNECTION_INFO,
5252
} from '@mongodb-js/compass-connections/src/connection-info-provider';
5353
import type { State } from '@mongodb-js/compass-connections/src/stores/connections-store-redux';
5454
import { createDefaultConnectionInfo } from '@mongodb-js/compass-connections/src/stores/connections-store-redux';
@@ -231,6 +231,17 @@ const EmptyWrapper = ({ children }: { children: React.ReactElement }) => {
231231
return <>{children}</>;
232232
};
233233

234+
const TEST_ENV_CURRENT_CONNECTION = {
235+
info: {
236+
id: 'TEST',
237+
connectionOptions: {
238+
connectionString: 'mongodb://localhost:27020',
239+
},
240+
},
241+
status: 'connected' as const,
242+
error: null,
243+
};
244+
234245
function createWrapper(
235246
options: TestConnectionsOptions,
236247
// When using renderHook, anything that will try to call createPortal will
@@ -331,9 +342,13 @@ function createWrapper(
331342
preloadStorageConnectionInfos={options.connections}
332343
>
333344
<StoreGetter>
334-
<TestingLibraryWrapper {...props}>
335-
{children}
336-
</TestingLibraryWrapper>
345+
<TestEnvCurrentConnectionContext.Provider
346+
value={TEST_ENV_CURRENT_CONNECTION}
347+
>
348+
<TestingLibraryWrapper {...props}>
349+
{children}
350+
</TestingLibraryWrapper>
351+
</TestEnvCurrentConnectionContext.Provider>
337352
</StoreGetter>
338353
</CompassConnections>
339354
</ConnectFnProvider>
@@ -461,7 +476,7 @@ function createConnectionInfoWrapper(
461476

462477
async function renderWithActiveConnection(
463478
ui: React.ReactElement,
464-
connectionInfo: ConnectionInfo = TEST_CONNECTION_INFO,
479+
connectionInfo: ConnectionInfo = TEST_ENV_CURRENT_CONNECTION.info,
465480
{
466481
connections,
467482
wrapper: Wrapper = EmptyWrapper,
@@ -483,7 +498,7 @@ async function renderWithActiveConnection(
483498

484499
async function renderHookWithActiveConnection<HookProps, HookResult>(
485500
cb: (props: HookProps) => HookResult,
486-
connectionInfo: ConnectionInfo = TEST_CONNECTION_INFO,
501+
connectionInfo: ConnectionInfo = TEST_ENV_CURRENT_CONNECTION.info,
487502
{
488503
connections,
489504
wrapper: Wrapper = EmptyWrapper,

package-lock.json

+14-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -91,5 +91,10 @@
9191
"packages/*",
9292
"configs/*",
9393
"scripts"
94-
]
94+
],
95+
"overrides": {
96+
"@types/enzyme": {
97+
"@types/react": "^17.0.5"
98+
}
99+
}
95100
}

packages/compass-aggregations/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@mongodb-js/testing-library-compass": "^1.0.1",
3939
"@mongodb-js/tsconfig-compass": "^1.0.5",
4040
"@types/babel__generator": "^7.6.8",
41+
"@types/enzyme": "^3.10.14",
4142
"@types/lodash": "^4.14.188",
4243
"@types/semver": "^7.3.9",
4344
"chai": "^4.3.6",

packages/compass-aggregations/src/components/aggregation-side-panel/index.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { FeedbackLink } from './feedback-link';
1818
import { addWizard } from '../../modules/pipeline-builder/stage-editor';
1919
import { UseCaseCard } from './stage-wizard-use-cases';
2020
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
21-
import { useConnectionInfoAccess } from '@mongodb-js/compass-connections/provider';
21+
import { useConnectionInfoRef } from '@mongodb-js/compass-connections/provider';
2222

2323
const containerStyles = css({
2424
height: '100%',
@@ -80,7 +80,7 @@ export const AggregationSidePanel = ({
8080
onSelectUseCase,
8181
}: AggregationSidePanelProps) => {
8282
const track = useTelemetry();
83-
const connectionInfoAccess = useConnectionInfoAccess();
83+
const connectionInfoRef = useConnectionInfoRef();
8484
const [searchText, setSearchText] = useState<string>('');
8585
const darkMode = useDarkMode();
8686

@@ -112,10 +112,10 @@ export const AggregationSidePanel = ({
112112
drag_and_drop: false,
113113
stage_name: useCase.stageOperator,
114114
},
115-
connectionInfoAccess.getCurrentConnectionInfo()
115+
connectionInfoRef.current
116116
);
117117
},
118-
[onSelectUseCase, track, connectionInfoAccess]
118+
[onSelectUseCase, track, connectionInfoRef]
119119
);
120120

121121
return (

packages/compass-aggregations/src/components/pipeline-builder-workspace/pipeline-as-text-workspace/pipeline-editor.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { changeEditorValue } from '../../../modules/pipeline-builder/text-editor
2121
import type { PipelineParserError } from '../../../modules/pipeline-builder/pipeline-parser/utils';
2222
import { useAutocompleteFields } from '@mongodb-js/compass-field-store';
2323
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
24-
import { useConnectionInfoAccess } from '@mongodb-js/compass-connections/provider';
24+
import { useConnectionInfoRef } from '@mongodb-js/compass-connections/provider';
2525

2626
const containerStyles = css({
2727
position: 'relative',
@@ -81,7 +81,7 @@ export const PipelineEditor: React.FunctionComponent<PipelineEditorProps> = ({
8181
}) => {
8282
const fields = useAutocompleteFields(namespace);
8383
const track = useTelemetry();
84-
const connectionInfoAccess = useConnectionInfoAccess();
84+
const connectionInfoRef = useConnectionInfoRef();
8585
const editorInitialValueRef = useRef<string>(pipelineText);
8686
const editorCurrentValueRef = useRef<string>(pipelineText);
8787
editorCurrentValueRef.current = pipelineText;
@@ -108,11 +108,11 @@ export const PipelineEditor: React.FunctionComponent<PipelineEditorProps> = ({
108108
num_stages,
109109
editor_view_type: 'text',
110110
},
111-
connectionInfoAccess.getCurrentConnectionInfo()
111+
connectionInfoRef.current
112112
);
113113
editorInitialValueRef.current = editorCurrentValueRef.current;
114114
}
115-
}, [num_stages, track, connectionInfoAccess]);
115+
}, [num_stages, track, connectionInfoRef]);
116116

117117
const annotations: Annotation[] = useMemo(() => {
118118
return syntaxErrors

packages/compass-aggregations/src/components/pipeline-builder-workspace/pipeline-builder-ui-workspace/dnd-wrapper.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { UseCaseCardLayout } from '../../aggregation-side-panel/stage-wizard-use
1717
import type { PipelineBuilderUIWorkspaceProps } from '.';
1818
import type { DraggedUseCase } from '../../aggregation-side-panel/stage-wizard-use-cases/use-case-card';
1919
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
20-
import { useConnectionInfoAccess } from '@mongodb-js/compass-connections/provider';
20+
import { useConnectionInfoRef } from '@mongodb-js/compass-connections/provider';
2121

2222
// Types
2323
type PipelineBuilderDndWrapperProps = {
@@ -72,7 +72,7 @@ const PipelineBuilderDndWrapper = ({
7272
})
7373
);
7474

75-
const connectionInfoAccess = useConnectionInfoAccess();
75+
const connectionInfoRef = useConnectionInfoRef();
7676

7777
const handleUseCaseDropped = useCallback(
7878
(event: DragEndEvent) => {
@@ -85,7 +85,7 @@ const PipelineBuilderDndWrapper = ({
8585
drag_and_drop: true,
8686
stage_name: draggedUseCase.stageOperator,
8787
},
88-
connectionInfoAccess.getCurrentConnectionInfo()
88+
connectionInfoRef.current
8989
);
9090
onUseCaseDropped(
9191
draggedUseCase.id,
@@ -95,7 +95,7 @@ const PipelineBuilderDndWrapper = ({
9595
}
9696
setDraggedUseCase(null);
9797
},
98-
[draggedUseCase, onUseCaseDropped, track, connectionInfoAccess]
98+
[draggedUseCase, onUseCaseDropped, track, connectionInfoRef]
9999
);
100100

101101
const handleSortEnd = useCallback(

packages/compass-aggregations/src/components/pipeline-toolbar/pipeline-ai.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ import type { RootState } from '../../modules';
1515
import { useLogger } from '@mongodb-js/compass-logging/provider';
1616
import { getPipelineStageOperatorsFromBuilderState } from '../../modules/pipeline-builder/builder-helpers';
1717
import { useTelemetry } from '@mongodb-js/compass-telemetry/provider';
18-
import { useConnectionInfoAccess } from '@mongodb-js/compass-connections/provider';
18+
import { useConnectionInfoRef } from '@mongodb-js/compass-connections/provider';
1919

2020
const useOnSubmitFeedback = (lastAIPipelineRequestId: string | null) => {
2121
const logger = useLogger('AI-PIPELINE-UI');
2222
const track = useTelemetry();
23-
const connectionInfoAccess = useConnectionInfoAccess();
23+
const connectionInfoRef = useConnectionInfoRef();
2424
return useCallback(
2525
(feedback: 'positive' | 'negative', text: string) => {
2626
const { log, mongoLogId } = logger;
@@ -42,7 +42,7 @@ const useOnSubmitFeedback = (lastAIPipelineRequestId: string | null) => {
4242
request_id: lastAIPipelineRequestId,
4343
text,
4444
}),
45-
connectionInfoAccess.getCurrentConnectionInfo()
45+
connectionInfoRef.current
4646
);
4747

4848
openToast('pipeline-ai-feedback-submitted', {
@@ -51,7 +51,7 @@ const useOnSubmitFeedback = (lastAIPipelineRequestId: string | null) => {
5151
timeout: 10_000,
5252
});
5353
},
54-
[logger, track, lastAIPipelineRequestId, connectionInfoAccess]
54+
[logger, track, lastAIPipelineRequestId, connectionInfoRef]
5555
);
5656
};
5757

Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import React from 'react';
2-
import { mount } from 'enzyme';
2+
import { render, screen } from '@mongodb-js/testing-library-compass';
33
import sinon from 'sinon';
44
import { expect } from 'chai';
55

66
import { StageEditor } from './stage-editor';
77

88
describe('StageEditor [Component]', function () {
9-
let component: ReturnType<typeof mount> | null;
109
const spy = sinon.spy();
1110
const stage = '{ name: "testing" }';
1211
const stageOperator = '$match';
1312

1413
beforeEach(function () {
15-
component = mount(
14+
render(
1615
<StageEditor
1716
namespace="test.test"
1817
stageValue={stage}
@@ -28,11 +27,7 @@ describe('StageEditor [Component]', function () {
2827
);
2928
});
3029

31-
afterEach(function () {
32-
component = null;
33-
});
34-
3530
it('renders the wrapper div', function () {
36-
expect(component?.find('StageEditor')).to.exist;
31+
expect(screen.getByTestId('stage-editor')).to.exist;
3732
});
3833
});

0 commit comments

Comments
 (0)