Skip to content

Commit abddc77

Browse files
authored
chore(compass-aggregations): clean up unused slices and utils COMPASS-6167 (#3615)
* chore(compass-aggregations): clean up unused slices and utils * chore(compass-aggregations): connect components deeper in the react tree
1 parent ce0da31 commit abddc77

32 files changed

+158
-2559
lines changed

package-lock.json

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

packages/compass-aggregations/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
"@mongodb-js/webpack-config-compass": "^1.0.2",
6060
"@testing-library/react": "^12.1.4",
6161
"@testing-library/user-event": "^13.5.0",
62-
"@types/decomment": "^0.9.2",
6362
"@types/prettier": "^2.7.1",
6463
"@types/semver": "^7.3.9",
6564
"chai": "^4.3.6",
@@ -73,8 +72,6 @@
7372
"eslint": "^7.25.0",
7473
"hadron-app-registry": "^9.0.1",
7574
"is-electron-renderer": "^2.0.1",
76-
"lodash.isempty": "^4.4.0",
77-
"lodash.isstring": "^4.0.1",
7875
"mocha": "^8.4.0",
7976
"mongodb": "^4.10.0",
8077
"mongodb-data-service": "^22.1.1",

packages/compass-aggregations/src/components/input/input.jsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import React, { PureComponent } from 'react';
22
import PropTypes from 'prop-types';
33
import InputToolbar from '../input-toolbar';
44
import InputWorkspace from '../input-workspace';
5+
import { connect } from 'react-redux';
6+
import { refreshInputDocuments, toggleInputDocumentsCollapsed } from '../../modules/input-documents';
57

68
import styles from './input.module.less';
79

8-
class Input extends PureComponent {
9-
static displayName = 'InputComponent';
10-
10+
export class Input extends PureComponent {
1111
static propTypes = {
1212
toggleInputDocumentsCollapsed: PropTypes.func.isRequired,
1313
refreshInputDocuments: PropTypes.func.isRequired,
@@ -45,4 +45,17 @@ class Input extends PureComponent {
4545
}
4646
}
4747

48-
export default Input;
48+
export default connect(
49+
(state) => {
50+
return {
51+
documents: state.inputDocuments.documents,
52+
isLoading: state.inputDocuments.isLoading,
53+
isExpanded: state.inputDocuments.isExpanded,
54+
count: state.inputDocuments.count
55+
};
56+
},
57+
{
58+
toggleInputDocumentsCollapsed: toggleInputDocumentsCollapsed,
59+
refreshInputDocuments: refreshInputDocuments
60+
}
61+
)(Input);

packages/compass-aggregations/src/components/input/input.spec.jsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { mount } from 'enzyme';
33
import sinon from 'sinon';
44
import { expect } from 'chai';
55

6-
import Input from '../input';
6+
import { Input } from './input';
77
import InputToolbar from '../input-toolbar';
88
import styles from './input.module.less';
99

@@ -26,7 +26,6 @@ describe('Input [Component]', function() {
2626
documents={[]}
2727
isExpanded
2828
isLoading
29-
openLink={sinon.spy()}
3029
count={0} />
3130
);
3231
});
@@ -57,7 +56,6 @@ describe('Input [Component]', function() {
5756
documents={[]}
5857
isExpanded={false}
5958
isLoading
60-
openLink={sinon.spy()}
6159
count={0} />
6260
);
6361
});

packages/compass-aggregations/src/components/pipeline-builder-workspace/pipeline-builder-ui-workspace.jsx

Lines changed: 31 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,10 @@ import Stage from '../stage';
55
import Input from '../input';
66
import AddStage from '../add-stage';
77
import ModifySourceBanner from '../modify-source-banner';
8-
8+
import { moveStage } from '../../modules/pipeline-builder/stage-editor';
99
import { sortableContainer, sortableElement } from 'react-sortable-hoc';
1010

1111
import styles from './pipeline-builder-ui-workspace.module.less';
12-
import {
13-
refreshInputDocuments,
14-
toggleInputDocumentsCollapsed,
15-
} from '../../modules/input-documents';
16-
import { openLink } from '../../modules/link';
17-
import { moveStage } from '../../modules/pipeline-builder/stage-editor';
1812

1913
const SortableStage = sortableElement(({ idx, ...props }) => {
2014
return <Stage index={idx} {...props}></Stage>;
@@ -25,16 +19,10 @@ const SortableContainer = sortableContainer(({ children }) => {
2519
});
2620

2721
export class PipelineBuilderUIWorkspace extends PureComponent {
28-
static displayName = 'PipelineBuilderUIWorkspace';
29-
3022
static propTypes = {
3123
stageIds: PropTypes.array.isRequired,
3224
editViewName: PropTypes.string,
33-
inputDocuments: PropTypes.object.isRequired,
34-
onStageMoveEnd: PropTypes.func.isRequired,
35-
toggleInputDocumentsCollapsed: PropTypes.func.isRequired,
36-
refreshInputDocuments: PropTypes.func.isRequired,
37-
openLink: PropTypes.func.isRequired
25+
onStageMoveEnd: PropTypes.func.isRequired
3826
};
3927

4028
/**
@@ -47,52 +35,12 @@ export class PipelineBuilderUIWorkspace extends PureComponent {
4735
this.props.onStageMoveEnd(oldIndex, newIndex);
4836
};
4937

50-
/**
51-
* Render the modify source banner if neccessary.
52-
*
53-
* @returns {Component} The component.
54-
*/
55-
renderModifyingViewSourceBanner() {
56-
if (this.props.editViewName) {
57-
return <ModifySourceBanner editViewName={this.props.editViewName} />;
58-
}
59-
}
60-
61-
/**
62-
* Render a stage list.
63-
*
64-
* @returns {Component} The component.
65-
*/
66-
renderStageList = () => {
67-
return (
68-
<SortableContainer
69-
axis="y"
70-
lockAxis="y"
71-
onSortEnd={this.onStageMoved}
72-
useDragHandle
73-
transitionDuration={0}
74-
helperContainer={() => {
75-
return this.stageListContainerRef ?? document.body;
76-
}}
77-
helperClass="dragging"
78-
// Slight distance requirement to prevent sortable logic messing with
79-
// interactive elements in the handler toolbar component
80-
distance={10}
81-
>
82-
{this.props.stageIds.map((id, index) => {
83-
return <SortableStage key={id} idx={index} index={index} />;
84-
})}
85-
</SortableContainer>
86-
);
87-
};
88-
8938
/**
9039
* Renders the pipeline workspace.
9140
*
9241
* @returns {React.Component} The component.
9342
*/
9443
render() {
95-
const inputDocuments = this.props.inputDocuments;
9644
return (
9745
<div
9846
data-testid="pipeline-builder-ui-workspace"
@@ -102,19 +50,28 @@ export class PipelineBuilderUIWorkspace extends PureComponent {
10250
>
10351
<div className={styles['pipeline-workspace-container']}>
10452
<div className={styles['pipeline-workspace']}>
105-
{this.renderModifyingViewSourceBanner()}
106-
<Input
107-
toggleInputDocumentsCollapsed={
108-
this.props.toggleInputDocumentsCollapsed
109-
}
110-
refreshInputDocuments={this.props.refreshInputDocuments}
111-
documents={inputDocuments.documents}
112-
isLoading={inputDocuments.isLoading}
113-
isExpanded={inputDocuments.isExpanded}
114-
openLink={this.props.openLink}
115-
count={inputDocuments.count}
116-
/>
117-
{this.renderStageList()}
53+
{this.props.editViewName && (
54+
<ModifySourceBanner editViewName={this.props.editViewName} />
55+
)}
56+
<Input />
57+
<SortableContainer
58+
axis="y"
59+
lockAxis="y"
60+
onSortEnd={this.onStageMoved}
61+
useDragHandle
62+
transitionDuration={0}
63+
helperContainer={() => {
64+
return this.stageListContainerRef ?? document.body;
65+
}}
66+
helperClass="dragging"
67+
// Slight distance requirement to prevent sortable logic messing with
68+
// interactive elements in the handler toolbar component
69+
distance={10}
70+
>
71+
{this.props.stageIds.map((id, index) => {
72+
return <SortableStage key={id} idx={index} index={index} />;
73+
})}
74+
</SortableContainer>
11875
<AddStage />
11976
</div>
12077
</div>
@@ -127,17 +84,15 @@ export class PipelineBuilderUIWorkspace extends PureComponent {
12784
*
12885
* @param {import('./../../modules/').RootState} state
12986
*/
130-
const mapState = (state) => ({
131-
stageIds: state.pipelineBuilder.stageEditor.stageIds,
132-
editViewName: state.editViewName,
133-
inputDocuments: state.inputDocuments
134-
});
87+
const mapState = (state) => {
88+
return {
89+
stageIds: state.pipelineBuilder.stageEditor.stageIds,
90+
editViewName: state.editViewName
91+
}
92+
};
13593

13694
const mapDispatch = {
137-
onStageMoveEnd: moveStage,
138-
toggleInputDocumentsCollapsed,
139-
refreshInputDocuments,
140-
openLink
95+
onStageMoveEnd: moveStage
14196
};
14297

14398
export default connect(mapState, mapDispatch)(PipelineBuilderUIWorkspace);
Lines changed: 19 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,29 @@
11
import React from 'react';
2-
import { shallow } from 'enzyme';
2+
import { mount } from 'enzyme';
33
import { expect } from 'chai';
4-
import { PipelineBuilderUIWorkspace } from './pipeline-builder-ui-workspace';
4+
import { Provider } from 'react-redux';
5+
import configureStore from '../../stores/store'
6+
import PipelineBuilderUIWorkspace from './pipeline-builder-ui-workspace';
57
import Stage from '../stage';
68

7-
/* eslint react/prop-types: 0 */
8-
function createPipelineWorkspace({
9-
toggleInputDocumentsCollapsed = () => {},
10-
refreshInputDocuments = () => {},
11-
openLink = () => {},
12-
inputDocuments = {},
13-
} = {}) {
14-
return (<PipelineBuilderUIWorkspace
15-
stageIds={[]}
16-
inputDocuments={inputDocuments}
17-
toggleInputDocumentsCollapsed={toggleInputDocumentsCollapsed}
18-
refreshInputDocuments={refreshInputDocuments}
19-
openLink={openLink}
20-
/>);
9+
function renderPipelineStageEditor(options) {
10+
const store = configureStore(options);
11+
return mount(
12+
<Provider store={store}>
13+
<PipelineBuilderUIWorkspace></PipelineBuilderUIWorkspace>
14+
</Provider>
15+
);
2116
}
2217

23-
describe('PipelineWorkspace [Component]', function() {
24-
it('renders', function() {
25-
shallow(createPipelineWorkspace({
26-
inputDocuments: {
27-
documents: [],
28-
isLoading: false,
29-
isExpanded: true,
30-
count: 0
31-
}
32-
}));
18+
describe('PipelineBuilderUIWorkspace [Component]', function () {
19+
it('renders', function () {
20+
expect(() => renderPipelineStageEditor()).to.not.throw;
3321
});
3422

35-
it('renders the stages contained in the pipeline', function() {
36-
const wrapper = shallow(createPipelineWorkspace({
37-
inputDocuments: {
38-
documents: [],
39-
isLoading: false,
40-
isExpanded: true,
41-
count: 0
42-
}
43-
}));
44-
expect(wrapper.find(Stage)).to.have.lengthOf(0);
23+
it('renders the stages contained in the pipeline', function () {
24+
const wrapper = renderPipelineStageEditor({
25+
sourcePipeline: [{$match: {_id: 1}}, {$limit: 10}, {$out: 'out'}]
26+
});
27+
expect(wrapper.find(Stage)).to.have.lengthOf(3);
4528
});
4629
});

0 commit comments

Comments
 (0)