Skip to content

Commit 0ef5b8a

Browse files
chore(compass-aggregations): adapt CreateViewPlugin to work with dynamically provided connectionId for supporting multiple connections COMPASS-7861 (#5755)
1 parent 7020d1c commit 0ef5b8a

File tree

12 files changed

+431
-214
lines changed

12 files changed

+431
-214
lines changed

packages/compass-aggregations/src/components/create-view-modal/create-view-modal.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,7 @@ import {
99
spacing,
1010
TextInput,
1111
} from '@mongodb-js/compass-components';
12-
import {
13-
createView,
14-
changeViewName,
15-
toggleIsVisible,
16-
} from '../../modules/create-view';
12+
import { createView, changeViewName, close } from '../../modules/create-view';
1713
import type { LoggerAndTelemetry } from '@mongodb-js/compass-logging/provider';
1814
import { withLoggerAndTelemetry } from '@mongodb-js/compass-logging/provider';
1915
import type { CreateViewRootState } from '../../stores/create-view';
@@ -27,7 +23,7 @@ const progressContainerStyles = css({
2723
type CreateViewModalProps = {
2824
createView: () => void;
2925
isVisible?: boolean;
30-
toggleIsVisible: (newVal: boolean) => void;
26+
closeModal: () => void;
3127
name?: string;
3228
changeViewName: (name: string) => void;
3329
isDuplicating?: boolean;
@@ -63,7 +59,7 @@ class CreateViewModal extends PureComponent<CreateViewModalProps> {
6359
};
6460

6561
onCancel = () => {
66-
this.props.toggleIsVisible(false);
62+
this.props.closeModal();
6763
};
6864

6965
/**
@@ -121,7 +117,7 @@ const MappedCreateViewModal = withLoggerAndTelemetry(
121117
connect(mapStateToProps, {
122118
createView,
123119
changeViewName,
124-
toggleIsVisible,
120+
closeModal: close,
125121
})(CreateViewModal),
126122
'COMPASS-CREATE-VIEW-UI'
127123
);

packages/compass-aggregations/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import StageEditor from './components/stage-editor';
77
import CreateViewModal from './components/create-view-modal';
88
import {
99
connectionInfoAccessLocator,
10+
connectionsManagerLocator,
1011
dataServiceLocator,
1112
type DataServiceLocator,
1213
} from '@mongodb-js/compass-connections/provider';
@@ -60,10 +61,9 @@ export const CreateViewPlugin = registerHadronPlugin(
6061
activate: activateCreateViewPlugin,
6162
},
6263
{
63-
dataService: dataServiceLocator as DataServiceLocator<'createView'>,
64+
connectionsManager: connectionsManagerLocator,
6465
logger: createLoggerAndTelemetryLocator('COMPASS-CREATE-VIEW-UI'),
6566
workspaces: workspacesServiceLocator,
66-
connectionInfoAccess: connectionInfoAccessLocator,
6767
}
6868
);
6969

Lines changed: 71 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,77 @@
1-
import reducer, { INITIAL_STATE, reset } from './';
1+
import reducer, {
2+
INITIAL_STATE,
3+
reset,
4+
open,
5+
close,
6+
toggleIsRunning,
7+
handleError,
8+
clearError,
9+
changeViewName,
10+
} from './';
211
import { expect } from 'chai';
312

413
describe('create view module', function () {
5-
describe('#reducer', function () {
6-
describe('when an action is provided', function () {
7-
describe('when the action is reset', function () {
8-
it('returns the reset state', function () {
9-
expect(reducer(INITIAL_STATE, reset())).to.deep.equal({
10-
...INITIAL_STATE,
11-
});
12-
});
13-
});
14+
it('handles the open and close actions', function () {
15+
const stateAfterOpen = reducer(
16+
INITIAL_STATE,
17+
open({
18+
connectionId: 'TEST',
19+
sourceNs: 'test.coll',
20+
sourcePipeline: [],
21+
duplicate: true,
22+
})
23+
);
24+
expect(stateAfterOpen).to.deep.equal({
25+
...INITIAL_STATE,
26+
connectionId: 'TEST',
27+
isRunning: false,
28+
isVisible: true,
29+
isDuplicating: true,
30+
name: '',
31+
source: 'test.coll',
32+
pipeline: [],
33+
});
34+
35+
expect(reducer(stateAfterOpen, close())).to.deep.equal(INITIAL_STATE);
36+
});
37+
38+
it('handles the reset action', function () {
39+
const isRunningState = reducer(INITIAL_STATE, toggleIsRunning(true));
40+
expect(reducer(isRunningState, reset())).to.deep.equal({
41+
...INITIAL_STATE,
42+
});
43+
});
44+
45+
it('handles the toggleIsRunning action', function () {
46+
const isRunningState = reducer(INITIAL_STATE, toggleIsRunning(true));
47+
expect(isRunningState).to.deep.equal({
48+
...INITIAL_STATE,
49+
isRunning: true,
50+
});
51+
expect(reducer(isRunningState, toggleIsRunning(false))).to.deep.equal({
52+
...isRunningState,
53+
isRunning: false,
54+
});
55+
});
56+
57+
it('handles the handleError and clearError actions', function () {
58+
const err = new Error('Oops!');
59+
const erroredState = reducer(INITIAL_STATE, handleError(err));
60+
expect(erroredState).to.deep.equal({
61+
...INITIAL_STATE,
62+
error: err,
63+
});
64+
65+
expect(reducer(erroredState, clearError())).to.deep.equal({
66+
...erroredState,
67+
error: null,
68+
});
69+
});
70+
71+
it('handles the changeViewName action', function () {
72+
expect(reducer(INITIAL_STATE, changeViewName('Yikes'))).to.deep.equal({
73+
...INITIAL_STATE,
74+
name: 'Yikes',
1475
});
1576
});
1677
});

0 commit comments

Comments
 (0)